app.c
来自「AVR单片机 C语言程序设计经典实用」· C语言 代码 · 共 90 行
C
90 行
//********************************************************************
// File Name : Gpio.c
// Author : Steaven
// Created : 2008-06-09
// Modified :
// Revision : V0.0
//********************************************************************
#include "includes.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 = 0x00; //PortA - Input with Pull-Up
PORTA = 0x00;
DDRB = 0x00; //PortB - Input with Pull-Up
PORTB = 0x00;
DDRC = 0x00; //PortC - Input with Pull-Up
PORTC = 0x00;
DDRD = 0x00; //PortD - Input with Pull-Up
PORTD = 0x00;
}
//********************************************************************
// 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 : 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 + =
减小字号Ctrl + -
显示快捷键?