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.

Help with LCD and 16f690

Status
Not open for further replies.

Delisaber

Member
Firstly Hello to everybody,

Im so new in MCU topic..Before I was programming PLC. but this is so different for me :)

I have 2*8 LCD and pic16f690 and Im using MPLABX xc8.. I tried maybe 10 different codes and I checked all internet.. still I couldnt write anything on LCD. There is ready library name is "xlcd.h" but it didnt work. when I try it I have many many strange errors.

maybe someone can help me.


sorry for my bad english :)
 
Im using 4bit mode.
data port PC4-PC7
RS - RB6
RW - RC2
EN - RC3
I config xlcd.h file like this and when I try OpenXLCD function it give strange errors. Like this


make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
make[1]: Entering directory `D:/Projeler/MPLABXProjects/16f690/XLCDH690.X'
make -f nbproject/Makefile-default.mk dist/default/production/XLCDH690.X.production.hex
make[2]: Entering directory `D:/Projeler/MPLABXProjects/16f690/XLCDH690.X'
"C:\Program Files (x86)\Microchip\xc8\v1.10\bin\xc8.exe" --pass1 --chip=16F690 -Q -G --asmlist --double=24 --float=24 --emi=wordwrite --opt=default,+asm,-asmfile,+speed,-space,-debug,9 --addrqual=ignore -P -N255 --warn=0 --summary=default,-psect,-class,+mem,-hex,-file --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+config,+clib,+plib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -obuild/default/production/main.p1 main.c
"C:\Program Files (x86)\Microchip\xc8\v1.10\bin\xc8.exe" --chip=16F690 -G --asmlist -mdist/default/production/XLCDH690.X.production.map --double=24 --float=24 --emi=wordwrite --opt=default,+asm,-asmfile,+speed,-space,-debug,9 --addrqual=ignore -P -N255 --warn=0 --summary=default,-psect,-class,+mem,-hex,-file --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+config,+clib,+plib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -odist/default/production/XLCDH690.X.production.cof build/default/production/main.p1
Microchip MPLAB XC8 C Compiler (Free Mode) V1.10
Copyright (C) 2012 Microchip Technology Inc.
(1273) Omniscient Code Generation not available in Free mode (warning)
:0: error: undefined symbol:
_OpenXLCD(dist/default/production\XLCDH690.X.production.obj)
make[2]: Leaving directory `D:/Projeler/MPLABXProjects/16f690/XLCDH690.X'
make[1]: Leaving directory `D:/Projeler/MPLABXProjects/16f690/XLCDH690.X'
(908) exit status = 1
make[2]: *** [dist/default/production/XLCDH690.X.production.hex] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2

BUİLD FAILED (exit value 2, total time: 1s)
 
It isn't a strange output... It's mearly stating that _OpenXLCD() hasn't been defined... Have you included the line "#include<XLCD.H>"... Or does the function have an underscore at the beginning.

Open the XLCD.H file....COPY the function name (identifier) and paste this into your code... If the header file has been included the line SHOULD be defined....

Otherwise please post you code....
 
my code is like this. I did it just now for show you.
Code:
/* 
 * File:   main.c
 * Author: Selcuk
 *
 * Created on 23 Ekim 2012 Sal?, 02:38
 */

#include <stdio.h>
#include <stdlib.h>
#include <plib/xlcd.h>
#include <pic16f690.h>
#include <delays.h>
#include <xc.h>
__CONFIG(FOSC_INTRCIO & WDTE_OFF & PWRTE_OFF & MCLRE_OFF & CP_OFF & CPD_OFF & BOREN_ON & IESO_ON & FCMEN_ON);
void Delay5MS(){
    _delay(5100);
}
void Delay1MS(){
    _delay(1025);
}
void Delay15MS(){
    _delay(5100);
    _delay(5100);
    _delay(5100);
}
void Delay20MS(){
    _delay(5100);
    _delay(5100);
    _delay(5100);
    _delay(5100);
}
void Delay200US(){
    _delay(200);
}
void Delay50US(){
    _delay(45);
}
void Delay1US(){
_delay(1);
}
void DelayFor18TCY(void)
{
    for(int i=0;i<18;i++){

    }
}
void DelayPORXLCD(void){
Delay5MS();
Delay5MS();
Delay5MS();
}
void DelayXLCD(void){
Delay5MS();
}
/*
 * 
 */
int main() {

    OpenXLCD(FOUR_BIT & LINES_5X7);
    WriteDataXLCD('H');
    while(1){
        
    }
}

as u see its like this
#include <plib/xlcd.h>
maybe probem is here but I dont know how it should be. it comes like this automaticly.maybe Ishould add it to some folder in my project ?
 
#include <plib/xlcd.h>
maybe probem is here but I dont know how it should be. it comes like this automaticly.maybe Ishould add it to some folder in my project ?

Go to the microchip directory look for the header file in the "include" directory.... If the directory "PLIB" is in this directory.. Then it should work...

Other wise copy the Header "XLCD.H" and the source files to YOUR project directory.... CHANGE the line "#include <plib/xlcd.h>" to #include"xlcd.h" ...
 
PLIB directory under the INCLUDE directory. I copied Xlcd.h to source folder in my project and I added #include"xlcd.h" like this but error is still same.
 
PLIB directory under the INCLUDE directory. I copied Xlcd.h to source folder in my project and I added #include"xlcd.h" like this but error is still same.

You will also need the source "FILES" ie OpenXLD.. read / write etc..

I haven't got the new compiler installed so I'm unable to compile the code for you... Have you left the build directory in MPLAB the same as default or have you changed it? Or indeed, are you using MPLAB?
 
I didnt change it. its same default. I added XLCD Directory in source directory.all sub libraries inside now. error changed. Im using MPLABX xc8 compiler.
Error

"C:\Program Files (x86)\Microchip\xc8\v1.10\bin\xc8.exe" --pass1 --chip=16F690 -Q -G --asmlist --double=24 --float=24 --emi=wordwrite --opt=default,+asm,-asmfile,+speed,-space,-debug,9 --addrqual=ignore -P -N255 --warn=0 --summary=default,-psect,-class,+mem,-hex,-file --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+config,+clib,+plib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -obuild/default/production/main.p1 main.c
make[2]: *** No rule to make target `C:/Program Files \(x86\)/Microchip/xc8/v1.10/sources/pic18/plib/XLCD/busyxlcd.c', needed by `build/default/production/_ext/86510327/busyxlcd.p1'. Stop.
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
make[2]: Leaving directory `D:/Projeler/MPLABXProjects/16f690/XLCDH690.X'
make[1]: Leaving directory `D:/Projeler/MPLABXProjects/16f690/XLCDH690.X'

BUİLD FAILED (exit value 2, total time: 401ms)
 
Ok! back to the drawing board...... Take a look at MY tutorials down below in my signature.... These routines have all the LCD functions you need..

The above warning / error tell me that linker is looking for the object files in the compilation rather than the code.... Other than renaming the code...

Use mine, it'll be easier...
 
I tried something from your tutorials... I wrote this code and there are in LCD firs line a little gray boxes and second line is empty..where is problem ?
Code:
/* 
 * File:   main.c
 * Author: Selcuk
 *
 * Created on 23 Ekim 2012 Sal?, 05:47
 */

#include <stdio.h>
#include <stdlib.h>
#include <pic.h>
#include <pic16f690.h>
#include <xc.h>
__CONFIG(FOSC_INTRCIO & WDTE_OFF & PWRTE_OFF & MCLRE_OFF & CP_OFF & CPD_OFF & BOREN_ON & IESO_ON & FCMEN_ON);
/*
 * 
 */
#define LCD_PORT 	PORTC		// constants
#define LCD_TRIS	TRISC		//
#define LCD_RS 		PORTBbits.RB6
#define LCD_RW		PORTCbits.RC2
#define LCD_E		PORTCbits.RC3

		// Required prototypes.. each function needs to be declared
		// if called BEFORE definition.
void Delay5MS(){
    _delay(5100);
}
void Delay1MS(){
    _delay(1025);
}
void Delay15MS(){
    _delay(5100);
    _delay(5100);
    _delay(5100);
}
void Delay150MS()
{
    for(int i=0;i<10;i++)
    {
        Delay15MS();
    }
}
void Delay20MS(){
    _delay(5100);
    _delay(5100);
    _delay(5100);
    _delay(5100);
}
void Delay200US(){
    _delay(200);
}
void Delay50US(){
    _delay(45);
}
void Delay1US(){
_delay(1);
}
void LCD_init(void), LCD_cmd(unsigned char ch);
void LCD_goto(char line, char column), LCD_clr(void);
void LCD_cur(unsigned char ch), pulse_E(void), LCD_hex(int value);
void LCD_char(unsigned char ch), LCD_charD(unsigned char ch);
int main() {


	ADCON0 = 0x00;					// Analogue off
        ADCON1 = 0x00;
        ANSELH=0x00;
        ANSEL=0x00;
        LCD_RW=1;// Analogue off
        //ADCON2 = 0x00;					// Analogue off
	LCD_TRIS = 0x00;
	Delay150MS();				// let LCD stabilise
	LCD_init();						// Initalise screen
	LCD_goto(1,0);					// line 1.
	//HSerinit();
        LCD_char('A');
	while(1)						// endless Loop
		{
            PORTCbits.RC0=0;
		}
    
}
void LCD_init()
	{
	LCD_cmd(0x20);					// 4 bit
	LCD_cmd(0x28);					// display shift
	LCD_cmd(0x6);					// character mode
	LCD_cmd(0xc);					// display on / off and cursor
	LCD_clr();						// clear display
	}

/*
void LCD_hex(int value)
	{
	char data;								// dispay hex values.
	data = value >> 4 & 0xf;				// send upper nibble
	data = HEX_Table[data]; 				// hex lookup
	LCD_char(data);
	data = value & 0xf;						// send lower nibble
	data = HEX_Table[data]; 				// hex lookup
	LCD_char(data);
	}
*/
void LCD_goto(char line, char column)		// combines line and lineW
	{
	unsigned char data = 0x80;				// default to 1
	if(line == 2)data = 0xc0;				// change to 2
	data += column;							// add in  column
	LCD_cmd(data);
	}

void LCD_clr()
	{
	LCD_cmd(1);								// Clr screen
	}

void LCD_cur(char on)
	{
	unsigned char cur = 0xc;				// cursor off
	if(on) cur = 0xd;						// cursor on
	LCD_cmd(cur);
	}

void LCD_cmd(unsigned char ch)
	{
	LCD_PORT = ch >> 4 & 0xf;			// write high nibble
	LCD_RS = 0;
	pulse_E();
	LCD_PORT = ch & 0xf;				// write low nibble
	LCD_RS = 0;
	pulse_E();
	Delay5MS();
	}

void LCD_charD(unsigned char ch)
	{
	ch+=0x30;
	LCD_char(ch);						// convert to ascii
	}

void LCD_char(unsigned char ch)
	{
	LCD_PORT = ch >> 4 & 0xf;			// High nibble
	LCD_RS = 1;
	pulse_E();
	LCD_PORT = ch & 0xf;				// low nibble
	LCD_RS = 1;
	pulse_E();
	Delay5MS();
	}

void pulse_E()
	{
	LCD_E = 1;
	Delay1US();
	LCD_E = 0;
	}
 
My code has the LCDport as the lower nibble "D0 - D3" You need to modify to suit the high nibble "D4 - D7"

Code:
void LCD_cmd(unsigned char ch)
	{
	LCD_PORT = ch  & 0xf0;			// write high nibble
	LCD_RS = 0;
	pulse_E();
	LCD_PORT = ch <<4 & 0xf0;				// write low nibble
	LCD_RS = 0;
	pulse_E();
	Delay5MS();
	}

Do the same to the data and hex ( if needed ) .
 
LCD_charD(); converts digits to ascii.... However its easier to use sprintf(); and then LCD_print(); Sprintf can convert a bunch of data into a string..

say you need this

" TEMP = 23°C" You would use
Code:
char LCDbuff[20];
sprintf(LCDbuff, " %d%cC", temp,0xDF);

This is '%d' will convert a integer variable "temp" into ascii.. Then print the ascii character '%c' for the degree symbol '°' then print the capitol C... Much easier.
The result will be in the buffer.

You then use
Code:
LCD_print(LCDbuff);
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top