1 Attachment(s)
Help on lCD and PIC18F4550 setup
Hi, sorry to post this beginner question, but I'm having trouble displaying text to the LCD with Pic18F4550 on 4Mz..
Code:
Code:
Define OSC 48 ' Core is running at 48MHz
Define LCD_DREG PORTB
Define LCD_DBIT 4
Define LCD_RSREG PORTB
Define LCD_RSBIT 4
Define LCD_EREG PORTB
Define LCD_EBIT 4
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2500
DEFINE LCD_DATAUS 250
ADCON1 = 15 ' Set PORTA and PORTE to digital
Pause 100 ' Wait for LCD to start up
mainloop:
Lcdout $fe, 1 ' Clear screen
Pause 500 ' Wait .5 second
Lcdout "Hello" ' Display "Hello"
Pause 500 ' Wait .5 second
Lcdout $fe, $c0, "World" ' Move to line 2 and display "World"
Pause 500 ' Wait .5 second
Goto mainloop ' Do it forever
End
Attached is my pin connections on easypic6Attachment 5962
I'm having doubts with my LCD Settings, and how can I make it work using 8Mz crystal?
thanks in advance,
tacbanon
Re: Help on lCD and PIC18F4550 setup
I think this should be portb.5
Code:
Define LCD_DREG PORTB
Define LCD_DBIT 4
Define LCD_RSREG PORTB
Define LCD_RSBIT 4
Define LCD_EREG PORTB
Define LCD_EBIT 4
And if you are using a 4 or 8 mhz crystal, then you probably are not running at 48mhz.
Re: Help on lCD and PIC18F4550 setup
Okay no luck yet on the LCD but I managed to run the USBdemo(by mister_e) on 8Mz using..
__CONFIG _CONFIG1L, _PLLDIV_2_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
Re: Help on lCD and PIC18F4550 setup
Code:
Define LCD_DREG PORTB
Define LCD_DBIT 0
Define LCD_RSREG PORTB
Define LCD_RSBIT 4
Define LCD_EREG PORTB
Define LCD_EBIT 5
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2500
DEFINE LCD_DATAUS 250
Re: Help on lCD and PIC18F4550 setup
Thanks for the responce mister_e and scalerobotics. I tried your suggestions but still have no text display on the LCD...
I make sure that in the configuration setting Oscillator is HS..any idea what I'm doing wrong?
regards,
tacbanon
Re: Help on lCD and PIC18F4550 setup
Quote:
Originally Posted by
scalerobotics
And if you are using a 4 or 8 mhz crystal, then you probably are not running at 48mhz.
Now I'm using 20Mhz crystal...but still no display.
Re: Help on lCD and PIC18F4550 setup
tacbanon,
Not sure why you want to run at 48 MHz clock rate, but here is a routine that I have used at 8 MHz on a 18F4550 (and I know it works) on my EasyPic6 with PBP v2.6.
Code:
'****************************************************************
'* Name : EasyPic_18F4550_DisplayDemo.pbp *
'* Author : John R. Ellis *
'* Date : 11/28/2009 *
'* Version : 1.0 *
'* Notes : Setup is for use on EasyPic6 development board *
'* : *
'* Device : 18F4550 installed in EasyPic6 *
'* Memory : 408 bytes of Program Memory required *
'* Ref: : *
'****************************************************************
Define OSC 8
;--- if you un-comment these, you must comment the ones in the .inc file--
ASM ; 18F2550/4550, 8mhz crystal
__CONFIG _CONFIG1L, _PLLDIV_2_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
__CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H
__CONFIG _CONFIG2L, _PWRT_ON_2L & _BOR_OFF_2L & _VREGEN_ON_2L
__CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
__CONFIG _CONFIG3H, _PBADEN_OFF_3H ; PortB resets as digital
__CONFIG _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
ENDASM
INCLUDE "ALLDIGITAL.pbp" ' Sets all registers for digital ops.
' User must make sure the AllDigital.pbp file
' is in same directory location as this source
' code before compiling.
'DEFINE SHOWDIGITAL 1 ' When uncommented will show analog settings
' in Assembler Results window.
' A/D & Comparators disabled for digital ops
' All of these statements should be commented out when using the
' INCLUDE "AllDigital.pbp" statement to set digital ops.
'ADCON1 = %00001111
'CMCON = 7
' Initialize Hardware
' -------------------
TRISA =%00000000
TRISB =%00000000
TRISC =%00000000
TRISD =%00000000
TRISE.0 = 0
TRISE.1 = 0
TRISE.2 = 0
INTCON2.7 = 0
'** DEFINE LCD Control Constants **
'====================================
L CON 254 ' Control Byte ($FE)
Clr CON 1 ' Clear the display
Line1 CON 128 ' Point to beginning of line 1 ($80)
Line2 CON 192 ' Point to beginning of line 2 ($C0)
' LCD DEFINES FOR USE WIH 2x16 LCD INSTALLED IN EASYPIC6
'=======================================================
DEFINE LCD_DREG PORTB ' Use PortB for LCD Data
DEFINE LCD_DBIT 0 ' Use lower(4) 4 bits of PortB
' PORTB.0 thru PORTB.3 connects to
' LCD DB4 thru LCD DB-7 respectively
DEFINE LCD_RSREG PORTB ' PORTB for RegisterSelect (RS) bit
DEFINE LCD_RSBIT 4 ' PORTB.4 pin for LCD's RS line
DEFINE LCD_EREG PORTB ' PORTB for Enable (E) bit
DEFINE LCD_EBIT 5 ' PORTB.5 pin for LCD's E line
DEFINE LCD_BITS 4 ' Using 4-bit bus
DEFINE LCD_LINES 2 ' Using 2 line Display
DEFINE LCD_COMMANDUS 2000 ' Command Delay (uS)
DEFINE LCD_DATAUS 200 ' Data Delay (uS)
'Main Loop
'=========
Main:
Pause 1000 ' Delay to let LCD start up
LCDOut L,CLR:Pause 50 ' Clear Display
LCDOut L,Line1+2," TEST " ' Display "TEST" on 1st line
PAUSE 500
LCDOut L,Line2+2,"..Power On.. !!" ' Display "Power on" on 2nd line
PAUSE 10000
Goto Main ' Continue loop
Re: Help on lCD and PIC18F4550 setup
Quote:
Originally Posted by
jellis00
tacbanon,
Not sure why you want to run at 48 MHz clock rate,
probably to use the USB... just an idea.
To run @48MHz using a 4MHZ crystal, add those line at the top of your code. It's a copy/paste from my USBDemo
Code:
'
' Pic Configuration
' =================
asm
__CONFIG _CONFIG1L, _PLLDIV_1_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
; ; ; USB clock source comes from the 96 MHz PLL divided by 2
; ; [OSC1/OSC2 Src: /1][96 MHz PLL Src: /2]
; No prescale (4 MHz oscillator input drives PLL directly)
__CONFIG _CONFIG1H, _FOSC_XTPLL_XT_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
; ; ; Oscillator Switchover mode disabled
; ; Fail-Safe Clock Monitor disabled
; XT oscillator, PLL enabled, XT used by USB
__CONFIG _CONFIG2L, _PWRT_ON_2L & _BOR_ON_2L & _BORV_2_2L & _VREGEN_ON_2L
__CONFIG _CONFIG2H, _WDT_OFF_2H
__CONFIG _CONFIG3H, _MCLRE_ON_3H & _LPT1OSC_OFF_3H & _PBADEN_OFF_3H & _CCP2MX_ON_3H
__CONFIG _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _ICPRT_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L
endasm
DEFINE OSC 48
now check the datasheet for the complete Config Fuse explanation. The OIscillator block on this one is not so simple.
Re: Help on lCD and PIC18F4550 setup
Hi everyone, sorry for the late reply. I got it working now, of course with the help of mister_e's suggestion...thanks steve
Re: Help on lCD and PIC18F4550 setup
I always put these reminder comments in my code when attempting to program to my EASYPIC6. Are you sure you have the switch settings correct on your EASYPIC6 according to these instructions?
' * NOTES for use with EasyPic6 development board:
'For use with COG 2x16 LCD:
' - Turn on Port Expander switches SW6.1, SW6.2, SW6.3, SW6.4 and SW6.5.
' - Turn on COG LCD 2x16 switches SW10.1, SW10.2, SW10.3, SW10.4, SW10.5
' and SW10.6.
Re: Help on lCD and PIC18F4550 setup
Hi jellis00, thanks for the tip..
regards,
tacbanon
1 Attachment(s)
Re: Help on lCD and PIC18F4550 setup
Hi, I'm trying to run this example code using the Matrix keypad routine from Mister_e
Code:
INCLUDE "KeyPad.bas" asm
__CONFIG _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
__CONFIG _CONFIG2L, _PWRT_ON_2L & _BOR_ON_2L & _BORV_2_2L & _VREGEN_ON_2L
__CONFIG _CONFIG2H, _WDT_OFF_2H
__CONFIG _CONFIG3H, _MCLRE_ON_3H & _LPT1OSC_OFF_3H & _PBADEN_OFF_3H & _CCP2MX_ON_3H
__CONFIG _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _ICPRT_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L
endasm
DEFINE OSC 48
DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 0
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 5
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 4
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
DEFINE LCD_COMMANDUS 2000
DEFINE LCD_DATAUS 50
'
' Hardware connection
' ===================
DEFINE KEYPAD_ROW 4 ' 8 row
define KEYPAD_ROW_PORT PORTD ' on PORTB
DEFINE KEYPAD_ROW_BIT 4 '
DEFINE KEYPAD_COL 4 ' 4 col
DEFINE KEYPAD_COL_PORT PORTD ' on PORTA
DEFINE KEYPAD_COL_BIT 0 '
DEFINE KEYPAD_DEBOUNCEMS 200 ' debounce delay = 200 mSec
define KEYPAD_AUTOREPEAT 1 ' use auto-repeat
'
' Serial Communication definition
' ===============================
'DEFINE HSER_TXSTA 24h ' enable transmit, BRGH=1
'DEFINE HSER_SPBRG 129 ' 9600 Bauds
'
' Variables definition
' ===================
myvar var byte
' ---------------------------------[Program Start]----------------------------------------------
start:
@ READKEYPAD _myvar
Lcdout $fe, 128,"Key=",dec myvar
goto start
But the program just freeze on my easypic6, initially displays "Key=20", I'm using PortD for my keypad(4x4) and I made sure I have pull down-PortD. I set DEFINE KEYPAD_COL_BIT 0 and DEFINE KEYPAD_ROW_BIT 4 (I also tried to inverse them 4-0) but the same problem. Can you tell me what I'm doing wrong on my setup?
thanks,
tacbanon