Ambient
New Member
So I have finally written my first PIC program, just wondering if you guys can take a quick look and tell me if it looks alright.
Notenly error I get is "Register in Operand not in bank 0", but I specified bank 1 already for those instructions. I am assuming it is a default warning just as a reminder.
The purpose of the program is to flash red, white, and blue LED's in sequence, with a 1M ohm pot and A/D (only lower 8 bits) determining the number of times Timer0 has to overflow before going to the next LED in the sequence. I know it may not be the most efficient program, but I just need it to work.
Thanks for any help you can provide.
List p=12f683
include P12F683.INC
Delay EQU 0x0020 ;variable RAM address
Done EQU 0x0021
red EQU b'00000001'
wht EQU b'00000010'
blue EQU b'00000100'
org 0x0000
goto INIT
NOP
NOP
NOP
org 0x0004
GOTO ISR
org 0x0005
INIT
CLRWDT
BSF STATUS,RP0 ;selects memory Bank 1
MOVLW b'01000001'
MOVWF OSCCON ;sets oscillator to 1MHz
MOVLW b'00000001'
MOVWF OPTION_REG ;enables Timer0, 1:4 PS (1.024ms/overflow)
MOVLW b'10100000'
MOVWF INTCON ;enable GIE, Timer0 interrupt
MOVLW b'00000111'
MOVWF CMCON0 ;disables comparator
BCF STATUS,RP0 ;selects memory Bank 0
CLRF GPIO
BSF STATUS,RP0 ;Bank 1 selected
MOVLW b'00010000' ;GP4 analog input enable, FOSC/2
MOVWF ANSEL
MOVLW b'00011000' ;GP0,1,2,5 as outputs, GP3,4 as inputs.
MOVWF TRISIO ;GP3,5 are for future add-ons.
MOVLW b'10001101' ;right justify, VDD ref, AN0, ADON
MOVWF ADCON0
BCF STATUS,RP0 ;Bank 0 selected
START
CLRWDT
CLRF TMR0
BSF ADCON0,GO ;get A/D data for "Delay" variable
BTFSC ADCON0,GO
GOTO $-1
MOVF ADRESL,W
MOVWF Delay
BCF ADCON0,ADON ;disables A/D till next use.
;==================RED=========================
RedON
MOVLW red
MOVWF GPIO ;turns red LED on.
BTFSC Done,h'0001';tests for decrementing complete
GOTO WhtON ;executed when complete
GOTO $-2 ;executed when not complete
;==================WHITE========================
WhtON
MOVLW wht
MOVWF GPIO ;turns white LED on.
BTFSC Done,h'0001'
GOTO BlueON
GOTO $-2
;==================BLUE=========================
BlueON
MOVLW blue
MOVWF GPIO ;turns blue LED on.
BTFSC Done,h'0001'
GOTO RedLoop
GOTO $-2
;*********************ISR************************
ISR
CLRWDT
BCF INTCON,T0IE
DECFSZ Delay,F
RETFIE ;If not done decrementing, returns to current loop
MOVLW h'0001'
MOVWF Done ;done decrementing, places h'1' in "Done" register
RETFIE
END
Notenly error I get is "Register in Operand not in bank 0", but I specified bank 1 already for those instructions. I am assuming it is a default warning just as a reminder.
The purpose of the program is to flash red, white, and blue LED's in sequence, with a 1M ohm pot and A/D (only lower 8 bits) determining the number of times Timer0 has to overflow before going to the next LED in the sequence. I know it may not be the most efficient program, but I just need it to work.
Thanks for any help you can provide.
List p=12f683
include P12F683.INC
Delay EQU 0x0020 ;variable RAM address
Done EQU 0x0021
red EQU b'00000001'
wht EQU b'00000010'
blue EQU b'00000100'
org 0x0000
goto INIT
NOP
NOP
NOP
org 0x0004
GOTO ISR
org 0x0005
INIT
CLRWDT
BSF STATUS,RP0 ;selects memory Bank 1
MOVLW b'01000001'
MOVWF OSCCON ;sets oscillator to 1MHz
MOVLW b'00000001'
MOVWF OPTION_REG ;enables Timer0, 1:4 PS (1.024ms/overflow)
MOVLW b'10100000'
MOVWF INTCON ;enable GIE, Timer0 interrupt
MOVLW b'00000111'
MOVWF CMCON0 ;disables comparator
BCF STATUS,RP0 ;selects memory Bank 0
CLRF GPIO
BSF STATUS,RP0 ;Bank 1 selected
MOVLW b'00010000' ;GP4 analog input enable, FOSC/2
MOVWF ANSEL
MOVLW b'00011000' ;GP0,1,2,5 as outputs, GP3,4 as inputs.
MOVWF TRISIO ;GP3,5 are for future add-ons.
MOVLW b'10001101' ;right justify, VDD ref, AN0, ADON
MOVWF ADCON0
BCF STATUS,RP0 ;Bank 0 selected
START
CLRWDT
CLRF TMR0
BSF ADCON0,GO ;get A/D data for "Delay" variable
BTFSC ADCON0,GO
GOTO $-1
MOVF ADRESL,W
MOVWF Delay
BCF ADCON0,ADON ;disables A/D till next use.
;==================RED=========================
RedON
MOVLW red
MOVWF GPIO ;turns red LED on.
BTFSC Done,h'0001';tests for decrementing complete
GOTO WhtON ;executed when complete
GOTO $-2 ;executed when not complete
;==================WHITE========================
WhtON
MOVLW wht
MOVWF GPIO ;turns white LED on.
BTFSC Done,h'0001'
GOTO BlueON
GOTO $-2
;==================BLUE=========================
BlueON
MOVLW blue
MOVWF GPIO ;turns blue LED on.
BTFSC Done,h'0001'
GOTO RedLoop
GOTO $-2
;*********************ISR************************
ISR
CLRWDT
BCF INTCON,T0IE
DECFSZ Delay,F
RETFIE ;If not done decrementing, returns to current loop
MOVLW h'0001'
MOVWF Done ;done decrementing, places h'1' in "Done" register
RETFIE
END