Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Objective:
To learn how to configure Timer 0 as counter.
To utilize PROTEUS to construct a simple basic counter circuit.
Timer 0 can be configured as an 8-bit or 16-bit timer or counter. The T0CON register controls
the operation of Timer0. When the clock source is the instruction cycle clock, it operates as a
timer. When the clock source is the T0CKI pin, it operates as a counter.
7 6 5 4 3 2 1 0
value after TMR0ON T08BIT T0CS T0SE PSA T0PS2 T0PS1 T0PS0
reset 1 1 1 1 1 1 1 1
TMR0ON: Timer0 on/off control bit
0 = stops Timer0
1 = Enables Timer0
T08BIT: Timer0 8-bit/16-bit control bit
0 = Timer0 is configured as a 16-bit timer
1 = Timer0 is configured as an 8-bit timer
T0CS: Timer0 clock source select
0 = Instruction cycle clock
1 = Transition on T0CKI pin
T0SE: Timer0 source edge select bit
0 = Increment on falling edge transition on T0CKI pin
1 = Increment on rising edge transition on T0CKI pin
PSA: Timer0 prescaler assignment bit
0 = Timer0 prescaler is assigned . Timer0 clock input comes from prescaler output.
1 = Timer0 prescaler is not assigned. Timer0 clock input bypasses prescaler.
T0PS2:T0PS0: Timer0 prescaler select bits
000 = 1:2 prescaler value
001 = 1:4 prescaler value
010 = 1:8 prescaler value
011 = 1:16 prescaler value
100 = 1:32 prescaler value
101 = 1:64 prescaler value
110 = 1:128 prescaler value
111 = 1:256 prescaler value
EEEB371 E4-1
To configure Timer 0 as counter, the following configuration need to be made on T0CON
register:
Procedure
TMR0 Counter
1. Construct the simple counter circuit below using PROTEUS. Your instructor will verify
your circuit.
EEEB371 E4-2
2. The external impulse supplied through the switch at RA4 will be recorded in TMR0L
register and the value of the current impulse count will be displayed at the LEDs.
3. Write the source code in MikroC Compiler, build it and download the Hex file into the
microcontroller and simulate the PROTEUS program. Print out the source file and write
down your observation.
void main()
{
ADCON1 = 0x0F; // Configure all ports with analog function as digital
CMCON = 7; // Disable comparators
do
{
Display_Freq(TMR0L); //Pass the current value in TMR0L reg to Display_Freq function
} while(1); // Infinite loop
4. Task: You are required to construct an electronic counter whereby the current count value
will be displayed on a 7-segment display. Your counter should be able to display the
numbers 0 9. Implement a reset switch so that you may reset the number to 0 anytime
you wish. Use Proteus to build your electronic counter circuit. Build the source code
using C language, download and run the application. Later on, write the same program
using assembly language and verify with Proteus. Write down your observation and
print out the source file with proper comments.
5. Exit from MPLAB, MikroC and PROTEUS. Shutdown your PC and rearrange your
workstation before you leave.
EEEB371 E4-3