CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Problem with PIC16f886 and 16x2 Lcd

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
mars79



Joined: 19 Jun 2013
Posts: 6
Location: Bulgaria, Plovdiv

View user's profile Send private message Send e-mail

Problem with PIC16f886 and 16x2 Lcd
PostPosted: Wed Jun 19, 2013 1:37 am     Reply with quote

Hello everyone. I read some similar topics in the forum but I could not find solution to my problem. Use 4-bit mode.
For some time I have a problem with the operation of this display. Sometimes it is activated without a problem sometimes shows squares on the first row and nothing else.

The display driver using flex lcd. Define pins as follows:

Code:
#define LCD_DB4   PIN_B3
#define LCD_DB5   PIN_B2
#define LCD_DB6   PIN_B1
#define LCD_DB7   PIN_B0

#define LCD_E     PIN_B5
#define LCD_RS    PIN_B7
//#define LCD_RW    PIN_B6

//#define USE_LCD_RW   1



This is the program:
Code:
#include <16F886.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP, NOMCLR
#use delay(clock = 4000000)

#include "Flex_LCD.c"

//============================
void main()
{

setup_adc_ports(NO_ANALOGS);
setup_comparator(NC_NC_NC_NC);

lcd_init();              // Initialize the LCD

lcd_putc("\fLine 1");
lcd_putc("\nLine 2");

while(1);
}


This is the connection diagram:


Thanks!
temtronic



Joined: 01 Jul 2010
Posts: 9245
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Jun 19, 2013 5:36 am     Reply with quote

Please add

delay_ms(1000);

before and after the

lcd_init();

line.

The first delay of 1 second allows the LCD module to 'powerup' correctly.
They require this time to 'get organized'(it's a spec often overlooked).
The second delay allows the lcd_init() to 'configure' the LCD_module.
The module needs a little bit of time to reconfigure from 8bit mode to 4bit.

You should be able to reduce the delays to less than 500ms.All LCD modules have different 'powerup' and 'write' times, so I start with 1 second and confirm they work THEN reduce if I can.
Most will work with 500/250 timings.

hth
jay
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

PostPosted: Wed Jun 19, 2013 7:52 am     Reply with quote

How are you programming this? What debugger/programmer are you using? I ask because you've used ICSP programming pins for general IO, so you can't do any in-circuit debugging. Then again, clearly a LCD display and a PIC on their own isn't going to be able to do very much, so what about the other connections that you will need at sometime to make this do anything useful?

Also, you've not connected MCLR to anything so if this really is your circuit then it will stop and restart at more or less anytime it feels like it due to noise.

Then again, where is the decoupling?

All this is basic hardware stuff and should be sorted out before going any further. And in-circuit debugging really is useful. I always make sure I can debug in-circuit.
oxo



Joined: 13 Nov 2012
Posts: 219
Location: France

View user's profile Send private message

PostPosted: Wed Jun 19, 2013 8:05 am     Reply with quote

RF_Developer wrote:
How are you programming this? What debugger/programmer are you using? I ask because you've used ICSP programming pins for general IO, so you can't do any in-circuit debugging. Then again, clearly a LCD display and a PIC on their own isn't going to be able to do very much, so what about the other connections that you will need at sometime to make this do anything useful?

Also, you've not connected MCLR to anything so if this really is your circuit then it will stop and restart at more or less anytime it feels like it due to noise.

Then again, where is the decoupling?

All this is basic hardware stuff and should be sorted out before going any further. And in-circuit debugging really is useful. I always make sure I can debug in-circuit.


He has #fuses NOMCLR
mars79



Joined: 19 Jun 2013
Posts: 6
Location: Bulgaria, Plovdiv

View user's profile Send private message Send e-mail

PostPosted: Wed Jun 19, 2013 10:32 am     Reply with quote

This is the wiring diagram that I made today. The problem came after I changed the board. Before I used the pin RB5 for RS and RB4 for E. I also had an external reset and then pushing his programs work. A moment ago I made the following change: RS to RB5 and E to RB4. Also changed the program:

Code:

#include <16F886.H>
#Fuses XT, NOWDT, PUT, NOMCLR, NOBROWNOUT, NOLVP, NOPROTECT 
#use delay(clock = 4000000)


#include "Flex_LCD.c"

#byte pA   =0xFF   
#byte pB   =0   
#byte pC   =0   
#byte pE   =0xFF   

VOID MAIN (VOID)
{

setup_adc_ports(NO_ANALOGS);
setup_comparator(NC_NC_NC_NC);

      lcd_init();
      delay_ms(150);
      printf(lcd_putc,"\fTest");

do {


}while(1);

}

also made the changes in flex_lcd.c
... and everything works.

Thanks for your help!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jun 19, 2013 11:51 am     Reply with quote

Quote:
#byte pA =0xFF
#byte pB =0
#byte pC =0
#byte pE =0xFF

This is wrong and will not do what you want it to do.

The bold lines in the code below show how it should be done:
http://www.ccsinfo.com/forum/viewtopic.php?t=42713&highlight=byte+porta+portb+portc+portd+porte+getenv+SFR
Also look in main() to see how to set a port to a value.
mars79



Joined: 19 Jun 2013
Posts: 6
Location: Bulgaria, Plovdiv

View user's profile Send private message Send e-mail

PostPosted: Thu Jun 20, 2013 12:42 am     Reply with quote

Thanks for the useful information! I do not have much experience with CCS compiler. More I worked with Mikroc.
The program is uart communication between microcontroller and bluetooth module.

I do not know whether I should use:

Code:

porta = 0;
portb = 0;
portc = 0;
porte = 0;


after:
Code:

Set_tris_a(0b00000001);
Set_tris_b(0b00000000);
Set_tris_c(0b10000000);
Set_tris_e(0b11111111);


This is the code:
Code:

#include <16f886.h>   
#Fuses XT, NOWDT, PUT, NOMCLR, NOBROWNOUT, NOLVP, NOPROTECT 
#use delay(clock=4000000)     
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7,FORCE_SW,bits=8,parity=N,TIMEOUT=300,STOP=1)
#include "flex_lcd.c"                 

#byte porta = getenv("SFR:PORTA")
#byte portb = getenv("SFR:PORTB")
#byte portc = getenv("SFR:PORTC")
#byte porte = getenv("SFR:PORTE")

int reply;

VOID MAIN (VOID)
{

   Set_tris_a(0b00000001);
   Set_tris_b(0b00000000);
   Set_tris_c(0b10000000);
   Set_tris_e(0b11111111);

   
   delay_ms(150);

setup_adc_ports(NO_ANALOGS);
setup_comparator(NC_NC_NC_NC);

      lcd_init();
      delay_ms(150);
 

do{

putc( "...a request" );

reply = getc();

printf(lcd_putc,"\f", reply);

delay_ms(50);


}while (true);
}   
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group