initial.c
来自「AVR单片机C语言程序设计实例精粹」· C语言 代码 · 共 71 行
C
71 行
//***************************************************************
// File Name : Gpio.c
// Author : Steaven
// Created : 2008-06-09
// Modified :
// Revision : V0.0
//***************************************************************
#include "app.h"
//local function(s) declaration
void Gpio_Init(void);
void Timer2_Init(void);
void Interrupt_Init(void);
//***************************************************************
// Function : Hardware_Init
// Input : none
// Output : none
// Description : ATmega16 Hardware Initialization
//***************************************************************
void Hardware_Init(void)
{
Gpio_Init();
Timer2_Init();
Interrupt_Init();
}
//***************************************************************
// Function : Gpio_Init
// Input : none
// Output : none
// Description : ATmega16 GPIO Initialization
//***************************************************************
void Gpio_Init(void)
{
DDRB &= 0xF0; //Key1~Key4,GPIO input
PORTB &= 0xF0; //Key1~Key4,GPIO no pull-up
DDRD |= 0xF0; //LED1~LED4,GPIO output
PORTB &= 0x0F; //LED1~LED4,Gpio output 'L'
}
//***************************************************************
// Function : Timer_Init
// Input : none
// Output : none
// Description : ATmega16 Timer Initialization
//***************************************************************
void Timer2_Init(void)
{
ASSR = 0x00; //Timer2 clocked by sys clk
TCCR2 = 0x47; //1024 division,8M/1024,CTC Mode
TCNT2 = 0x00; //Clear Counter
OCR2 = 78; //78 * 1024/8M = 10ms
TIMSK |= 0x80; //Enable OCIE2
TIFR |= 0x80; //Clear OCIF2
}
//***************************************************************
// Function : Interrupt_Init
// Input : none
// Output : none
// Description : ATmega16 Interrupt Initialization
//***************************************************************
void Interrupt_Init(void)
{
SREG |= 0x80; //Enable Global Interrupt
}
//=========================END OF FILE=========================//
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?