Timer 0: Laboratory Activity 3
Timer 0: Laboratory Activity 3
TIMER 0
Objectives:
At the end of the laboratory activity, the students are expected to:
To be familiar with different factors that needed to configure the timer 0
To configure the prescale to produce a TMR0 intrude on that will augment the counter
factor for various periods by expecting an oscillator of recurrence 4MHz.
Make or change the example assembly program in accordance to the problem.
Theory
The Timer0 module is an 8-bit timer/counter that is included with all 8-bit PIC® MCU
devices. The Timer0 is more than just a timer. It has all the following features:
8-bit timer/counter register (TMR0)
8-bit prescaler (independent of Watchdog Timer)
Programmable internal or external clock source
Programmable external clock edge selection
[ CITATION Tim20 \l 1033 ]
Fosc = 4Mhz
Where prescale:
Procedure
1. Open the activity 3 - pdf file. Read and understand the concepts of the code
2. Look for PIC16F84A datasheet. This will serve as reference for the laboratory proper
3. Open MPLAB X IDE v5.35. Press Ctrl + Shift + N to open a new window. Choose
Microchip Embedded and Standalone Project and click Next >.
4. Pick the device PIC16F84A by choosing from the list on the pull down menu. You can
also pick the device by typing the device name. Continue by clicking Next >.
5. On the next window select the “Simulator” as the tool. Click Next >
6. Use MPASM as compiler
7. Name your project with an appropriate project name.
8. The project window is located at the left side of the screen. Look for the Source Files
under the Project Window. Right click the Source Files, go to New, and click Other
9. A new window will open. Choose Assembler then pick Assemblyfile.asm. Click Next
to continue. 10. On the next window, type the filename for the ASM file preferred
11. The .asm file should now be present in the Project Navigation windows under the
Source Files. Moreover, it should be automatically opened in the Editor window.
12. Copy the code from “Activity 3 – Timer0”. Modify the code according to the
requirements needed in problems 1a, 1b, and 2.
13. Do the following:
Problems:
1. Configure the prescale to generate a TMR0 interrupt that will increment the
counter variable for each of the following periods exactly assuming using an
oscillator of 4 MHz.
a. 8.192 ms
b. 1.024 ms
2. Create or modify the example assembly program above that will increment to
exactly 1 second.
1a
#include <p16f84a.inc>
__config(_HS_OSC & _PWRTE_OFF & _CP_OFF & _WDT_OFF)
cblock 0x0C
Display
endc
ORG 0
BSF STATUS,RP0
MOVLW b'00000100' ;Timer0 is configured. Sourced from the
;Processor clock
MOVWF OPTION_REG ;Maximum Prescaler
CLRF TRISB ;Make PORTB all output
CLRF Display
BCF STATUS,RP0 ;bank0
movlw 0x00 ;TMR0=0
movwf TMR0
ForeverLoop
BTFSS INTCON,T0IF ;wait here until Timer0 rolls over
GOTO ForeverLoop
BCF INTCON,T0IF ;flag must be cleared within the software
movlw 0x00
movwf TMR0
INCF Display,f ;increment display variable
MOVF Display,w ;send to the LEDs
MOVWF PORTB
GOTO ForeverLoop
END
1b
;John Jerome Colico GE3 Activity 3
;Number 1B
;Prescale = 1:4 ;Tout = 1.024mS ; Fout = 976.563 Hz
#include <p16f84a.inc>
__config(_HS_OSC & _PWRTE_OFF & _CP_OFF & _WDT_OFF)
cblock 0x0C
Display
endc
ORG 0
BSF STATUS,RP0
MOVLW b'00000001' ;configure Timer0. Sourced from the Processor clock
MOVWF OPTION_REG ;Maximum Prescaler
CLRF TRISB ;Make PORTB all output
CLRF Display
BCF STATUS,RP0
MOVLW 0x00
MOVWF TMR0
ForeverLoop
BTFSS INTCON,T0IF ;wait here until Timer0 rolls over
GOTO ForeverLoop
BCF INTCON,T0IF ;flag must be cleared in software
MOVLW 0x00
MOVWF TMR0
INCF Display,f ;increment display variable
MOVF Display,w ;send to the LEDs
MOVWF PORTB
GOTO ForeverLoop
END
2.
In the activity it was well established by using the formula to solve the problem. By using
algebra to know which value is well suited to obtain the needed results. The prescale present in
the formula can be seen in the last 3 bits (000 up to 111) ranging from 2 to 256 This is important
because the device should know how to count within a specified scenario. In which it is critical
for the device to have an accurate output.
Conclusion
The activity conducted were successfully executed and met the requirements needed. It showed
the ability of PIC16F84A in terms of timing application in which accurate and critical timing is
important. The use of datasheet is important since all of the technical specification needed in this
activity is well documented in the datasheet. Furthermore, the formula used is critical in these
activity. In which proper configuration of prescale and TMRO is important in the timing
application as well as the knowledge about the PIC16F84A specifications.