//文件名:main.c
//描述:检测独立按键的键号,显示在1602上
#include
#include
#include"key.h"
#include"LCD.h"
#include"define.h"
void main(void)
{
DDRA=0XFF;
PORTA=0X00;
DDRB=0XFF;
PORTB=0X00;
DDRD=0X00;
PORTD|=0X0F;//上拉电阻使能
TCCR0=0X0D;
TCNT0=0X00;
OCR0=0X39;
TIMSK|=0X02;
TIFR|=0X02;
SEI(); //T0初始化,10ms中断,CTC模式
LCD_Reset();
LCD_Show_String(0,0,"=*=KEY DEMO=*=");
LCD_Show_String(1,0,"NO KEY PRESSED");
while(1)
{
;
}
}
//函数名:Time0
//输入:无
//输出:无
//描述:中断处理程序
#pragma interrupt_handler Time0:20
void Time0(void)
{
static uint key_count=0;
if(get_key0()==true)
{
LCD_Show_String(1,0,"KEY0 IS PRESSED");
key_count=0;
}
if(get_key1()==true)
{
LCD_Show_String(1,0,"KEY1 IS PRESSED");
key_count=0;
}
if(get_key2()==true)
{
LCD_Show_String(1,0,"KEY2 IS PRESSED");
key_count=0;
}
if(get_key3()==true)
{
LCD_Show_String(1,0,"KEY3 IS PRESSED");
key_count=0;
}
if(key_count++>=500)
{
LCD_Show_String(1,0,"NOKEY IS PRESSED");
key_count=0;
}
}
附电路图: