Hello,
I bought the following product and am trying to run a sample program on it provided by their website. I have a PIC16F874A installed and can't seem to get the sample programs to work. All I get is a single row of solid blocks on the LCD.
Here is the original code:
Code:
' PICBASIC PRO program to display key number on LCD
' Define LOADER_USED to allow use of the boot loader.
' This will not affect normal program operation.
Define LOADER_USED 1
' RESET_ORG can be set to move the BASIC program out of the way
' of any boot loader running from location 0, such as the
' Microchip USB boot loader
'Define RESET_ORG 800h
Define OSC 48 ' Core is running at 48MHz
' Define LCD connections
Define LCD_DREG PORTD
Define LCD_DBIT 4
Define LCD_RSREG PORTE
Define LCD_RSBIT 0
Define LCD_EREG PORTE
Define LCD_EBIT 1
' Define program variables
col var byte ' Keypad column
row var byte ' Keypad row
key var byte ' Key value
INTCON2.7 = 0 ' Enable PORTB pullups
ADCON1 = 15 ' Make PORTA and PORTE digital
Low PORTE.2 ' LCD R/W low (write)
Pause 100 ' Wait for LCD to start
Lcdout $fe, 1, "Press any key" ' Display sign on message
loop: Gosub getkey ' Get a key from the keypad
Lcdout $fe, 1, #key ' Display ASCII key number
Goto loop ' Do it forever
' Subroutine to get a key from keypad
getkey:
Pause 50 ' Debounce
getkeyu:
' Wait for all keys up
PORTB = 0 ' All output pins low
TRISB = $f0 ' Bottom 4 pins out, top 4 pins in
If ((PORTB >> 4) != $f) Then getkeyu ' If any keys down, loop
Pause 50 ' Debounce
getkeyp:
' Wait for keypress
For col = 0 to 3 ' 4 columns in keypad
PORTB = 0 ' All output pins low
TRISB = (dcd col) ^ $ff ' Set one column pin to output
Pauseus 1
row = PORTB >> 4 ' Read row
If row != $f Then gotkey ' If any keydown, exit
Next col
Goto getkeyp ' No keys down, go look again
gotkey: ' Change row and column to key number 1 - 16
key = (col * 4) + (ncd (row ^ $f))
Return ' Subroutine over
End
Because PBP3 doesn't like it using the instruction Loop as a label, I changed it to Looper. Also changed INTCON2.7 = 0 to OPTION_REG.7 = 0 for the 874A and changed the define osc 48 to define osc 20.
I am new to this type of code and find it difficult to read, so the problem doesn't stand out for me. What I'm left with is this:
Code:
;----[16F874A Hardware Configuration]-------------------------------------------
#IF __PROCESSOR__ = "16F874A"
#DEFINE MCU_FOUND 1
#CONFIG
cfg = _XT_OSC ; XT oscillator
cfg&= _WDT_OFF ; WDT disabled
cfg&= _PWRTE_OFF ; PWRT disabled
cfg&= _BODEN_OFF ; BOR disabled
cfg&= _LVP_OFF ; RB3 is digital I/O, HV on MCLR must be used for programming
cfg&= _CPD_OFF ; Data EEPROM code protection off
cfg&= _WRT_OFF ; Write protection off; all program memory may be written to by EECON control
cfg&= _DEBUG_OFF ; In-Circuit Debugger disabled, RB6 and RB7 are general purpose I/O pins
cfg&= _CP_OFF ; Code protection off
__CONFIG cfg
#ENDCONFIG
#ENDIF
;----[Verify Configs have been specified for Selected Processor]----------------
; Note: Only include this routine once, after all #CONFIG blocks
#IFNDEF MCU_FOUND
#ERROR "No CONFIGs found for [" + __PROCESSOR__ +"]"
#ENDIF
define osc 20 ' Core is running at 20MHz
' Define LCD connections
Define LCD_DREG PORTD
Define LCD_DBIT 4
Define LCD_RSREG PORTE
Define LCD_RSBIT 0
Define LCD_EREG PORTE
Define LCD_EBIT 1
' Define program variables
col var byte ' Keypad column
row var byte ' Keypad row
key var byte ' Key value
OPTION_REG.7 = 0 ' Enable PORTB pullups
ADCON1 = 15 ' Make PORTA and PORTE digital
Low PORTE.2 ' LCD R/W low (write)
Pause 100 ' Wait for LCD to start
Lcdout $fe, 1, "Press any key" ' Display sign on message
looper: Gosub getkey ' Get a key from the keypad
Lcdout $fe, 1, #key ' Display ASCII key number
Goto looper ' Do it forever
' Subroutine to get a key from keypad
getkey:
Pause 50 ' Debounce
getkeyu:
' Wait for all keys up
PORTB = 0 ' All output pins low
TRISB = $f0 ' Bottom 4 pins out, top 4 pins in
If ((PORTB >> 4) != $f) Then getkeyu ' If any keys down, loop
Pause 50 ' Debounce
getkeyp:
' Wait for keypress
For col = 0 to 3 ' 4 columns in keypad
PORTB = 0 ' All output pins low
TRISB = (dcd col) ^ $ff ' Set one column pin to output
Pauseus 1
row = PORTB >> 4 ' Read row
If row != $f Then gotkey ' If any keydown, exit
Next col
Goto getkeyp ' No keys down, go look again
gotkey: ' Change row and column to key number 1 - 16
key = (col * 4) + (ncd (row ^ $f))
Return ' Subroutine over
End
Does anything jump out to anyone? I'm just playing with this board and am trying to get it to work. It says "PIC18F4550 recommended" but lists the 16F874 as a compatible chip. Thanks in advance.
Tony
Product in question
Schematic and code links
Bookmarks