Programa SCM c para control de temperatura
Este es un programa de control de temperatura que escribí para su referencia
#include lt; reg52.hgt
#define uint unsigned int
#define uchar unsigned char
tabla de códigos uchar[]={0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f, 0x00}
uchar tem;
sbit aa=P2^0;
sbit bb=P2^1;
sbit cc=P2^2;
sbit DQ=P3^7;
sbit jia=P3^0;
sbit jian=P3^2;
sbit ji=P2 ^ 3;
bit deng=P2^5;
/////////////////////////// ////////////
char gong, gongshi, gongge;
uint num, num0;
///// //////////////////////////////////
retraso nulo(uint z) //z =110 es un milisegundo
{
while(z--);
}
void delay_50us(uint t) // Retraso 50us
{
uchar j;
for(;tgt;0;t--)
for(j=19 ; jgt;0;j--);
}
///////////////////////// // ///////////////////////////////////////////////// ////// //////
void init18b20() //Inicializar 18b20
{
uchar t;
DQ=1;
retraso(8);
DQ=0;
retraso(80); 1;
retraso(8);
t=DQ
retraso(6); p>void wb18b20(uchar dat) //Escribe 1 byte de datos en 18b20
{
uchar i;
for(i=0; ilt; 8; i)
{
DQ=0;
DQ=0x01; p>
DQ=1;
dat=datgt;
}
retraso(5); >} p>
uchar rb18b20() //Leer 1 byte de datos de 18b20
{
uchar i, valor;
para (i= 0; ilt; 8; i )
{
DQ=0;
valorgt;=1;
> DQ=1;
if(DQ)
valor=valor|0x80
retraso(4); /p>
valor de retorno;
}
void rt18b20() //valor de temperatura de 18b20 grados
{
uchar a, b, c;
init18b20();
wb18b20(0xcc);
wb18b20(0x44); (1);
init18b20();
wb18b20(0xcc);
wb18b20(0xbe); );
b=rb18b20();
blt;lt;=4;
b =(aamp;0xf0)gt;gt;4;
c=bamp;0x80;
if(c==0x00)
{}
más
{
b=~b;
}
tem=b;
}
void inittimer0( )
{
TMOD=0x01;
EA=1
ET0=1; =(65536-20500)/256;
TL0=(65536-20500)256;
TR0=1; >////////////////////////////////////////////////// /// //////////////////////////////////
anulación de teclas nulas() p>
{
if(jia==0)
{
retraso(10);
if(jia ==0)
{
P0=tabla[10];
gong;
if(gong==100)
{
gong=0;
}
};
mientras(!jia ); p>
retraso(10);
mientras(!jia
}
if(jian==0)
{
demora(10);
si(jian==0)
{
P0=tabla[10] ;
gong--;
if(gong==-1)
{
gong=99;
}
};
mientras(!jian);
retraso(10);
}
}
nulo led()
{
cc=0; ; aa=0 ;P0=tabla[gong/10]
;retraso(500);
cc=0;bb=0;aa=1;P0=table[gong10];retraso(500);
cc=0;bb= 1;aa=0;P0=tabla[tem/10];retraso(500);
cc=0;bb=1;aa=1;P0=tabla[tem10];retraso(500) ;
}
void wenkong()
{
if((temgt;gong)|(tem==gong))
{
ji=1;
deng=1
}
más
{
ji=0;
deng=0
}
}
nulo; principal()
{
gong=30
ji=0
inittimer0(); > mientras(1)
{
wenkong();
teclascan()
}
}
void timer0() interrupción 1
{
TH0=(65536-20500)/256
TL0=(65536; -20500)256;
número ;
led();
if(num==10)
{
rt18b20();
número=0
}
}