初级会员
- 积分
- 64
- 金钱
- 64
- 注册时间
- 2019-7-16
- 在线时间
- 6 小时
|
发表于 2019-9-18 21:46:28
|
显示全部楼层
#include "stc89.h"
sbit LED0=P1^0;
sbit key1=P0^0;
sbit key2=P0^1;
sbit OE245=P4^1;
sbit IO=P3^3;
unsigned int timers;
unsigned char keytwo()
{
static unsigned char sda=0;
static unsigned char fg;
if(key2!=1)
{
fg++;
if(fg==2)
{
sda++;
sda%=2;
}
if(fg>2)fg=2;
}
if(key2==1)fg=0;
return sda;
}
void keyone()
{
static unsigned char fg,
sda;
EA=1;
sda=keytwo();
P0=0xFF;
if(key1!=1)
{
if(sda==0)
{
fg++;
if(fg==2)
{
LED0=0;
timers=0;
}
if(fg>2)fg=2;
}
}
if(key1==1)fg=0;
}
void InitTimer0()
{
TMOD = 0x01;
TH0 = 0x0F8;
TL0 = 0x0CD;
EA = 0;
ET0 = 1;
TR0 = 1;
}
void init_timer() interrupt 1
{
TH0 = 0x0F8;
TL0 = 0x0CD;
timers++;
if(timers==5000)
{
timers=0;
LED0=1;
EA=0;
}
}
void main()
{
IO=1;
OE245=0;
InitTimer0();
while(1)
{
keyone();
keytwo();
}
} |
|