Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Hi-Tech LCD example troubble

Status
Not open for further replies.

Kryten

New Member
Hello I get som errors when I try to compile with Hi-Tech c compiler.

I use the lcd.c and get errors when compiling..

Errors:
Code:
Error   [237] C:\Users\Karl Kristian\Documents\C prosjekter\LCD_test2\include\lcd.c; 38. function "_lcd_write" redefined
Error   [237] C:\Users\Karl Kristian\Documents\C prosjekter\LCD_test2\include\lcd.c; 51. function "_lcd_clear" redefined
Error   [237] C:\Users\Karl Kristian\Documents\C prosjekter\LCD_test2\include\lcd.c; 60. function "_lcd_puts" redefined
Error   [237] C:\Users\Karl Kristian\Documents\C prosjekter\LCD_test2\include\lcd.c; 69. function "_lcd_putch" redefined
Error   [237] C:\Users\Karl Kristian\Documents\C prosjekter\LCD_test2\include\lcd.c; 80. function "_lcd_goto" redefined
Error   [237] C:\Users\Karl Kristian\Documents\C prosjekter\LCD_test2\include\lcd.c; 87. function "_lcd_init" redefined

The lcd.c file as is:
Code:
/*
 *	LCD interface example
 *	Uses routines from delay.c
 *	This code will interface to a standard LCD controller
 *	like the Hitachi HD44780. It uses it in 4 bit mode, with
 *	the hardware connected as follows (the standard 14 pin 
 *	LCD connector is used):
 *	
 *	PORTD bits 0-3 are connected to the LCD data bits 4-7 (high nibble)
 *	PORTA bit 3 is connected to the LCD RS input (register select)
 *	PORTA bit 1 is connected to the LCD EN bit (enable)
 *	
 *	To use these routines, set up the port I/O (TRISA, TRISD) then
 *	call lcd_init(), then other routines as required.
 *	
 */

#ifndef _XTAL_FREQ
 // Unless specified elsewhere, 4MHz system frequency is assumed
 #define _XTAL_FREQ 8000000
#endif


#include	<htc.h>
#include	"lcd.h"

#define	LCD_RS RA4
#define	LCD_RW RA2
#define LCD_EN RC5

#define LCD_DATA	PORTC

#define	LCD_STROBE()	((LCD_EN = 1),(LCD_EN=0))

/* write a byte to the LCD in 4 bit mode */

void lcd_write(unsigned char c)
{
	__delay_us(40);
	LCD_DATA = ( ( c >> 4 ) & 0x0F );
	LCD_STROBE();
	LCD_DATA = ( c & 0x0F );
	LCD_STROBE();
}

/*
 * 	Clear and home the LCD
 */

void lcd_clear(void)
{
	LCD_RS = 0;
	lcd_write(0x1);
	__delay_ms(2);
}

/* write a string of chars to the LCD */

void lcd_puts(const char * s)
{
	LCD_RS = 1;	// write characters
	while(*s)
		lcd_write(*s++);
}

/* write one character to the LCD */

void lcd_putch(char c)
{
	LCD_RS = 1;	// write characters
	lcd_write( c );
}


/*
 * Go to the specified position
 */

void lcd_goto(unsigned char pos)
{
	LCD_RS = 0;
	lcd_write(0x80+pos);
}
	
/* initialise the LCD - put into 4 bit mode */
void lcd_init()
{
	char init_value;

	ADCON1 = 0x06;	// Disable analog pins on PORTA

	init_value = 0x3;
	TRISA=0;
	TRISC=0;
	LCD_RS = 0;
	LCD_EN = 0;
	LCD_RW = 0;
	
	__delay_ms(15);	// wait 15mSec after power applied,
	LCD_DATA	 = init_value;
	LCD_STROBE();
	__delay_ms(5);
	LCD_STROBE();
	__delay_us(200);
	LCD_STROBE();
	__delay_us(200);
	LCD_DATA = 2;	// Four bit mode
	LCD_STROBE();

	lcd_write(0x28); // Set interface length
	lcd_write(0xF); // Display On, Cursor On, Cursor Blink
	lcd_clear();	// Clear screen
	lcd_write(0x6); // Set entry Mode
}

It seems that the compiler thinks that all functions are done twice or something..

My main file:
Code:
//////////////////////////////////////////////////////////////
//     Temp from DS18S20 to LCD                             //
//          PIC16F688                                       //
//////////////////////////////////////////////////////////////

#include <pic.h>
//#include "delay.h"
#include "include\lcd.c"

__CONFIG (UNPROTECT & MCLRDIS & PWRTDIS & WDTDIS & INTOSCIO & BOREN);

/////////////////////////////////////////////////////////////
// Port setup                                              //
/////////////////////////////////////////////////////////////

#define _XTAL_FREQ 8000000
#define DS1820_DATAPIN RA0


/////////////////////////////////////////////////////////////
// Div routines                                            //
/////////////////////////////////////////////////////////////




/////////////////////////////////////////////////////////////
// Main routine                                            //
/////////////////////////////////////////////////////////////


void main (void)
{
	TRISC = 0;
	lcd_init();
	lcd_goto(0);	// select first line
	lcd_puts("12345678");
	lcd_goto(0x40);	// Select second line
	lcd_puts("Hello world");

	for(;;);
}


I really apreciate help..

And I know its here I can get it

Im going to have at least one DS18B20P connected later on. I need to get this working first and work my way up to the final point....

Will post about the totalt project as I get it going
 
Check to see if you have listed lcd.c in the project as a source. If so you should not use the #include for it,
Code:
#include "include\lcd.c"




Curious why the one file uses pic.h and the other htc.h.
 
Last edited:
Yes its listed as scource

How do I add it then?

No reason for pic.h and htc.h... I just always use pic.h and the lcd.c uses htc.h

I have changed it now so they use the same..
 
Last edited:
It fails even more...

But I added it in the other files catalog in project tree.. and used:
Code:
#include "include\lcd.c"
in main.c It worked ;)
 
I think there is something wrong with timing here.
I get some messages in Proteus saying that the controller receives data when its not ready..

Also the LCD_EN pin is always high... Result Cursor (or rather on character) blinking...

Have to test some more and see if have the correct clk all over, I mean in proteus as well.
 
In LCD.c

Code:
#define    LCD_RS RA4
#define    LCD_RW RA2
#define LCD_EN RC5

#define LCD_DATA    PORTC
#define    LCD_STROBE()    ((LCD_EN = 1),(LCD_EN=0))
In lcd_init()
Code:
    TRISA=0;
    TRISC=0;
    LCD_RS = 0;
    LCD_EN = 0;
    LCD_RW = 0;

It looks like it should be working.

Must be some sort of user error here. Try stepping through the code in the simulator. I do not use Proteus , if it can't use MPLAB SIM.
 
In the main.c
Code:
void main (void)
{
	TRISC = 0;
	lcd_init();
	lcd_goto(0);	// select first line
	lcd_puts("12345678");
	lcd_goto(0x40);	// Select second line
	lcd_puts("Hello world");

	for(;;);
}
I didnt understand the
Code:
 for (;;);

so i changed it with
Code:
while(1);
It seems to work in MPLAB SIM.

EDIT
Is there a way to see LCD in MPLAB Sim?
 
Last edited:
Im trying the oshnsoft simulator. it loops in one part of the program.
Code:
07FD    2FFD    	GOTO 0x7FD
I get from the disasembler
 
Code:
for(;;);

is a loop forever here sort of thing

I would use this to loop forever
Code:
while(1);

The idea is that after the program does what you
want it to do the loop forever thing to ensure that
it does not crash or restart. The computer does not just stop.
It has to do something. So loop forever.

I still encourage you to use MPLAB SIM so you can see the high level code.
 
Thank you. Im waiting on my samples (16f688) from microchip.
I will try to get hold of a programmer and try it in HW when I get my samples. I have the LCD, and hope that MPLAB SIM is correct in that it works. ;)
 
I looked at it now. And it dosent seem to control the pins at all. ?!?!?! Im really confused... (added a debug bit and it gets set)
 
Here it is

Thanks mate !!

Heres the files..
 

Attachments

  • LCD test.zip
    77.8 KB · Views: 199
Last edited:
Somehow I assumed that example code would properly configure the chip. We all know what they say about assumptions.

For each PIC you use you have to check the data sheet regarding the ports even if you use them all for digital IO. For the 16F688 PORTA is not all digital by default. You have to turn off comparators and analog in puts.

Code:
void main (void)
{    
[B]  // setup PORTA for all digital IO
  CMCON0 = 0x07;  // turn off comparators
  ANSEL = 0x00;   // turn off ADC inputs[/B] 
  
//    vait_1_sec ();
    lcd_init();
//    lcd_goto(0x80);    // select first line
//    lcd_puts("12345678");
//    lcd_goto(0xC0);    // Select second line
//    lcd_puts("Hello world");
    while(1);
}
 
Status
Not open for further replies.

Latest threads

Back
Top