Jared Post
Jared Post

Reputation: 21

PIC 18F1220 Tring to Flash a Couple LEDs but Cannot

I'm trying to get a PIC 18F1200 to flash a couple of LEDs and it should not be difficult. I've been programming PICs with assembly for over two years, both 16F and 18F but this is the first time with the 18F1220. One LED is on PortA,7 and the other is on PortB,3. I think I'm turning off the A/D module as well as the interrupts. I've turned of MCLR and I'm using the onboard oscillator at 8 MHz. The datasheets are my bible and I have been looking through it but I only end up getting a flashing LED on RB3 that is not turning on and off every second but flashing on and off irregularly. Can anyone point me in the right direction. I must be missing something. Thanks for any replies, I'll gladly test out any suggestions.

Here is my current code:

;******************************************************************************
LIST P=18F1220      ;directive to define processor
#Include <P18F1220.INC> ;processor specific variable definitions
; Compiler Directives:
Radix Dec
;******************************************************************************
; Configuration Bits:
CONFIG  OSC = INTIO2    ; Internal RC, OSC1 as RA7, OSC2 as RA6
CONFIG  FSCM = OFF      ; Fail Safe Clock Monitor Disabled
CONFIG  IESO = OFF      ; Internal External Switch Over Mode Disabled
CONFIG  PWRT = OFF      ; Power-Up Timer Disabled
CONFIG  BOR = OFF       ; Brown-out Reset disabled in hardware and software
CONFIG  BORV = 27       ; Brown-out Voltage bits
CONFIG  WDT = OFF       ; HW Disabled - SW Controlled
CONFIG  WDTPS = 1       ; Watchdog Timer Postscale Select bits
CONFIG  MCLRE = OFF     ; MCLR Disabled
CONFIG  STVR = OFF      ; Stack full/underflow will not cause Reset
CONFIG  LVP = OFF       ; Single-Supply ICSP disabled
CONFIG  DEBUG = OFF     ; Background debugger disabled, RB6 and RB7 configured as general purpose I/O pins
CONFIG  CP0 = OFF       ; Block 0 (000800-001FFFh) not code-protected
CONFIG  CP1 = OFF       ; Block 1 (002000-003FFFh) not code-protected
CONFIG  CPB = OFF       ; Boot block (000000-0007FFh) not code-protected
CONFIG  CPD = OFF       ; Data EEPROM not code-protected
CONFIG  WRT0 = OFF      ; Block 0 (000800-001FFFh) not write-protected
CONFIG  WRT1 = OFF      ; Block 1 (002000-003FFFh) not write-protected
CONFIG  WRTB = OFF      ; Configuration registers (300000-3000FFh) not write-protected
CONFIG  WRTC = OFF      ; Boot block (000000-0007FFh) not write-protected
CONFIG  WRTD = OFF      ; Data EEPROM not write-protected
CONFIG  EBTR0 = OFF     ; Block 0 (000800-001FFFh) not protected from table reads executed in other blocks
CONFIG  EBTR1 = OFF     ; Block 1 (002000-003FFFh) not protected from table reads executed in other blocks
CONFIG  EBTRB = OFF     ; Boot block (000000-0007FFh) not protected from table reads executed in other blocks
;******************************************************************************
; Variable definitions
CBLOCK  0x080
Count1
CountA
CountB
ENDC
;******************************************************************************
; Reset vector
ORG     0x0000
GOTO    Main                ; Go to Start of Main Code
;******************************************************************************
; High priority interrupt vector
ORG     0x0008
BRA     HighInt             ; Go to High Priority Interrupt Routine
;******************************************************************************
; Low Priority Interrupt Vector and Routine
ORG     0x0018
BRA     LowInt
;******************************************************************************
; High Priority Interrupt Routine
HighInt:
MOVLW   0x00
MOVWF   EEADR
BCF     EECON1,EEPGD    ; Point to DATA memory
BCF     EECON1,CFGS     ; Access EEPROM
BSF     EECON1,RD       ; EEPROM Read
INCF    EEDATA,F
BCF     EECON1,EEPGD    ; Point to DATA memory
BCF     EECON1,CFGS     ; Access EEPROM
BSF     EECON1,WREN     ; Enable writes
MOVLW   55h             ; REQUIRED SEQUENCE
MOVWF   EECON2          ; | Write 55h
MOVLW   0AAh            ; |
MOVWF   EECON2          ; | Write 0AAh
BSF     EECON1,WR       ; ----- Set WR bit to begin write
BCF     EECON1,WREN     ; Disable writes on write complete (EEIF set)
BTFSS   PIR2,EEIF       ; Check to See if Interrupt Flag Has Been Set
GOTO    $-2             ; Not Set (Write In Progress), Go Back & Check Again
BCF     PIR2,EEIF       ; Clear EEIF Interrupt Flag
RETFIE  FAST
LowInt:
MOVLW   0x01
MOVWF   EEADR
BCF     EECON1,EEPGD    ; Point to DATA memory
BCF     EECON1,CFGS     ; Access EEPROM
BSF     EECON1,RD       ; EEPROM Read
INCF    EEDATA,F
BCF     EECON1,EEPGD    ; Point to DATA memory
BCF     EECON1,CFGS     ; Access EEPROM
BSF     EECON1,WREN     ; Enable writes
MOVLW   55h             ; REQUIRED SEQUENCE
MOVWF   EECON2          ; | Write 55h
MOVLW   0AAh            ; |
MOVWF   EECON2          ; | Write 0AAh
BSF     EECON1,WR       ; ----- Set WR bit to begin write
BCF     EECON1,WREN     ; Disable writes on write complete (EEIF set)
BTFSS   PIR2,EEIF       ; Check to See if Interrupt Flag Has Been Set
GOTO    $-2             ; Not Set (Write In Progress), Go Back & Check Again
BCF     PIR2,EEIF       ; Clear EEIF Interrupt Flag
RETIE
;******************************************************************************
; Start of Main Program
Main:
CALL        INITIALIZE
FlashLED:
BSF         LATB,3          ; Turn On LED
BCF         LATA,7  
CALL        Delay1S         ; Wait 1 Second
BCF         LATB,3          ; Turn Off LED
BSF         LATA,7
CALL        Delay1S         ; Wait 1 Second
GOTO        FlashLED
;******************************************************************************
INITIALIZE:
MOVLW       0x72        ; SET INTERNAL OSCILLATOR FREQUENCY
MOVWF       OSCCON      ; INITIALIZE
MOVLW       0x00        ;
MOVWF       INTCON      ; Disable Interrupts
MOVLW       0x80        ; |
MOVWF       INTCON2     ; |
MOVLW       0x00        ; |
MOVWF       INTCON3     ; |
MOVWF       PIE1        ; |
MOVWF       PIE2        ; |
MOVWF       RCON        ; Disables Interrupts
MOVLW       0X00        ; SET UP PORTB TO BE ALL OUTPUTS   
MOVWF       TRISB       ; INITIALIZE
CLRF        PORTB       ; CLEAR PORTB OUTPUTS
MOVLW       0X00        ; SET UP PORTA TO BE ALL OUTPUTS
MOVWF       TRISA       ; INITIALIZE
CLRF        PORTA       ; CLEAR PORTA
MOVLW       0X00        ; SET UP ADC
MOVWF       ADCON0      ; ENABLE ADC, BUT DO NOT START CONVERSION
MOVLW       0XFF        ; SET UP ADC
MOVWF       ADCON1      ; AN0/RA0=ANALOG INPUT
CALL        Delay50
RETURN
; ===== MilliSecond Delay Subroutines ===== (48 MHz Clock)
Delay255
MOVLW   0xFF            ; Delay 255 MilliSeconds
GOTO    D0
Delay100
MOVLW   0x64            ; Delay 100 MilliSeconds
GOTO    D0
Delay50
MOVLW   0x32            ; Delay 50 MilliSeconds
GOTO    D0
Delay20
MOVLW   0x14            ; Delay 20 Milliseconds
GOTO    D0
Delay5
MOVLW   0x05            ; Delay 5.000 MilliSeconds
D0  MOVWF   Count1
Delay1
MOVLW   0x5F            ; Delay 1.000 MilliSeconds
MOVWF   CountA
MOVLW   0x0A
MOVWF   CountB
MSDelay
DECFSZ  CountA,F
GOTO        SKP
DECFSZ  CountB,F
SKP GOTO        MSDelay
DECFSZ  Count1,F
GOTO        Delay1
RETURN
; ===== 1 Second Delay Subroutine =====
Delay1S                 ; 11,999,993 Cycles
MOVLW   0x6C
MOVWF   Count1
MOVLW   0x29
MOVWF   CountA
MOVLW   0x1B
MOVWF   CountB
Delay1S_Sub
DECFSZ  Count1,F
GOTO        SKP1
DECFSZ  CountA,F
SKP1    GOTO        SKP2
DECFSZ  CountB,F
SKP2    GOTO        Delay1S_Sub
NOP                 ; 3 Cycles
NOP
NOP
RETURN              ; 4 Cycles (Including Call)
; ===== 100 MicroSecond Delay Subroutine =====
Delay100uS                  ; 1,193 Cycles
MOVLW   0xEE
MOVWF   Count1
MOVLW   0x01
MOVWF   CountA
Delay_100uS_Sub
DECFSZ  Count1,F
GOTO        SKP3
DECFSZ  CountA,F
SKP3    GOTO        Delay_100uS_Sub
NOP                     ; 3 Cycles
NOP
NOP
RETURN                  ; 4 Cycles (Including Call)

;******************************************************************************
END                         ;End of Program

The EEPROM read and write sequences were added to see if one of the interrupts were being triggered. Looking at the EEPROM contents suggests that this is not what is happening.

Thanks for looking!

Upvotes: 2

Views: 505

Answers (1)

GJ.
GJ.

Reputation: 10937

You have a typo!

Your LowInt interrupt doesn't finish with RETFIE instruction, it finish with label RETIE instead.

Upvotes: 2

Related Questions