红外遥控控制+1602液晶显示程序
时间:10-02
整理:3721RD
点击:
疑惑:bit hwread ()中的elsezz{;}为什么不能用return 0;
为什么要用定时器中断,不用为什么会经常跑飞?
为什么数组a在中断响应和始终是0?
#include <reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
uint count,k;
uchar c[4]={0};
uchar b[]={"0123456789ABCDEF"};
sbit hw=P3^2;
sbit RS=P2^0;
sbit RW=P2^1;
sbit LCDE=P2^2;
sbit FB=P0^7;
delayms (uint a)
{
uchar i;
while(a--)
{
for(i=0;i++;i<114)
{;}
}
}
bit busy ()
{
bit bus;
RS=0;
RW=1;
LCDE=0;
_nop_();
_nop_();
LCDE=1;
_nop_();
_nop_();
_nop_();
_nop_();
bus=FB;
_nop_();
_nop_();
_nop_();
_nop_();
LCDE=0;
return bus;
}
write(uchar date)
{
RW=0;
RS=1;
LCDE=0;
P0=date;
_nop_();
_nop_();
LCDE=1;
_nop_();
_nop_();
_nop_();
_nop_();
LCDE=0;
delayms(2);
}
writerom(uchar date)
{
RW=0;
RS=0;
LCDE=0;
P0=date;
_nop_();
_nop_();
LCDE=1;
_nop_();
_nop_();
_nop_();
_nop_();
LCDE=0;
delayms(2);
}
writedate(uchar adr,uchar date )
{
writerom(adr|0x80);
write(date);
}
uchar read()
{
uchar date;
RW=1;
RS=1;
LCDE=0;
_nop_();
_nop_();
LCDE=1;
_nop_();
_nop_();
date=P0;
_nop_();
_nop_();
_nop_();
_nop_();
LCDE=0;
return date;
}
clear()
{
writerom(0x01);
}
uchar readdate (uchar adr)
{
writerom(adr);
return(read());
}
lcdintl()
{
writerom(0x06);
writerom(0x0f) ;
writerom(0x38) ;
clear();
delayms(10);
}
bit hwread ()
{
uchar i,date,j;
for(j=0;j<4;j++)
{
for(i=0;i<8;i++)
{
date>>=1;
TH0=TL0=0;
TR0=1;
while(hw==0);
TR0=0;
k=TH0*256+TL0;
if((k>370)&&(k<650))
{
TH0=TL0=0;
TR0=1;
while(hw==1);
TR0=0;
count=TH0*256+TL0;
TH0=TL0=0;
if((count>1300)&&(count<1800))
{date|=0x80;}
else
if((count>400)&&(count<650))
{date|=0x00;}
else
{;}
}
else
{return 0 ;}
}
c[j]=date;
}
return 1;
}
main()
{
EA=1;
EX0=1;
ET0=1;
IT0=1;
TMOD=0X01;
lcdintl();
clear();
delayms(10);
TR0=0;
while(1);
}
void hwcheak (void) interrupt 0
{
uint l,h;
EX0=0;
TH0=TL0=0;
TR0=1;
while(hw==0);
TR0=0;
l=TH0*256+TL0;
TH0=TL0=0;
TR0=1;
while(hw==1);
TR0=0;
h=TH0*256+TL0;
if((l>7800)&&(l<8800)&&(h>3600)&&(h<4700))
{
if(hwread()==1)
{
writedate(0x00,'h');
write('w');
write(b[c[0]>>4]);
write(b[c[0]&0x0f]);
write(b[c[1]>>4]);
write(b[c[1]&0x0f]);
write(b[c[2]>>4]);
write(b[c[2]&0x0f]);
write(b[c[3]>>4]);
write(b[c[3]&0x0f]);
}
}
EX0=1;
}
为什么要用定时器中断,不用为什么会经常跑飞?
为什么数组a在中断响应和始终是0?
#include <reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
uint count,k;
uchar c[4]={0};
uchar b[]={"0123456789ABCDEF"};
sbit hw=P3^2;
sbit RS=P2^0;
sbit RW=P2^1;
sbit LCDE=P2^2;
sbit FB=P0^7;
delayms (uint a)
{
uchar i;
while(a--)
{
for(i=0;i++;i<114)
{;}
}
}
bit busy ()
{
bit bus;
RS=0;
RW=1;
LCDE=0;
_nop_();
_nop_();
LCDE=1;
_nop_();
_nop_();
_nop_();
_nop_();
bus=FB;
_nop_();
_nop_();
_nop_();
_nop_();
LCDE=0;
return bus;
}
write(uchar date)
{
RW=0;
RS=1;
LCDE=0;
P0=date;
_nop_();
_nop_();
LCDE=1;
_nop_();
_nop_();
_nop_();
_nop_();
LCDE=0;
delayms(2);
}
writerom(uchar date)
{
RW=0;
RS=0;
LCDE=0;
P0=date;
_nop_();
_nop_();
LCDE=1;
_nop_();
_nop_();
_nop_();
_nop_();
LCDE=0;
delayms(2);
}
writedate(uchar adr,uchar date )
{
writerom(adr|0x80);
write(date);
}
uchar read()
{
uchar date;
RW=1;
RS=1;
LCDE=0;
_nop_();
_nop_();
LCDE=1;
_nop_();
_nop_();
date=P0;
_nop_();
_nop_();
_nop_();
_nop_();
LCDE=0;
return date;
}
clear()
{
writerom(0x01);
}
uchar readdate (uchar adr)
{
writerom(adr);
return(read());
}
lcdintl()
{
writerom(0x06);
writerom(0x0f) ;
writerom(0x38) ;
clear();
delayms(10);
}
bit hwread ()
{
uchar i,date,j;
for(j=0;j<4;j++)
{
for(i=0;i<8;i++)
{
date>>=1;
TH0=TL0=0;
TR0=1;
while(hw==0);
TR0=0;
k=TH0*256+TL0;
if((k>370)&&(k<650))
{
TH0=TL0=0;
TR0=1;
while(hw==1);
TR0=0;
count=TH0*256+TL0;
TH0=TL0=0;
if((count>1300)&&(count<1800))
{date|=0x80;}
else
if((count>400)&&(count<650))
{date|=0x00;}
else
{;}
}
else
{return 0 ;}
}
c[j]=date;
}
return 1;
}
main()
{
EA=1;
EX0=1;
ET0=1;
IT0=1;
TMOD=0X01;
lcdintl();
clear();
delayms(10);
TR0=0;
while(1);
}
void hwcheak (void) interrupt 0
{
uint l,h;
EX0=0;
TH0=TL0=0;
TR0=1;
while(hw==0);
TR0=0;
l=TH0*256+TL0;
TH0=TL0=0;
TR0=1;
while(hw==1);
TR0=0;
h=TH0*256+TL0;
if((l>7800)&&(l<8800)&&(h>3600)&&(h<4700))
{
if(hwread()==1)
{
writedate(0x00,'h');
write('w');
write(b[c[0]>>4]);
write(b[c[0]&0x0f]);
write(b[c[1]>>4]);
write(b[c[1]&0x0f]);
write(b[c[2]>>4]);
write(b[c[2]&0x0f]);
write(b[c[3]>>4]);
write(b[c[3]&0x0f]);
}
}
EX0=1;
}
十大是的师傅师傅师傅师傅