PIC16C to PIC18F4331 LCD Prob.

Dec 05, 2007 8 Replies

Hi All,



Got the LCD working perfectly on the PIC16C54C. When I transferred the code to PIC18F4331, apparantly all hell broke loose. Nothing was displayed.



I tried simulating the code on MPLAB and its working fine. Tried to zoom down onto the possible cause. Inserted BSF PORTA,2 / 3 / 4 with LED tied to it.



To my horror, the code stucks at this part:



BSF PORTA,2 BSF PORTA,3



CALL DELAY CALL INITLCD CALL DELAY



BSF PORTA,4



PORTA,4 (LED) never got lit up. Is this a problem of the program stuck or resetting? If so what could attribute to theses? The config code are as follows: CONFIG OSC = XT CONFIG WDTEN = OFF CONFIG PWMPIN = OFF CONFIG PWM4MX = RB5 CONFIG SSPMX = RC7 CONFIG FLTAMX = RC1



By the way, the LED is able to light up as coded if I removed a great amount of subroutines. Don't think it is a stack overflow problem as MPLAB doesn't show such an error. Could it be due to page issues?? or?? I am lost all possibilities just keep flooding me now.....



Thanks ywz


...

...

Looks like it's hanging waiting for something in INITLCD. Status bit perhaps? Is the clock faster, so the timings are wrong? Voltage levels the same? Using the same ports? Anything different about initialisation sequence?

If you can't figure it out, try doing a binary search inserting your LED command halfway between points until you find where it's hanging. Primitive, so primitive, but doable. Maybe you have a bank selection issue or something of that ilk.

Don't you have a debugger so you can see what's going on in the target hardware? We are in the 21st century.

Also, you should (almost) never do BSF PORTx. Use BSF LATx.

Best regards, Spehro Pefhany

"it\'s the network..." "The Journey is the reward" speff@interlog.com Info for manufacturers: http://www.trexon.com Embedded software/hardware/analog Info for designers: http://www.speff.com
:

:

formatting link

increase the delay routine and see what happens...

is it possible you're simply turning it off before you see anything? or maybe the output isn't responding fast enough before you then turn it off? Have you placed a scope or some kind of external trigger lock to monitor this? I guess the simplest thing to do is write a basic couple lines just to turn on/off an LED via a state of an input. That would verify that your understanding of the code you're using is correct.

"I\'d rather have a bottle in front of me than a frontal lobotomy" http://webpages.charter.net/jamie_5

Hi All,

Using LATA instead doesn't solve the problem.

The subroutine "INITLCD" doesn't hang if run isolatedly without the other portions of the code. However, when placed with all the codes, the program hangs at that routine.

Ok,,, let me suggest this.. Is it possible you are executing to much code between an event that is getting expired? or maybe you have an interrupt running to fast for other code to get executed ? it's very possible you are exceeding the uC's clock speed and code usage ? Just a thought but I still think you have an obvious problem you're over looking.

"I\'d rather have a bottle in front of me than a frontal lobotomy" http://webpages.charter.net/jamie_5

Hi All,

Solved the problem partially. Apparantly must be LVP=off to use RB3. Does this affect anything like prevent the chip from being erased or rewritten?

Another mistake spotted:

ADDWF PCL,F RETLW 1 RETLW 2

This does not work. When it hits the ADDWF PCL, it jumps to another part of the code and not RETLW 1.

My chips are having prob. reprogramming now. Is LVP=off the prob.??

This is due to paging. I resolved it.

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required