欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

《初学者C51自学笔记》之ADC0804

程序员文章站 2024-02-24 09:28:25
...

《初学者C51自学笔记》之ADC0804

《初学者C51自学笔记》之ADC0804 

《初学者C51自学笔记》之ADC0804 

#include<reg52.h>
#define uchar unsigned char 
#define uint unsigned int 

sbit rs=P2^4;
sbit rw=P2^5;
sbit e=P2^6;
sbit adcs=P3^5;
sbit adrd=P3^0;
sbit adwr=P3^3;
sbit P23=P2^3;

uchar table1[]=" www.baidu.com ";
uchar table2[]="LCD1602 test ok!";
uchar table3[]="0123456789"; 

//延时函数,在12MHz的晶振频率下
//大约50us的延时
void delay_50us(uint t)
{
	uchar j;
	for(;t>0;t--)
        for(j=19;j>0;j--);
}

void write_com(uchar com)//液晶写指令
{
	e=0;
	rs=0;
	rw=0;
	P0=com;
	delay_50us(10);
	e=1;
	delay_50us(20);
	e=0;
}

void write_data(uchar dat)//液晶写数据
{
	e=0;
	rs=1;
	rw=0;
	P0=dat;
	delay_50us(10);
	e=1;
	delay_50us(20);
	e=0;	
}

void init(void)//液晶初始化
{
	delay_50us(300);
	write_com(0x38);
	delay_50us(100);
	write_com(0x38);
	delay_50us(100);
	write_com(0x38);
	write_com(0x38);
	write_com(0x08);
	write_com(0x01);
	write_com(0x06);
	write_com(0x0c);
}

void main()
{
	uchar value;
	uchar k,l,m,n;
	uchar i;
     //关点阵
	P23=1;
	P1=0x00;
	P23=0;
	P1=0xff;
	while(1)
	{
		//数据写入过程
		adcs=0;
		adwr=0;
		delay_50us(2);
		adwr=1;
		adcs=1;
		delay_50us(10);
		//读数据过程
		adcs=0;
		adrd=0;
		delay_50us(1);
		value=P1;	 
		adrd=1;
		adcs=1;
		//把数据分开
		k=value/100; 
		l=value%100;  
		m=l/10;       
		n=l%10; 
		//覆盖液晶原来的数据并显示      
		table1[2]=table3[n];
		table1[1]=table3[m];
		table1[0]=table3[k];
		init();
		write_com(0x80);
		for(i=0;i<3;i++)
		{
			 write_data(table1[i]);
			 delay_50us(20);
		}
	}

		
}