PDA

View Full Version : 18F87K22 Port B Digital



gavo
- 28th July 2014, 17:48
Hi,

I am using a PIC18F87K22 and want to write a simple message to the LCD but something is not right, perhaps the set up of Port B is not correct?, any help would be greatly appreciated, I have the following code below:


DEFINE OSC 16
Define LCD_DREG PORTB ' Define LCD connections
Define LCD_DBIT 0
Define LCD_RSREG PORTB
Define LCD_RSBIT 4
Define LCD_EREG PORTB
Define LCD_EBIT 5
DEFINE LCD_BITS 4 'LCD bus size 4 or 8
DEFINE LCD_LINES 2 'Number lines on LCD
DEFINE LCD_COMMANDUS 2000 'Command delay time in us
DEFINE LCD_DATAUS 50 'Data delay time in us

ANCON0 = 0
ANCON1 = 0
ANCON2 = 0
Pause 10 ' Wait for LCD to startup



STARTUP:


Lcdout $fe, 1,"HELLO "
Lcdout $fe,$C0,"WORLD "
PAUSE 4000

goto startup



END

pedja089
- 28th July 2014, 18:23
There is no fuse, and OSCCON isnt set.
Here is config for internal osc and 16MHz:

#CONFIG
CONFIG RETEN = OFF
CONFIG INTOSCSEL = LOW
CONFIG SOSCSEL = LOW
CONFIG XINST = OFF
CONFIG FOSC = INTIO2
CONFIG PLLCFG = OFF
CONFIG FCMEN = OFF
CONFIG IESO = OFF
CONFIG PWRTEN = ON
CONFIG BOREN = OFF
CONFIG BORV = 3
CONFIG BORPWR = ZPBORMV
CONFIG WDTEN = OFF
CONFIG WDTPS = 1048576
CONFIG RTCOSC = SOSCREF
CONFIG CCP2MX = PORTC
CONFIG MSSPMSK = MSK7
CONFIG MCLRE = OFF
CONFIG STVREN = ON
CONFIG BBSIZ = BB2K
CONFIG CP0 = OFF
CONFIG CP1 = OFF
CONFIG CP2 = OFF
CONFIG CP3 = OFF
CONFIG CP4 = OFF
CONFIG CP5 = OFF
CONFIG CP6 = OFF
CONFIG CP7 = OFF
CONFIG CPB = OFF
CONFIG CPD = OFF
CONFIG WRT0 = OFF
CONFIG WRT1 = OFF
CONFIG WRT2 = OFF
CONFIG WRT3 = OFF
CONFIG WRT4 = OFF
CONFIG WRT5 = OFF
CONFIG WRT6 = OFF
CONFIG WRT7 = OFF
CONFIG WRTC = OFF
CONFIG WRTB = OFF
CONFIG WRTD = OFF
CONFIG EBRT0 = OFF
CONFIG EBRT1 = OFF
CONFIG EBRT2 = OFF
CONFIG EBRT3 = OFF
CONFIG EBRT4 = OFF
CONFIG EBRT5 = OFF
CONFIG EBRT6 = OFF
CONFIG EBRT7 = OFF
CONFIG EBRTB = OFF
#ENDCONFIG

DEFINE OSC 16
DEFINE NO_CLRWDT 1
OSCCON = %01110010

longpole001
- 28th July 2014, 23:19
here is commented config for 18f67k22 , 64mhz internal



' config for 18F67K22

#CONFIG

;----- CONFIG1L Options --------------------------------------------------
CONFIG XINST = OFF
CONFIG SOSCSEL = DIG ; Digital (SCLKI) mode; I/O port functionality of RC0 and RC1 is enabled
CONFIG INTOSCSEL = HIGH ; LF-INTOSC in High-power mode during Sleep
CONFIG RETEN = ON

;----- CONFIG1H Options --------------------------------------------------
CONFIG IESO = OFF
CONFIG FCMEN = OFF
CONFIG PLLCFG = ON
CONFIG FOSC = INTIO2 ; Internal RC oscillator

;----- CONFIG2L Options --------------------------------------------------
CONFIG BORPWR = ZPBORMV ; ZPBORMV instead of BORMV is selected
CONFIG BORV = 2 ; 2V
CONFIG BOREN = SBORDIS ; Enabled in hardware, SBOREN disabled
CONFIG PWRTEN = ON ; Power up timer on

;----- CONFIG2H Options --------------------------------------------------
CONFIG WDTPS = 512 ; 1:512
CONFIG WDTEN = ON ; WDT ON

;----- CONFIG3L Options --------------------------------------------------
CONFIG RTCOSC = INTOSCREF ; RTCC uses internal osc

;----- CONFIG3H Options --------------------------------------------------
CONFIG MCLRE = ON ; MCLR Enabled, RG5 disabled
CONFIG MSSPMSK = MSK7 ; 7 Bit address masking mode
CONFIG CCP2MX = PORTC ; RC1

;----- CONFIG4L Options --------------------------------------------------
CONFIG DEBUG = OFF
CONFIG BBSIZ = BB1K ; 1K word Boot Block size
CONFIG STVREN = ON

;----- CONFIG5L Options --------------------------------------------------

CONFIG CP0 = OFF
CONFIG CP1 = OFF
CONFIG CP2 = OFF
CONFIG CP3 = OFF
CONFIG CP4 = OFF
CONFIG CP5 = OFF
CONFIG CP6 = OFF
CONFIG CP7 = OFF

;----- CONFIG5H Options --------------------------------------------------
CONFIG CPD = OFF
CONFIG CPB = OFF

;----- CONFIG6L Options --------------------------------------------------
CONFIG WRT0 = OFF
CONFIG WRT1 = OFF
CONFIG WRT2 = OFF
CONFIG WRT3 = OFF
CONFIG WRT4 = OFF
CONFIG WRT5 = OFF
CONFIG WRT6 = OFF
CONFIG WRT7 = OFF

;----- CONFIG6H Options --------------------------------------------------
CONFIG WRTD = OFF
CONFIG WRTB = OFF
CONFIG WRTC = OFF

;----- CONFIG7L Options --------------------------------------------------
CONFIG EBRT0 = OFF
CONFIG EBRT1 = OFF
CONFIG EBRT2 = OFF
CONFIG EBRT3 = OFF
CONFIG EBRT4 = OFF
CONFIG EBRT5 = OFF
CONFIG EBRT6 = OFF
CONFIG EBRT7 = OFF

;----- CONFIG7H Options --------------------------------------------------
CONFIG EBRTB = OFF

#ENDCONFIG




usually the problems are with C port or D port as config affects use of those ports





' ------- Setup port B Variables & directions ----------
INTCON2.7 = 0 ' Weak Pullups Globle PortB - 1= globel PortB disable, 0 = PortB Globle enable
INTCON2.0 = 1 ' RBIP - RB PortB Change Interupt Priority - 1 = High Priorty , 0 = Low Priority

TRISB = %11011111 ' setup Port B input=1,output=0 for I/O pins
PORTB = %00000000 ' Clear Outputs

Aussie Barry
- 29th July 2014, 02:45
You should also note that the PBP manual states ""a program should wait for up to half a second before sending the first command to an LCD. It can take quite a while for an LCD to start up."

I recently wasted an entire evening learning (the hard way) just how long it can take for an LCD to start up!

Change your line
Pause 10 ' Wait for LCD to startup

to

Pause 500 ' Wait for LCD to startup

and see how it goes.

Cheers
Barry
VK2XBP

gavo
- 29th July 2014, 07:50
Thanks All - Worked like a charm!, I now know to set Config Bits..;-)