|
51單片機(jī)做的用熱敏電阻來測溫并用數(shù)碼管顯示,下面是電路原理圖:
源程序:
- #include<reg52.h>
- #define uchar unsigned char
- #define uint unsigned int
- //
- unsigned char code dispbitcode[]=
- {0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
- //
- //
- unsigned char code LEDcode[]=
- {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x00,0x40};
- //
- //
- unsigned char dispbuf[8]={10,10,10,10,10,10,0,0};
- //
- unsigned char dispcount;
- unsigned int uiResult;
- bit sflag;
- sbit START=P3^1;
- sbit OE=P3^0;
- sbit EOC=P3^2;
- sbit P17=P1^7;
- //
- void delay(uint z) //延時(shí)函數(shù),約1ms
- {
- uint x,y;
- for(x=z;x>0;x--)
- for(y=110;y>0;y--);
- }
- void Display()
- {for(dispcount=0;dispcount<5;dispcount++)
- {P2=0xff;
- P1=LEDcode[dispbuf[dispcount]];
- if(dispcount==3)
- {P17=1;}
- P2=dispbitcode[dispcount];
- delay(1);
- P2=0xff;
- }
- }
- //
- void ADC0809()
- {
- unsigned char i;
- unsigned long y;
- // START=0;
- START=1;
- START=0;
- P0=0Xff;
- //EOC=1;
- while(EOC==0);
- OE=1;
- uiResult=P0;
- OE=0;
- y=uiResult;
- uiResult=(y*2516)/128;
- if(uiResult<2732)
- { uiResult=2732-uiResult;sflag=1;}
- else
- { uiResult=uiResult-2732;sflag=0;}
- i=4;
- dispbuf[1]=0;
- dispbuf[2]=0;
- dispbuf[3]=0;
- dispbuf[4]=0;
- if(sflag==1)
- { dispbuf[0]=11;}
- else
- { dispbuf[0]=10;}
- dispbuf[5]=10;
- dispbuf[6]=10;
- dispbuf[7]=10;
- while(uiResult/10)
- {dispbuf[i]=uiResult%10;
- uiResult=uiResult/10;
- i--;
- }
- dispbuf[i]=uiResult;
- }
- //
- void main(void)
- {
- xdata unsigned char kk = 0;
-
- START=0;
- OE=0;
- uiResult=148;
- while(1)
- {
- kk++;
- Display();
- ADC0809();
- }
- }
- //
復(fù)制代碼
|
-
-
熱敏電阻溫度計(jì).zip
2016-9-12 11:47 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
111.31 KB, 下載次數(shù): 200, 下載積分: 黑幣 -5
評分
-
查看全部評分
|