|
|
View previous topic :: View next topic |
Author |
Message |
RaulHuertas
Joined: 31 May 2008 Posts: 7
|
learning to use LCDs, 2x16 |
Posted: Fri Aug 29, 2008 12:07 pm |
|
|
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
|
|
|
RaulHuertas
Joined: 31 May 2008 Posts: 7
|
Doesn't work |
Posted: Fri Aug 29, 2008 1:38 pm |
|
|
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
|
|
Posted: Fri Aug 29, 2008 1:41 pm |
|
|
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. |
|
|
|
|
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
|