#include <STC32G.H>
#include <intrins.H>
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
uint i,j;
sbit DQ=P3^4;
uchar code tab[]={0XC0,0XF9,0XA4,0XB0,0X99,0X92,0X82,0XF8,0X80,0X90,0XBF,0XFF};
uchar yi,er,san,si;
uchar irdata[33];
uchar ircord[4];
bit deal_ok,ir_ok;
uchar time,point=10;
void delayms(int ms);
void allinit();
void display(uchar yi,uchar er,uchar san,uchar si);
void dsinit();
uchar read();
uchar temget();
void write(uchar dat);
void t0_init(void);
void main()
{
uchar wendu;
allinit();
yi=11;er=11;san=11;si=11;
while(1)
{
wendu=temget();
er=wendu/100;
san=wendu%100/10;
si=wendu%10;
display(yi,er,san,si);
}
}
void delayms(int ms)
{
int i,j;
for(i=ms;i>0;i--)
for(j=845;j>0;j--);
}
void allinit()
{
P0M0=0X00;P0M1=0X00;
P1M0=0X00;P1M1=0X00;
P2M0=0X00;P2M1=0X00;
P3M0=0X00;P3M1=0X00;
P4M0=0X00;P4M1=0X00;
}
void t0_init(void)
{
EAXFR=1;
CKCON=0X00;
WTST=0X00;
AUXR |= 0x80;
TMOD &= 0xF0;
TL0 = 0xCD;
TH0 = 0xD4;
TF0 = 0;
TR0 = 1;
ET0=1;
EA=1;
}
/********************************************************************
* Ãû³Æ : display()
* ¹¦ÄÜ : ÊýÂë¹ÜÏÔʾº¯Êý
* ÊäÈë : ÎÞ
* Êä³ö : ÎÞ
***********************************************************************/
void display(uchar yi,uchar er,uchar san,uchar si) //ÏÔʾº¯Êý
{
P2=tab[yi];
P41 = 0;
delayms(2);
P41 = 1;
P2=tab[er];
P42 = 0;
delayms(2);
P42 = 1;
P2=tab[san];
P44 = 0;
delayms(2);
P44 = 1;
P2=tab[si];
P45 = 0;
delayms(2);
P45 = 1;
}
uchar temget()
{
uchar temp;
uchar low,high;
dsinit();
write(0xcc);
write(0x44);
Delay500us(); Delay500us();
dsinit();
write(0xcc);
write(0xbe);
low=read();
high=read();
temp=high<<4;//0000 0101 =0101 0000
temp |= (low>>4); // 1010 0110 0000 0110 | 0101 0000=0101 0110
return temp;
}
uchar read()
{
uchar i;
uchar dat;
for(i=0;i<8;i++)
{
DQ=0;
_nop_();
dat>>=1;
DQ=1;
if(DQ==1)
{
dat |= 0x80;// dat=dat|0x80; 0000 0000 | 1000 0000 =1000 0000
}
Delay100us();
}
return dat;
}
void write(uchar dat)
{
uchar i;
for(i=0;i<8;i++)
{
DQ=0;
DQ=dat&0x01;//0100 0100 & 0000 0001 // 0000 0001
Delay100us();
DQ=1;
dat>>=1;//dat=dat>>1;//1001 0000//0010 0001
}
}
void dsinit()
{
DQ=0;
Delay500us();
DQ=1;
Delay500us();
}
void TM0_Isr() interrupt 1
{
i++;
TL0 = 0xCD;
TH0 = 0xD4;
if(i==500) //500*1MS=500MS
{
i=0;
P0=_crol_(P0,1);
}
} |