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.

PIC16F690 and HD4470 LCD 16x2, string writing problems

Status
Not open for further replies.

sundhir52

New Member
hi guys,
i am new to the forum,
i have been struggling with something and was hoping you guys could help.

i am currently using a pic16f690 and a 16x2 character LCD, to display a string.
my initialization seems to be done correctly as i am getting the both rows visible in the background, and not the single row of solid black blocks. i can move the cursor to different positions on the screen, but i can't print any text or characters to the screen, any ideaz?

i am using it in 8-bit mode,
my enable pin is on RB4,
RW is grounded as i am only printing to the screen,
RS is connected to RB6,
and my data lines D0-D7 -> are connected to PORTC

your help is greatly appreciated
thanks
 
hi guys,
i am new to the forum,
i have been struggling with something and was hoping you guys could help.

i am currently using a pic16f690 and a 16x2 character LCD, to display a string.
my initialization seems to be done correctly as i am getting the both rows visible in the background, and not the single row of solid black blocks. i can move the cursor to different positions on the screen, but i can't print any text or characters to the screen, any ideaz?

i am using it in 8-bit mode,
my enable pin is on RB4,
RW is grounded as i am only printing to the screen,
RS is connected to RB6,
and my data lines D0-D7 -> are connected to PORTC

your help is greatly appreciated
thanks

hi and welcome,
If you post your full code, one of us will look it over.
If you are confident that you are correctly initialising the LCD within the program, the problem could be in the write character subr.
Use the 'hash' symbol on the MENU to insert your code, it will keep the formatting.
 
Thanks alot, here is the lcd library i configured to use:

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


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

#define LCD_RS RB4
#define LCD_RW RB5
#define LCD_EN RB6

#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&0xff);
LCD_STROBE();
}

/*
* Clear and home the LCD
*/

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

/* 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 );
}

void
lcd_putcmd(unsigned char cmd)
{
LCD_RS = 0; // write command
lcd_write( cmd );
}


/*
* 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()
{

LCD_RS = 0;
LCD_EN = 0;
LCD_RW = 0;

__delay_ms(15); // wait 15mSec after power applied,

LCD_DATA=0x30;
LCD_STROBE();
__delay_ms(5);
LCD_DATA=0x30;
LCD_STROBE();
__delay_us(200);

lcd_putcmd(0x06);
lcd_putcmd(0x0f); // Display On, Cursor On, Cursor Blink
lcd_putcmd(0x1f);
lcd_putcmd(0x38); // Set interface length
lcd_clear(); // Clear screen

}

and my main file is :

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

__CONFIG(XT & WDTDIS & BORDIS & UNPROTECT);

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

void initialise (void)
{
lcd_init();
lcd_goto(0x00);
lcd_puts("Hello");

__delay_us(200);
}


void main (void)
{

PORTC=0X00;
PORTB=0X00;
ANSEL=0X00;
TRISC=0X00;
TRISB=0X00;

initialise ();

while(1)
{}

}

much appreciated
 
hi s52,
I dont do C, I'm an assembler guy, but there are many 'C' guru members that will advise.
 
hi guys,
i am new to the forum,
i have been struggling with something and was hoping you guys could help.

i am currently using a pic16f690 and a 16x2 character LCD, to display a string.
my initialization seems to be done correctly as i am getting the both rows visible in the background, and not the single row of solid black blocks. i can move the cursor to different positions on the screen, but i can't print any text or characters to the screen, any ideaz?

i am using it in 8-bit mode,
my enable pin is on RB4,
RW is grounded as i am only printing to the screen,
RS is connected to RB6,
and my data lines D0-D7 -> are connected to PORTC

your help is greatly appreciated
thanks

You need a LCD_busy routine to see if the controller is ready to receive a command and you need to have a small delay in your strobe routine when toggling the ENABLE. (a nop() should work)
---> change this. #define LCD_STROBE() ((LCD_EN = 1),(LCD_EN=0))

Check the datasheet for data timing. https://www.electro-tech-online.com/custompdfs/2010/04/HD44780.pdf
 
Last edited:
---> change this. #define LCD_STROBE() ((LCD_EN = 1),(LCD_EN=0))
]

I have tried to add a delay, i tried a nop, i tried making strobe a function and putting in a 1us delay,
after which i tried executing the line LCD_puts("hello"); which just resulted in the cursor not being show at all . . .
 
hey guys thanks for the help, turns out the problem was the ANSELH register of all things . . . . good news is it works now :)
 
hey guys thanks for the help, turns out the problem was the ANSELH register of all things . . . . good news is it works now :)

Great, glad it working!
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top