-
LCD problem
i am using a 18F4550 and the plan is to send messages from usb to the lcd, the problem is i can not get my screen stable, can i run the pic at 20Mhz?
Any ideas would be welcome
Code:
INCLUDE "MODEDEFS.BAS"
DEFINE LOADER_USED 1
DEFINE RESET_ORG 1000h ' For Microchip USB Bootloader
DEFINE OSC 20 ' Define crystal as 20Mhz
'Define ACDIN parameters
Define ADC_BITS 10 ' Set number of bits in result
DEFINE ADC_CLOCK 3 ' Set clock source ( 3 = RC )
DEFINE ADC_SAMPLEUS 50 ' Set sampling time to micro-seconds
'This Part set PORTA 0-3 an analog inputs,4 as digital
TRISA = %00011111 'set PORTA 0-5 as inputs
ADCON1 = %00001010 'ADC use vss and vdd as ref.
ADCON2 = %10000111 'FRC (clock derived from A/D RC oscillator),Right justify output
TRISC = %10000000
TRISB = %10011000
TRISD = %00000000
'**************************************Serial port setup*************************************
'*Serial port Setup 3800 8N1*
DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
DEFINE HSER_CLROERR 1 ' Clear overflow automatically
DEFINE HSER_SPBRG 56 ' 38400 Baud @ 48MHz, -0.16%
SPBRGH = 1
BAUDCON.3 = 1 ' Enable 16 bit baudrate generator
'**************************************LCD setup*********************************************
' Set LCD Data port
DEFINE LCD_DREG PORTD
' Set starting Data bit (0 or 4)if 4-bit bus
DEFINE LCD_DBIT 0
' Set LCD Register Select port
DEFINE LCD_RSREG PORTD
' Set LCD Register Select bit
DEFINE LCD_RSBIT 5
' Set LCD Enable port
DEFINE LCD_EREG PORTD
' Set LCD Enable bit
DEFINE LCD_EBIT 4
' Set LCD bus size (4 or 8 bits)
DEFINE LCD_BITS 4
' Set number of lines on LCD
DEFINE LCD_LINES 2
' Set command delay time in us
DEFINE LCD_COMMANDUS 2000
' Set data delay time in us
DEFINE LCD_DATAUS 50
'**************************************Variables*********************************************
buffer Var Byte[70]
cnt Var Byte
LED Var PORTD.4
CELL1 var byte[70]
i var byte
USBInit
Low LED ' LED off
'**************************************Main Program******************************************
LCDOUT $FE,1
PAUSE 1000
main:
LCDOUT $FE,2
LCDOUT "line 1"
LCDOUT $FE, $C0
LCDOUT "line 2"
PAUSE 1000
goto main
END
-
Hi Andre, Try this, dunno if it will help, but worth a try,
Code:
main:
LCDOUT $FE,$80
LCDOUT "line 1 "
LCDOUT $FE, $C0
LCDOUT "line 2"
PAUSE 1000
goto main
-
How do you have the OSC configed?
This might be a clue
http://www.picbasic.co.uk/forum/show...9&postcount=14
-
Dave, I don't think that your link will help because the code show that the OP use MicroChip bootloader.
One day I should Try it myself :o
Main Problem is
As far as I remember, Microchip Bootloader config fuses and code assume 48MHz BUT with a 20MHz crystal. So I would try
-
Well at least I got the OSC 48 part. :o
Never used a boot loader though.
Do you set the configs the same as with out one?
-
Most Bootloader I know, will ignore the config fuses in your code as they're already set in their firmware and don't have the ability to re-program them on the fly. HOWEVER, for many PIC18, you can do it later in your code. Darrel Already post something on that... BUT, using this, you will probably screw up most Bootloader... no free lunch ;)
Bootloader are nice for firmware upgrade, but for development, they have their own limitations.
-
-
Thanks guys
Changing to define osc 48 fixed all the problems, LCD serial everything. Now for the question -- Why???
On all the other projects you set the define to the cristal freq. but now you set almost 1.5 times higher.
I am confused :confused:can someone PLEASE explain this to me
-
Well, look in the datasheet, Oscillator section, and check the available configuration fuses setting. Yes they're a bit tricky to understand...
From there, you may discover that you can even have a processor speed of 48MHz using a 4MHz crystal... this is accomplished by the internal set of clock divider and PLL.
As Microchip's bootloader set the Config Fuses for an internal processor speed of 48Mhz, your code must follow it.