CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Custom LCD Driver

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
wea
Guest







Custom LCD Driver
PostPosted: Tue May 27, 2003 7:25 am     Reply with quote

Hi, i have a trouble.. My LCD pinouts are

LCD RS = RE0
LCD ENABLE = RE1
LCD DB4 = RD4
LCD DB5 = RD5
LCD DB6 = RD6
LCD DB7 = RD7

using 16f877.. this connections are same with melabs development board labXT..

how can i modify lcd library for my pinouts? need help please.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514779
acid
Guest







Re: Custom LCD Driver
PostPosted: Tue May 27, 2003 9:52 am     Reply with quote

You have need to change struct "lcd_map "
The first line is bit 0 the last line is bit 8

I.E. int data: 4 are the data I/O lcd (b4..b7)


:=Hi, i have a trouble.. My LCD pinouts are
:=
:=LCD RS = RE0
:=LCD ENABLE = RE1
:=LCD DB4 = RD4
:=LCD DB5 = RD5
:=LCD DB6 = RD6
:=LCD DB7 = RD7
:=
:=using 16f877.. this connections are same with melabs development board labXT..
:=
:=how can i modify lcd library for my pinouts? need help please.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514783
wea
Guest







Re: Custom LCD Driver
PostPosted: Tue May 27, 2003 10:33 am     Reply with quote

:=You have need to change struct "lcd_map "
:=The first line is bit 0 the last line is bit 8
:=
:=I.E. int data: 4 are the data I/O lcd (b4..b7)
:=


any little example?, it will be helpfull.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514785
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: Custom LCD Driver
PostPosted: Tue May 27, 2003 12:36 pm     Reply with quote

:=Hi, i have a trouble.. My LCD pinouts are
:=
:=LCD RS = RE0
:=LCD ENABLE = RE1
:=LCD DB4 = RD4
:=LCD DB5 = RD5
:=LCD DB6 = RD6
:=LCD DB7 = RD7
:=
:=using 16f877.. this connections are same with melabs development board labXT..
:=
:=how can i modify lcd library for my pinouts? need help please.
--------------------------------------------------------------

This LCD driver would be more suitable for modification.
<a href="http://www.VermontFicks.org/lcdc.htm" TARGET="_blank">http://www.VermontFicks.org/lcdc.htm</a>
He uses one port for the data bits and another port for
the control lines. So you can easily modify his driver to
use ports D and E instead. Also, you have to change
the processor from 16F84 to 16F877, etc.

A few comments:
Remember that on power-up, Port E is configured as analog
inputs (per the 16F877 data sheet). So make sure you have
this line at the start of your program:

setup_adc_ports(NO_ANALOGS);

Also, in the sample code at the link above, he has WDT
enabled in the #fuses statement, but he doesn't have any
"restart_wdt()" statement in his main code. So that's
one mistake in that code. Fix it by removing WDT from
the #fuses statement.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514789
wea
Guest







Re: Custom LCD Driver
PostPosted: Tue May 27, 2003 2:16 pm     Reply with quote

Thanks for answer. But in this script, i cant change DATA pins(A0-A3 to D4-D7) any help about that?
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514793
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: Custom LCD Driver
PostPosted: Tue May 27, 2003 3:28 pm     Reply with quote

:=Thanks for answer. But in this script, i cant change DATA pins(A0-A3 to D4-D7) any help about that?
----------------------------------------------

You could edit every line where he's writing to the DATA
pins, and do a left-shift by 4 bits. For example,

<PRE>
Where he has this:
DATA = 0x03;
You can do this:
DATA = (0x03 << 4);
Also do this where he write 0x02 to DATA.
<BR>
<BR>
Where he has this:
DATA = swap ( cX ) | 0x08;
PULSE_EN;
DATA = swap ( cX );
PULSE_EN;
<BR>
You can do this:
DATA = cX | 0x80; // Output high nybble of cX first
PULSE_EN;
DATA = swap ( cX ); // Then output low nybble
PULSE_EN;
<BR>
Where he has this:
DATA = swap ( cX ); /* send high nibble */
PULSE_EN;
DATA = swap ( cX ); /* send low nibble */
PULSE_EN;
You can do this
DATA = cX; /* send high nibble */
PULSE_EN;
DATA = swap ( cX ); /* send low nibble */
PULSE_EN;
</PRE>

I think the changes above should work. You should review it.
Also, I didn't list all the code that has to be changed.
But the other code that has to be modified is similar to
the examples shown above.


Here's another sample driver, that is more flexible
for modification than the previous one. This one is
written for a different compiler than CCS, but you
could translate it.
<a href="http://web.ukonline.co.uk/j.winpenny/pic/lcdtest.txt" TARGET="_blank">http://web.ukonline.co.uk/j.winpenny/pic/lcdtest.txt</a>
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514795
TSchultz



Joined: 08 Sep 2003
Posts: 66
Location: Toronto, Canada

View user's profile Send private message

RE: Custom LCD Driver
PostPosted: Tue May 27, 2003 3:47 pm     Reply with quote

:=Hi, i have a trouble.. My LCD pinouts are
:=
:=LCD RS = RE0
:=LCD ENABLE = RE1
:=LCD DB4 = RD4
:=LCD DB5 = RD5
:=LCD DB6 = RD6
:=LCD DB7 = RD7
:=
:=using 16f877.. this connections are same with melabs development board labXT..
:=
:=how can i modify lcd library for my pinouts? need help please.

Here is a driver I wrote quite a while ago, it was done for an 8 bit interface, but can be easily changed for 4 bit. Also the various pins used are easily changed. It was used on a PIC16F877 with an Optrex LCD display.

<pre>
/*********************************************************
Program: aLCD.C
Author: Troy Schultz
Date: 28 August 2000
**********************************************************
Driver for LCD modules using Hitachi HD44780 or compatible
driver IC.

Assumes FAST_IO is used.

Functions:
lcd_init() Initalization for LCD, must be called before
any other LCD function.

lcd_putc(c) Print c to display at current position.
Recognizes the following control codes;
\f Clear display
\n Goto second line
\b backspace

lcd_goto(x,y) Set current position to x,y on LCD
Upper left corner is 1,1

lcd_getc(x,y) Reads character at current position on LCD
**********************************************************
Revisions:
16 Nov 2000 TAS Added conditional compile in lcd_write(),
ICE emulator does not apear to work
properly with lcd_read() which is used
to read the busy flag. If EMULATION is
defined then delays are used.
**********************************************************/
// Control line definitions
#bit LCD_RS = 0x05.3 // RA3
#bit LCD_ENABLE = 0x05.4 // RA4
#bit LCD_RW = 0x05.5 // RA5
/*
#bit LCD_RS = 0x09.0
#bit LCD_ENABLE = 0x09.2
#bit LCD_RW = 0x09.1
*/
#byte LCD_WORD = 0x08 // RD0-7

// Function Prototypes
byte lcd_read( void );
void lcd_write( byte address, byte b );
void lcd_init( void );
void lcd_gotoxy( byte x, byte y);
void lcd_putc( char c);
char lcd_getc( void );

byte lcd_read( void ) {
byte word;

set_tris_d(0xFF); // set port D as inputs
delay_cycles(1);
LCD_RW = 1;
delay_cycles(1);
LCD_ENABLE = 1;
delay_cycles(4);
word = LCD_WORD;
LCD_ENABLE = 0;

LCD_RW = 0;
set_tris_d(0x00); //set port D as outputs
return( word );
}

void lcd_write( byte address, byte b ) {
LCD_ENABLE = 0;
LCD_RS = 0;
delay_cycles(4);
#IFNDEF EMULATION
while ( bit_test(lcd_read(),7) ) ;
#ELSE
delay_ms(1);
#ENDIF
LCD_RS = address;
LCD_RW = 0;
delay_cycles(1);
LCD_WORD=b;
delay_cycles(1);
LCD_ENABLE = 1;
delay_cycles(4);
LCD_ENABLE = 0;
}

void lcd_init( void ) {
byte i;

set_tris_d(0x00); //set port D as outputs
LCD_RS = 0;
LCD_RW = 0;
delay_ms(15);
for(i=1;i<=3;++i) {
LCD_ENABLE = 0;
LCD_WORD=0b00111000; //8 Bit Interface, 2 Lines
delay_cycles(1);
LCD_ENABLE = 1;
delay_ms(5);
}
lcd_write(0,0b00111000); //8 Bit Interface, 2 Lines
lcd_write(0,0b00001110); //Turn on display and cursor
lcd_write(0,0x00000001); //clear display
lcd_write(0,0x00000110); //Increment cursor
}


void lcd_gotoxy( byte x, byte y) {
byte address;

if(y!=1)
address=0x40;
else
address=0;
address+=x-1;
lcd_write(0,0x80|address);
}

void lcd_putc( char c) {
switch (c) {
case '\f' :
lcd_write(0,1);
#IFDEF EMULATION
delay_ms(5);
#ENDIF
break;
case '\n' :
lcd_gotoxy(1,2);
break;
case '\b' :
lcd_write(0,0x10);
break;
default :
lcd_write(1,c);
break;
}
}

char lcd_getc( void ) {
char c;

LCD_RS=1;
c = lcd_read();
LCD_RS=0;
return(c);
}

This is probably not the best way to do it, but at the time it worked well and I didn't have time to improve it.

Hope this helps.
-Troy
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514796
acid
Guest







Re: Custom LCD Driver
PostPosted: Wed May 28, 2003 12:45 am     Reply with quote

<font face="Courier New" size=-1>:=:=You have need to change struct "lcd_map "
:=:=The first line is bit 0 the last line is bit 8
:=:=
:=:=I.E. int data: 4 are the data I/O lcd (b4..b7)
:=:=
:=
:=
:=any little example?, it will be helpfull.

Hello
If you do use ccs's compiler driver, you have need to do this:
In the struct "lcd_pin_map" ,
the line "boolean enable" , represents the first port's bit, that is in PIN_B0
the line "boolean rs" , represents the second port's bit, that is in PIN_B1 and so on
the last bit are B4-b7 that is " int data : 4 "
To change port you have need set address in #byte
I.E: #byte lcd = 6 //portb
#byte lcd = 7 //portc
#byte lcd = 8 //portd

you are careful to this :

STRUCT lcd_pin_map const LCD_WRITE = {0,0,0,0,0}; // For write mode all pins are out
it set the tris register

the first zero rapresents the first line in the struct
the second zero rapresents the second line in the struct
the third zero rapresents the third line in the struct
the quarter zero rapresents the quarter line in the struct
the fifth zero rapresents the fifth line in the struct



struct lcd_pin_map { // This structure is overlayed
boolean enable; // on to an I/O port to gain
boolean rs; // access to the LCD pins.
boolean rw; // The bits are allocated from
boolean unused; // low order up. ENABLE will
int data : 4; // be pin B0.
} lcd;



#if defined(__PCH__)
#if defined use_portb_lcd
#byte lcd = 0xF81 // This puts the entire structure
#else
#byte lcd = 0xF83 // This puts the entire structure
#endif
#else
#if defined use_portb_lcd
#byte lcd = 6 // on to port B (at address 6)
#else
#byte lcd = 8 // on to port D (at address 8)
#endif
#endif

#if defined use_portb_lcd
#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;
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);
} ___________________________
This message was ported from CCS's old forum
Original Post ID: 144514802
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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