154k views
17 votes
write an assembly program that uses the output compare function of a timer to toggle an led every second

1 Answer

3 votes

; Set up output compare function

movlw 0x3E

movwf TOCON

; Set up LED port as output

bcf TRISB, 0

; Set up timer

movlw 0xFF

movwf TMR1

movlw 0x60

movwf PR1

; Enable timer and output compare function

bsf T1CON, TMR1ON

bsf T1CON, T1OSCEN

; Main loop

loop:

; Wait for output compare event

btfss T1CON, OCF1

goto loop

; Toggle LED

bcf PORTB, 0

btfss PORTB, 0

bsf PORTB, 0

; Clear output compare flag

bcf T1CON, OCF1

; Repeat

goto loop

User Joe Hankin
by
5.4k points