{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

doc4345 - Timers Program Examples 1 Introduction This...

Info icon This preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Timers Program Examples 1. Introduction This Application Note provides to customers C and Assembler program examples for Timers. These examples are developped for the different configuration modes of this feature. 1.1 References Atmel 8051 Microcontrollers Hardware Manual 8051 Microcontrollers Application Note Rev. 4345A–8051–06/04
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
2 4345A–8051–06/04 2. C Examples 2.1 Timer 0 2.1.1 Mode 13 bits Timer Software Gated (not used) /** * @file $RCSfile: t0_m0_t_gs.c,v $ * * Copyright (c) 2004 Atmel. * * Please read file license.txt for copyright notice. * @brief This file is an example to use timer0 in mode 0. * This file can be parsed by Doxygen for automatic documentation * generation. * Put here the functional description of this file within the software * architecture of your program. * @version $Revision: 1.0.0 $ $Name: $ */ /* @section I N C L U D E S */ #include "reg_c51.h" /** * FUNCTION_PURPOSE: This file set up timer 0 in mode 0 (13 bits timer) * with a software gate. * The 13-bits register consist of all 8 bits of TH0 and the lower 5 bits * of TL0. The upper 3 bits of TL0 are undeterminate and are ignored. * FUNCTION_INPUTS: void * FUNCTION_OUTPUTS: void */ void main(void) { TMOD &= 0xF0; /* Timer 0 mode 0 with software gate */ /* GATE0=0; C/T0#=0; M10=0; M00=0; */ TH0 = 0x00; /* init values */ TL0 = 0x00; ET0=1; /* enable timer0 interrupt */ EA=1; /* enable interrupts */ TR0=1; /* timer0 run */ while(1); /* endless */ } /** * FUNCTION_PURPOSE: timer0 interrupt * FUNCTION_INPUTS: void * FUNCTION_OUTPUTS: P1.0 toggle period = 2 * 8192 cycles */ void it_timer0(void) interrupt 1 /* interrupt address is 0x000b */ { TF0 = 0; /* reset interrupt flag (already done by hardware)*/ P1_0 = ~P1_0;/* P1.0 toggle when interrupt. */ }
Image of page 2
3 4345A–8051–06/04 2.1.2 Mode 13 bits Timer Hardware Gated /** * @file $RCSfile: t0_m0_t_gh.c,v $ * * Copyright (c) 2004 Atmel. * * Please read file license.txt for copyright notice. * * @brief This file is an example to use timer0 in mode 0. * * This file can be parsed by Doxygen for automatic documentation * generation. * Put here the functional description of this file within the software * architecture of your program. * * @version $Revision: 1.0.0 $ $Name: $ */ /* @section I N C L U D E S */ #include "reg_c51.h" /** * FUNCTION_PURPOSE: This file set up timer 0 in mode 0 (13 bits timer) * with a hardware gate. * The 13-bits register consist of all 8 bits of TH0 and the lower 5 bits * of TL0. The upper 3 bits of TL0 are undeterminate and are ignored. * FUNCTION_INPUTS: P3.2(INT0)=1 : GATE Input * FUNCTION_OUTPUTS: void */ void main(void) { TMOD &= 0xF0; /* Timer 0 mode 0 with hardware gate */ TMOD |= 0x08; /* GATE0=1; C/T0#=0; M10=0; M00=0; */ TH0 = 0x00; /* init values */ TL0 = 0x00; ET0=1; /* enable timer0 interrupt */ EA=1; /* enable interrupts */ TR0=1; /* timer0 run */ while(1); /* endless */ } /** * FUNCTION_PURPOSE: timer0 interrupt * FUNCTION_INPUTS: void * FUNCTION_OUTPUTS: P1.0 toggle period = 2 * 8192 cycles */ void it_timer0(void) interrupt 1 /* interrupt address is 0x000b */ { TF0 = 0; /* reset interrupt flag (already done by hardware)*/ P1_0 = ~P1_0;/* P1.0 toggle when interrupt. */ }
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
4 4345A–8051–06/04 2.1.3 Mode 13 bits Counter Software Gated (not used) /** * @file $RCSfile: t0_m0_c_gs.c,v $ * * Copyright (c) 2004 Atmel.
Image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern