|
如題,附件自取
KZECC7JM@B_@%HZ})%5JI[7.png (118.37 KB, 下載次數(shù): 51)
下載附件
2020-4-15 17:01 上傳
單片機(jī)源程序如下:
- #include <reg52.h>
- #define uchar unsigned char
- #define uint unsigned int
- #define ulong unsigned long
- #define p0 P0
- #define p3 P3
-
- sbit en=P1^0;
- sbit rs=P1^2;
- sbit rw=P1^1;
- sbit adda=P1^3;
- sbit addb=P1^4;
- sbit addc=P1^5;
- sbit ale=P1^6;/*選擇通道*/
- sbit start=P1^7;/*上升ad沿復(fù)位,下降沿ad開始轉(zhuǎn)換模數(shù)*/
- sbit eoc=P3^0; /*為1時(shí)就可以取數(shù)據(jù)了(硬件自己干的)*/
- sbit oe=P3^1; /*為0 ad輸出高阻態(tài),為1 ad向單片機(jī)輸數(shù)據(jù)(你要做的)*/
- uint vm0;
- uchar v,v_2,v_1,v_0;
-
- char cont[]={'0','1','2','3','4','5','6','7','8','9'};
- void init();
- void init2();
- void delay(uint z);
- void delay1(uint m);
- void write_com(uchar com);
- void write_data(uchar date);
- void LCD_set_xy( unsigned char x, unsigned char y );
- void LCD_write_char(unsigned char X,unsigned char Y,unsigned char data1)
- {
- LCD_set_xy( X, Y );
- write_data( data1);
-
- }
- void LCD_set_xy( unsigned char x, unsigned char y )
- {
- unsigned char address;
- if (y == 0) address = 0x80 + x;
- else address = 0xc0 + x;
- write_com( address);
- }
- void write_string(unsigned char X,unsigned char Y,unsigned char *s)
- {
- LCD_set_xy( X, Y );
- while (*s)
- {
- write_data( *s );
- s ++;
- }
-
- }
- void main()
- {
- init();
- init2();
- delay(100);
- while(1)
- {
- start=0;
- start=1;
- oe=0;
- start=0;
- while(eoc==1);
- oe=1;
- v=p0;
- oe=0;
- if(v>50)
- {
- vm0=((uint)v*196)/100;
- }
- else
- {
- vm0=(uint)v*2;
- }
- v_2=(vm0/100)%10;
- v_1=(vm0%100)/10;
- v_0=vm0%10;
- write_string(0,0,"U:");
- LCD_write_char(2,0,v_2+'0');
- LCD_write_char(3,0,'.');
- LCD_write_char(4,0,v_1+'0');
- LCD_write_char(5,0,v_0+'0');
- write_string(6,0,"v");
-
- }
-
- }
- void init()
- {
- en=0;
- rw=0;
- write_com(0x38);
- write_com(0x0c);
- write_com(0x06);
- write_com(0x01);
- }
- void init2()
- {
- adda=0;
- addb=0;
- addc=0;
- ale=0;
- delay(10);
- ale=1;
- delay(10);
- ale=0;
- }
- void delay(uint z)
- {
- uchar x,y;
- for (x=z;x>0;x--)
- for (y=10;y>0;y--);
- }
- void write_com(uchar com)
- {
- rs=0;
- ……………………
- …………限于本文篇幅 余下代碼請從51黑下載附件…………
復(fù)制代碼
所有資料51hei提供下載:
adc0808簡單的實(shí)驗(yàn)(用lcd1602顯示電壓)有仿真和程序.rar
(41.13 KB, 下載次數(shù): 75)
2020-4-15 17:01 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
|
|