標(biāo)題:
ATmega128 定時器測試
[打印本頁]
作者:
liuqq
時間:
2015-5-21 23:45
標(biāo)題:
ATmega128 定時器測試
功能說明/*全部定時1S*/
#define F_CPU 16000000UL
#include "DS12864.h"
#include <avr/io.h>
#include <avr/interrupt.h>
volatile unsigned int count0=0,flag0=0;
volatile unsigned int count1=0,flag1=0;
volatile unsigned int count2=0,flag2=0;
volatile unsigned int count3=0,flag3=0;
/**************************************************************
隸屬模塊:定時器測試模塊
函數(shù)名稱:Timer0_Init()
函數(shù)功能: 初始化
入口參數(shù): 無
返回參數(shù):無
***************************************************************/
void Timer0_Init()
{
TCNT0 = 0x06;
TCCR0 = 0x03;//64分頻
TIMSK |= (1<<TOIE0);//使能定時器0中斷
}
/**************************************************************
隸屬模塊:定時器測試模塊
函數(shù)名稱:Timer1_Init()
函數(shù)功能: 初始化
入口參數(shù): 無
返回參數(shù):無
***************************************************************/
void Timer1_Init()
{
TCNT1H = 0x3C;
TCNT1L = 0xB0;
TCCR1A = 0x00;
TCCR1B = 0x03;//64分頻
TIMSK |= (1<<TOIE1);//使能定時器1中斷
}
/**************************************************************
隸屬模塊:定時器測試模塊
函數(shù)名稱:Timer2_Init()
函數(shù)功能: 初始化
入口參數(shù): 無
返回參數(shù):無
***************************************************************/
void Timer2_Init()
{
TCNT2 = 0x06;
TCCR2 = 0x03;//64分頻
TIMSK |= (1<<TOIE2);//使能定時器2中斷
}
/**************************************************************
隸屬模塊:定時器測試模塊
函數(shù)名稱:Timer3_Init()
函數(shù)功能: 初始化
入口參數(shù): 無
返回參數(shù):無
***************************************************************/
void Timer3_Init()
{
TCNT3H = 0x3C;
TCNT3L = 0xB0;
TCCR3A = 0x00;
TCCR3B = 0x03;//64分頻
ETIMSK |= (1<<TOIE3);//使能定時器3中斷
}
/************************測試函數(shù)**************************/
int main(void)
{
DDRD = 0xF0;
DDRE = 0xF0;
LCD12864_Init();
SREG &=~(1<<7);
Timer0_Init();
Timer1_Init();
Timer2_Init();
Timer3_Init();
SREG |= (1<<7);
LCD12864_Dis_Str(0,0,"定時器0:");
LCD12864_Dis_Str(0,1,"定時器1:");
LCD12864_Dis_Str(0,2,"定時器2:");
LCD12864_Dis_Str(0,3,"定時器3:");
while(1)
{
//TODO:: Please write your application code
if(count0>1999){
count0=0;
flag0=(flag0+1)%10;
LCD12864_Dis_Ctr(5,0,flag0+0x30);
}
if(count1>4)
{
count1=0;
flag1=(flag1+1)%10;
LCD12864_Dis_Ctr(5,1,flag1+0x30);
}
if(count2>999)
{
count2=0;
flag2=(flag2+1)%10;
LCD12864_Dis_Ctr(5,2,flag2+0x30);
}
if(count3>4)
{
count3=0;
flag3=(flag3+1)%10;
LCD12864_Dis_Ctr(5,3,flag3+0x30);
}
}
}
/**************************************************************
隸屬模塊:定時器測試模塊
函數(shù)名稱:SIGNAL(TIMER0_OVF_vect)
函數(shù)功能: 定時器0中斷函數(shù)
入口參數(shù): 無
返回參數(shù):無
***************************************************************/
SIGNAL(TIMER0_OVF_vect)
{
TCNT0 = 0x06;
count0++;
}
/**************************************************************
隸屬模塊:定時器測試模塊
函數(shù)名稱:SIGNAL(TIMER1_OVF_vect)
函數(shù)功能: 定時器1中斷函數(shù)
入口參數(shù): 無
返回參數(shù):無
***************************************************************/
SIGNAL (TIMER1_OVF_vect)
{
TCNT1H = 0x3C;
TCNT1L = 0xB0;
count1++;
}
/**************************************************************
隸屬模塊:定時器測試模塊
函數(shù)名稱:SIGNAL(TIMER2_OVF_vect)
函數(shù)功能: 定時器2中斷函數(shù)
入口參數(shù): 無
返回參數(shù):無
***************************************************************/
SIGNAL (TIMER2_OVF_vect)
{
count2++;
}
/**************************************************************
隸屬模塊:定時器測試模塊
函數(shù)名稱:SIGNAL(TIMER3_OVF_vect)
函數(shù)功能: 定時器3中斷函數(shù)
入口參數(shù): 無
返回參數(shù):無
***************************************************************/
SIGNAL (TIMER3_OVF_vect)
{
TCNT3H = 0x3C;
TCNT3L = 0xB0;
count3++;
}
復(fù)制代碼
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1