ATmega128 Timer Test

Publisher:760802csyLatest update time:2019-11-22 Source: 51heiKeywords:ATmega128 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Function description/*All timing 1S*/


#define F_CPU 16000000UL


#include "DS12864.h"


#include


#include


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;


/**********************************************************************


Subordinate module: timer test module


Function Name: Timer0_Init()


Function: Initialization


Entry parameters: None


Return parameter: None


*******************************************************************/


void Timer0_Init()


{


TCNT0 = 0x06;


TCCR0 = 0x03; //64 division


TIMSK |= (1<

}


/**********************************************************************


Subordinate module: timer test module


Function Name: Timer1_Init()


Function: Initialization


Entry parameters: None


Return parameter: None


*******************************************************************/


void Timer1_Init()


{


TCNT1H = 0x3C;


TCNT1L = 0xB0;


TCCR1A = 0x00;


TCCR1B = 0x03; //64 division


TIMSK |= (1<

}


/**********************************************************************


Subordinate module: timer test module


Function Name: Timer2_Init()


Function: Initialization


Entry parameters: None


Return parameter: None


*******************************************************************/


void Timer2_Init()


{


TCNT2 = 0x06;


TCCR2 = 0x03; //64 division


TIMSK |= (1<

}


/**********************************************************************


Subordinate module: timer test module


Function name: Timer3_Init()


Function: Initialization


Entry parameters: None


Return parameter: None


*******************************************************************/


void Timer3_Init()


{


TCNT3H = 0x3C;


TCNT3L = 0xB0;


TCCR3A = 0x00;


TCCR3B = 0x03; //64 division


ETIMSK |= (1<

}


/****************************Test function***************************/


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,"Timer 0:");


LCD12864_Dis_Str(0,1,"Timer 1:");


LCD12864_Dis_Str(0,2,"Timer 2:");


LCD12864_Dis_Str(0,3,"Timer 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);


  } 


    }


}


/**********************************************************************


Subordinate module: timer test module


Function name: SIGNAL(TIMER0_OVF_vect)


Function: Timer 0 interrupt function


Entry parameters: None


Return parameter: None


*******************************************************************/


SIGNAL(TIMER0_OVF_vect)


{


TCNT0 = 0x06;


count0++;


   


}


/**********************************************************************


Subordinate module: timer test module


Function name: SIGNAL(TIMER1_OVF_vect)


Function: Timer 1 interrupt function


Entry parameters: None


Return parameter: None


*******************************************************************/


SIGNAL (TIMER1_OVF_vect)


{


TCNT1H = 0x3C;


TCNT1L = 0xB0;


count1++;


}


/**********************************************************************


Subordinate module: timer test module


Function name: SIGNAL(TIMER2_OVF_vect)


Function: Timer 2 interrupt function


Entry parameters: None


Return parameter: None


*******************************************************************/


SIGNAL (TIMER2_OVF_vect)


{


count2++; 


}


/**********************************************************************


Subordinate module: timer test module


Function name: SIGNAL(TIMER3_OVF_vect)


Function: Timer 3 interrupt function


Entry parameters: None


Return parameter: None


*******************************************************************/


SIGNAL (TIMER3_OVF_vect)


{


TCNT3H = 0x3C;


TCNT3L = 0xB0;


count3++;


}


Keywords:ATmega128 Reference address:ATmega128 Timer Test

Previous article:ATmega128 time1 overflow interrupt. The usage of timer 1 in this mode is the same as that of 51
Next article:USART test---ATMEGA128

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号