ADVANCED TECHNIQUES FOR DESIGN ENGINEERS
The fourth and final LCD function simply clears the
display and positions the cursor at the home position:
// CONFIG1
#pragma config FOSC = INTOSC // Oscillator
Selection Bits->INTOSC oscillator: I/O function
on CLKIN pin
#pragma config WDTE = OFF // Watchdog Timer
Enable->WDT disabled
#pragma config PWRTE = OFF // Power-up Timer
Enable->PWRT disabled
#pragma config MCLRE = ON // MCLR Pin Function
Select->MCLR/VPP pin function is MCLR
#pragma config CP = OFF // Flash Program Memory
Code Protection->Program memory code protection
is disabled
#pragma config BOREN = ON // Brown-out Reset
Enable->Brown-out Reset enabled
#pragma config CLKOUTEN = OFF // Clock Out
Enable->CLKOUT function is disabled. I/O or
oscillator function on the CLKOUT pin
void LCD_Clear(void) {
LCD_WriteCommand(LCD_CLEAR);
LCD_GoTo(0, 0);
The PICBASIC PRO port is almost not a port at all as
it consists of functions we have already ported. There is no
need to preload the cmd, row, and col variables:
;************************************************
;* LCD_Clear
;************************************************
cmd = LCD_CLEAR
call LCD_WriteCommand
row = 0
col = 0
call LCD_Goto
return
Almost There
The SPI and LCD port are finished. However, we need
to take care of some other necessities before we can apply
our ported code. I relied on the configuration fuse settings
that PICBASIC PRO set for the PIC16LF1708 with only a
couple of exceptions. I turned off the watchdog timer and
the power-up timer:
#CONFIG
__config _CONFIG1, _FOSC_INTOSC & _WDTE_OFF
& _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _BOREN_ON &
_CLKOUTEN_OFF
__config _CONFIG2, _WRT_OFF & _PPS1WAY_OFF &
_ZCDDIS_ON & _PLLEN_OFF & _STVREN_ON & _BORV_LO &
_LPBOR_OFF & _LVP_OFF
#ENDCONFIG
// CONFIG2
#pragma config WRT = OFF // Flash Memory
Self-Write Protection->Write protection off
#pragma config PPS1WAY = ON // Peripheral Pin
Select one-way control->The PPSLOCK bit cannot be
cleared once it is set by software
#pragma config ZCDDIS = ON // Zero-cross detect
disable->Zero-cross detect circuit is disabled at
POR
#pragma config PLLEN = OFF // Phase Lock Loop
enable->4x PLL is enabled when software sets the
SPLLEN bit
#pragma config STVREN = ON // Stack Overflow/
Underflow Reset Enable->Stack Overflow or Underflow
will cause a Reset
#pragma config BORV = LO // Brown-out Reset
Voltage Selection->Brown-out Reset Voltage
(Vbor), low trip point selected.
#pragma config LPBOR = OFF // Low-Power Brown
Out Reset->Low-Power BOR is disabled
#pragma config LVP = OFF // Low-Voltage
Programming Enable->High-voltage on MCLR/VPP must
be used for programming
If you don’t have any special requirements, it’s much
easier to use the PICBASIC PRO-supplied configuration
fuse data. The Code Configurator can also be used to
generate the system oscillator and watchdog configuration
values, which are directly portable. You need only replace
the C hexadecimal notation “0x” with the PICBASIC PRO
hexadecimal notation “$:”
You can also use the Code Configurator to generate
the configuration fuse settings. It will generate this:
;************************************************
;* INITIALIZE OSCILLATOR
;************************************************
OSCCON = $72 ;SCS INTOSC; SPLLEN disabled;
IRCF 8MHz_HF;
OSCSTAT = $00 ;SOSCR disabled;
OSCTUNE = $00 ;TUN 0;
BORCON = $00 ;SBOREN disabled; BORFS disabled;
;************************************************
;* INITIALIZE WATCHDOG TIMER
;************************************************
WDTCON = $16 ;WDTPS 1:65536; SWDTEN OFF
July/August 2018 83