?? app.c
字號:
//***************************************************************
// File Name : Gpio.c
// Author : Steaven
// Created : 2008-06-09
// Modified :
// Revision : V0.0
//***************************************************************
#include "iom16v.h"
#include "DataType.h"
#include "app.h"
//local function declaration
void Gpio_Init(void);
void Timer0_Init(void);
void Interrupt_Init(void);
//***************************************************************
// Function : Hardware_Init
// Input : none
// Output : none
// Description : ATmega16 Hardware Initialization
//***************************************************************
void Hardware_Init(void)
{
Gpio_Init();
Timer0_Init();
Interrupt_Init();
}
//***************************************************************
// Function : Gpio_Init
// Input : none
// Output : none
// Description : ATmega16 GPIO Initialization
//***************************************************************
void Gpio_Init(void)
{
DDRA = 0xFF; //端口A設置為輸出
PORTA = 0x00; //初始化輸出0
DDRB = 0x0F; //端口B設置為輸出
PORTB = 0xF0; //初始化輸出0
DDRC = 0xFF; //端口C設置為輸出
PORTC = 0x00; //初始化輸出0
DDRD = 0xFF; //端口D設置為輸出
PORTD = 0x00; //初始化輸出0
}
//***************************************************************
// Function : Timer0_Init
// Input : none
// Output : none
// Description : ATmega16 Timer0 Initialization,10ms Interval
//***************************************************************
void Timer0_Init(void)
{
TCCR0 = 0x0D; //1024 division,8M/1024,CTC Mode
TCNT0 = 0x00; //Clear Counter
OCR0 = 78; //78 * 1024/8M = 10ms
TIMSK |= 0x02; //Enable OCIE0
TIFR |= 0x02; //Clear OCIF0
}
//***************************************************************
// Function : Interrupt_Init
// Input : none
// Output : none
// Description : ATmega16 Interrupt Initialization
//***************************************************************
void Interrupt_Init(void)
{
SREG |= 0x80; //Enable Global Interrupt
}
//***************************************************************
// Function : Get_Key0/1/2/3
// Input : none
// Output : Key Press Status
// Description : Key Press Status Check
//***************************************************************
INT8U Get_Key0(void)
{
static INT8U Key_Flag = 0;
if(Key_Flag == 0)
{
if((PINB & 0x10) == 0x00)
{
Key_Flag = 1;
}
}
else if(Key_Flag == 1)
{
if((PINB & 0x10) == 0x10)
{
Key_Flag = 0;
return(true);
}
}
return(false);
}
INT8U Get_Key1(void)
{
static INT8U Key_Flag = 0;
if(Key_Flag == 0)
{
if((PINB & 0x20) == 0x00)
{
Key_Flag = 1;
}
}
else if(Key_Flag == 1)
{
if((PINB & 0x20) == 0x20)
{
Key_Flag = 0;
return(true);
}
}
return(false);
}
INT8U Get_Key2(void)
{
static INT8U Key_Flag = 0;
if(Key_Flag == 0)
{
if((PINB & 0x40) == 0x00)
{
Key_Flag = 1;
}
}
else if(Key_Flag == 1)
{
if((PINB & 0x40) == 0x40)
{
Key_Flag = 0;
return(true);
}
}
return(false);
}
INT8U Get_Key3(void)
{
static INT8U Key_Flag = 0;
if(Key_Flag == 0)
{
if((PINB & 0x80) == 0x00)
{
Key_Flag = 1;
}
}
else if(Key_Flag == 1)
{
if((PINB & 0x80) == 0x80)
{
Key_Flag = 0;
return(true);
}
}
return(false);
}
//***************************************************************
// Function : Buzzer_ON/OFF
// Input : none
// Output : none
// Description : Buzzer ON/OFF Control
//***************************************************************
void Buzzer_ON(void)
{
PORTB |= 0x08;
}
void Buzzer_OFF(void)
{
PORTB &= ~0x08;
}
//=========================END OF FILE=========================//
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -