#include"STC12C5620AD.H"
//#include"TIMER0.H"
//sbit Key5 =P2^2; //触摸按键引脚
//sbit Key2 =P2^3;
//sbit Key3 =P3^0;
//sbit Key4 =P3^1;
sbit bell =P2^0;
extern unsigned char keyboard();
void delay()
{
unsigned char i;
for(i=0;i<320;i++);
}
void main(void)
{
Init_Timer0();
//if(systemTime10Ms)
// {
// systemTime10Ms=0;
switch(keyboard())
{
case 1: bell = 0 ; delay(); delay();
case 2: bell = 0 ; delay(); delay(); delay();
case 3: bell = 0 ; delay(); delay(); delay();delay() ;
case 4: bell = 0 ; delay(); delay(); delay();delay(); delay();
}
}
// }
//独立按键 P10-P13
extern unsigned char keyboard()
{
unsigned char key_number =0 ; // 按键号
unsigned char key_temp = 0; //暂存按键值
static unsigned char key_code = 0; //按键值
static unsigned char key_count = 0; //电平有效次数
static unsigned char key_flag = 0; //按键有效标志位
key_temp = P1&0x0F;
if(key_temp != 0x0F)
{
key_count++;
if(key_count == 10)
{
key_flag = 1;
key_code = key_temp;
}
}
else //松手判断
{
key_count = 0;
if(key_flag==1)
{
key_flag = 0;
switch(key_code)
{
case 0x0e: key_number = 1;
case 0x0D: key_number = 2;
case 0x0b: key_number = 3;
case 0x07: key_number = 4;
}
}
}
return(key_number);
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
额忘记把这个写上去,不过试了还是不能用,你能不能在编译器里帮我看下
一周热门 更多>