|
|
View previous topic :: View next topic |
Author |
Message |
Markdem
Joined: 24 Jun 2005 Posts: 206
|
Changing LCD pinouts |
Posted: Mon Jul 25, 2005 12:59 am |
|
|
Hi All, i am using the standed LCD240.c driver to drive my LCD and it works great. I have no added a ethernet interface to my pic for web based administraton, but it uses port B. Can i change the pins that the LCD uses, but i need to use two ports . eg 4 bit data on port A and the control pins to be on port D. I have had a look on the web, but all i can find is how to change just the port.
Thanks, Mark |
|
|
Guest
|
|
Posted: Mon Jul 25, 2005 3:43 am |
|
|
Hi Again, i have just been looking at the forum again, and i have found some code.I am not too sure how i missed it last time.
I have made the chages to it the way i need them, but he LCD will not start. eg i just have black squares in the display
My pinouts are as follows:
PIC LCD
A1 D4
A2 D5
A3 D6
A4 D7
A5 enable
C2 RS
C3 Rw
The following is my code:
Code: |
struct lcd_pin_map
{
BOOLEAN dummy; // PinA0 is not used
int data : 4;
BOOLEAN enable;
int unusedA6_A7 : 2;
int unusedB;
int unusedC0 : 1;
BOOLEAN rs;
BOOLEAN rw;
int unusedC3_C7 : 4;
int unusedD;
int unusedE;
} lcd;
#if defined(__PCH__)
#locate lcd = 0xF80
#else
#locate lcd = 5
#endif
struct lcd_tris_map
{
BOOLEAN dummy; // PinA0 is not used
int data : 4;
BOOLEAN enable;
int unusedA5_A7 : 2;
int unusedB : 8;
int unusedC0 : 1;
BOOLEAN rs;
BOOLEAN rw;
int unusedC3_C7 : 5;
int unusedD : 8;
int unusedE : 8;
} lcdtris;
#if defined(__PCH__)
#locate lcdtris = 0xF92
#else
#locate lcdtris = 0x85
#endif
#define set_tris_lcd(x) lcdtris.data = (x); lcdtris.rs = 0; lcdtris.rw = 0; lcdtris.enable = 0;
#define lcd_type 2 // 0=5x7, 1=5x10, 2=2 lines
#define lcd_line_two 0x40 // LCD RAM address for the second line
BYTE const LCD_INIT_STRING[4] = {0x20 | (lcd_type << 2), 0xc, 1, 6};
// These bytes need to be sent to the LCD
// to start it up.
// The following are used for setting
// the I/O port direction register.
#define LCD_WRITE 0 // For write mode all pins are out
#define LCD_READ 15 // For read mode data pins are in
BYTE lcd_read_byte() {
BYTE low,high;
set_tris_lcd(LCD_READ);
lcd.rw = 1;
delay_cycles(1);
lcd.enable = 1;
delay_cycles(1);
high = lcd.data;
lcd.enable = 0;
delay_cycles(1);
lcd.enable = 1;
delay_us(1);
low = lcd.data;
lcd.enable = 0;
set_tris_lcd(LCD_WRITE);
return( (high<<4) | low);
}
void lcd_send_nibble( BYTE n ) {
lcd.data = n;
delay_cycles(1);
lcd.enable = 1;
delay_us(2);
lcd.enable = 0;
}
void lcd_send_byte( BYTE address, BYTE n ) {
lcd.rs = 0;
while ( bit_test(lcd_read_byte(),7) ) ;
lcd.rs = address;
delay_cycles(1);
lcd.rw = 0;
delay_cycles(1);
lcd.enable = 0;
lcd_send_nibble(n >> 4);
lcd_send_nibble(n & 0xf);
}
void lcd_init() {
BYTE i;
set_tris_lcd(LCD_WRITE);
lcd.rs = 0;
lcd.rw = 0;
lcd.enable = 0;
delay_ms(15);
for(i=1;i<=3;++i) {
lcd_send_nibble(3);
delay_ms(5);
}
lcd_send_nibble(2);
for(i=0;i<=3;++i)
lcd_send_byte(0,LCD_INIT_STRING[i]);
}
void lcd_gotoxy( BYTE x, BYTE y) {
BYTE address;
if(y!=1)
address=lcd_line_two;
else
address=0;
address+=x-1;
lcd_send_byte(0,0x80|address);
}
void lcd_putc( char c) {
switch (c) {
case '\f' : lcd_send_byte(0,1);
delay_ms(2);
break;
case '\n' : lcd_gotoxy(1,2); break;
case '\b' : lcd_send_byte(0,0x10); break;
default : lcd_send_byte(1,c); break;
}
}
char lcd_getc( BYTE x, BYTE y) {
char value;
lcd_gotoxy(x,y);
lcd.rs=1;
value = lcd_read_byte();
lcd.rs=0;
return(value);
}
|
and my main program:
Code: |
#include <16F877a.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#include <marklcd420.c>
void main() {
delay_ms(500);
lcd_init();
delay_ms(500);
while(TRUE)
{
lcd_gotoxy(1,1);
printf(lcd_putc,"Line 1");
lcd_gotoxy(1,2);
printf(lcd_putc,"Line 2");
lcd_gotoxy(1,3);
printf(lcd_putc,"Line 3");
lcd_gotoxy(1,4);
printf(lcd_putc,"Line 4");
delay_ms(500);
}
}
|
Can anyone see where i have gone wrong??
Thank you very much
Mark |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jul 25, 2005 4:09 am |
|
|
I see a few things. Your chart below, doesn't match the two
pin structures. Your structures use Pin C1 and C2. So
which one is correct -- the chart or the structures ?
Quote: | PIC LCD
A1 D4
A2 D5
A3 D6
A4 D7
A5 enable
C2 RS
C3 Rw |
Another thing is that in your tris map structure, you're saying that
A5 to A7 are unused. But you really mean A6 to A7 as shown
in your pin map structure. The width is right, so that one is
just a typo, but it should be fixed.
Then finally, pin A4 is open drain. Do you have a pull-up resistor on it ?
You could use a 4.7K ohm resistor. |
|
|
Guest
|
|
Posted: Mon Jul 25, 2005 4:30 am |
|
|
Hi PCM programmer, thankyou so much for your help. The code was OK, but the Pinout i gave was wrong. Rs and Rw is C1 and C2. I also did not know that i had to pull A4 up. I am only new to this.
Thanks, Mark |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|