原理圖
把led顯示改為6位,并把顯示溫度改為熱敏電阻的阻值程序:
#include<reg51.h>
#include <intrins.h>
#define Disdata P3
#define discan P0
sbit adrd=P2^7; //IO¿ú¶¨òå
sbit adwr=P2^6;
sbit csad=P2^4;
sbit DIN=P3^7; //LEDD¡êyμã¿ØÖÆ
unsigned char j,k,ad_data,t;
unsigned char dis[4]={0x00,0x00,0x00,0x00};
unsigned char code dis_7[12]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x40};
/* 12ÑôLED¶ÎÂë±í¶Ôó| "0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "2»áá" "-" */
unsigned char code scan_con[4]={0xfe,0xfd,0xfb,0xf7}; // áDé¨Ãè¿ØÖÆ×Ö
void delay(unsigned int t)
{
for(;t>0;t--)
{
;
}
} //11΢ÃëÑóê±oˉêy
void scan()
{
char k;
for(k=0;k<4;k++) //ËÄλLEDé¨Ãè¿ØÖÆ
{
Disdata=dis_7[dis[k]];
if(k==1)
{
DIN=1; //¼óèëD¡êyμã
}
discan=scan_con[k];
delay(90);
discan=0xff;
}
}
void ad0804()
{
P1=0xff; //¶áè¡P1¿ú֮ǰÏè¸øÆäD′è«1
csad=0; //Ñ¡í¨ADCS
adrd=0; //AD¶áê1Äü
ad_data=P1; //ADêy¾Y¶á衸3¸øP1¿ú
adrd=1;
csad=1; //1رÕADCS
adwr=0;
}
void ad_compute() //u=2.55+T/100, 2.55·′ó3ÔúADéÏÎa0x83
{
unsigned char t_temp;
//if(ad_data>=0x83)
//{
ad_data=ad_data-0x83;
t_temp=ad_data*2-4;
if(t_temp<=110)
{
dis[3]=t_temp/100;
dis[2]=t_temp/10-dis[3]*10;
dis[1]=t_temp%10;
dis[0]=t%5*2;
}
else
{
t_temp=256-t_temp;
dis[3]=11;
dis[2]=t_temp/10;
dis[1]=t_temp%10;
dis[0]=t%5*2;
}
//
// }
}
void main() // Ö÷3ìDò
{
while(1)
{
ad0804();
ad_compute();
scan();
}
}
改成測熱敏電阻的阻值并用六位LED顯示
|