Robots - Notes -
IR
Remote Control
prog04.asm
;**********************************************************************
; Notes: Toggle Pin 4 on Timer1 overflow vis ISR *
; Toggle Pin 5 in main loop *
;**********************************************************************
list p=12F683 ; list directive to define processor
#include <p12F683.inc> ; processor specific variable definitions
errorlevel -302 ; suppress message 302 from list file
__CONFIG _FCMEN_ON & _IESO_OFF & _CP_OFF & _CPD_OFF & _BOD_OFF & _MCLRE_OFF
& _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT
; '__CONFIG' directive is used to embed configuration word within .asm file.
; The lables following the directive are located in the respective .inc
file.
; See data sheet for additional information on configuration word settings.
;***** VARIABLE DEFINITIONS
w_temp EQU 0x70 ; variable used for context saving
status_temp EQU 0x71 ; variable used for context saving
counter EQU 0x20
;**********************************************************************
ORG 0x000 ; processor reset vector
goto main ; go to beginning of program
ORG 0x004 ; interrupt vector location
movwf w_temp ; save off current W register contents
movf STATUS,w ; move status register into W register
movwf status_temp ; save off contents of STATUS register
; isr code can go here or be located as a call subroutine elsewhere
bcf STATUS, RP0 ; bank 0
btfsc PIR1, TMR1IF ; Timer1 overflow interrupt?
goto t1_int ; yes goto t1_int
goto end_isr
t1_int ; Routine when Timer1 overflows
btfsc GPIO, 4 ; test GP4 skip next if 0
goto clearbit4 ; else goto clearbit
bsf GPIO, 4 ; set GP4 to 1
goto endtoggle ; goto loop
clearbit4
bcf GPIO, 4 ; set GP4 to 0
endtoggle
bcf PIR1, TMR1IF ; clear the timer1 overflow interrupt flag
goto end_isr ; ready to leave ISR (for this request)
end_isr
movf status_temp,w ; retrieve copy of STATUS register
movwf STATUS ; restore pre-isr STATUS register contents
swapf w_temp,f
swapf w_temp,w ; restore pre-isr W register contents
retfie ; return from interrupt
main
; remaining code goes here
; initialize timer1
clrf T1CON ; stop Timer1, Internal Clock Source,
; T1 oscillator disabled, prescaler 1:1
clrf TMR1H ; set timer 1 high byte = 0
clrf TMR1L ; set timer 1 low byte = 0
bcf PIR1, TMR1IF ; clear timer1 overflow interrupt flag
bsf STATUS,RP0 ; bank 1
bsf PIE1, TMR1IE ; enable timer1 overflow interrupt
bcf STATUS,RP0 ; bank 0
bsf INTCON, PEIE ; enable peripherals interrupts
bsf INTCON, GIE ; enable global interrupts
bsf T1CON, TMR1ON ; timer1 on
; initialize Pin 5 and 4 as output
; pin 5 toggles by main loop
; pin 4 toggles by timer1 overflow ISR only
bcf STATUS,RP0 ; bank 0
clrf GPIO ; init GPIO
movlw 07h ; set GP<2:0> to
movwf CMCON0 ; digital I/O
bsf STATUS,RP0 ; bank 1
clrf ANSEL ; digital I/O
movlw 0Ch ; set GP<3:2> as input
movwf TRISIO ; set GP<5:4,1:0> as output
bcf STATUS,RP0 ; bank 0
loop
incfsz counter, f ; increment counter and skip next if 0
goto loop ; else goto loop
btfsc GPIO, 5 ; test GP5skip next if 0
goto clearbit ; else goto clearbit
bsf GPIO, 5 ; set GP5 to 1
goto loop ; goto loop
clearbit
bcf GPIO, 5 ; set GP5 to 0
goto loop ; goto loop
; initialize eeprom locations
ORG 0x2100
DE 0x00, 0x01, 0x02, 0x03
END ; directive 'end of program'
If you have any questions or comments about this page please email me at: debots_replacethis_dinkdaze.org with at sign.
|