|
C51通過(guò)ADC0808采集多路 AD 值 后 計(jì)算 結(jié)果
最終在lcd 屏上顯示 通過(guò)按鍵切換 具體顯示的 變量是哪個(gè)
壓縮包里有 keil代碼工程 和 protues 工程
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)
單片機(jī)源程序如下:
- #include<reg52.h>
- #include<intrins.h>
- #include<stdio.h>
- #define uchar unsigned char
- uchar i,j,CH;
- sbit EOC=P2^7;
- sbit AE=P2^6;
- sbit ST=P2^5;
- sbit OE=P2^4;
- sbit SWITCH=P3^3;
- sbit ADDA=P2^0;
- sbit ADDB=P2^1;
- sbit ADDC=P2^2;
- sbit RS=P3^0;
- sbit LCDEN=P3^1;
- sbit HLE=P3^5;
- sbit HOE=P3^6;
- uchar addata,f,KEY=0,ALERT,x,pro,y,z;
- uchar lastKEY;
- uchar code dis[]="Channel";
- uchar code detalZ[]="IT ";
- uchar code disp1[]="OT ";
- uchar code disp2[]="ET ";
- uchar code disv1[]="YT ";
- uchar code disv2[]="QA ";
- uchar code result[]="result ";
- unsigned int canshu_p = 2;
- unsigned int canshu_g = 9;
- //unsigned int CHA[6] ;
- unsigned int CHA[6] ;
- float fenzi,fenmu;
- void delay()
- {
- for(i=0;i<10;i++)
- for(j=0;j<100;j++);
- }
- void write_com(uchar com)
- {
- RS=0;
- delay();
- P1=com;
- delay();
- LCDEN=1;
- delay();
- LCDEN=0;
- delay();
- }
- void write_data(uchar dat)
- {
- RS=1;
- delay();
- P1=dat;
- delay();
- LCDEN=1;
- delay();
- LCDEN=0;
- delay();
- }
- void display()
- {
-
- if(lastKEY!=KEY)
- {
- write_com(0x01);//清屏
- lastKEY = KEY;
- }
-
-
-
-
- write_com(0x80);
-
- for(x=0;x<7;x++)
- {
- write_data(dis[x]);
- }
-
-
- write_com(0x80+0x08);
-
- //write_data(KEY+0x30);
- if(KEY==0){
-
- for(x=0;x<6;x++)
- {
- write_data(detalZ[x]);
- }
- }
- if(KEY==1){
-
- for(x=0;x<2;x++)
- {
- write_data(disp1[x]);
- }
- }
- if(KEY==2){
-
- for(x=0;x<2;x++)
- {
- write_data(disp2[x]);
- }
- }
-
- if(KEY==3){
-
- for(x=0;x<2;x++)
- {
- write_data(disv1[x]);
- }
- }
- if(KEY==4){
- for(x=0;x<2;x++)
- {
- write_data(disv2[x]);
- }
- }
-
- if(KEY==5){
-
- for(x=0;x<8;x++)
- {
- write_data(result[x]);
- }
- }
-
- write_com(0x80+0x47);
- write_data(CHA[KEY]/100+0x30);
- write_data(CHA[KEY]/10%10+0x30);
- write_data(CHA[KEY]%10+0x30);
- }
- void init()
- { HLE=0;
- LCDEN=0;
- write_com(0x38);//顯示設(shè)置
- write_com(0x0c);//顯示開關(guān)
- write_com(0x06);//屏幕不移動(dòng)
- write_com(0x01);//清屏
- write_com(0x80);
- for(x=0;x<7;x++)
- {
- write_data(dis[x]);
- }
- CH=0;
- IT1=1;
- EX1=1;
- EA=1;
- TMOD=0x01;
- TH0=(65536-1250)/256;
- TL0=(65536-1250)%256;
- ET0=1;
- TR0=1;
-
- }
- void gettem(uchar x)
- {
- switch(x)
- {
- case 0:{ADDA=0;ADDB=0;ADDC=0;break;}
- case 1:{ADDA=0;ADDB=0;ADDC=1;break;}
- case 2:{ADDA=0;ADDB=1;ADDC=0;break;}
- case 3:{ADDA=0;ADDB=1;ADDC=1;break;}
- case 4:{ADDA=1;ADDB=0;ADDC=0;break;}
- // case 5:{ADDA=1;ADDB=0;ADDC=1;break;}
- // case 6:{ADDA=1;ADDB=1;ADDC=0;break;}
- // case 7:{ADDA=1;ADDB=1;ADDC=1;break;}
- }
- OE=0;
- AE=1;
- ST=1;
- AE=0;
- ST=0;
- while(!EOC);
- OE=1;
- addata=P0;
- CHA[x]=addata;
- }
- main()
- {
- init();
- display();
- while(1)
- {
- ALERT=0xff;
- z=0x7f;
- for(y=0;y<8;y++)
- {
- if(CHA[y]>30)
- ALERT=ALERT&z;
- z=_cror_(z,1);
- }
- HLE=1;
- P1=ALERT;
- delay();
- HLE=0;
-
-
- fenzi = (float)CHA[0];
- fenmu=(float)CHA[1];
- CHA[5] = (unsigned int)((fenzi/fenmu)*100);
- display();
- }
-
- }
- void X1_ISR(void) interrupt 2
- {
- if(SWITCH==0)
- {
- delay();
- if(SWITCH==0)
- {
- KEY++;
-
- }
- if(KEY==6)
- KEY=0;
-
- }
-
- }
- void T0_ISR(void) interrupt 1
- {
- TH0=(65536-1250)/256;
- TL0=(65536-1250)%256;
- CH++;
- if(CH==5)
- CH=0;
- gettem(CH);
- }
復(fù)制代碼
所有資料51hei提供下載:
多adc采集計(jì)算.zip
(160.7 KB, 下載次數(shù): 109)
2020-6-15 15:56 上傳
點(diǎn)擊文件名下載附件
|
評(píng)分
-
查看全部評(píng)分
|