|
|
View previous topic :: View next topic |
Author |
Message |
dlee425 Guest
|
LCD Display Conversion |
Posted: Wed Jun 09, 2004 12:25 pm |
|
|
I have looked at the LCD.C file and still can not get this to work.
What I have is a pic16f876 with the data lines as follows:
C0=RS
C1=D1
C2=RW
C3=ENA
C4=D5
C5=D6
C7=D7
B1=D4
B2=D3
B3=D2
B4=D1
We have the displays from a project. These are already setup and just needs to be coded.
Can anyone help.....
Thanks,
Donnie Lee |
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Wed Jun 09, 2004 12:32 pm |
|
|
You have D1 in two places. Is C1 supposed to be D0? Plus, are you able to move the connections around if needed? |
|
|
Guest
|
|
Posted: Wed Jun 09, 2004 1:30 pm |
|
|
rnielsen wrote: | You have D1 in two places. Is C1 supposed to be D0? Plus, are you able to move the connections around if needed? |
Yes its D0.
No the circuit boards are already made up. Is there any changes I can make in the LCD.C file in examples to make the display work???
Thanks,
Donnie |
|
|
Kasper
Joined: 14 Jan 2004 Posts: 88 Location: Aurora, Ontario, Canada
|
Re: LCD Display Conversion |
Posted: Wed Jun 09, 2004 3:33 pm |
|
|
in 4 bit mode, you need to have access to:
RS, RW,E,D7,D6,D5,D4, preferrably on the same port.
Code: |
struct lcd_pin_map { // This structure is overlayed on port C
BOOLEAN rs;
BOOLEAN D1;
BOOLEAN rw;
BOOLEAN enable;
int data : 4;
} lcd;
#byte lcd = 7 // This puts the entire structure on the port C
|
The problem here is that you do not have D4 on port C, so you will have to change all data writes to toggle B1, which is your D4.
try changing this:
Code: |
void lcd_send_nibble( BYTE n ) {
lcd.data = n;
if(bit_test(n,0)) { // if I am not too high on caffein, it should be testing the data which would go to pin D4 and set pin B1 instead
output_high(pin_b1);
}
else(
output_low(pin_b1);
}
delay_cycles(1);
lcd.enable = 1;
delay_us(2);
lcd.enable = 0;
}
|
A similar approach in the lcd_read_bute function is needed to read the data from port B1, but for standard writes, it should not be needed, as only bit 7 is checked,as the busy flag, not bit 4 .
Hope this helps
Kasper
dlee425 wrote: | I have looked at the LCD.C file and still can not get this to work.
What I have is a pic16f876 with the data lines as follows:
C0=RS
C1=D1
C2=RW
C3=ENA
C4=D5
C5=D6
C7=D7
B1=D4
B2=D3
B3=D2
B4=D1
We have the displays from a project. These are already setup and just needs to be coded.
Can anyone help.....
Thanks,
Donnie Lee |
|
|
|
Guest
|
Re: LCD Display Conversion |
Posted: Thu Jun 10, 2004 1:19 pm |
|
|
[quote="Kasper"]in 4 bit mode, you need to have access to:
RS, RW,E,D7,D6,D5,D4, preferrably on the same port.
Code: |
struct lcd_pin_map { // This structure is overlayed on port C
BOOLEAN rs;
BOOLEAN D1;
BOOLEAN rw;
BOOLEAN enable;
int data : 4;
} lcd;
#byte lcd = 7 // This puts the entire structure on the port C
|
The problem here is that you do not have D4 on port C, so you will have to change all data writes to toggle B1, which is your D4.
try changing this:
Code: |
void lcd_send_nibble( BYTE n ) {
lcd.data = n;
if(bit_test(n,0)) { // if I am not too high on caffein, it should be testing the data which would go to pin D4 and set pin B1 instead
output_high(pin_b1);
}
else(
output_low(pin_b1);
}
delay_cycles(1);
lcd.enable = 1;
delay_us(2);
lcd.enable = 0;
}
|
A similar approach in the lcd_read_bute function is needed to read the data from port B1, but for standard writes, it should not be needed, as only bit 7 is checked,as the busy flag, not bit 4 .
Tryed this and still no go.
D1 is D0
So I wrote:
BOOLEAN rs;
BOOLEAN D0;
BOOLEAN rw;
BOOLEAN enable;
Now in your code you have the following:
void lcd_send_nibble( BYTE n ) {
lcd.data = n;
if(bit_test(n,0)) { // if I am not too high on caffein, it should be testing the data which would go to pin D4 and set pin B1 instead
output_high(pin_b1);
}
else(
output_low(pin_b1);
}
delay_cycles(1);
lcd.enable = 1;
delay_us(2);
lcd.enable = 0;
}
It has if(Bit_test(n,0)) then it has a bracket {
Thanks for you help...
Iam still learning..
Donnie |
|
|
Guest
|
16F876 Display Help!! |
Posted: Thu Jun 10, 2004 2:44 pm |
|
|
Here is a copy of my code. It still will not function.
Please help....
Donnie
Code: | ///////////////////////////////////////////////////////////////////////////
//// ////
//// lcd_init() Must be called before any other function. ////
//// ////
//// lcd_putc(c) Will display c on the next position of the LCD. ////
//// The following have special meaning: ////
//// \f Clear display ////
//// \n Go to start of second line ////
//// \b Move back one position ////
//// ////
//// lcd_gotoxy(x,y) Set write position on LCD (upper left is 1,1) ////
//// ////
//// lcd_getc(x,y) Returns character at position x,y on LCD ////
//// ////
//// C0 - RS ////
//// C1 - D0 ////
//// C2 - RW ////
//// C3 - ENA ////
//// C4 - D5 ////
//// C5 - D6 ////
//// C7 - D7 ////
//// B1 - D4 ////
//// ////
//// LCD pins D0-D3 are not used and PIC D3 is not used. ////
///////////////////////////////////////////////////////////////////////////
struct lcd_pin_map {
int unusedA; //A0-A7 Not Used
BOOLEAN dummy; // B0 Not Used
BOOLEAN D4; // B1 Data
int unusedB : 6; // The Rest Of B Not Used
BOOLEAN rs; //C0
BOOLEAN blank; //C1
BOOLEAN rw; //C2
BOOLEAN enable; //C3
BOOLEAN D5; //C4
BOOLEAN D6; //C5
BOOLEAN dummy2; //C6
int data : 1; //C7 Data Lines
} lcd;
#if defined(16F876)
// #byte lcd = 0xF82 // This puts the entire structure
//#else
#byte lcd = 7 // on to port C (at address 7)
#endif
#define set_tris_lcd(x) set_tris_b(x)
#else
#define set_tris_lcd(x) set_tris_d(x)
#endif
#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.
struct lcd_pin_map const LCD_WRITE = {0,0,0,0,0}; // For write mode all pins are out
struct lcd_pin_map const LCD_READ = {0,0,0,0,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;
// if(bit_test(n,0))
// output_high(PIN_B1); //B1 Toggles High
// else
// output_low(PIN_B1); //B1 Toggles Low
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);
while ( bit_test(lcd_read_byte(),7) ); // wait until busy flag is low
lcd.rs=1;
value = lcd_read_byte();
lcd.rs=0;
return(value);
}
|
|
|
|
Kasper
Joined: 14 Jan 2004 Posts: 88 Location: Aurora, Ontario, Canada
|
|
Posted: Thu Jun 10, 2004 2:51 pm |
|
|
you should use the struct as I wrote it
Code: |
struct lcd_pin_map { // This structure is overlayed on port C
BOOLEAN rs;
BOOLEAN D1;
BOOLEAN rw;
BOOLEAN enable;
int data : 4;
} lcd;
#byte lcd = 7
|
if you have more than 8 elements in the struct, as you have in yours and put it on a port, I am not sure how exactly the compiler will handle it, I will check later.
in the above structure, you have all the pins needed to control the LCD |
|
|
Kasper
Joined: 14 Jan 2004 Posts: 88 Location: Aurora, Ontario, Canada
|
Re: 16F876 Display Help!! |
Posted: Thu Jun 10, 2004 2:55 pm |
|
|
Try this.. it may work
Kasper
Code: |
///////////////////////////////////////////////////////////////////////////
//// ////
//// lcd_init() Must be called before any other function. ////
//// ////
//// lcd_putc(c) Will display c on the next position of the LCD. ////
//// The following have special meaning: ////
//// \f Clear display ////
//// \n Go to start of second line ////
//// \b Move back one position ////
//// ////
//// lcd_gotoxy(x,y) Set write position on LCD (upper left is 1,1) ////
//// ////
//// lcd_getc(x,y) Returns character at position x,y on LCD ////
//// ////
//// C0 - RS ////
//// C1 - D0 ////
//// C2 - RW ////
//// C3 - ENA ////
//// C4 - D5 ////
//// C5 - D6 ////
//// C7 - D7 ////
//// B1 - D4 ////
//// ////
//// LCD pins D0-D3 are not used and PIC D3 is not used. ////
///////////////////////////////////////////////////////////////////////////
struct lcd_pin_map { // This structure is overlayed on port C
BOOLEAN rs;
BOOLEAN D1;
BOOLEAN rw;
BOOLEAN enable;
int data : 4;
} lcd;
#byte lcd = 7 // on to port C (at address 7)
#define set_tris_lcd(x) set_tris_c(x)
#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.
struct lcd_pin_map const LCD_WRITE = {0,0,0,0,0}; // For write mode all pins are out
struct lcd_pin_map const LCD_READ = {0,0,0,0,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;
if(bit_test(n,0)) {
output_high(PIN_B1); //B1 Toggles High
}
else {
output_low(PIN_B1); //B1 Toggles Low
}
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);
while ( bit_test(lcd_read_byte(),7) ); // wait until busy flag is low
lcd.rs=1;
value = lcd_read_byte();
lcd.rs=0;
return(value);
}
|
|
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Fri Jun 11, 2004 3:08 pm |
|
|
kasper, as for overlaying over mutiple ports,... it works fine. I do it all the time on PIC 18 's .
struct lcd_pin_def
{
BOOLEAN w_bar; // A0 Write bar active low
BOOLEAN r_bar; // A1 Read bar active low
BOOLEAN cd; // A2 Command/Data BAR 1=command 0=data
BOOLEAN reset_bar; // A3 Reset active low
BOOLEAN ce_bar; // A4 Chip Enable BAR active low
BOOLEAN fs; // A5 Font select
BOOLEAN unusedA6; // A6 Unused
BOOLEAN unusedA7; // A7 Unused
int unusedB: 8 ;// B Unused
int unusedC: 8 ;// C Unused
int data : 8 ;// D=Data bus
};
struct lcd_pin_def LCD; |
|
|
|
|
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
|