#include
#define uchar unsigned char
#define uint unsigned int
sbit hw=P0^0;
sbit kz=P0^1;
sbit red=P2^7;
sbit greed=P2^4;
sbit bj=P2^1;
sbit ml=P2^0;
uchar num;
uchar code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
void delayms(uint);
void baojin()
{
red=1;
bj=1;
delayms(5000);
num=num+1;
red=0;
bj=0;
delayms(1000);
}
void menling()
{
P1=0xc0;
greed=1;
ml=1;
delayms(1000);
ml=0;
greed=0;
delayms(5000);
}
void shuma()
{
P1=table[num];
}
void delayms(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
void main()
{
P1=0xc0;
P2=0x00;
delayms(60000);
while(1)
{
if(hw==1)
{
if(kz==1) baojin();
else menling();
shuma();
}
else P2=0x00;
delayms(1000);
}
}
P0-0红外的输入
P0-1选择门铃、报警
P2-4绿灯
P2-7红灯
P2-1报警
P2-0门铃
头文件不对,应该是include"reg52.h"