blueroomelectronics
Well-Known Member
I've moved a couple things around and added OSCCON
Code:
list p=18F1320
include <p18F1320.inc>
CONFIG OSC = INTIO2, WDT = OFF, LVP = OFF
cblock 0x00
Count
advtemp
L2T
endc
org 0x00 ; reset vector
LED macro x,y ;MACRO LED <PORTA>, <TRISA>
movlw x
movwf LATA ;LATA = x
movlw y
movwf TRISA ;TRISA = y
call Delay ;call the Delay subroutine
endm ;end macro
goto Main
org 0x08 ; ISR Low vector
goto ISR
org 0x18 ; ISR Low vector
goto ISR
Main movlw 0x72 ; 8MHz clock select
movwf OSCCON
CLRF PORTB ;Initialize PORTB by clearing output data latches
CLRF LATB ;Alternate method to clear output data latches
MOVLW 0x01 ;A/D Config
MOVWF ADCON1 ;ADCON1: All analog except AN0
MOVLW b'00000010' ;TRISB Config
MOVWF TRISB ;Set RB1 as input RB<7:2> and RB0 as outputs
MOVLW b'11001000' ;INTCON Config
MOVWF INTCON ;Enable GIE/GIEH, PEIE/GIEL, RBIE Disable rest
MOVLW b'11110101' ;INTCON2 Config
MOVWF INTCON2 ;Enable RBPU, Rising Edge Interrupts, High Priority
MOVLW b'11001000' ;INTCON3 Config
MOVWF INTCON3 ;High Priority, Enable INT1 and Clear Flags
movlw b'00010101' ;enable A/D, AN5
movwf ADCON0
StartUp bsf ADCON0,GO ;Start A/D conversion
adloop btfsc ADCON0,DONE ;Check if done. If not goto adloop else skip loop
goto adloop
MOVLW 0xEE ;Button Pressed Preset
CPFSLT ADRESH ;If ADRESH < Skip the goto else start over
goto StartUp ;because no button pressed
Check1 MOVLW 0xBF ;4th button Preset
CPFSGT ADRESH ;If ADRESH > BFH then this button was pressed
goto Check2 ;If not then it wasnt pressed skip to next check
MOVLW 0x04
MOVWF L2T ;Set L2T to 0x04 (MY LOOP COUNTER)
goto LEDXT ;Goto LEDXT which is the Light X Times where x = 4h for this button
Check2 MOVLW 0x7F ;3rd button preset
CPFSGT ADRESH ;If ADRESH > 7FH then this button was pressed
goto Check3 ;If not then it wasnt pressed skip to next check
MOVLW 0x03
MOVWF L2T ;Set L2T to 0x03 (MY LOOP COUNTER)
goto LEDXT ;Goto LEDXT which is the Light X Times where x = 3h for th
Check3 MOVLW 0x3F ;Same as others
CPFSGT ADRESH
goto Check4
MOVLW 0x02
MOVWF L2T
goto LEDXT
Check4 MOVLW 0x00 ;Same
CPFSEQ ADRESH ;If ADRESH = 0 then goto LED1T because button 1 was hit
goto StartUp ;if not then goto startup
goto LED1T ;LED 1 Time
LED1T
call ScrollMe ;Scroll LEDs 1 time
goto StartUp ;Goto Startup
LEDXT ;LEDXT loop
call ScrollMe ;Scroll 1 time
DECFSZ L2T ;Decrement L2T and skip the next line if 0
goto LEDXT ;goto ledxt loop
goto StartUp ;Goto StartUp
Delay decfsz Count,f ;decrement Count and skip when zero
goto $-2 ;not zero? repeat
return
ScrollMe
LED b'00000001',b'10111110' ; Light LED 1
LED b'01000000',b'10111110' ; Light LED 2
LED b'01000000',b'00111111' ; Light LED 3
LED b'10000000',b'00111111' ; Light LED 4
LED b'10000000',b'01111110' ; Light LED 5
LED b'00000001',b'01111110' ; Light LED 6
return ; Return from where called
ISR BCF INTCON3, 0 ; Clear INT1
BCF INTCON, 0 ; Clear RBIF: RB Port Change Interrupt Flag bit
LED b'00000001',b'01111110' ; Light LED 6
call Delay ; 2 delays
call Delay
retfie ; Return from where called
END