Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

PIC16F877A - TIMER0 MODULE

(USING TIMER MODE)

8 bit timer (00h-FFh) . Registers associated with TIMER0 : option_reg , intcon , tmr0

1. Option_reg Register:

RBPU INTEDG T0CS T0SE PSA PS2 PS1 PS0

TMR0 Clock Source Select bit 1 = RA4/T0CKI (Counter Mode) 0 =Fosc/4 (Timer Mode)
bit 5 T0CS
1 = high-to-low transition on 0 = low-to-high transition
bit 4 T0SE TMR0 Source Edge Select bit
T0CKI pin on T0CKI pin
1 = Prescaler is assigned to the 0 = Prescaler is assigned to
bit 3 PSA Prescaler Assignment bit
WDT the Timer0 module
bit 2-0 PS2:PS0 Prescaler Rate Select bits

2. Intcon Register:

GIE PEIE TMR0IE INTE RBIE TMR0IF INTF RBIF

bit 7 GIE Global Interrupt Enable bit 1 = Enables all interrupts 0 = Disables all interrupts
TMR0 Overflow Interrupt Enable bit 1 = TMR0 interrupt enabled 0 = TMR0 interrupt
bit 5 TMR0IE
disabled
TMR0 Overflow Interrupt Flag bit 1 = TMR0 register has 0 = TMR0 register did not
bit 2 TMR0IF overflowed(must be cleared) overflow
** Interrupt on overflow from FFh to 00h.
;****************************************************; decfsz tmr0ctr_1,f
; timer0_LED.asm goto loop_1s
; 10s return
;**************************************************** ;************************************************
list p=PIC16F877A delay_TMR0_100ms:
include p16f877A.inc ;10ms x 10 = 100ms
__config _hs_osc & _wdt_off & _pwrte_on & _lvp_off movlw .10
errorlevel -302 ;Suppress bank warning movwf tmr0ctr_0
;**************** Label Definition ******************** loop_100ms:
cblock h'20' call delay_TMR0_10ms
tmr0ctr decfsz tmr0ctr_0,f
reference goto loop_100ms
tmr0ctr_0 return
tmr0ctr_1 ;*************************************************
tmr0ctr_2 delay_TMR0_10ms:
endc ;1000 x 0,2us x 32 = 9984 us = 10000us =10ms
;**************** Program Start *********************** movlw .11
org 0 ;Reset Vector movwf tmr0ctr
goto main clrf reference
org 4 ;Interrupt Vector0 clrf tmr0
goto int loop_10ms:
;**************** Initial Process ********************* movf tmr0,w
main: subwf reference,w
call init_gpio btfsc status,c
call init_tmr0 goto loop_10ms
led_flash: decfsz tmr0ctr,f
bsf portb,0 goto $+2
call delay_TMR0_10s return
bcf a portb,0 movlw .100
call delay_TMR0_10s addwf reference,f
goto led_flash goto loop_10ms
;************************************************* ;*************** Interruption Process *****************
init_gpio: int:
banksel trisb retfie
clrf trisb end
return
;************************************************
init_tmr0:
movlw 0x04
movwf option_reg
;T0CS=0 INTERNAL CLOCK , PSA=0 , PS2:PS0=100 1:32 RATE
banksel portb
clrf portb
;portb<0> led
banksel intcon
bsf intcon,7
;GIE=1 INTERUPT ENABLE
bsf intcon,5
;TMR0IE=1 OVERFLOW INTERRUPT ENABLE
bcf intcon,2
;TMR0IF=0 OVERFLOE INTERRUPT FLAG
banksel tmr0
return
;*************************************************
delay_TMR0_10s:
;1s x 10 = 10s
movlw .10
movwf tmr0ctr_2
loop_10s:
call delay_TMR0_1s
decfsz tmr0ctr_2,f
goto loop_10s
return
;*************************************************
delay_TMR0_1s:
;100ms x 10 = 1s
movlw .10
movwf tmr0ctr_1
loop_1s:
call delay_TMR0_100ms

You might also like