#include<stdio.h>
#include<reg52.h>
#include<math.h>
sbit INTR_ADC=P3^6;
sbit WR_ADC=P3^7;
sbit T=P1^6;//nut bam Tang
sbit G=P1^7;//nut bam Giam
sbit D=P3^3;//den Do
sbit V=P3^4;//den Vang
sbit X=P3^5;//den Xanh
long int x,k,ch,dv,d,ndkc;
float volt;
unsigned long int i;
unsigned char M[10]={0XC0,0XF9,0XA4,0XB0,0X99,0X92,0X82,0XF8,0X80,0X9 0};
void tre (unsigned long int t)
{
for(i=0;i<=t;i++);
}
void hienthi()
{
P1=1;P0=M[ch];tre(100);
P1=2;P0=M[dv];tre(100);
P1=4;P0=0X9C;tre(100);
P1=8;P0=0xC6;tre(100);
P1=0;//cac Led sang dong deu
}
void batki()
{
if((T==1)||(G==1)) {d=0;tre(100);}//bam nut thi reset bien dem d, tao tre giua cac lan bam
d=d+1;//dem qua trinh lap cua chuong trinh nay
if (T==1) ndkc=ndkc+1;
if (G==1) ndkc=ndkc-1;
ch=ndkc/10;
dv=ndkc%10;
hienthi();
}
void main()
{
ndkc=30;
while(1)
{
T=0;
G=0;
if((T==1)||(G==1))//kiem tra nut bam nhiet do khong che
{
while(1)
{
batki();
if(d==100) break;//neu lap 100 lan ma k co su tac dong nut bam thi thoat
}
}
WR_ADC=0;//cho phep ADC bien doi
tre(100);//thoi gian tre cho ADC bien doi xong
WR_ADC=1;//khong cho ADC bien doi
x=P2;//gan gia tri bien doi vao x
volt=x*2.5/255;
k=volt*100;//nhiet do thuc
ch=k/10;
dv=k%10; // 0-9
if(k>ndkc) {D=0;V=0;X=1;}
if(k==ndkc){D=0;V=1;X=0;}
if(k<ndkc) {D=1;V=0;X=0;}
hienthi();
}
}
#include<reg52.h>
#include<math.h>
sbit INTR_ADC=P3^6;
sbit WR_ADC=P3^7;
sbit T=P1^6;//nut bam Tang
sbit G=P1^7;//nut bam Giam
sbit D=P3^3;//den Do
sbit V=P3^4;//den Vang
sbit X=P3^5;//den Xanh
long int x,k,ch,dv,d,ndkc;
float volt;
unsigned long int i;
unsigned char M[10]={0XC0,0XF9,0XA4,0XB0,0X99,0X92,0X82,0XF8,0X80,0X9 0};
void tre (unsigned long int t)
{
for(i=0;i<=t;i++);
}
void hienthi()
{
P1=1;P0=M[ch];tre(100);
P1=2;P0=M[dv];tre(100);
P1=4;P0=0X9C;tre(100);
P1=8;P0=0xC6;tre(100);
P1=0;//cac Led sang dong deu
}
void batki()
{
if((T==1)||(G==1)) {d=0;tre(100);}//bam nut thi reset bien dem d, tao tre giua cac lan bam
d=d+1;//dem qua trinh lap cua chuong trinh nay
if (T==1) ndkc=ndkc+1;
if (G==1) ndkc=ndkc-1;
ch=ndkc/10;
dv=ndkc%10;
hienthi();
}
void main()
{
ndkc=30;
while(1)
{
T=0;
G=0;
if((T==1)||(G==1))//kiem tra nut bam nhiet do khong che
{
while(1)
{
batki();
if(d==100) break;//neu lap 100 lan ma k co su tac dong nut bam thi thoat
}
}
WR_ADC=0;//cho phep ADC bien doi
tre(100);//thoi gian tre cho ADC bien doi xong
WR_ADC=1;//khong cho ADC bien doi
x=P2;//gan gia tri bien doi vao x
volt=x*2.5/255;
k=volt*100;//nhiet do thuc
ch=k/10;
dv=k%10; // 0-9
if(k>ndkc) {D=0;V=0;X=1;}
if(k==ndkc){D=0;V=1;X=0;}
if(k<ndkc) {D=1;V=0;X=0;}
hienthi();
}
}
Comment