📄 main.c
字号:
#include <at89x52.h>
#define address 0x0aa
#define power 0x0fe
#define menu 0x0f8
#define up 0x0fd
#define enter 0x0fb
#define down 0x0fc
void clsconnect_key(void);
void power_key(void);
void manu_key(void);
void up_key(void);
void down_key(void);
void enter_key(void);
void init(void);
void delay(unsigned char t);
bit interruptFlag,flag = 0;
unsigned char command,recommand;
main()
{
init();
while(1)
{
if(interruptFlag==1)
{
interruptFlag=0;
if(SM2)
{
if(command==address)
{
SM2=0;
recommand = address;
TB8 = 1;
SBUF = recommand;
while(~TI){}
P2 = 0xff; //led
}
TI = 0;
RI = 0;
EA = 1;
REN = 1;
}
else
{
if(RB8)
{
if(command == address)
{
clsconnect_key();
TB8 = 1;
SBUF = recommand;
while(~TI){}
}
REN= 1;
TI = 0;
RI = 0;
EA = 1;
}
else
{
switch(command)
{
case power :
power_key() ;break;
case menu :
manu_key() ;break;
case up :
up_key() ;break;
case down :
down_key() ;break;
case enter :
enter_key() ;break;
}
if(flag == 1)
{
flag = 0;
TB8 = 1 ;
SBUF = recommand;
while(~TI){}
TI = 0;
RI = 0;
EA = 1;
REN = 1;
}
}
}
}
}
}
void clsconnect_key()
{
P2 = 0xdf;
recommand=command ;
}
void power_key()
{
P2 = 0xfe;
recommand=command ;
flag = 1;
delay(255);
P2 = 0xff;
}
void manu_key()
{
P2 = 0xf7 ;
recommand=command ;
flag = 1;
delay(255);
P2 = 0xff;
}
void up_key()
{
P2 = 0xfb ;
recommand=command ;
flag = 1;
delay(255);
P2 = 0xff;
}
void down_key()
{
P2 = 0xfd ;
recommand=command ;
flag = 1;
delay(255);
P2 = 0xff;
}
void enter_key()
{
P2 = 0xef;
recommand=command ;
flag = 1;
delay(255);
P2 = 0xff;
}
void serial(void) interrupt 4 using 1
{
EA=0;
REN=0;
command = SBUF;
interruptFlag = 1;
RI=0;
}
void init()
{
P2 = 0xff;
interruptFlag=0;
TI = 0;
SCON = 0x0f0; /* mode 1: 8-bit UART, enable receiver */
TMOD = 0x20; /* timer 1 mode 2: 8-Bit reload */
TH1 = 0x0f3; /* reload value 2400 baud */
TL1 = 0x0f3;
PCON = 0x00;
TR1 = 1; /* timer 1 run */
TB8 = 1;
ES = 1;
EA = 1;
}
void delay(unsigned char t)
{
unsigned char i , j;
for(i = 0;i < t;i ++)
{
for(j = 0; j < 180 ; j++)
{}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -