#include <reg52.h>
#include <intrins.h>
#define key_input P3
#define key_mask 0x0f
#define key_state_0 0
#define key_state_1 1
#define key_state_2 2
typedef unsigned char uchar ;
typedef unsigned int uint;
uchar tab[] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uchar disbuf[] = {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07};
sbit buzzer=P0^6;
char Key_Read(void)
{
static char key_state=0;
char key_press,key_return=0;
key_press=key_mask&key_input;
switch(key_state)
{
case key_state_0:
if(key_press!=key_mask)
key_state=key_state_1;
break;
case key_state_1:
if(key_press==key_mask&key_input)
{
if(key_press==0x0e)key_return=1;
if(key_press==0x0d)key_return=2;
if(key_press==0x0b)key_return=3;
if(key_press==0x07)key_return=4;
key_state=key_state_2;
}
break;
case key_state_2:
if(key_press==key_state_0)
key_state=key_state_0;
break;
}
return key_return;
}
void Display(uchar which,uchar num)
{
P2=0xc0;P0=0xff;P2=0x00;
P2=0xc0;P0=disbuf[which];P2=0x00;
P2=0xe0;P0=tab[num];P2=0x00;
}
void Time0() interrupt 1 using 3
{
char i;
TH0=(65536-1000)/256;
TL0=(65536-1000)%256;
i=Key_Read;
if(i==1)Display(0,1);
if(i==2)Display(7,1);
if(i==3)buzzer=1;
if(i==4)buzzer=0;
}
void main()
{
TH0=(65536-1000)/256;
TL0=(65536-1000)%256;
ET0=0;
TR0=1;
EA=1;
while(1)
{
;
}
}
Rebuild target 'Target 1'
assembling STARTUP.A51...
compiling main.c...
linking...
Program Size: data=36.0 xdata=0 code=346
creating hex file from "一个人的寂寞"...
"一个人的寂寞" - 0 Error(s), 0 Warning(s).
用的IAP15转接板,没有一点现象,晕死
|