9 Baseline Code Example

Coding strategies for Baseline devices generally follow those for Mid-range devices, taking into account the smaller memory and the reduced feature set implemented by these devices. However, the paging issues associated with function calls on Baseline devices are different to other 8-bit PIC devices and need special attention.

The following Baseline code example writes increasing values to PORTA.

Baseline Code Example Showing Calls

#include <xc.inc>

PROCESSOR 16F570

; PIC16F570 Configuration Bit Settings
CONFIG  "FOSC = EXTRC_CLKOUT"  // Oscillator (EXTRC with CLKOUT on OSC2/CLKOUT)
CONFIG  "WDTE = OFF"           // Watchdog Timer Enable bit (Disabled)
CONFIG  "CP = OFF"             // Code Protection bit (Code protection off)
CONFIG  "IOSCFS = 8MHz"        // Internal Oscillator Frequency (8 MHz INTOSC Speed)
CONFIG  "CPSW = OFF"           // Flash Data Memory (Code protection off)
CONFIG  "BOREN = OFF"          // BOR Disabled
CONFIG  "DRTEN = OFF"          // DRT Disabled

PSECT udata_shr                // objects in common memory
counter:
    DS      1
loc:
    DS      1

PSECT  resetVec,class=CODE,delta=2
resetVec:
    ljmp    main

PSECT code
main:
    movlw   0
    tris    PORTA
    movf    counter,w
    /* write increasing values to PORTA */
loop:
    fcall   increment
    movwf   PORTA
    goto    loop
	
/* increment the value in W, returning it in W */
PSECT entryCode,class=ENTRY,delta=2
increment:
    movwf   loc
    incf    loc,w
    return

    END     resetVec