Issue w/ Conversion to PIC18F26K22

Thread Starter

Peaches41

Joined Dec 15, 2016
70
Thank you for taking the time to view my post.
I have recently started to use a PIC18LF26k22 as an upgrade from a PIC16F690. I am programming in assembly. I have checked all my initialization to make sure all is correct. I have read the datasheet and understand the mapping of the data memory, sfr, and the program allocation in the PIC18LF26k22. I also familiarized myself with the access bank and the use of the BSR. All of my data memory is held in bank zero so I am not using the BSR and just using access bank accordingly in my programming. I have done the "Hello World" to verify all is correct to that point. I then started to convert my program for the 16F690 over to the PIC18LF26k22 which is for control of an LCD which I know is proven for the PIC16F690. In single blocking through the code after the conversion the code runs fine, goes from before the call, runs the call for the correct time, and returns to a breakpoint set right after the call. The call is for a one second delay which is at 8mhz. As you can see in my code below, I have set a led to light at the point where I am having an issue, I use the led to signal to me that the code is correct at that point in code and not getting lost or reset. I started with the led before the call and tested it to check code, and it functioned fine, I then placed the led at the beginning in the subroutine and all was fine. I stepped the led through the code to where you see it in the code. At that point it does not light stating to me that the code is not functioning correctly here.
I would like some guidance on where I am wrong in my efforts to convert this program that functions fine w/ a PIC16F690. I have replaced the delay+1 with another named variable that was listed w/in my cblock to see if having not using the upper half of the delay variable made any difference, but found none in my testing. I am not sure what to do now and was hoping for assistance from some more qualifies eyes and minds.
Thankful for your help,

Peaches
 

Attachments

AlbertHall

Joined Jun 4, 2014
11,587
The first suspect here is the watchdog timer, especially as the problem occurs during a long delay with no CLRWDT instructions. The WDT functions differently between the two chips.

Please post the complete code.
 

Thread Starter

Peaches41

Joined Dec 15, 2016
70
Thank you for your response to my post. I do not think it is a wdt issue as I do not have it enabled in my config. settings as shown below.

Code:
;Setup CONFIG1H
  CONFIG FOSC = INTIO67, PLLCFG = OFF, PRICLKEN = On, FCMEN = OFF, IESO = OFF
  ;Setup CONFIG2L
  CONFIG PWRTEN = OFF, BOREN = OFF, BORV = 190
  ;Setup CONFIG2H
  CONFIG WDTEN = OFF, WDTPS = 1
  ;Setup CONFIG3H
  CONFIG MCLRE = INTMCLR, CCP2MX = PORTB3, CCP3MX = PORTB5, HFOFST = OFF, T3CMX = PORTB5, P2BMX = PORTB5, PBADEN = OFF
  ;Setup CONFIG4L
  CONFIG STVREN = OFF, LVP = OFF, XINST = OFF
  ;Setup CONFIG5L
  CONFIG CP0 = OFF, CP1 = OFF, CP2=OFF, CP3=OFF
  ;Setup CONFIG5H
  CONFIG CPB = OFF, CPD = OFF
  ;Setup CONFIG6L
  CONFIG WRT0 = OFF, WRT1 = OFF, WRT2 = OFF, WRT3 = OFF
  ;Setup CONFIG6H
  CONFIG WRTB = OFF, WRTC = OFF, WRTD = OFF
  ;Setup CONFIG7L
  CONFIG EBTR0 = OFF, EBTR1 = OFF, EBTR2 = OFF, EBTR3 = OFF
  ;Setup CONFIG7H
  CONFIG EBTRB = OFF
Mod edit: code tags

Thanks for your help.
Peaches
 
Last edited by a moderator:

AlbertHall

Joined Jun 4, 2014
11,587
OK, so post the complete code as there is nothing in the bit you posted that looks wrong.
If you post it as part of the message then please use {CODE} your code here {/CODE} tags (except use square brackets instead of curly ones) or add it as an attachment.
 

Thread Starter

Peaches41

Joined Dec 15, 2016
70
Thank you Mr. Hall for your response,
Please see below an attachment of my code.

Peaches
Code:
;------------------------------------------------------------------------------
; PROCESSOR DECLARATION
;------------------------------------------------------------------------------
     LIST      R=DEC
     LIST      P=PIC18LF26K22          ; list directive to define processor
     #INCLUDE <P18LF26K22.INC>         ; processor specific variable definitions

;------------------------------------------------------------------------------
;
; CONFIGURATION WORD SETUP
;
;------------------------------------------------------------------------------

     ;Setup CONFIG1H
     CONFIG FOSC = INTIO67, PLLCFG = OFF, PRICLKEN = On, FCMEN = OFF, IESO = OFF
     ;Setup CONFIG2L
     CONFIG PWRTEN = OFF, BOREN = OFF, BORV = 190
     ;Setup CONFIG2H
     CONFIG WDTEN = OFF, WDTPS = 1
     ;Setup CONFIG3H
     CONFIG MCLRE = INTMCLR, CCP2MX = PORTB3, CCP3MX = PORTB5, HFOFST = OFF, T3CMX = PORTB5, P2BMX = PORTB5,      PBADEN = OFF
     ;Setup CONFIG4L
     CONFIG STVREN = OFF, LVP = OFF, XINST = OFF
     ;Setup CONFIG5L
     CONFIG CP0 = OFF, CP1 = OFF, CP2=OFF, CP3=OFF
     ;Setup CONFIG5H
     CONFIG CPB = OFF, CPD = OFF
     ;Setup CONFIG6L
     CONFIG WRT0 = OFF, WRT1 = OFF, WRT2 = OFF, WRT3 = OFF
     ;Setup CONFIG6H
     CONFIG WRTB = OFF, WRTC = OFF, WRTD = OFF
     ;Setup CONFIG7L
     CONFIG EBTR0 = OFF, EBTR1 = OFF, EBTR2 = OFF, EBTR3 = OFF
     ;Setup CONFIG7H
     CONFIG EBTRB = OFF

;------------------------------------------------------------------------------
;
; VARIABLE DEFINITIONS
;------------------------------------------------------------------------------

    CBLOCK  0x60
COUNT1        
COUNTA
COUNT_B    
COUNTB
DELAY : 2
ONE_REV
HOLD
ZERO
NUMBER
FORTY_FOUR
FORTY_FIVE
LOCATION
FORTY_FOUR_L
FORTY_FIVE_L
FIND_VALUE
READ_VALUE
READ_FLAG        
HUNDREDS
TENS_D
TENS_C
TENS_B
TENS_A
ONES
TOTAL : 2
INCREASE
LOW_NIBBLE
HIGH_NIBBLE
CENTER_X
NUM_LETTERS
TABLE : 2
LOCATION_HIGH               
LOCATION_LOW     
CHARACTER_AO     
CHARACTER_PZ      
TEMP          
HIGH_T          
LOW_T          
HOLD_PCLATH
CHECK_LEFT   
CHECK_RIGHT
TABLE_START_LOCATION
TABLE_START_LOCATION_A
TABLE_START_LOCATION_B
TABLE_START_LOCATION_B_UP
TABLE_START_LOCATION_B_VALUE
TABLE_START_LOCATION_C                                 
CHECK_RIGHT_B
CHECK_LEFT_B
CHECK_LEFT_C
MENU_PAGE
CHOOSE_TABLE
CHECK_PAGE                                            
    ENDC


;------------------------------------------------------------------------------
; RESET VECTOR
;------------------------------------------------------------------------------

RES_VECT  ORG     0x0000            ; processor reset vector
          GOTO    START             ; go to beginning of program

;------------------------------------------------------------------------------
; HIGH PRIORITY INTERRUPT VECTOR
;------------------------------------------------------------------------------

ISRH      ORG     0x0008

          ; Run the High Priority Interrupt Service Routine
;          GOTO    HIGH_ISR            

;------------------------------------------------------------------------------
; LOW PRIORITY INTERRUPT VECTOR
;------------------------------------------------------------------------------

ISRL      ORG     0x0018
         
          ; Run the Low Priority Interrupt Service Routine
;          GOTO    LOW_ISR            

;------------------------------------------------------------------------------
; HIGH PRIORITY INTERRUPT SERVICE ROUTINE
;------------------------------------------------------------------------------

;HIGH_ISR 

          ; Insert High Priority ISR Here

;          RETFIE  FAST

;------------------------------------------------------------------------------

;------------------------------------------------------------------------------
; MAIN PROGRAM
;------------------------------------------------------------------------------

START     ORG        0X001A

;------------------------------------------------------------------------------
;INITIALIZE MICROCONTROLLER

        MOVLW   b'00000000'           
        MOVWF   PORTA, 0
        MOVLW   b'00000000'           
        MOVWF   PORTB, 0
        MOVLW   b'00000000'          
        MOVWF   PORTC, 0
  
        MOVLW   b'00111111'        ;USED FOR TOGGLE SWITCH 
        MOVWF   TRISA, 0
        MOVLW   b'00000000'           
        MOVWF   TRISB, 0
        MOVLW   b'00000000'            
        MOVWF   TRISC, 0
   
        CLRF    LATA, 0                  
        CLRF    LATB, 0
        CLRF    LATC, 0                  
   
;------------------------------------------------------------------------------
        CLRF    ANSELA, 0          ;digital I/O    SET PORTA PINS TO DIGITAL
        CLRF    ANSELB, 0          ;digital I/O    SET PORTB PINS TO DIGITAL
        CLRF    ANSELC, 0          ;digital I/O    SET PORTC PINS TO DIGITAL
;------------------------------------------------------------------------------
        MOVLW   b'00000000'          
        MOVWF   CM1CON0, 0
        MOVLW   b'00000000'        
        MOVWF   CM2CON0, 0
;-------------------------------------------------------------------------------
        MOVLW   b'00000000'              
        MOVWF   T1CON, 0
        CLRF        TMR1L, 0
        CLRF        TMR1H, 0
        MOVLW   b'00000000'
        MOVWF   PIR1, 0
        MOVLW   b'00000000'
        MOVWF   PIR2, 0                 
        MOVLW   b'01000000'          
        MOVWF   INTCON, 0
        MOVLW   b'01000000'               
        MOVWF   INTCON2,   
        MOVLW   b'00000000'                
        MOVWF   PIE1, 0
        MOVLW   b'01101100'                  
        MOVWF   OSCCON, 0
        MOVLW   b'00000000'                   
        MOVWF   SLRCON, 0

;-------------------------------------------------------------------------------


;------------------------------------------------------------------------------          
MAIN
;BEGINNING OF PROGRAM
;------------------------------------------------------------------------------
                  NOP
    CALL    ONE_SEC_DELAY, 0          
    NOP
    BSF    PORTB, RB7, 0                   ;USED FOR TEST ONLY
;    GOTO    $

;------------------------------------------------------------------------------   
;------------------------------------------------------------------------------
;SUBROUTINES
;------------------------------------------------------------------------------
    ORG    0XE00
   

;-------------------------------------------------------------------------------

;-------------------------------------------------------------------------------
;DELAY ONE SECOND
ONE_SEC_DELAY

    MOVLW    0XFF        
    MOVWF    DELAY+1, 0
    MOVLW    0XFF         
    MOVWF    DELAY, 0
    MOVLW    0X0B
    MOVWF    ONE_REV, 0
   
DEL:   
    DECFSZ    DELAY, F, 0
    GOTO    DEL
    DECFSZ    DELAY+1, F, 0
    GOTO    DEL

   
    BSF    PORTB, RB7, 0

    DECFSZ    ONE_REV, F, 0
    GOTO    DEL
    NOP 
   

   
   
    RETURN
;-------------------------------------------------------------------------------
     END
;------------------------------------------------------------------------------
Mod edit: code tags
 

Attachments

Last edited by a moderator:

AlbertHall

Joined Jun 4, 2014
11,587
This program works correctly in the simulator (MPLABX V3.45, MPASM V5.70). The one second delay is approximately one second at an oscillator frequency of 8MHz.

Which assembler, programmer, debugger are you using?
What hardware is connected to the PIC? Can you post a schematic, please?
 

Thread Starter

Peaches41

Joined Dec 15, 2016
70
This program works correctly in the simulator (MPLABX V3.45, MPASM V5.70). The one second delay is approximately one second at an oscillator frequency of 8MHz.

Which assembler, programmer, debugger are you using?
What hardware is connected to the PIC? Can you post a schematic, please?
I am using the exact same as you stated (MPLABX V3.45, MPASM V5.70). The hardware that is connected to this pic is just an LED on RB7 and an LCD connected to RC0-6. I have both vss connected to ground and a .1uf cap on my vdd line. I am running this from a coin cell battery which is running currently at 2,6v. I am programming this chip with a Microchip PM3 programmer. I do know that the program flows correctly, meaning that it calls the subroutine, performs the delay and returns correctly from the subroutine, but I was just wondering why the LED would not light even though the program seems to run correctly? I am trying to troubleshoot why my program will not run my converted LCD program from a PIC16F690.
Thanks for your help Mr. Hall.
Peaches
 

spinnaker

Joined Oct 29, 2009
7,835
Do you have any test equipment? Can you see the RB7 pin going high?

Post a schematic.

I see you are also using an LCD. You are very brave trying to write to an LCD with assembler. ;)
 

spinnaker

Joined Oct 29, 2009
7,835
I don't see where you are setting RB& high. Am I missing something? How is the LED connected to RB7? Post a schematic.
 

Thread Starter

Peaches41

Joined Dec 15, 2016
70
I don't see where you are setting RB& high. Am I missing something? How is the LED connected to RB7? Post a schematic.
Thank you for responding to my post. You say that I am brave for programming the lcd in assembly and I thank you for saying that but assembly is all I know so I dont know any different. It does take a lot of time and effort to make it work but it works well. If you look in the code I posted above and look 4 lines up from the return in the subroutine you will see that I do indeed turn the LCD on. I do probe the pin w/ osc. scope and mmeter and see no voltage. The led is connected to ground through a 330 ohm resister.

TY
Peaches
 

djsfantasi

Joined Apr 11, 2010
7,911
I assume BSF sets the specified bit. (And BCF does the opposite) What I don't get is what is bit 0 of RB7? Isn't RB7 a single but?
 

Thread Starter

Peaches41

Joined Dec 15, 2016
70
I assume BSF sets the specified bit. (And BCF does the opposite) What I don't get is what is bit 0 of RB7? Isn't RB7 a single but?
Thanks for your reply.
The "0" in the line of code states that I am using the access bank and not the BSR register. The "0" represents the "a" in the syntax per the datasheet.

BSF PORTB, RB7, 0 means the following: (bit set f) portb, bit 7, access bank


Thanks
Peaches
 

JohnInTX

Joined Jun 26, 2012
4,594
Try the BCF/BSF on LATB instead of PORTB.
EDIT: Also, RB7 is used by the programmer/debugger. Make sure there is no interference there.

FWIW, you don't need to use the ,0 to specify the ACCESS bank. If you are using the uCHIP supplied processor.inc files, the SFR addresses are fully specified and MPASM will figure out whether or not the register is in the ACCESS bank or not.
 
Last edited:

Thread Starter

Peaches41

Joined Dec 15, 2016
70
Try the BCF/BSF on LATB instead of PORTB.
FWIW, you don't need to use the ,0 to specify the ACCESS bank. If you are using the uCHIP supplied processor.inc files, the SFR addresses are fully specified and MPASM will figure out whether or not the register is in the ACCESS bank or not.
I am still a little confused on the lat vs port issue. I still need to do more research on this as the 16F690 I previously used did not use LAT. This is just part of my learning curve w/ a new uC.


Thank you John for your help.

Peaches
 

JohnInTX

Joined Jun 26, 2012
4,594
See the EDIT about RB7 sharing the ICSP lines..

PORT vs LAT: When you do any bcf/bsf on any register, the register byte (all 8 bits) are read, the bit is flipped internally then the byte is written back to the port. The problem is that when you specify PORT for bsf/bcf, the initial value is what is read on the pin itself - not necessarily what you wrote previously. You can write a 1 but if the voltage on the port pin is such that it is not a 1 when bsf/bcf is executed on the 'PORT' the initial value will be read as '0' instead of 1.

Consider this case:
You initialize the PORTB to 01h but the pin is loaded such that the actual voltage on pin RB0 is below a logic 1 - driving an LED without a resistor for example or a capacitive load that takes time to charge.
You then bsf/bcf to some other pin on the same port. That action causes the entire port to be read as before but this time, RB0 reads back as a '0' not a '1 due to the excessive load / low voltage on the pin. When the bcf/bsf completes, the value of RB0 gets changed back to '0' as that is what was read by the bcf/bsf. The problem is very common in baseline and midrange which have only PORTs. The 18F and 16F1xxx address this issue by providing the LATx registers. When you write to LATx (or PORT for that matter) it saves a copy of what was written to the port in the LAT register. Then when you do a bsf/bcf on LATx, you read the copy of the data, not the voltage on the physical pin. That prevents a loaded pin (or noise or whatever) from fouling the initial value for the instructions. The rule then is read from PORT, write or bit modify to LAT. Note that a byte-write to PORT also writes the LAT. This was done for compatibility reasons but you still need to observe the read PORT / write LAT rule.

I don't know if that is what is happening in your case since you are starting at 0 and going to 1 without other writes to the port but that's the answer to your PORT/LAT question. Since it runs in the sim, I'd be looking at the hardware.

Cheers.

EDIT: You can make things easier on yourself by using #define for you IO. That way you can move it around without messing with your code.
Code:
#define LED LATB,7

bsf LED ; set port bit
bcf LED ; clear port bit
You also might want to use btg (toggle bit) to flash the LED on and off after each delay..
 
Last edited:

Thread Starter

Peaches41

Joined Dec 15, 2016
70
John,
Thank you for your insightful response to my continued questions. Your explanation of port v. lat was very understandable to me and cleared up my confusion on the subject. I also need to look further into the instruction set for the PIC18F for implementation of "btg" etc. which would simplify what I am trying to do(as well as #define). I will also look into the EDIT about RB7 sharing the ICSP lines as it may be something I overlooked in my checking priority of the pins. Thanks for your continued help, this time as I try to convert from PIC16F to PIC18F which being painful now will show many dividends paid in the future.

TY
Peaches
 

JohnInTX

Joined Jun 26, 2012
4,594
John,
Thank you for your insightful response to my continued questions. Your explanation of port v. lat was very understandable to me and cleared up my confusion on the subject. I also need to look further into the instruction set for the PIC18F for implementation of "btg" etc. which would simplify what I am trying to do(as well as #define). I will also look into the EDIT about RB7 sharing the ICSP lines as it may be something I overlooked in my checking priority of the pins. Thanks for your continued help, this time as I try to convert from PIC16F to PIC18F which being painful now will show many dividends paid in the future.

TY
Peaches
Yup. 18F is well worth the trouble to learn - you're doing fine. There is a bug in the 2ed code you posted. By commenting out the goto $ on line 202, your code calls the delay routine then returns then flows into the delay routine again without calling it. The RETURN will cause a stack underflow (and STVREN is not set in CONFIG4L) so *boom*. The sim is happy but your chip likely will go off into the weeds. A few other things too:
INTCON has PIE/GIEL set. If RCON:IPEN ever gets set it will enable interrupts and you don't have any service routines so possible *boom* again.
I made a few changes including using the #define for LED and it flashes the LED on the sim using bsf/bcf.
It should run on your hardware. Be sure to Clean and Build Main Project (NOT for debug..) before blasting a chip to run stand-alone.
Good luck!
Code:
;------------------------------------------------------------------------------
; PROCESSOR DECLARATION
;------------------------------------------------------------------------------
  LIST  R=DEC
  LIST  P=PIC18LF26K22  ; list directive to define processor
  #INCLUDE <P18LF26K22.INC>  ; processor specific variable definitions

;------------------------------------------------------------------------------
;
; CONFIGURATION WORD SETUP
;
;------------------------------------------------------------------------------

  ;Setup CONFIG1H
  CONFIG FOSC = INTIO67, PLLCFG = OFF, PRICLKEN = On, FCMEN = OFF, IESO = OFF
  ;Setup CONFIG2L
  CONFIG PWRTEN = OFF, BOREN = OFF, BORV = 190
  ;Setup CONFIG2H
  CONFIG WDTEN = OFF, WDTPS = 1
  ;Setup CONFIG3H
  CONFIG MCLRE = INTMCLR, CCP2MX = PORTB3, CCP3MX = PORTB5, HFOFST = OFF, T3CMX = PORTB5, P2BMX = PORTB5,  PBADEN = OFF
  ;Setup CONFIG4L
  CONFIG STVREN = OFF, LVP = OFF, XINST = OFF
  ;Setup CONFIG5L
  CONFIG CP0 = OFF, CP1 = OFF, CP2=OFF, CP3=OFF
  ;Setup CONFIG5H
  CONFIG CPB = OFF, CPD = OFF
  ;Setup CONFIG6L
  CONFIG WRT0 = OFF, WRT1 = OFF, WRT2 = OFF, WRT3 = OFF
  ;Setup CONFIG6H
  CONFIG WRTB = OFF, WRTC = OFF, WRTD = OFF
  ;Setup CONFIG7L
  CONFIG EBTR0 = OFF, EBTR1 = OFF, EBTR2 = OFF, EBTR3 = OFF
  ;Setup CONFIG7H
  CONFIG EBTRB = OFF

;------------------------------------------------------------------------------
;
; VARIABLE DEFINITIONS
;------------------------------------------------------------------------------

  CBLOCK  0x60
COUNT1
COUNTA
COUNT_B
COUNTB
DELAY : 2
ONE_REV
HOLD
ZERO
NUMBER
FORTY_FOUR
FORTY_FIVE
LOCATION
FORTY_FOUR_L
FORTY_FIVE_L
FIND_VALUE
READ_VALUE
READ_FLAG
HUNDREDS
TENS_D
TENS_C
TENS_B
TENS_A
ONES
TOTAL : 2
INCREASE
LOW_NIBBLE
HIGH_NIBBLE
CENTER_X
NUM_LETTERS
TABLE : 2
LOCATION_HIGH
LOCATION_LOW 
CHARACTER_AO
CHARACTER_PZ 
TEMP   
HIGH_T   
LOW_T   
HOLD_PCLATH
CHECK_LEFT
CHECK_RIGHT
TABLE_START_LOCATION
TABLE_START_LOCATION_A
TABLE_START_LOCATION_B
TABLE_START_LOCATION_B_UP
TABLE_START_LOCATION_B_VALUE
TABLE_START_LOCATION_C
CHECK_RIGHT_B
CHECK_LEFT_B
CHECK_LEFT_C
MENU_PAGE
CHOOSE_TABLE
CHECK_PAGE
  ENDC

#define LED LATB,7  ; define the IO 

;------------------------------------------------------------------------------
; RESET VECTOR
;------------------------------------------------------------------------------

RES_VECT  ORG  0x0000  ; processor reset vector
  GOTO  START  ; go to beginning of program

;------------------------------------------------------------------------------
; HIGH PRIORITY INTERRUPT VECTOR
;------------------------------------------------------------------------------

ISRH  ORG  0x0008
   clrf INTCON ; no interrupts yet - force OFF
   return    ; not retfie!

;------------------------------------------------------------------------------
; LOW PRIORITY INTERRUPT VECTOR
;------------------------------------------------------------------------------

ISRL  ORG  0x0018
   clrf INTCON ; no interrupts yet - force OFF
   return    ; not retfie!

;------------------------------------------------------------------------------

;------------------------------------------------------------------------------
; MAIN PROGRAM
;------------------------------------------------------------------------------

START  ORG    0X0020  ; had to make some space

;------------------------------------------------------------------------------
;INITIALIZE MICROCONTROLLER

    MOVLW  b'00000000'
    MOVWF  PORTA, 0
    MOVLW  b'00000000'
    MOVWF  PORTB, 0
    MOVLW  b'00000000'
    MOVWF  PORTC, 0

    MOVLW  b'00111111'     ;USED FOR TOGGLE SWITCH
    MOVWF  TRISA, 0
    MOVLW  b'00000000'   
    MOVWF  TRISB, 0
    MOVLW  b'00000000'
    MOVWF  TRISC, 0

    CLRF  LATA, 0
    CLRF  LATB, 0
    CLRF  LATC, 0

;------------------------------------------------------------------------------
    CLRF  ANSELA, 0      ;digital I/O  SET PORTA PINS TO DIGITAL
    CLRF  ANSELB, 0      ;digital I/O  SET PORTB PINS TO DIGITAL
    CLRF  ANSELC, 0      ;digital I/O  SET PORTC PINS TO DIGITAL
;------------------------------------------------------------------------------
    MOVLW  b'00000000'
    MOVWF  CM1CON0, 0
    MOVLW  b'00000000'
    MOVWF  CM2CON0, 0
;-------------------------------------------------------------------------------
    MOVLW  b'00000000'
    MOVWF  T1CON, 0
    CLRF  TMR1L, 0
    CLRF  TMR1H, 0
    MOVLW  b'00000000'
    MOVWF  PIR1, 0
    MOVLW  b'00000000'
    MOVWF  PIR2, 0
 
    MOVLW  b'00000000'  ;b'01000000'  don't leave this on w/no int handlers
    MOVWF  INTCON, 0
 
    MOVLW  b'01000000'
    MOVWF  INTCON2
    MOVLW  b'00000000'
    MOVWF  PIE1, 0
    MOVLW  b'01101100'
    MOVWF  OSCCON, 0
    MOVLW  b'00000000'
    MOVWF  SLRCON, 0

;-------------------------------------------------------------------------------
;------------------------------------------------------------------------------   
MAIN
;BEGINNING OF PROGRAM
;------------------------------------------------------------------------------
mainLoop:
  NOP
   CALL  ONE_SEC_DELAY, 0
   NOP
   BSF   LED  ; LED on

   CALL   ONE_SEC_DELAY

   BCF   LED ; LED off
   goto   mainLoop
;   GOTO   $  // this caused stack underflow by flowing down to a subroutine

;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
;SUBROUTINES
;------------------------------------------------------------------------------
   ORG   0XE00  ; you don't need this plus it can cause overwrites when main gets bigger

;-------------------------------------------------------------------------------

;-------------------------------------------------------------------------------
;DELAY ONE SECOND
ONE_SEC_DELAY
   MOVLW   0XFF
   MOVWF   DELAY+1, 0
   MOVLW   0XFF 
   MOVWF   DELAY, 0
   MOVLW   0X0B
   MOVWF   ONE_REV, 0

DEL:
   DECFSZ   DELAY, F, 0
   GOTO   DEL
   DECFSZ   DELAY+1, F, 0
   GOTO   DEL

       ;BSF   PORTB, RB7, 0

   DECFSZ   ONE_REV, F, 0
   GOTO   DEL

   NOP
   RETURN
;-------------------------------------------------------------------------------
   END
;------------------------------------------------------------------------------
 
Last edited:

JohnInTX

Joined Jun 26, 2012
4,594
.. Also, since you are not using MCLR/ consider using the Power On Reset Timer in the CONFIG regs. Be sure to take a look at parameters D003 and D004 in 27.1 DC Characteristics (min Vdd and rate of rise to ensure internal reset).
 
Top