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 support@ccsinfo.com

LCD/16F877

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







LCD/16F877
PostPosted: Mon Mar 03, 2003 7:24 pm     Reply with quote

I am k eep getting Error when compling this code, can some one tell me what I am doing wrong.


#include <16F877.H>
#fuses HS,NOWDT,NOPROTECT
#use delay(clock=40000000)
#include<lcd_t.C>
int x;
main()
{
lcd_init();
do
{
delay_ms(100);
x = 2;
printf(lcd_putc, "\%u", x);
delay_ms(100);
}
while( 1 );
}

*****************************************************

// As defined in the following structure the pin connection is as follows:
// D0 enable
// D1 rs
// D2 rw
// D4 D4
// D5 D5
// D6 D6
// D7 D7
//
// LCD pins D0-D3 are not used and PIC D3 is not used.

// Un-comment the following define to use port B
// #define use_portb_lcd TRUE


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;



#byte lcd = 8 // on to port D (at address 8)


#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_d(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_d(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_d(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: 12313
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: LCD/16F877
PostPosted: Mon Mar 03, 2003 8:13 pm     Reply with quote

:=I am keep getting Error when compling this code, can some one tell me what I am doing wrong.

:=
:=
:=#include <16F877.H>

The following line should probably have the NOLVP parameter
added to the end.

:=#fuses HS,NOWDT,NOPROTECT

You have typed 40 MHz in the next line, and it
probably should be 4 MHz.
:=#use delay(clock=40000000)

I don't know what this "lcd_t.c" file is. It's not a CCS file.
Does it contain the function prototypes ?

:=#include <lcd_t.C>
:=int x;

If the "lcd_t.c" file does not contain function prototypes,
then you need to add them, or you need to move this entire
"main()" function to the end of the program.

:=main()
:={
:=lcd_init();
:=do
:={
:=delay_ms(100);
:=x = 2;
:=printf(lcd_putc, "\%u", x);
:=delay_ms(100);
:=}
:=while( 1 );
:=}
:=

This next line is not a comment. It will cause a compiler
error. I wonder why you did not see this.

:=*****************************************************
:=
:=// As defined in the following structure the pin connection is as follows:
:=// D0 enable
:=// D1 rs
:=// D2 rw
:=// D4 D4
:=// D5 D5
:=// D6 D6
:=// D7 D7
:=//
:=// LCD pins D0-D3 are not used and PIC D3 is not used.
:=
:=// Un-comment the following define to use port B
:=// #define use_portb_lcd TRUE
:=
:=
:=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;
:=
:=
:=
:=#byte lcd = 8 // on to port D (at address 8)
:=
:=
:=#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_d(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_d(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_d(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);
:=
:=
There is no closing brace at the end of this function.
___________________________
This message was ported from CCS's old forum
Original Post ID: 12314
slahiri
Guest







Re: LCD/16F877
PostPosted: Tue Mar 04, 2003 6:27 am     Reply with quote

:=:=I am keep getting Error when compling this code, can some one tell me what I am doing wrong.
:=
:=:=
:=:=
:=:=#include <16F877.H>
:=
:=The following line should probably have the NOLVP parameter
:=added to the end.
:=
:=:=#fuses HS,NOWDT,NOPROTECT
:=
:=You have typed 40 MHz in the next line, and it
:=probably should be 4 MHz.
:=:=#use delay(clock=40000000)
:=
:=I don't know what this "lcd_t.c" file is. It's not a CCS file.
:=Does it contain the function prototypes ?
:=
:=:=#include <lcd_t.C>
:=:=int x;
:=
:=If the "lcd_t.c" file does not contain function prototypes,
:=then you need to add them, or you need to move this entire
:="main()" function to the end of the program.
:=
:=:=main()
:=:={
:=:=lcd_init();
:=:=do
:=:={
:=:=delay_ms(100);
:=:=x = 2;
:=:=printf(lcd_putc, "\%u", x);
:=:=delay_ms(100);
:=:=}
:=:=while( 1 );
:=:=}
:=:=
:=
:=This next line is not a comment. It will cause a compiler
:=error. I wonder why you did not see this.
:=
:=:=*****************************************************
:=:=
:=:=// As defined in the following structure the pin connection is as follows:
:=:=// D0 enable
:=:=// D1 rs
:=:=// D2 rw
:=:=// D4 D4
:=:=// D5 D5
:=:=// D6 D6
:=:=// D7 D7
:=:=//
:=:=// LCD pins D0-D3 are not used and PIC D3 is not used.
:=:=
:=:=// Un-comment the following define to use port B
:=:=// #define use_portb_lcd TRUE
:=:=
:=:=
:=:=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;
:=:=
:=:=
:=:=
:=:=#byte lcd = 8 // on to port D (at address 8)
:=:=
:=:=
:=:=#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_d(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_d(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_d(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);
:=:=
:=:=
:=There is no closing brace at the end of this function.
:=
:=

I have change every thing you have asked me to change. I am using CCS LCD driver. My LCD is connected to PORTD. I was able to complie code but I don't see any thing on my LCD. I am posting my code again, Please take a look at it.

#include <16F877.H>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#include<lcd.C>
int x;
main()
{
lcd_init();
do
{
x = 2;
printf(lcd_putc, "\%u", x);
}
while( 1 );
}


___________________________
This message was ported from CCS's old forum
Original Post ID: 12321
Paladdin
Guest







Re: LCD/16F877
PostPosted: Tue Mar 04, 2003 6:48 am     Reply with quote

:=
:=I have change every thing you have asked me to change. I am using CCS LCD driver. My LCD is connected to PORTD. I was able to complie code but I don't see any thing on my LCD. I am posting my code again, Please take a look at it.
:=
:=#include <16F877.H>
:=#fuses HS,NOWDT,NOPROTECT,NOLVP
:=#use delay(clock=4000000)
:=#include<lcd.C>
:=int x;
:=main()
:={
:=lcd_init();
:=do
:={
:=x = 2;
:=printf(lcd_putc, "\%u", x);
:=}
:=while( 1 );
:=}
:=
:=

LCD hardware cursor advances as you write and is easy to go out of the display. Maybe not the origin of the bug, but you should clear your LCD display before attempt any writes. You can accomplish this sending it a '\f' char:

printf(lcd_putc, "\f\%u", x) ;

This puts cursor at first line, first position. Jump to the next line with an '\n'.

It useful take a look at lcd.c source and, even more, reading any Hitachi display compatible docs. You will learn even how to send your very own custom chars to show on it :)

Good luck,
___________________________
This message was ported from CCS's old forum
Original Post ID: 12322
slahiri
Guest







Re: LCD/16F877
PostPosted: Tue Mar 04, 2003 9:40 am     Reply with quote

:=:=
:=:=I have change every thing you have asked me to change. I am using CCS LCD driver. My LCD is connected to PORTD. I was able to complie code but I don't see any thing on my LCD. I am posting my code again, Please take a look at it.
:=:=
:=:=#include <16F877.H>
:=:=#fuses HS,NOWDT,NOPROTECT,NOLVP
:=:=#use delay(clock=4000000)
:=:=#include<lcd.C>
:=:=int x;
:=:=main()
:=:={
:=:=lcd_init();
:=:=do
:=:={
:=:=x = 2;
:=:=printf(lcd_putc, "\%u", x);
:=:=}
:=:=while( 1 );
:=:=}
:=:=
:=:=
:=
:=LCD hardware cursor advances as you write and is easy to go out of the display. Maybe not the origin of the bug, but you should clear your LCD display before attempt any writes. You can accomplish this sending it a '\f' char:
:=
:=printf(lcd_putc, "\f\%u", x) ;
:=
:=This puts cursor at first line, first position. Jump to the next line with an '\n'.
:=
:=It useful take a look at lcd.c source and, even more, reading any Hitachi display compatible docs. You will learn even how to send your very own custom chars to show on it <img src="http://www.ccsinfo.com/pix/forum/smile.gif" border="0">
:=
:=Good luck,


I am using LCD which has controller HD44780A00. And this are PIN out. My other question is if I hold my logic prob on D0 which the enable pin for LCD what should I see.


LCD PIN OUT
1--GND
2--VCC
3--VEE--contrast
4--RS
5--R/W
6--E
7--14--DB0--DB7



// As defined in the following structure the pin connection is as follows:
// D0 enable
// D1 rs
// D2 rw
// D4 D4
// D5 D5
// D6 D6
// D7 D7
// LCD pins D0-D3 are not used and PIC D3 is not used
___________________________
This message was ported from CCS's old forum
Original Post ID: 12332
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: LCD/16F877
PostPosted: Tue Mar 04, 2003 1:07 pm     Reply with quote

:=I am using LCD which has controller HD44780A00. And this are PIN out. My other question is if I hold my logic prob on D0 which the enable pin for LCD what should I see.
:=
:=
:=LCD PIN OUT
:=1--GND
:=2--VCC
:=3--VEE--contrast
:=4--RS
:=5--R/W
:=6--E
:=7--14--DB0--DB7
:=
:=
-------------------------------------------------------------
What about the contrast pin ? That could be the problem.
See this recent post:
<a href="http://www.pic-c.com/forum/general/posts/12317.html" TARGET="_blank">http://www.pic-c.com/forum/general/posts/12317.html</a>
What voltage do you have connected to pin 3 (contrast pin) ?
___________________________
This message was ported from CCS's old forum
Original Post ID: 12344
slahiri
Guest







Re: LCD/16F877
PostPosted: Tue Mar 04, 2003 1:53 pm     Reply with quote

:=:=I am using LCD which has controller HD44780A00. And this are PIN out. My other question is if I hold my logic prob on D0 which the enable pin for LCD what should I see.
:=:=
:=:=
:=:=LCD PIN OUT
:=:=1--GND
:=:=2--VCC
:=:=3--VEE--contrast
:=:=4--RS
:=:=5--R/W
:=:=6--E
:=:=7--14--DB0--DB7
:=:=
:=:=
:=-------------------------------------------------------------
:=What about the contrast pin ? That could be the problem.
:=See this recent post:
:= <a href="http://www.pic-c.com/forum/general/posts/12317.html" TARGET="_blank"> <a href="http://www.pic-c.com/forum/general/posts/12317.html" TARGET="_blank">http://www.pic-c.com/forum/general/posts/12317.html</a></a>
:=What voltage do you have connected to pin 3 (contrast pin) ?


I do have two black line showing on the LCD when I power up.
___________________________
This message was ported from CCS's old forum
Original Post ID: 12346
karth
Guest







Re: LCD/16F877
PostPosted: Tue Mar 04, 2003 2:58 pm     Reply with quote

I had to write code for a LCD driver that had a KSO108 driver. the enable pin is an input to LCD driver, and each time it receive a command the enable pin has to be toggled.

example:

write to LCD
enable pin low
enable pin high

and you should keep all d0 d7 data pin on the same port.

good luck...
___________________________
This message was ported from CCS's old forum
Original Post ID: 12347
slahiri
Guest







Re: LCD/16F877
PostPosted: Tue Mar 04, 2003 6:15 pm     Reply with quote

:=:=:=I am using LCD which has controller HD44780A00. And this are PIN out. My other question is if I hold my logic prob on D0 which the enable pin for LCD what should I see.
:=:=:=
:=:=:=
:=:=:=LCD PIN OUT
:=:=:=1--GND
:=:=:=2--VCC
:=:=:=3--VEE--contrast
:=:=:=4--RS
:=:=:=5--R/W
:=:=:=6--E
:=:=:=7--14--DB0--DB7
:=:=:=
:=:=:=
:=:=-------------------------------------------------------------
:=:=What about the contrast pin ? That could be the problem.
:=:=See this recent post:
:=:= <a href="http://www.pic-c.com/forum/general/posts/12317.html" TARGET="_blank"> <a href="http://www.pic-c.com/forum/general/posts/12317.html" TARGET="_blank"> <a href="http://www.pic-c.com/forum/general/posts/12317.html" TARGET="_blank">http://www.pic-c.com/forum/general/posts/12317.html</a></a></a>
:=:=What voltage do you have connected to pin 3 (contrast pin) ?
:=
:=
:=I do have two black line showing on the LCD when I power up.


I would like thank every one those who help me thank you all. My LCD works
___________________________
This message was ported from CCS's old forum
Original Post ID: 12354
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