hongwai.c
字号:
#include "89c2051.h"
#define NOKEY 1
#define KEY_BACK 2
#define KEY_FORWARD 3
bit autostate = 0;
unsigned char switchl = 0;
unsigned char workstate = 0;
unsigned char timerdelay = 0;
unsigned int timertime = 0;
unsigned int timertime1 = 0;
void delay(unsigned int temp)
{
unsigned char i;
unsigned int j;
for(j=0;j<temp;j++)
{
for(i=0;i<255;i++);
}
}
void chip_init(void)
{
P3M1 = 0x80;
TMOD = 0x01;
AUXR = 0x00;
TH0 = 0xff;
TL0 = 0xf5;/////9c
IE = 0x82;
TR0 = 1;
SH00T = 0;
SWITCH = 1;
BACK = 1;
RECEIVE = 1;
FORWARD = 1;
P_UNLOAD = 0;
P_LOAD = 0;
}
unsigned char key(void)
{
if(SWITCH!=switchl)
{
delay(10);
if(SWITCH!=switchl)
{
switchl = SWITCH;
if(SWITCH==0)
{
workstate = 0;
}
else
{
workstate = 1;
}
}
}
if(!FORWARD)
{
delay(10);
if(!FORWARD)
{
return(KEY_FORWARD);
}
else
{
return(NOKEY);
}
}
if(!BACK)
{
delay(10);
if(!BACK)
{
return(KEY_BACK);
}
else
{
return(NOKEY);
}
}
}
void timer0_inter(void) interrupt TF0_VECTOR
{
TH0 = 0xff;
TL0 = 0xf5;////9c
SH00T = ~SH00T;
if(timerdelay<200)
{
timerdelay++;
}
}
void timer_delay(void)
{
if(timerdelay>=180)
{
timertime++;
timertime1++;
timerdelay = 0;
}
}
void main(void)
{
unsigned char keytemp;
chip_init();
while(1)
{
timer_delay();
keytemp = key();
if(workstate)
{
LED_A = 0;
LED_H = 1;
if(RECEIVE)
{
if(timertime1>600)
{
P_UNLOAD = 0;
P_LOAD = 1;
autostate =1;
}
timertime = 0;
}
else
{
if(autostate)
{
if(timertime>=200)
{
P_UNLOAD = 0;
P_LOAD = 0;
autostate = 0;
}
}
else
{
P_UNLOAD = 0;
P_LOAD = 0;
}
timertime1 = 0;
}
}
else
{
LED_A = 1;
LED_H = 0;
if(keytemp == KEY_BACK)
{
P_UNLOAD = 1;
P_LOAD = 0;
}
else if(keytemp == KEY_FORWARD)
{
P_UNLOAD = 0;
P_LOAD = 1;
}
else
{
P_UNLOAD = 0;
P_LOAD = 0;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -