;First test run
;Microcontroller model: PIC12F629
;Clock Frequency 4.0 MHz
;Configuration Word: 31E9h
;
;*****[ Variables ]*****
MOD_1 equ 0x55
MOD_2 equ 0x56
CODE equ 0xAA
Pin_7 equ 0
Pin_6 equ 1
Pin_5 equ 2
fileA equ 26h
fileB equ 27h
fileC equ 28h
count equ 29h
Button1 equ 30h
Button2 equ 31h
;
;===========================================================================
org 0x0000 ; Program Origin at mem location 0
bcf PCLATH,3
bcf PCLATH,4
goto L0001
org 0x0004 ; Interrupt Location
btfsc GPIO,Pin_6 ; Checks if button one was pressed
call L0004
btfsc GPIO,Pin_5 ; Checks if button two was pressed
call L0005
;L0000:
;Continue Interrupt by initializing
bcf INTCON,0 ; Clears interrupt
movlw 8 ; resets original loop counter
movwf count ; and stores, then resets original
movlw CODE ; CODE back into fileC
movwf fileC
retfie
;---------------------------------------------------------------------------
L0001:
;Initialization
clrw
bcf STATUS,RP0 ; Bank 0
clrf TMR0 ; Clear Timer 0
;
;Set GPIO
;
;
clrf GPIO ; Init GPIO
movlw 07h ; Set GP<2:0> to
movwf CMCON ; digital IO
bsf STATUS,RP0 ; Bank 1
movlw 06h ; Set GP<2:1> as inputs
movwf TRISIO ; and set GP<5:3, 0>
; as outputs
movlw 8Fh ; Turn off T0CKI,
movwf OPTION_REG ; prescaler for WDT = 1:128
;
;Set Interrupts
;
movlw 06h ; Set IOC<2:1> to
movwf IOC ; interrupt on change
; for button presses
;
movlw 88h ; Set INTCON<7,3> to
movwf INTCON ; trigger interrupts
bcf STATUS,RP0 ; Bank 0
;
;===========================================================================
L0002:
;Main Program Start
movlw CODE ; Stores the code in register W
movwf fileC ; Moves CODE to file A
bcf INTCON,7 ; Disables GIE interrupt
call L0003
bsf INTCON,7 ; Enables GIE interrupt
call L0010
goto L0002 ; Repeat forever
;
;---------------------------------------------------------------------------
L0003:
;Serial Code output
bcf STATUS,0 ; Clears the carry bit
movlw 8
movwf count
SLoop btfss fileC,0
bcf GPIO,Pin_7
btfsc fileC,0
bsf GPIO,Pin_7
rrf fileC,1
call L0006
decfsz count,1
goto SLoop
bcf GPIO,Pin_7
call L0006
return
;
;---------------------------------------------------------------------------
L0004:
;Button One Pressed
bsf Button1,0 ; Troubleshooting viewable change
; call L0006
movlw CODE
addlw MOD_1
movwf fileC
call L0003
bcf Button1,0 ; Troubleshooting viewable change
return
;
;---------------------------------------------------------------------------
L0005:
;Button Two Pressed
bsf Button2,0 ; Troubleshooting viewable change
; call L0006
movlw CODE
addlw MOD_2
movwf fileC
call L0003
bcf Button2,0 ; Troubleshooting viewable change
return
;
;---------------------------------------------------------------------------
L0006:
;Delay Function 200ms
movlw 01h ; Change to 9Eh after testing
movwf fileB
DelB movlw 01h ; Change to FDh
movwf fileA
DelA decfsz fileA,1
goto DelA
decfsz fileB,1
goto DelB
return
;
;---------------------------------------------------------------------------
L0007:
;Debouncer
;
;---------------------------------------------------------------------------
L0010:
;SLEEP function
movf GPIO,w ; Stores GPIO in w so
; changes can be compared
bcf INTCON,0 ; Clears GPIF
; sleep
return
;
;---------------------------------------------------------------------------
END