⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 app.c

📁 AVR单片机C语言程序设计实例精粹
💻 C
字号:
//***************************************************************
// File Name : Gpio.c
// Author    : Steaven
// Created   : 2008-06-09
// Modified  : 
// Revision  : V0.0
//***************************************************************

#include "iom16v.h" 
#include "DataType.h"
#include "app.h"

//***************************************************************
// Function    : Hardware_Init
// Input       : none
// Output      : none
// Description : ATmega16 Hardware Initialization
//***************************************************************
void Hardware_Init(void)
{
    Gpio_Init();
    Timer0_Init();
    Timer1_Init();
    Interrupt_Init();
}

//***************************************************************
// Function    : Gpio_Init
// Input       : none
// Output      : none
// Description : ATmega16 GPIO Initialization
//***************************************************************
void Gpio_Init(void)
{
 	 DDRA  = 0xFF;
    PORTA = 0x00;
    DDRB  = 0xFF;
    PORTB = 0x00;
    DDRC  = 0xFF;
    PORTC = 0x00;
    DDRD  = 0xFF;
    PORTD = 0x00;
	 //while(1) {;}
}

//***************************************************************
// 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    : Timer1_Init
// Input       : none
// Output      : none
// Description : ATmega16 Timer1 Initialization,1s Interval
//***************************************************************
void Timer1_Init(void)
{
	TCCR1A = 0x00;  //WGM1[3:0]=0100,OCR1A
   TCCR1B = 0x0D;  //1024 division,8M/1024,CTC Mode	
   TCNT1  = 0x00;  //Clear Counter
	OCR1A  = 7813;  //7813 * 1024/8M = 1s 
	TIMSK |= 0x10;  //Enable OCIE1A
	TIFR  |= 0x10;  //Clear OCIF1A
}

//***************************************************************
// Function    : Interrupt_Init
// Input       : none
// Output      : none
// Description : ATmega16 Interrupt Initialization
//***************************************************************
void Interrupt_Init(void)
{
	SREG |= 0x80;   //Enable Global Interrupt
}

//***************************************************************
// Function    : Interrupt_Init
// Input       : none
// Output      : none
// Description : ATmega16 Interrupt Initialization
//***************************************************************
void LED_ON_OFF(INT8U Index,INT8U Action)
{
    if(Action == cLED_ON)
    {
        PORTC |= (1 << Index);
    }
    else
    {
        PORTC &= ~(1 << Index);
    }
}

//***************************************************************
// Function    : Interrupt_Init
// Input       : Data - Integer Type Data
//               pdata - Pointer to BCD Data Array
// Output      : none
// Description : Convert Integer Data to BCD Type Data
//***************************************************************
void INT2BCD(INT8U Data,INT8U *pdata)
{
    *pdata++ = Data % 10;
    *pdata   = Data / 10;
}

INT8U DataConvert(INT8U Data)
{
    if(Data <= 9)
		{
		    return(SegTable[Data]);
		}
		return(0);
}
 		  
  
//=========================END OF FILE=========================//

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -