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 support@ccsinfo.com

RE: Simple LCD setup

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







RE: Simple LCD setup
PostPosted: Wed Mar 08, 2006 4:36 am     Reply with quote

Hi,

I'm trying to setup a very simple program to setup an lcd with an 8-bit interface and then display a single char on the screen to check it is working. Is there anything obviously wrong with my code?

#include "C:\Program Files\PICC\work\TQFPtest3.h"

#define LCD_RS PIN_E5
#define LCD_RW PIN_E6
#define LCD_E PIN_E7

#define RS_HIGH 1
#define RS_LOW 0

// Note: 8-bit LCD data bus connected to port D

void LCDputC(int8 data, int1 RS)
{
if(RS == RS_HIGH)
output_high(LCD_RS);
else
output_low(LCD_RS);

printf("data: %x\n", data);

delay_ms(1);
output_high(LCD_E);
delay_ms(1);

output_d(data);
delay_ms(1);

output_low(LCD_E);
delay_ms(1);
}

void LCDinit()
{
LCDputC(0x3f, RS_LOW);
LCDputC(0x0f, RS_LOW);
LCDputC(0x01, RS_LOW);
delay_ms(2);
LCDputC(0x02, RS_LOW);
}

void main()
{
int i;

setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
setup_timer_4(T4_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
setup_oscillator(False);


delay_ms(1000); // LCD power up delay
set_tris_d(0x00); // Both ports are set as outputs
set_tris_e(0x00);
output_low(LCD_RW); // Always in write mode
LCDinit(); // Init LCD function

LCDputC(0x31, RS_HIGH);
}

P.S: I know the PIC is working correctly as I have tested it by writing data to the serial port. Also I have checked the connections between the PIC ports and the LCD are correct.
Ttelmah
Guest







PostPosted: Wed Mar 08, 2006 5:08 am     Reply with quote

There is LCD code supplied with the compiler, and versions with more flexible I/O, on the code forum. Why not look at these?...
Now that having been said, the initialisation sequence is not complete.
The normal sequence required, is:
delay 15 mSec (you have this)
Send 'function set'
delay 4.1mSec or more
Send 'function set' again.
wait 100uSec or more
Send 'function set' yet again.
Now send configuration
Display 'off'
Display 'on'
send 'entry mode set'

You are only sending about half of the sequence needed to ensure a good initilialisation. If you look at the supplied LCD.C code, you will see, that it sends 'function set' three times, with 5mSec between each, and only then sends the initialisation string.
You may need to adjust the LCD bias voltage to actually 'see' anything on the screen.

Best Wishes
Chorus
Guest







RE: Incorrect init
PostPosted: Wed Mar 08, 2006 5:29 am     Reply with quote

Hi,

Are you I need to send the function set command (0x3f) three times? My data sheet seems to show that I only need to send 4 different bytes with delays to setup LCD

Here is a link to the datasheet:-
http://digital-io.com/specification/Char/AA16206.pdf
Ttelmah
Guest







PostPosted: Wed Mar 08, 2006 5:36 am     Reply with quote

The 'quad send', is the default for emulations of the Hitachi display controller, _to ensure initialisation, whatever mode the unit is in_. The problem is that the simpler sequence, assumes the unit has woken up cleanly (with the chip deselected), and this is not guaranteed. Most manufacturers show both sequences.
Even looking at the default from your data sheet, you are not meeting the timing delays they specify between the commands. These are _vital_...

Best Wishes
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