Jump to content

Recommended Posts

I have a problem with the LCD setup. PIC is 18F2520

 

Here is the code:

 

#define LCD_ARGS 1, /* Interface type: mode 0 = 8bit, 1 = 4bit(low nibble), 2 = 4bit(upper nibble) */ \

0, /* Use busy signal: 1 = use busy, 0 = use time delays */ \

PORTC, TRISC, /* Data port and data port tris register */ \

PORTA, TRISA, /* Control port and control port tris register */ \

6, /* Bit number of control port is connected to RS */ \

4, /* Bit number of control port is connected to RW */ \

7 /* Bit number of control port is connected to Enable */

#include <lcd_driver.h> // LCD template code

 

This will not work but this does:

 

#define LCD_ARGS 2, /* Interface type: mode 0 = 8bit, 1 = 4bit(low nibble), 2 = 4bit(upper nibble) */ \

0, /* Use busy signal: 1 = use busy, 0 = use time delays */ \

PORTC, TRISC, /* Data port and data port tris register */ \

PORTA, TRISA, /* Control port and control port tris register */ \

1, /* Bit number of control port is connected to RS */ \

2, /* Bit number of control port is connected to RW */ \

3 /* Bit number of control port is connected to Enable */

#include <lcd_driver.h> // LCD template code

 

LCD works OK on High Nibble. Can anyone help me?

 

LCD is wired: RC0 -> DB4 RC1 -> DB5 RC2 -> DB6 RC3 -> DB7 for low nibble.

All I get is a flashing block cursor.

 

Same working LCD is wired: RC4 -> DB4 RC5 -> DB5 RC6 -> DB6 RC7 -> DB7 for high nibble.

Swapped LCD from another project using 16F883 chip. LCD works..

 

I usually use the high nibble but this project called for the LOW nibble.

The PCBoard has already been made so it

will be a hassle to change it to swap the pins to high.

Surely the LOW Nibble option is OK but what's wrong?

A bug in lcd_driver.h?

 

Carlos

Share this post


Link to post
Share on other sites

Well, I discovered that RC1 is always a 1. This pin is multiplexed with the CCP2 module.

This may be interfering with data to LCD. There is also a connection between Timer1 and CCP2.

Turning on T1OSCEN changes Dig I/O on RC1 to Analog. Crazy stuff here. I have turned off the CCP2

module using ccp2con = 0 but nothing clears RC1

 

I have tried to set it to work with its alternative RB3 but can't change it in the config bits for 3H.

 

Anyone got an answer here? I don't know what else to try.

 

Carlos

Share this post


Link to post
Share on other sites

Found the problem!

 

Can't use RA6 and RA7 as control pins for LCD.Probably due to the fact

all chips can't operate without crystal. Or sumtin' like 'at.

Rewired the board to use Hi nibble. No luck!

Then I rewired and used RA1,2 and 3 as LCD control port.

Works just fine as usual.

 

Carlos

Edited by Carlos

Share this post


Link to post
Share on other sites

Hi Carlos,

 

Have you got the config set correctly to use RA6 and RA7 as I/O pins ?

 

#pragma config OSC = INTIO67 // Internal oscillator block, port function on RA6 and RA7

I have used this PIC in a project with these pins for I/O.

 

Cheers

 

Reynard

Share this post


Link to post
Share on other sites

Hi

 

Yes the config is INTO67.

 

The pins do work as I/O but will not control the LCD.using lcd_header.h in LO nibble mode.

 

I've rewired the board and all is OK using A for control port and HI nibble.

 

Yeah, I've used the standard Boost C LCD setup for some time using any port for control.

This was the first time using those 2 lines for control.

 

Thanks...

 

Carlos

Share this post


Link to post
Share on other sites

Hi Carlos,

 

I have build a simple circuit using the 18F2520 and a 2x16 display.

 

#pragma CLOCK_FREQ 1000000
#define LCD_ARGS 1, /* Interface type: mode 0 = 8bit, 1 = 4bit(low nibble), 2 = 4bit(upper nibble) */ \
 0, /* Use busy signal: 1 = use busy, 0 = use time delays */ \
 PORTC, TRISC, /* Data port and data port tris register */ \
 PORTA, TRISA, /* Control port and control port tris register */ \
 5, /* Bit number of control port is connected to RS */ \
 6, /* Bit number of control port is connected to RW */ \
 7 /* Bit number of control port is connected to Enable */
#include <lcd_driver.h> // LCD template code
char *mesg = " Hello World ";
void main()
{
adcon1 = 0x0f;

lcd_setup();	 // Initialise the LCD display
lcd_clear();	 // Clear the LCD display
lcd_datamode();
lcd_write('A');
lprintf( mesg );    // Display a startup message on the LCD
lcd_datamode();
lcd_write('B');
while (1) {}
}

 

This is my code using low nibble on port C (0,1,2,3) and control on port A (5,6,7).

 

The LCD is displaying correctly.

 

There is a small problem when using lcd_write() in that you have to set the lcd_datamode() first as you do not know that state of the RS signal. It may have been left RS = 0 which screws up any single character writes.

 

There seems to be a bit of a bug in the lcd_write() function not setting the RS signal when writing a character.

 

Hope this helps.

 

Cheers

 

Reynard

Share this post


Link to post
Share on other sites

Thanks for the interest and help.

Will not work with mine.

I can easily rewire using A1 A2 instead of A6 A7 an salvage the pcb.

 

I was wondering if it works correctly why is the bug affecting your code?

 

Carlos

Share this post


Link to post
Share on other sites

Hi Carlos,

 

This one is a bit of a mystery.

 

I was only using the default oscillator frequency of 1MHz. I could try cranking it up to 8MHz.

 

I am using silicon version 7 but I don't see anything in the errata sheet that would cause problems.

 

The problem I was getting is the RS signal being left at 0 after the clear display or other command function. Then when I write a single character the RS signal is not being changed to a 1 to write the data. It works using the printf because it sets the RS signal before writing the data.

 

Have you tried writing your own LCD driver. I always avoid using drivers that come with a compiler. They never do exactly what I want and seldom run using inetrrupts for any of the serial ports.

 

It is sad that you have to modify your PCB for something that should work.

 

Good luck.

 

Reynard

Share this post


Link to post
Share on other sites

Found the cockpit error Reynard.

 

I assumed PortA was placed inline in order. Not so!

It goes 01234576. I thought it was 01234567.

 

Like I said, cockpit error.

Thanks for your help.

 

Carlos

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...