📄 main.c
字号:
//***************************************************************
// File Name : LED.c
// Author : Steaven
// Created : 2008-07-26
// Modified :
// Revision : V0.0
//***************************************************************
#include "iom16v.h"
#include "DataType.h"
#include "app.h"
#include "lcd.h"
//global variables
INT8U Key0_Flag = 0; //Flag of Key0 Pressed
INT8U Key1_Flag = 0; //Flag of Key0 Pressed
INT8U Key2_Flag = 0; //Flag of Key0 Pressed
INT8U Key3_Flag = 0; //Flag of Key0 Pressed
INT8U NoKey_Flag = 0; //Flag of No Key Pressed
void main(void)
{
Hardware_Init();
LCD_Reset();
LCD_Show_String(0,0,"=*= KEY DEMO =*=");
LCD_Show_String(1,0,"No Key Pressed! ");
while(1)
{
if(Key0_Flag == 1)
{
Key0_Flag = 0;
LCD_Show_String(1,0,"Key0 is Pressed! ");
}
if(Key1_Flag == 1)
{
Key1_Flag = 0;
LCD_Show_String(1,0,"Key1 is Pressed! ");
}
if(Key2_Flag == 1)
{
Key2_Flag = 0;
LCD_Show_String(1,0,"Key2 is Pressed! ");
}
if(Key3_Flag == 1)
{
Key3_Flag = 0;
LCD_Show_String(1,0,"Key3 is Pressed! ");
}
if(NoKey_Flag == 1)
{
NoKey_Flag = 0;
LCD_Show_String(1,0,"No Key Pressed! ");
}
}
}
//***************************************************************
// Function : Timer0_Interrupt
// Input : none
// Output : none
// Description : ATmega16 T/C0 ISR
//***************************************************************
#pragma interrupt_handler Timer0_Interrupt:20
void Timer0_Interrupt(void)
{
static INT16U key_count = 0;
static INT8U buzzer_count = 0;
static INT8U buzzer_status = 0;
//Clear Timer0 OCIF Flag
TIFR |= 0x02;
TCNT0 = 0x00;
//Key Detection
if(Get_Key0() == true)
{
Key0_Flag = 1;
key_count = 0;
buzzer_status = 1;
}
if(Get_Key1() == true)
{
Key1_Flag = 1;
key_count = 0;
buzzer_status = 1;
}
if(Get_Key2() == true)
{
Key2_Flag = 1;
key_count = 0;
buzzer_status = 1;
}
if(Get_Key3() == true)
{
Key3_Flag = 1;
key_count = 0;
buzzer_status = 1;
}
//No Key Count
if(key_count++ >= 500)
{
key_count = 0;
NoKey_Flag = 1;
}
//Buzzer Control
if(buzzer_status == 1)
{
Buzzer_ON();
if(buzzer_count++ >= 50)
{
Buzzer_OFF();
buzzer_status = 0;
buzzer_count = 0;
}
}
}
//=========================END OF FILE=========================//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -