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

16F877A LCD 4-bit MODE

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
[email protected]



Joined: 23 Jun 2012
Posts: 22

View user's profile Send private message

16F877A LCD 4-bit MODE
PostPosted: Tue Sep 25, 2012 10:20 am     Reply with quote

I tried out the following code in my development board. The compiler shows no error but I am not getting the output in LCD. Pls...anyone check this with your device and help me solve the error....pls...I am beginner.

Thanks in advance

Code:
#include <16F877A.h>
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES HS                       //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD                    //No EE protection
#FUSES NOWRT                    //Program memory not write protected

#use delay(clock=20000000)

#define LCD_ENABLE PIN_D2
#define LCD_RS PIN_D0
#define LCD_RW PIN_D1
#define LCD_DATA_PORT 08h

void lcd_init();
void lcd_cmd(char c);
void lcd_data(char d);

void lcd_init()
{
   lcd_cmd(0x28);
   delay_ms(200);
   lcd_cmd(0x0c);
   delay_us(10);
   lcd_cmd(0x06);
   delay_us(10);
   lcd_cmd(0x01);
   delay_us(10);
}


void lcd_cmd(char c)
{
   output_d(c);
   output_low(LCD_RS);
   output_low(LCD_RW);
   delay_ms(1);
   output_high(LCD_ENABLE);
   delay_ms(1);
   output_low(LCD_ENABLE);
}

void lcd_data(char d)
{
   output_d(d);
   output_high(LCD_RS);
   output_low(LCD_RW);
   delay_ms(1);
   output_high(LCD_ENABLE);
   delay_ms(1);
   output_low(LCD_ENABLE);
}

void main()
{
while(1)
{
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_CLOCK_DIV_2);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);

         lcd_init();
         lcd_cmd(0x01);
         lcd_cmd(0x80);
         lcd_data('E');
         lcd_data('L');
         lcd_data('I');     
         lcd_data('T');     
         lcd_data('E');     
         
         lcd_cmd(0xC0); 
         lcd_data('w');     
         lcd_data('e');     
         lcd_data('l');     
         lcd_data('c');     
         lcd_data('o');
         lcd_data('m');
         lcd_data('e');

   //TODO: User Code
}
}

_________________
-humble request from a beginner
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Tue Sep 25, 2012 11:10 am     Reply with quote

You're not the first to have LCD problems.

I'm assuming that you have proven that the board is working by flashing an LED.

Do a search on this forum for LCD problems. You'll get loads of suggestions.

Also try the LCD_flex driver, rather than writing your own.

Mike
Ttelmah



Joined: 11 Mar 2010
Posts: 19496

View user's profile Send private message

PostPosted: Tue Sep 25, 2012 2:42 pm     Reply with quote

The most obvious missing thing is the delay at the start. Most LCD's need significant time after power is applied before they can be initialised. You are calling your lcd_init, only a few uSec after the chip powers up. Add something like a 1/4 second delay before this.

Best Wishes
[email protected]



Joined: 23 Jun 2012
Posts: 22

View user's profile Send private message

PostPosted: Fri Dec 21, 2012 6:08 am     Reply with quote

Flex_LCD Driver also does not work for me!
But I was able to display in LCD using AT-168 controller with the same hardware.
temtronic



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

View user's profile Send private message

PostPosted: Fri Dec 21, 2012 6:26 am     Reply with quote

Quick comments...
1) Title says 4 bit mode, but code is 8 bit mode.

2) As mr. t. pointed out, different LCD modules require different setup times. I typically powerup, wait 1 second, do LCD_init, wait another second and have NEVER had ANY module not run right.

3) I have used the 16F877/flex_LCD driver for years, so I know they will work together.

4) Then there's the non standard use of portD for both LCD control lines AND data. Pretty sure that will not work.

5) You should add comments to most lines of code so that a day, week, month form now, you'll know what you did and why. lcd_cmd(0x0c) means ??? as an example. It also helps others to figure out your code.

hth
jay
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