Các bác cho hỏi sao mạch đo nhiệt độ của e lại nhảy lung tung thế này nhỉ đây là code
#include <REGX51.H>
#include <stdio.H>
///////////////////////////////////////
//thiet lap cong ADC
sbit ADC_RD = P2^2;
sbit ADC_WR = P2^1;
sbit ADC_INTR = P2^0;
///////////////////////////////////////
// dat chan dieu khien led
sbit b=P2^3;
sbit c=P2^4;
sbit d=P2^5;
sbit e=P2^6;
float volt;
unsigned char u[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x9 0};
unsigned char v[]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x1 0};
unsigned char dem,x;
float ketqua,ketqua1=0,ketqua2=0;
///////////////////////////////////////
void delay(unsigned int t)
{ unsigned int i;
for(i=0;i<t;i++);
}
///////////////////////////////////////
void quet(unsigned int a)
{ unsigned int nghin,tram,chuc,donvi;
//__________________________________________________ ____________________
nghin=a/1000;
tram=(a%1000)/100;
chuca%1000)%100)/10;
donvia%1000)%100)%10;
//__________________________________________________ _______________________
P0=u[nghin]; b=1;
delay(50);
P0=b=0;
P0=v[tram]; c=1;
delay(50);
P0=c=0;
P0=u[chuc]; d=1;
delay(50);
P0=d=0;
P0=u[donvi];e=1;
delay(50);
P0=e=0;
}
void tre(unsigned int time)
{ int k,i;
for(k=0;k<129;k++)
{for( i=0;i<time;i++)
;
}}
////////////////////////////////////////
// dieu khien ADC
void DK_ADC(void)
{ // tham do ADC
ADC_WR = 1;
ADC_RD = 1;
delay(50);
ADC_WR = 0; // bat dau chuyen doi
ADC_RD = 0;
while(!ADC_INTR); // cho chuyen doi xong
dem++;
x = P1 ;// xuat du lieu vao P1
volt (5*x*1.0)/255));
ketqua = (int)(volt*100);
ketqua1 = ketqua1+ketqua;
if(dem==30)
{ dem=0;
ketqua2= ketqua1/30;
ketqua2 = ketqua2*100;
ketqua1=0;
}
}
///////////////////////////
void main()
{
while(1)
{
DK_ADC();
quet(ketqua2);
}
}
#include <REGX51.H>
#include <stdio.H>
///////////////////////////////////////
//thiet lap cong ADC
sbit ADC_RD = P2^2;
sbit ADC_WR = P2^1;
sbit ADC_INTR = P2^0;
///////////////////////////////////////
// dat chan dieu khien led
sbit b=P2^3;
sbit c=P2^4;
sbit d=P2^5;
sbit e=P2^6;
float volt;
unsigned char u[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x9 0};
unsigned char v[]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x1 0};
unsigned char dem,x;
float ketqua,ketqua1=0,ketqua2=0;
///////////////////////////////////////
void delay(unsigned int t)
{ unsigned int i;
for(i=0;i<t;i++);
}
///////////////////////////////////////
void quet(unsigned int a)
{ unsigned int nghin,tram,chuc,donvi;
//__________________________________________________ ____________________
nghin=a/1000;
tram=(a%1000)/100;
chuca%1000)%100)/10;
donvia%1000)%100)%10;
//__________________________________________________ _______________________
P0=u[nghin]; b=1;
delay(50);
P0=b=0;
P0=v[tram]; c=1;
delay(50);
P0=c=0;
P0=u[chuc]; d=1;
delay(50);
P0=d=0;
P0=u[donvi];e=1;
delay(50);
P0=e=0;
}
void tre(unsigned int time)
{ int k,i;
for(k=0;k<129;k++)
{for( i=0;i<time;i++)
;
}}
////////////////////////////////////////
// dieu khien ADC
void DK_ADC(void)
{ // tham do ADC
ADC_WR = 1;
ADC_RD = 1;
delay(50);
ADC_WR = 0; // bat dau chuyen doi
ADC_RD = 0;
while(!ADC_INTR); // cho chuyen doi xong
dem++;
x = P1 ;// xuat du lieu vao P1
volt (5*x*1.0)/255));
ketqua = (int)(volt*100);
ketqua1 = ketqua1+ketqua;
if(dem==30)
{ dem=0;
ketqua2= ketqua1/30;
ketqua2 = ketqua2*100;
ketqua1=0;
}
}
///////////////////////////
void main()
{
while(1)
{
DK_ADC();
quet(ketqua2);
}
}
Comment