#include<reg51.h>
#define uchar unsigned char
sbit OUT = P0^0 ;
sbit CS7279 = P2^2;
sbit CLK = P1^2;
sbit DAT = P1^3;
sbit KEY = P3^3;
sbit LED = P3^7;
//******************7279子程序******************
void s_7279(uchar dat);
uchar r_7279(void);
//******************延时子程序******************
void delay(uchar s);
//******************寄存器的定义和数组的开辟****
uchar MIMA[]={8,8,4,0,2,0,1,9};
uchar codebuf[8],codenum,ERROR;
uchar code TABLE[32]={0xff,0xff,0xff,0xf6,0x01,0x04,0x07,0xff,0xff,0xff,0xff,0x00,0x02,0x05,0x08,0xff,0xff,0xff,0xff,0xf5,0x03,0x06,0x09,0xff,0xff,0xff,0xff,0xf4,0xf3,0xf2,0xf1,0xff};
//******************中断子程序*****************
void int1(void) interrupt 2 using 1
{ uchar keynum,key,i;
s_7279(0x15);
keynum = r_7279();
CS7279 = 1;
key=TABLE[keynum];
if(key<10)
{ if(codenum<8)
{codebuf[codenum]=key;
CS7279=0;
s_7279(0x80+codenum);
s_7279(key);
CS7279=1;
codenum++;
}
}
if(key==0xf4)
{ERROR=0;
if(codenum<8)
{
ERROR=1;}
else
{
for(i=0;i<8;i++)
{
if(MIMA[i]!=codebuf[i])
ERROR=1;}
}
if(ERROR==0)
{LED=1;}
else
{LED=0;}
codenum=0;
}
}
//******************主程序*********************
void main()
{ CS7279=0;
s_7279(0xa4);
CS7279 = 1;
EA = 1;
EX1 = 1;
IT1 = 1;
while(1)
{}
}
//******************7279发送子程序******************
void s_7279(uchar dat)
{ uchar i;
// LED = ~LED;
CS7279 = 0;
CLK = 0;
delay(0);
for(i=1;i<=8;i++)
{
if(dat&0x80)
DAT = 1;
else
DAT = 0;
dat = dat* 2; //数据右移
CLK = 1;
delay(1);
CLK = 0;
}
DAT = 0;
}
//******************7279接收子程序*****************
uchar r_7279(void)
{ uchar i,dat;
CS7279= 0;
DAT = 1;
delay(0);
for(i=1;i<=8;i++)
{ CLK=1;
delay(1);
dat = dat*2;
if(DAT)
dat = dat|0x01; //数据右移
CLK = 0;
delay(1);
}
DAT = 0;
return dat;
}
//******************延时子程序******************
void delay(uchar s)
{ uchar i;
if(s==0) //长延时
for(i=30;i>1;i--)
{;}
if(s==1) //短延时
for(i=8;i>1;i--)
{;}
}
最好能把注释好的发我邮箱,主要解释下每句的作用
邮箱89532231@qq.com