Chao cac ban trong dien dan,
Minh dang lam mach do nhiet do nhưng khi mo phong thi nó nhay, ko hieu sao nua code ktra di ktra lai nhung chua tim duoc cho sai, cac ban trong dien dan ai da lam ve mach do nhiet do chi giup voi, cam on cac ban rat nhieu, mình gui file mophong va code len cac ban giup mình voi nhe.
Chuong trinh
#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 v;
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(70);
P1=2;P0=M[dv];tre(70);
P1=4;P0=0X9C ;tre(70);
P1=0;//cac Led sang dong deu
}
void dat()
{
if((T==1)||(G==1)) {d=0;tre(250);}//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=20;
while(1)
{
T=0;
G=0;
if((T==1)||(G==1))//kiem tra nut bam nhiet do khong che
{
while(1)
{
dat();
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
v=x*2.5/255;
k=v*100;//nhiet do thuc
ch=k/10;
dv=k%10;
if(k>ndkc) {D=1;V=0;X=0;}
if(k==ndkc){D=0;V=1;X=0;}
if(k<ndkc) {D=0;V=0;X=1;}
hienthi();
}
}
Minh dang lam mach do nhiet do nhưng khi mo phong thi nó nhay, ko hieu sao nua code ktra di ktra lai nhung chua tim duoc cho sai, cac ban trong dien dan ai da lam ve mach do nhiet do chi giup voi, cam on cac ban rat nhieu, mình gui file mophong va code len cac ban giup mình voi nhe.
Chuong trinh
#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 v;
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(70);
P1=2;P0=M[dv];tre(70);
P1=4;P0=0X9C ;tre(70);
P1=0;//cac Led sang dong deu
}
void dat()
{
if((T==1)||(G==1)) {d=0;tre(250);}//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=20;
while(1)
{
T=0;
G=0;
if((T==1)||(G==1))//kiem tra nut bam nhiet do khong che
{
while(1)
{
dat();
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
v=x*2.5/255;
k=v*100;//nhiet do thuc
ch=k/10;
dv=k%10;
if(k>ndkc) {D=1;V=0;X=0;}
if(k==ndkc){D=0;V=1;X=0;}
if(k<ndkc) {D=0;V=0;X=1;}
hienthi();
}
}
Comment