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

PIC 16f877 with LCD

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



Joined: 27 Oct 2006
Posts: 1

View user's profile Send private message

PIC 16f877 with LCD
PostPosted: Fri Oct 27, 2006 6:00 am     Reply with quote

Hi.,
I am working with PIC16f877 and also new to use PIC controller. Now i have to use LCD for displaying purpose. I am trying a lot to do that, but i am failing in that.. Please, anybody help me to know how to use LCD with PIC 16f877 in CCS C complier..
Expecting the reply...
Thanks a lot..

Confused
linux123



Joined: 09 Oct 2006
Posts: 17

View user's profile Send private message

LCD
PostPosted: Fri Oct 27, 2006 9:20 am     Reply with quote

My friend, try it´s:

mod_lcd.c
#ifndef lcd_enable
#define lcd_enable pin_e1 // pino enable do LCD
#define lcd_rs pin_e0 // pino rs do LCD
//#define lcd_rw pin_e2 // pino rw do LCD
#define lcd_d4 pin_d4 // pino de dados d4 do LCD
#define lcd_d5 pin_d5 // pino de dados d5 do LCD
#define lcd_d6 pin_d6 // pino de dados d6 do LCD
#define lcd_d7 pin_d7 // pino de dados d7 do LCD
#endif

#define lcd_type 2 // 0=5x7, 1=5x10, 2=2 linhas
//#define lcd_seg_lin 0x40 // Endereço da segunda linha na RAM do LCD

// a constante abaixo define a seqüência de inicialização do módulo LCD
byte CONST INI_LCD[4] = {0x20 | (lcd_type <<2>> 4);
// envia a segunda parte do byte
lcd_envia_nibble(dado & 0x0f);
}


void lcd_ini()
// rotina de inicialização do display
{
byte conta;
output_low(lcd_d4);
output_low(lcd_d5);
output_low(lcd_d6);
output_low(lcd_d7);
output_low(lcd_rs);
#ifdef lcd_rw
output_high(lcd_rw);
#endif
output_low(lcd_enable);
delay_ms(15);
// envia uma seqüência de 3 vezes 0x03
// e depois 0x02 para configurar o módulo
// para modo de 4 bits
for(conta=1;conta<=3;++conta)
{
lcd_envia_nibble(3);
delay_ms(5);
}
lcd_envia_nibble(2);
// envia string de inicialização do display
for(conta=0;conta<=3;++conta) lcd_envia_byte(0,INI_LCD[conta]);
}

void lcd_pos_xy( byte x, byte y)
{
byte endereco;
//if(y!=1)
switch(y) {
case 1 : endereco=0x80;break;
case 2 : endereco=0xc0;break;
case 3 : endereco=0x90;break;
case 4 : endereco=0xd0;break;

}
//endereco = lcd_seg_lin;
//else
//endereco = 0;
endereco += x-1;
//lcd_envia_byte(0,0x80|endereco);
lcd_envia_byte(0,endereco);
//lcd_send_byte(0,address);
}

void lcd_escreve( char c)
// envia caractere para o display
{
switch (c)
{
case '\f' : lcd_envia_byte(0,1);
delay_ms(2);
break;
case '\n' :
case '\r' : lcd_pos_xy(1,2);
break;
case '\b' : lcd_envia_byte(0,0x10);
break;
default : lcd_envia_byte(1,c);
break;
}
}

char lcd_le( byte x, byte y)
// le caractere do display
{
char valor;
// seleciona a posição do caractere
lcd_pos_xy(x,y);
// ativa rs
output_high(lcd_rs);
// lê o caractere
valor = lcd_le_byte();
// desativa rs
output_low(lcd_rs);
// retorna o valor do caractere
return valor;
}

aplication.c
#include <18f877.h>
.
.
.
#include <mod_lcd.c> //modulo para imprimir no LCD
main()
{
int val33=50;
lcd_ini(); //Inicializa o display de LCD 16X4 (start LCD)
lcd_escreve('\f'); //Limpa LCD (clear display)
lcd_escreve("I world...."); //Print text in LCD display.
printf(lcd_escreve,"Value:%2.2f",val33); //Print value of variable.
}


The module works with LCD 16X4 or 16X2.
Attention to pinout the LCD and PIC
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