本文包含原理图、PCB、源代码、封装库、中英文PDF等资源
您需要 登录 才可以下载或查看,没有账号?注册会员
×
复制代码
复制代码- 用51单片机控制ADC0804,当拧动A/D旁边的电位器时,液晶显示屏的数字随之变化
- #include<reg52.h>
- #include<intrins.h>
- #define uchar unsigned char
- #define uint unsigned int
- sbit dula=P2^6;
- sbit wela=P2^7;
- sbit lcden=P3^4;
- sbit lcdrs=P3^5;
- sbit key1=P3^6;
- sbit key2=P3^7;
- sbit adwr=P2^0;
- sbit adrd=P2^1;
- sbit INTR=P2^2;
- int i,num=200;
- uchar code table2[]="0123456789";
- void delay(uchar z)
- {
- uchar x,y;
- for(x=z;x>0;x--)
- for(y=110;y>0;y--);
- }
- void write_com(uchar com)
- {
- lcdrs=0;
- P0=com;
- delay(5);
- lcden=1;
- delay(5);
- lcden=0;
- }
- void write_date(uchar date)
- {
- lcdrs=1;
- P0=date;
- delay(5);
- lcden=1;
- delay(5);
- lcden=0;
- }
- void init()
- {
- dula=0;
- wela=0;
- write_com(0x38);
- write_com(0x0c);
- write_com(0x06);
- write_com(0x01);//液晶初始化
- write_com(0x80+0x40);//第二行显示电压
- write_date(0x55);
- write_date(0x3a);
- }
- void adinit()//启动ad转换函数
- {
- adwr=1;
- _nop_();
- adwr=0;
- _nop_();
- adwr=1;
- }
- void main()
- {
- uchar A1,B1,C1,D1,a,adval;
- init();
- while(1)
- {
- adinit();
- delay(50);
- adrd=0;
- adval=P1;
- _nop_();
- adrd=1;
- A1=adval/1000;
- B1=adval%1000/100;
- C1=adval%100/10;
- D1=adval%10;
- for(a=10;a>0;a--) 换成 \\\\write_com(0x80+0x42);
- { \\\\write_date(table2[A1]);
- write_com(0x80+0x42);
- write_date(table2[A1]); \\\\\write_date(table2[B1]);
- write_date(table2[B1]);
- write_date(table2[C1]); \\\\\write_date(table2[C1]);
- write_date(table2[D1]); \\\\\write_date(table2[D1])
- }
复制代码 |