Code:
'****************************************************************
'* Name : 18F26K20test.PBP *
'* Author : ************* *
'* Notice : Copyright (c) 2016 ************* *
'* : All Rights Reserved *
'* Date : 7/31/2016 *
'* Version : 1.0 *
'* Notes : PIC18F26K20 - Test *
'* : *
'****************************************************************
#MSG "Compiling code for " + __PROCESSOR__
' Device fuses configuration - PIC18F26K20
#CONFIG
CONFIG FOSC = HS ; HS oscillator
CONFIG FCMEN = OFF ; Fail-Safe Clock Monitor disabled
CONFIG IESO = OFF ; Oscillator Switchover mode disabled
CONFIG PWRT = OFF ; PWRT disabled
CONFIG BOREN = SBORDIS ; Brown-out Reset enabled in hardware only (SBOREN is disabled)
CONFIG BORV = 18 ; VBOR set to 1.8 V nominal
CONFIG WDTEN = ON ; WDT is always enabled. SWDTEN bit has no effect
CONFIG WDTPS = 512 ; 1:512
CONFIG CCP2MX = PORTC ; CCP2 input/output is multiplexed with RC1
CONFIG PBADEN = OFF ; PORTB<4:0> pins are configured as digital I/O on Reset
CONFIG LPT1OSC = OFF ; Timer1 configured for higher power operation
CONFIG HFOFST = ON ; HFINTOSC starts clocking the CPU without waiting for the oscillator to stablize.
CONFIG MCLRE = ON ; MCLR pin enabled; RE3 input pin disabled
CONFIG STVREN = ON ; Stack full/underflow will cause Reset
CONFIG LVP = OFF ; Single-Supply ICSP disabled
CONFIG XINST = OFF ; Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
CONFIG DEBUG = OFF ; Background debugger disabled, RB6 and RB7 configured as general purpose I/O pins
CONFIG CP0 = OFF ; Block 0 (000800-003FFFh) not code-protected
CONFIG CP1 = OFF ; Block 1 (004000-007FFFh) not code-protected
CONFIG CP2 = OFF ; Block 2 (008000-00BFFFh) not code-protected
CONFIG CP3 = OFF ; Block 3 (00C000-00FFFFh) 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-003FFFh) not write-protected
CONFIG WRT1 = OFF ; Block 1 (004000-007FFFh) not write-protected
CONFIG WRT2 = OFF ; Block 2 (008000-00BFFFh) not write-protected
CONFIG WRT3 = OFF ; Block 3 (00C000h-00FFFFh) not write-protected
CONFIG WRTC = OFF ; Configuration registers (300000-3000FFh) not write-protected
CONFIG WRTB = OFF ; Boot Block (000000-0007FFh) not write-protected
CONFIG WRTD = OFF ; Data EEPROM not write-protected
CONFIG EBTR0 = OFF ; Block 0 (000800-003FFFh) not protected from table reads executed in other blocks
CONFIG EBTR1 = OFF ; Block 1 (004000-007FFFh) not protected from table reads executed in other blocks
CONFIG EBTR2 = OFF ; Block 2 (008000-00BFFFh) not protected from table reads executed in other blocks
CONFIG EBTR3 = OFF ; Block 3 (00C000-00FFFFh) 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
#ENDCONFIG
define OSC 20 ' Using 20Mhz oscillator - remember to change fuse to HS
INCLUDE "bs2defs.bas"
restart:
TRISA = 011111 ' Set 0-4 pins on PortA to inputs, 5-7 pins to outputs
TRISB = 000000 ' Set all pins on PortB to outputs
TRISC = 000000 ' Set all pins on PortC to outputs
ANSEL = 000000 ' Make AN0 - AN7 Digital (pins RA0, RA1, RA2, RA3, RA5 on PIC18F26K20)
ANSELH = 000000 ' Make AN8 - AN15 Digital (pins RB2, RB3, RB1, RB4, RB0 on PIC18F26K20)
' Set all pins low to reset any pins that went high due to device connection
PORTA = 0 ' Set all pins on PORTA low
PORTB = 0 ' Set all pins on PORTB low
PORTC = 0
' Port alias setup
led1 var PORTB.0
led2 VAR PORTB.1
led3 VAR PORTB.2
led4 VAR PORTB.3
lcd var PORTB.4 ' Serial output to LCD
btnr var PORTA.0 ' Right arrow button
btns vAR PORTA.1 ' Select button
btnu var PORTA.2 ' Up arrow button
btnl var PORTA.3 ' Left arrow button
btnd var PORTA.4 ' Down arrow button
' Variable declaration
start:
SerOut lcd,N9600,[254,1] ' Clear LCD screen
Pause 1
goto ledanims
mainloop:
' For now, as a test of the buttons, just send a test string to the LCD
' After this is proven, send different texts (bluetooth, PIC to PIC, wordlength, etc.)
if btnr = 1 then btnrgt
if btns = 1 then btnsel
if btnu = 1 then btnup
if btnl = 1 then btnlft
if btnd = 1 then btndwn
goto mainloop
' ----------------------------------------------------------------------------
btnrgt:
SerOut lcd,N9600,[254,1] ' Clear LCD screen
Pause 1
serout lcd,N9600,["Right button"]
pause 500
goto start
btnsel:
SerOut lcd,N9600,[254,1] ' Clear LCD screen
Pause 1
serout lcd,N9600,["Select button"]
pause 500
goto start
btnup:
SerOut lcd,N9600,[254,1] ' Clear LCD screen
Pause 1
serout lcd,N9600,["Up button"]
pause 500
goto start
btnlft:
SerOut lcd,N9600,[254,1] ' Clear LCD screen
Pause 1
serout lcd,N9600,["Left button"]
pause 500
goto start
btndwn:
SerOut lcd,N9600,[254,1] ' Clear LCD screen
Pause 1
serout lcd,N9600,["Down button"]
pause 500
goto start
' ============================================================================
ledanims:
'high PORTB.0
'PORTB.0 = 1
led1 = 1
pause 500
led1 = 0
'led1 = 0 ' <--- If I add this back in, this pin works correctly
'PORTB.0 = 0
'low PORTB.0 ' <--- This statement does the job by itself
'high PORTB.1
'PORTB.1 = 1
led2 = 1
pause 500
'led2 = 0
'led2 = 0
PORTB.1 = 0
'PORTB.1 = 0
'low PORTB.1
'high PORTB.2
'PORTB.2 = 1
led3 = 1
pause 500
led3 = 0
'PORTB.2 = 0
'low PORTB.2
'high PORTB.3
'PORTB.3 = 1
led4 = 1
pause 500
led4 = 0
'PORTB.3 = 0
'low PORTB.3
goto ledanims
Bookmarks