|
|
BACK
Mode 13 bits Counter Software Gated (not used)
/********* * Copyright (c) 2004 Atmel. * @brief This file is an example to use timer0 in mode 0. * Put here the functional description of this file within the software * architecture of your program. * **********/ /* @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 counter) * with a software gate. The counter count up at each negative transition. * 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.4(T0) must be controlled by an external clock * FUNCTION_OUTPUTS: void **********/ void main(void) { TMOD &= 0xF0;/* Timer 0 mode 0 counter with software gate */ TMOD |= 0x04;/* GATE0=0; C/T0#=1; 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 * P3.4(T0) period *****/ 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. */ }
Mode 13 bits Counter Hardware Gated
/**** * Copyright (c) 2004 Atmel. * @brief This file is an example to use timer0 in mode 0. * Put here the functional description of this file within the software * architecture of your program. ****/ /* @section I N C L U D E S */ #include "8051.h" /**** * FUNCTION_PURPOSE: This file set up timer 0 in mode 0 (13 bits counter) * with a hardware gate. The counter count up at each negative transition. * 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 * P3.4(T0) controlled by an external clock * FUNCTION_OUTPUTS: void ****/ void main(void) { TMOD &= 0xF0;/* Timer 0 mode 0 counter with hardware gate */ TMOD |= 0x0C;/* GATE0=1; C/T0#=1; 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 * P3.4(T0) period
***/
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. */
}
Comments,
questions and discussion about this topic
BACK |
|
Programmer
ISP
89s
Free Software
a. Edsim 51
b. MIDE-51
c. ATMEL ISP
Lesson 1:
Architecture
1.1.Memory
1.2.SFR
1.3.Addressing
1.4.Instruction
Set
1.5.Assignment
Lesson 2:
Input Output
2.1.LED
2.2.Swicht
2.3.7
Segmen
2.4.LCD
Character
2.5.ADC
2.6.DAC
2.7.Motor
Stepper
2.8.Keypad
2.9.Assignment
Lesson 3:
Timer Counter
3.1.Basic
3.2.Mode
0
3.3.Mode
1
3.4.Mode
2
3.5.Mode
3
3.5.Assignment
Lesson 4:
Serial Comm.
4.1.Basic
4.2.LED
4.3.Rotate
LED
4.2 ADC
4.3.LCD
4.4.Assignment
Lesson 5:
Interuption
5.1.Basic
5.2.Timer
5.2.External
5.3.Assignment
|