; original File = J:\pic disassembler\picdisasm106\led.hex
processor 12F675
#include <P12F675.INC>
__config 0x3194
; _CPD_OFF & _CP_OFF & _BODEN_OFF & _MCLRE_OFF & _PWRTE_OFF & _WDT_OFF
; & _INTRC_OSC_NOCLKOUT
; RAM-Variable
LRAM_0x20 equ 0x20
ISRCOUNT equ 0x21 ;count number of interrupt
LRAM_0x22 equ 0x22
LRAM_0x23 equ 0x23
LRAM_0x24 equ 0x24
LRAM_0x25 equ 0x25
LRAM_0x26 equ 0x26
CounterA equ 0x27
CounterB equ 0x28
CounterC equ 0x29
temp equ 0x2A ;general purpose
LRAM_0x50 equ 0x50
CBD1 equ 0x5C ;contact bounce delay 1
CBD2 equ 0x5D ;contact bounce delay 2
LRAM_0x5F equ 0x5F
; Program
Org 0x0000
; Reset-Vector
GOTO MAIN
Org 0x0004
; Interrupt-Vector
MOVWF LRAM_0x5F
SWAPF STATUS,W
CLRF STATUS
MOVWF LRAM_0x24
MOVF PCLATH,W ; !!Bank Program-Page-Select
MOVWF LRAM_0x25
CLRF PCLATH ; !!Bank Program-Page-Select
MOVF LRAM_0x50,W
MOVWF LRAM_0x20 ; set (0x20) = (0x50)
BTFSS PIR1,0 ; Is TMR1IF on?
GOTO LADR_0x001E ; No.
BCF PIR1,0 ; Yes, turn TMR1IF off
INCF ISRCOUNT,F ; increment counter
MOVF ISRCOUNT,W
XORLW 0x0A ; counter = 10? (old=10)
BTFSS STATUS,Z
GOTO LADR_0x001A ; No
CLRF ISRCOUNT ; clear counter to 0
BSF STATUS,RP0 ; select bank 1
BCF PIR1,0 ; turn TMR1IF off
BCF STATUS,RP0 ; select bank 0
BCF GPIO,1 ; switch off LED
LADR_0x001A ; reload back TMR1 values. every 248mS or 4Hz
MOVLW 0x0B ; b'00001011' d'011'
MOVWF TMR1H ; !!Bank!! TMR1H - Unimplemented
MOVLW 0xDB ; b'11011011' d'219'
MOVWF TMR1L ; !!Bank!! TMR1L - PCON
LADR_0x001E
MOVF LRAM_0x20,W ; move (0x20) to (0x50)
MOVWF LRAM_0x50
MOVF LRAM_0x25,W ; pclath = (0x25)
MOVWF PCLATH ; !!Bank Program-Page-Select,
SWAPF LRAM_0x24,W ;
MOVWF STATUS ;
SWAPF LRAM_0x5F,F ;
SWAPF LRAM_0x5F,W ;
RETFIE
LADR_0x0027
BCF STATUS,RP0 ; !!Bank Register-Bank(0/1)-Select
MOVF LRAM_0x23,W
MOVWF PCLATH ; !!Bank Program-Page-Select
MOVF LRAM_0x22,W
MOVWF PCL ; !!Program-Counter-Modification
RETURN
LADR_0x002D
CALL LADR_0x0027
BCF PCLATH,3 ; !!Bank Program-Page-Select
BCF PCLATH,4 ; !!Bank Program-Page-Select
MOVWF INDF
INCF FSR,F
INCF LRAM_0x22,F
BTFSC STATUS,Z
INCF LRAM_0x23,F
DECF LRAM_0x50,F
BTFSS STATUS,Z
GOTO LADR_0x002D
RETURN
ISR_init ; 0x0039 setup timer1 and ebable interrupt
MOVLW 0x35 ; b'00110101' d'053' "5"
BCF STATUS,RP0 ; !!Bank Register-Bank(0/1)-Select
MOVWF T1CON ; prescaler = 1:8, timer1 enabled
BCF PIR1,0 ; clear tmr1 flag
MOVLW 0x0B ; b'00001011' d'011' set timer1 = 248mS
MOVWF TMR1H ; !!Bank!! TMR1H - Unimplemented
MOVLW 0xDB ; b'11011011' d'219'
MOVWF TMR1L ; !!Bank!! TMR1L - PCON
BSF STATUS,RP0 ; select bank 1
BCF PIR1,0 ; clear tmr1 flag
MOVLW 0xC0 ; b'11000000' d'192'
MOVWF INTCON ; enable interrupt GIE=1, PEIE=1
RETURN
MAIN
BCF STATUS,RP0 ; select Bank 0
CLRF ISRCOUNT
CLRF LRAM_0x26
MOVLW 0x01 ; W = b'00000001'
BSF STATUS,RP0 ; select Bank 1
MOVWF GPIO ; set gp0 as input, gp1 as output
CLRF ADCON0 ; ADC is disabled
MOVLW 0x02 ; W = b'00000010'
BCF STATUS,RP0 ; select Bank 0
; MOVWF GPIO ; switch on LED.. "insert call BLINK5T here"
CALL BLINK5T ; Blink LED 5 times
BSF STATUS,RP0 ; select Bank 1
CLRF IOCB ; !!Bank!! Unimplemented - IOCB
CLRF WPU ; !!Bank!! Unimplemented - WPU
MOVLW 0x07 ; W = b'00000111' d'007'
BCF STATUS,RP0 ; select Bank 0
MOVWF CMCON ; CMCOM=7 all ports digital
CALL ISR_init ; setup timer1 and enable interrupt
SW_SCAN
BCF STATUS,RP0 ; select Bank 0
BTFSS GPIO,0 ; Is SW1 ON?
GOTO LADR_0x0073 ; No
MOVF LRAM_0x26,W ; SW1 previous state
XORLW 0x00 ;
BTFSS STATUS,Z ; Is SW1 released?
GOTO LADR_0x0073 ; No
MOVLW 0x41 ; b'01000001' d'065' "A"
MOVWF CBD1
MOVLW 0xEE ; b'11101110' d'238'
MOVWF CBD2
LADR_0x0062
DECFSZ CBD2,F
GOTO LADR_0x0062
DECFSZ CBD1,F
GOTO LADR_0x0062
NOP
BTFSS GPIO,0 ; SW1 ON?
GOTO LADR_0x0072 ; No
MOVF LRAM_0x26,W ; Yes,
XORLW 0x00 ; LAST_STATE=0?
BTFSS STATUS,Z
GOTO LADR_0x0072
BCF GPIO,1 ; switch off LED
MOVLW 0x01 ; b'00000001' d'001'
MOVWF LRAM_0x26
BSF STATUS,RP0 ; !!Bank Register-Bank(0/1)-Select
BCF PIR1,0 ; !!Bank!! PIR1 - PIE1
LADR_0x0072
GOTO LADR_0x008D
LADR_0x0073 ; SW1 still ON
BCF STATUS,RP0 ; !!Bank Register-Bank(0/1)-Select
BTFSC GPIO,0 ; SW1 released?
GOTO LADR_0x008D ; No
MOVF LRAM_0x26,W ; Yes, update SW1 previous state.
XORLW 0x01 ;
BTFSS STATUS,Z ; Was SW1 still ON?
GOTO LADR_0x008D ; No
MOVLW 0x41 ; Yes, load 0x5c & 0x5d with #0x41EE
MOVWF CBD1
MOVLW 0xEE ; b'11101110' d'238'
MOVWF CBD2
LADR_0x007E
DECFSZ CBD2,F ; delay for ??? mS
GOTO LADR_0x007E
DECFSZ CBD1,F
GOTO LADR_0x007E
NOP
BTFSC GPIO,0 ; Is SW1 OFF?
GOTO LADR_0x008D ; No
MOVF LRAM_0x26,W ; Yes,
XORLW 0x01 ; SW1 old_state=1?
BTFSS STATUS,Z
GOTO LADR_0x008D ; Yes, back to main loop
; BSF GPIO,1 ; No, switch ON LED
call BLINK5T
CLRF LRAM_0x26
BSF STATUS,RP0 ; select bank 1
BSF PIR1,0 ; set TMR1IF
LADR_0x008D
GOTO SW_SCAN
LADR_0x008E ; ERROR condition
GOTO LADR_0x008E
BLINK5T
movlw 5
movwf temp
B5TLOOP
call BLINK
decfsz temp,1
goto B5TLOOP
return
;BLINK 0.5S ON 0.5S OFF
BLINK
BSF GPIO,1 ; switch on LED
call DELAY_500MS
BCF GPIO,1 ; switch off LED
call DELAY_500MS
return
;PIC Time Delay = 0.5000020 s with Osc = 4.000000 MHz
DELAY_500MS
movlw D'3'
movwf CounterC
movlw D'140'
movwf CounterB
movlw D'83'
movwf CounterA
loop
decfsz CounterA,1
goto loop
decfsz CounterB,1
goto loop
decfsz CounterC,1
goto loop
return
End