PDA

View Full Version : Problems with 18F458



Russian
- 18th August 2005, 20:57
Hi everyone, I hope I can get some help on this great forum! =)

I have recently moved from PIC16F18 to PIC18F458, and I have remade one of my old programs for testing with the new processor. The program is supposed to write som text on a standart HD44780 LCD, and it worked fine on the 16F84. When I now connect my LCD to 18F458, the screen shows the last to symbols of the text string in the start of line 1, the screen also flickers in a wierd way, and the cursor is blinking, although I turn it off in the program. Sometimes when I get my fingers close to the processor, or the quartz crystal the screen goes baserk and starts writing some nonsense on both lines (still flickering). I don't know whats worng, since I have everything correctly connected and everything. I don't think, that it could be the program, because I tried with the simpliest thing (two flashing LED's) and it also worked out kindda wierd...Any ideas? Thanks, any help will be appreciated!

Regards Denis

CocaColaKid
- 18th August 2005, 21:17
What does your code look like? What pins is the LCD connected to? What are you using for an oscillator?

Russian
- 19th August 2005, 16:33
I use a 4 Mhz crystal as osc. and I use PORTB as output, this is what my code looks like, I have included the library for LCD in the txt file:

LIST p=18F458 ;tell assembler what chip we are using
include "p18f458.inc" ;include the defaults for the chip
ERRORLEVEL 0, -302 ;suppress bank selection messages

cblock 0x20 ;start of general purpose registers
;LCD
count ;used in looping routines
count1 ;used in delay routine
counta ;used in delay routine
countb ;used in delay routine
tmp1 ;temporary storage
tmp2 templcd ;temp store for 4 bit mode
templcd2

endc

LCD_PORT Equ PORTB
LCD_TRIS Equ TRISB
LCD_RS Equ 0x04
LCD_RW Equ 0x06
LCD_E Equ 0x07


;--------Program-------------------


SetPorts
movlw 0x00 ;make all pins outputs
movwf LCD_TRIS ;wait for LCD to settle
call Delay100
call LCD_Init ;setup LCD
call LCD_CurOff

ld
call LCD_Line1
movlw 'H'
call LCD_Char
movlw 'e'
call LCD_Char
movlw 'l'
call LCD_Char
movlw 'l'
call LCD_Char
movlw 'o'
call LCD_Char
movlw ' '
call LCD_Char
movlw 'W'
call LCD_Char
movlw 'o'
call LCD_Char
movlw 'r'
call LCD_Char
movlw 'l'
call LCD_Char
movlw 'd'
call LCD_Char
movlw '!'
call LCD_Char
movlw '!'
call LCD_Char
movlw '!'
call LCD_Char

endprg goto endprg


include <lcd.lib>


;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

end

NavMicroSystems
- 19th August 2005, 18:48
Russian,

Do you have a pullup resistor on MCLR ?

And hey, this is a PICBASIC Forum !

CocaColaKid
- 19th August 2005, 19:03
Sorry but assembly is greek to me.

Felch
- 19th August 2005, 19:54
Did you configure your 18f458 correctly? Especially LVP_OFF! This was the mistake, i made.
Here is my code, check for the LCDPUTCHAR routine.

Russian
- 20th August 2005, 13:57
I'm sorry, I know that this is a PIC Basic forum thats why I hadn't posted my code In the first thread. Yes, I have a pullup on MCLR, and LVP is off. Here I have a picture of what my screen shows when my program tries to write "Hello world!!!"

Felch
- 20th August 2005, 15:04
May-be your clock speed is too high? PLL ON perhaps?
Try simulating your code in MPLAB. If this works OK, it's something in hardware. If not, you'll find the bug quickly.

CocaColaKid
- 22nd August 2005, 05:00
I was just looking at your picture an couldn't help but notice the leads coming for the crystal. Shouldn't there be a empty space in between the pins. It looks like the pins are spaced at 0.100". It might be just the picture but I think the crystal is actually 0.200" pin spacing.

mister_e
- 22nd August 2005, 05:34
My 2 cents... the crystal is really to far of the PIC, and try to remove both capacitor... breadboard capacitance

CocaColaKid
- 22nd August 2005, 14:31
I actually found running 22pF with our PIC's caused us loads of troubles. Things would reset all the time, corrupt displays and sensors. Removed the capacitors and everything works fantastic now. Scope the ocsillator output and noticed the capacitors were actually causing a lot of noise.

Ingvar
- 22nd August 2005, 17:55
100ms delay before you initialize your display could be too short. Many displays needs alot more. Try a couple of seconds and see if that makes it work.

Russian
- 28th August 2005, 16:21
No, I tried everything, removed the caps, set the most of the conf. bits to be negative, moved the osc. closer, increased the init delay (though it has worked well with 100 with the same display but a PIC16F84)....nothing helps, it still writes "!" in the start of the first line instead of the "Hello world!"

Russian
- 28th August 2005, 16:37
Btw. here is a picture of my cfg.

Felch
- 28th August 2005, 21:02
Switch OFF LVP and BOR (brown-out-reset). If does not help, send your full code, i'll try to simulate it.
Btw, do you use 8 or 4-bit interface to LCD?

PS. Are you sure your code worked and that you ported it correctly? Type of LCD is also interesting.
PS/1. X-tal must be placed right next to uP, no wires!

Russian
- 29th August 2005, 18:18
LVP & BOR off, now it is only the cursor that blinks in the start of the line, no letters, I have my x-tal next to the uP no caps, I use 4 bit connection, with the RW pin grounded (thats why the initialize delay is 100, I did that for decreasing the number of pins used on my old PIC). Well, the display uses a normal 44780 controller it has the normal japaneese signs in the end of the ASCII table replaced with kyrillic letters, since I bought the LCD in Russia, there are really not much more about the display. Btw. I noticed, that when I short the x-tal pins with my finger, the text gets on it's right place, but as soon as I remove my finger it gets back to the blinking at the start of line 1.

Here is my full code and the LCD library (not mine, I only edited it).

Felch
- 29th August 2005, 18:39
Btw. I noticed, that when I short the x-tal pins with my finger, the text gets on it's right place, but as soon as I remove my finger it gets back to the blinking at the start of line 1.

Haa, this might explain everything! What's your clock freq.? Too high possibly. Anyway, I'll take a look at the code now.

Did you know that sub delay100 actually delays only 1,4 ms!!! ? Otherwise code works OK (on PIC18F452). You must add delays:
- before initializing LCD, about 100mS (use MPLAB-s simulator to check time)
- delay about 2mS after sending cmd or data to LCD (in the lib file)
See code.

Russian
- 31st August 2005, 21:28
Sorry, but i have never tried to use MPLAB so I don't know how to use the simulator =( But, that delay, you added in the end of the LCD.lib file, there stands that it is written for an 11,0592MHz clock how should I handle that? Anway, I tried to compile the program and run it, well there stands a 0 in the end of line1 and there stands something wird in the end of line 2...And, btw. how do I make that 100mS delay before init (I am a almost total lost, especially when things don't work)? Just add a loop that takes your routine 100 times?

Thanks for great responding!!!

Felch
- 31st August 2005, 22:06
Hi!
MPLAB is a great simulator for checking loop execution times and so on. It has it's bad sides also but i guess not here.
Anyway, i wanted to point out that if your xtal freq.=4MHz (usual), your 100mS delay loop actually delays much less, abot 1,4 mS!!! This will most probably explain veird LCD behaviour since it's a relatively slow device. Datasheets indicate that user should poll the BUSY flag before sending any kind of data to screen. In practice, it is rearely done, usually one would simply wait long enough to be at the safe side and then send another data/cmd byte.
So i added a routine that would delay some time at mentioned crystal freq. If your clock is slower then it simply takes some more time and that's all. Everything should work. It it's faster, you must add delay time.
I can not possibly comment 0-s or other chars at end of lines since i am not familiar with your enviroment. Still i hope you got the general idea (make it slower or poll busy flag).
Btw, what is your xtal frequency and what about your programming language?
Does it really have no means for measuring loop times?

Drop me a mail if anything remains unclear
/Felch