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

learning to use LCDs, 2x16

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



Joined: 31 May 2008
Posts: 7

View user's profile Send private message

learning to use LCDs, 2x16
PostPosted: Fri Aug 29, 2008 12:07 pm     Reply with quote

Hello. I want to control an LCD. In the first try I wanted to use the lcd.c library, but the compiler didn't found it. So I said"O right, o right, i'll do it manually".

For this pin configuration:
RD0 -> RS
RD1 -> R/W
RD2 -> EN
RD3 -> BL(connected to the base of an 2222A)
RD4-> D4
RD5-> D5
RD6-> D6
RD7-> D7


this is my initialization routine:

#locate LCD_PORT = 8 //PORTD
#define LCD_EN 2
#define LCD_RW 1
#define LCD_RS 0
#define LCD_BL 3
void LCD_tick(){
bit_set(LCD_PORT, LCD_EN);
bit_clear(LCD_PORT, LCD_EN);
}
void LCD_Activate(){

set_tris_d(0x00);//port d output
delay_ms(50);
output_d( 0x00 );
bit_clear( LCD_PORT , LCD_RS);
bit_clear( LCD_PORT , LCD_RW );
LCD_PORT &= 0b00111111;LCD_tick();/*First Init*/
delay_ms(15);
LCD_PORT &= (0b00111111); LCD_tick();/*Second Init*/
delay_ms(5);
LCD_PORT &= 0b00111111; LCD_tick();/*thirdInit*/
delay_ms(5);


LCD_PORT &= 0b00101111; LCD_tick();/*Modo de 4 bits*/
delay_ms(5);

/*In the next sentences, firts is sended the nmost signifant nibble of an instruction and the the less significative, keeping the othere states of the LCD PORT intacts*/
LCD_PORT &= 0b00001111; LCD_tick();
LCD_PORT &= 0b10001111; LCD_tick();/*Display Off*/

LCD_PORT &= 0b00001111; LCD_tick();
LCD_PORT &= 0b00011111; LCD_tick();/*Clear Screen*/

LCD_PORT &= 0b00001111; LCD_tick();
LCD_PORT &= 0b01101111; LCD_tick();/*Entry Mode: INCREMENT, SHIFT OFF*/

LCD_PORT &= 0b00101111; LCD_tick();
LCD_PORT &= 0b10001111; LCD_tick();/*Function Set: 4 bits, 2 lines*/

LCD_PORT &= 0b00001111; LCD_tick();
LCD_PORT &= 0b11001111; LCD_tick();/*Display On*/

bit_set(LCD_PORT, LCD_RS);//Volver a modo de recibir caracteres

}
void LCD_WriteChar( char c){
LCD_PORT &= ( (c) | 0x0F );
LCD_tick();
LCD_PORT &= ( (c)<<4 | 0x0F );
LCD_tick();
}

/**Escribe una cadena de caracteres terminada en NULL*/
void LCD_WriteString( char* string){
while( *string ){
LCD_WriteChar(*string);
string++;
}

}

/**Enciende la luz de la pantalla LCD*/
void LCD_Iluminate(){
bit_set(LCD_PORT, LCD_BL);
}

/**Apaga la luz de la pantalla LCD*/
void LCD_NoIluminate(){
bit_clear(LCD_PORT, LCD_BL);
}


/******MAIN ROUTINE******/
void main()
{
char* testString = "Hello World!";
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
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);

// TODO: USER CODE!!
set_tris_a(0x00);
output_A(0b11110000);
LCD_Activate();
LCD_Iluminate();

LCD_WriteString(testString);



}




While testing, RW(RD1) stas high :S. I never set it high!. And also the display only activates one line(which means it's just self-initialized).

What is more wear, all port a is in clear state. Is the something wrong about how I handle manually inputs and outputs?
[/code]
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Aug 29, 2008 12:13 pm     Reply with quote

Flex LCD driver:
http://www.ccsinfo.com/forum/viewtopic.php?t=24661
RaulHuertas



Joined: 31 May 2008
Posts: 7

View user's profile Send private message

Doesn't work
PostPosted: Fri Aug 29, 2008 1:38 pm     Reply with quote

I think I have problems handling Input Output states :S.

#include "D:\Raul\Proyectos\CONEXIONPIC-LCD\UsingFLEXLCD\ProjectFlex-LCD.h"
#include <flex_lcd.c>
#use fast_io (A)
#use fast_io (D)

void main()
{

setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
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);

// TODO: USER CODE!!
set_tris_d(0x00);
set_tris_a(0x00);

lcd_init(); // Always call this first.

lcd_putc("\fHello World\n");
lcd_putc("Line Number 2");
output_high(PIN_A0);
output_low(PIN_A1);
output_high(PIN_A2);
output_low(PIN_A3);
output_high(PIN_A4);
output_low(PIN_A5);
while(1);



}


It's even wear the fact that I have no rsponse in A port :S. I'll test another program for check is not my PIc.

By the way, I'm using a PIC16F877A. CCS demo for Windows.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Aug 29, 2008 1:41 pm     Reply with quote

Quote:
#include <flex_lcd.c>
#use fast_io (A)
#use fast_io (D)


The Flex driver instructions say:
Quote:
Limitations:
1. This driver requires CCS "standard i/o" mode (The default mode
of the compiler).


Delete the fast_io statement for port D.
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