Help with LCD and 16f690

Status
Not open for further replies.
sprintf will not do floating point units on such a small chip. You'll need to use fixed point math.... 2352 then print the decimal around the decimal point.

I have written a routine that places a long formatted to a string... Check the compiler for the string conversion routines.
 
Hello again,
I changed MCU to 18F2550 and 4 lines (like HD44780) LCD. I used this your routine for it. now something is so strange.. when program run LCD is initialize but there is nothing on screen. but when I changed code and load again I see on LCD my old code.. where is problem?
 
main.c
Code:
/* 
 * File:   main.c
 * Author: Selcuk
 *
 * Created on 02 Kas?m 2012 Cuma, 08:42
 */

#include "main.h"



void Menu(int menuID);
int main() {

    TRISB=0;
    TRISBbits.TRISB2=0;
    LCD_TRIS = 0x00;
    TRISB=0;
    Delay150MS();
    TRISA=0;
    LATA=0;
    LCD_init();
    LCD_goto(2,5);
    LCD_char('T');
    while(1){
             LED=1;
           Delay5MS();
           LED=0;
           Delay5MS();
    }
    
}

lcd.c
Code:
#include "lcd.h"

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_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  & 0xf0;			// write high nibble
	LCD_RS = 0;
	pulse_E();
	LCD_PORT = ch <<4 & 0xf0;				// write low nibble
	LCD_RS = 0;
	pulse_E();
	Delay5MS();
	}


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

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

void pulse_E()
	{
	LCD_E = 1;
	Delay1US();
	LCD_E = 0;
	}
void string(const char *q,const int satir)
{
    int sayac=0;
   while (*q) {
       LCD_goto(satir,sayac);
       LCD_char(*q++);
       sayac++;
       }

}
 
Last edited:
and pin config
#define LCD_PORT LATB // constants
#define LCD_TRIS TRISB //
#define LCD_RS LATBbits.LATB2
#define LCD_E LATBbits.LATB3
againb Im using in 4Bit mode.
 
So you've changed to The high nibble of the LCD port ! Is the RW pin grounded? The other issue I found with the pic18's is.. I had to initialise them slightly different..

Here is some code I used for initialising an LCD to a pic18
Code:
void LCDinit(char c)
	{
	PORTB = 0;
	TRISB = 0x3;
	PORTB = 0x30;
	PORTB += 4;
	PORTB -= 4;
	Delay10KTCYx(22);
	PORTB += 4;
	PORTB -= 4;
	Delay10KTCYx(22);
	LCDcmd(0x32);
	Delay10KTCYx(22);
	LCDcmd(0x2C);
	Delay10KTCYx(28);
	LCDcmd(0x6);
	Delay10KTCYx(28);
	LCDcmd(0xC);
	Delay10KTCYx(10);
	LCDcmd(c);
	Delay1KTCYx(1);
	}

Obviously you must change the values..
 
Last edited:
I'm not sure... It must have something to do with the read write modify problem... The pic18 uses latches on the ports so I just assumed this was the difference...
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…