PIC16f690 2x16 LCD not working.

Thread Starter

Tamás Fegyvári

Joined Sep 26, 2017
15
Hi,
I have a 2x16 LCD and a PIC16f690.
I just cant make them work together. Is that possible, that this PIC is not able to do this?
I connect the pins like in the image but i used the internal oscillator.



And here is an example code. Its simple but is should work, but there is nothing on the display. I also used a resistor to set the contrast.
CSS:
#include <TestLCD.h>
#fuses   nomclr
#include <LCD.C>

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#define LCD_ENABLE_PIN PIN_C2
#define LCD_RS_PIN PIN_C0
#define LCD_RW_PIN PIN_C1
#define LCD_DATA4 PIN_C3
#define LCD_DATA5 PIN_C4
#define LCD_DATA6 PIN_C5
#define LCD_DATA7 PIN_C6

#include <lcd.c>

void main()
{


   lcd_init();

   lcd_init();
   delay_ms(1000);
   lcd_putc("\fReady...\n");

   while(TRUE)
   {
 
  

            lcd_putc('\f');
            lcd_gotoxy(3, 1);
            printf(lcd_putc, "Temperature:");
            delay_ms(1000);

   }

}
Any help is much appreciated
 

be80be

Joined Jul 5, 2008
2,394
Try this and change wiring to match
C:
#include <TestLCD.h>
#fuses   nomclr
#include <LCD.C>

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#define LCD_ENABLE_PIN PIN_C2
#define LCD_RS_PIN PIN_C0
#define LCD_RW_PIN PIN_C1
#define LCD_DATA4 PIN_B4
#define LCD_DATA5 PIN_B5
#define LCD_DATA6 PIN_B6
#define LCD_DATA7 PIN_B7

#include <lcd.c>

void main()
{

ANSEL = 0x00; // have to cheak for what your compler is using
   lcd_init();

   lcd_init();
   delay_ms(1000);
   lcd_putc("\fReady...\n");

   while(TRUE)
   {



            lcd_putc('\f');
            lcd_gotoxy(3, 1);
            printf(lcd_putc, "Temperature:");
            delay_ms(1000);

   }

}
 

Thread Starter

Tamás Fegyvári

Joined Sep 26, 2017
15
Thanks for the help.
Unfortunately still nothing.

I got an error for the ANSEL. "Undefined identifier"
I added this line " #byte ANSEL = 0x11e " After this i got no error. I found this solutionin an other forum but i have eno idea what does it mean.
 

AlbertHall

Joined Jun 4, 2014
12,619
Before sorting out the code, make sure the LCD is ready to display. If you adjust the contrast pot you should be able to get the top line of the display to show 16 boxes where the characters will be. Finally set the pot so the boxes are just barely visible. If you can't get the boxes then check the LCD wiring.
 

spinnaker

Joined Oct 29, 2009
7,830
Try this and change wiring to match
Code:
#include <TestLCD.h>
#fuses   nomclr
#include <LCD.C>

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#define LCD_ENABLE_PIN PIN_C2
#define LCD_RS_PIN PIN_C0
#define LCD_RW_PIN PIN_C1
#define LCD_DATA4 PIN_B4
#define LCD_DATA5 PIN_B5
#define LCD_DATA6 PIN_B6
#define LCD_DATA7 PIN_B7

#include <lcd.c>

void main()
{

ANSEL = 0x00; // have to cheak for what your compler is using
   lcd_init();

   lcd_init();
   delay_ms(1000);
   lcd_putc("\fReady...\n");

   while(TRUE)
   {



            lcd_putc('\f');
            lcd_gotoxy(3, 1);
            printf(lcd_putc, "Temperature:");
            delay_ms(1000);

   }

}

How does using PORTB for the data inputs fix the issue????
 

JohnInTX

Joined Jun 26, 2012
4,787
It does not look like you have initialized the PIC I/O ports. At the least you need:

PORTC=0x00; // init port
TRISC = 0x00; // make port pins all outputs
ANSEL = 0x00; // make pins digital
ANSELH= 0x00;
ADCON0 = 0x00; // turn ADC off
 
Last edited:

spinnaker

Joined Oct 29, 2009
7,830
Forget about getting the LCD to work for now .Begin at the beginning. Write a small program to independently toggle each of your outputs. Verify that each output toggles at the LCD pin.
 

spinnaker

Joined Oct 29, 2009
7,830
It does not look like you have initialized the PIC I/O ports

PORTC=0x00; // init port
TRISC = 0x00; // make port pins all outputs
ANSEL = 0x00; // make pins digital
ANSELH= 0x00;
ADCON0 = 0x00; // turn ADC off

That is why I asked for the code for lcd_init. I assume it is in there. Or I hope it is in there. It is the way I write my code. Or close to it. I use an lcd_config.h file to do all of my custom hardware configurations.
 

MrChips

Joined Oct 2, 2009
34,630
Getting an LCD to work from an MCU is like a 10-step recipe. Get a single step wrong and nothing works. Gets even more complicated when you've got 3 or more things wrong.

@spinnaker is right. You have to be able to validate each step along the way.

Start by making sure you can toggle an LED on a specific I/O pin.

Then try to write your own code without any third party library. You don't know yet that the library works.
 

shteii01

Joined Feb 19, 2010
4,644
I am not a PIC guy...
Is it valid approach to use 877 wiring and code in 690? Are they actually identical when it comes to this application?
 

be80be

Joined Jul 5, 2008
2,394
Most Lcd code is using upper port or lower port Like PORTC 0 to 3 or 4 to 7 not C3 to C6
And I no port B works better with that chip it's only the upper port 4 to 7 witch is good and there nothing on them no adc no Comparators
 

MrChips

Joined Oct 2, 2009
34,630
You can use any output port. Just make sure that your code matches the wiring.
Hence write your own code. It is not that difficult.

I can provide code to match the PIC16F877F with the LCD.
There are also some hardware issues that need attention.
 

spinnaker

Joined Oct 29, 2009
7,830
Most Lcd code is using upper port or lower port Like PORTC 0 to 3 or 4 to 7 not C3 to C6
And I no port B works better with that chip it's only the upper port 4 to 7 witch is good and there nothing on them no adc no Comparators

All you did was confuse the TS. Heck you are confusing me. ;)
 

MrChips

Joined Oct 2, 2009
34,630
To the TS, are you flexible on which pins you use?
Why make life difficult?
Use RC0-RC3 or RC4-RC7 for your 4-bit data port
or RB0-RB3 or RB4-RB7 as the man says.
 

spinnaker

Joined Oct 29, 2009
7,830
To the TS, are you flexible on which pins you use?
Why make life difficult?
Use RC0-RC3 or RC4-RC7 for your 4-bit data port
or RB0-RB3 or RB4-RB7 as the man says.
I don't see how changing pins makes life any easier except with the actual wiring or PCB design.

With any well written LCD library there should be no reason to have the data pins all on the same port. Assuming the library is configured according to how you have things wired. Any time I design a project with LCD, I first consider the pinout of the form factor I am using. I could make things easier when designing for PCB to make running the traces easier. Last thing I care about is which port I am coming from for each pin as long as the pin selected on the mcu does not present mcu pin conflicts life is good. For a perf board type of wiring it really doesn't matter unless you really want to keep things neat and organized while they run to the LCD.
 
Last edited:

Picbuster

Joined Dec 2, 2013
1,057
I use the interface (code below) or all my pic projects 690 /8722 /87k22 and more.
C:
/*
* 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):
*
* PORTC 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 RA0
#define LCD_RW RA1
#define LCD_EN RA2
#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();
__delay_us(20);
}

/*
*  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(0xE); // Display On, Cursor On, Cursor Blink
lcd_clear(); // Clear screen
lcd_write(0x6); // Set entry Mode
}
Moderators note: please use code tags when posting pieces of code
 
Last edited by a moderator:

Thread Starter

Tamás Fegyvári

Joined Sep 26, 2017
15
Wow. Thanks for the many answers.
I totally forgot to mention that is use CCS C. Sorry about this.

I even tried the compilers lcd example code. Still nothing.
Now i will try every method you mentiond.

At this moment i dont have a pot, but i tried some single resistors and set the contrast where the upper boxes barely visible.
 
Top