Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

simple lcd programm for pic16f877

Status
Not open for further replies.

chaudhryali55

Member level 2
Member level 2
Joined
Jan 18, 2011
Messages
43
Helped
4
Reputation
8
Reaction score
4
Trophy points
1,288
Location
gujrat,pakistan
Activity points
1,529
hi !

i need a help for writing a programm in c to display text on lcd like "hello".m using mplab compiler .and there is no built in functions for lcd..can anyone provide a code that will make the lcd to display text..m using pic16f877 ..thanks
 

you can see this code for understanding

void LCD_init()
{

LCD_command(0x38 );
delay(10);
LCD_command(0x06);
delay(10);
LCD_command(0x0C);
delay(10);
LCD_command(0x02);
delay(10);
LCD_command(0x01);
delay(10);

}

void LCD_command(unsigned char comm)
{

PORTB=comm;
rs = 0; //register select=command
delay(1);
rw = 0; //write
delay(1);
en = 1;
delay(10); //Enable H->L
en = 0;
delay(10);
}

void Sendchar(unsigned char dat)
{
PORTB=dat;
rs = 1; //register select=data
delay(1);
rw = 0; //write
delay(1);
en = 1;
delay(10); //Enable H->L
en = 0;
delay(10);
}

void main()
{
LCD_init();
Sendchar('h');
Sendchar('e');
Sendchar('l');
Sendchar('l');
Sendchar('o');
}
 

it is useful code thatnks... what header files should i use ? btw m using mikro c Pro compiler so i dont think i must need the header files... m i ri8 ?


btw thanks very much it really helped me.
 

you can use LCD.h
there s nothing in that file
i have attached it hegre please find it.
and ofcaurse the p16f877.h
 

Attachments

  • lcd.h.txt
    157 bytes · Views: 171

m using mickro c compiler .i just stoped for mplab...there is built in function of lcd in mikro c compiler but there is no RW function used as m using 8 bit.m hardware only works on the below asm code this is built code for pi simulator ide..can anybody provide me the same thing in c ? thanks in advance
Code:
Define ADC_CLOCK = 3 'default value is 3
Define ADC_SAMPLEUS = 10 'default value is 20
Define LCD_BITS = 8 'allowed values are 4 and 8 - the number of data interface lines
Define LCD_DREG = PORTB
Define LCD_DBIT = 0 '0 or 4 for 4-bit interface, ignored for 8-bit interface
Define LCD_RSREG = PORTD
Define LCD_RSBIT = 1
Define LCD_EREG = PORTD
Define LCD_EBIT = 3
Define LCD_RWREG = PORTD 'set to 0 if not used, 0 is default
Define LCD_RWBIT = 2 'set to 0 if not used, 0 is default
Define LCD_COMMANDUS = 2000 'delay after LCDCMDOUT, default value is 5000
Define LCD_DATAUS = 50 'delay after LCDOUT, default value is 100
Define LCD_INITMS = 2 'delay used by LCDINIT, default value is 100
'the last three Define directives set the values suitable for simulation; they should be omitted for a real device
 
Dim an0 As Word
 
TRISA = 0xff 'set all PORTA pins as inputs
ADCON1 = 0 'set all PORTA pins as analog inputs
Lcdinit 1 'initialize LCD module; cursor is blinking
 
loop:
   Adcin 0, an0
   Lcdcmdout LcdClear 'clear LCD display
   Lcdout "Analog input AN0" 'text for the line 1
   Lcdcmdout LcdLine2Home 'set cursor at the beginning of line 2
   Lcdout "Value: ", #an0 'formatted text for line 2
   WaitMs 1 'larger value should be used in real device
Goto loop 'loop forever
 

i used this programm and it runs fine on the simulator but on the hardware it is not implemented...i want a code that i can use all the 8 bits...and RW...thanks is advance..
 

IF you use Hitech C, this where you can find a working code:
C:\Program Files\HI-TECH Software\PICC\9.71a\samples\LCDemo
I have tested this sample and it works fine, but you should understand a few things:
This one uses a 4 bit interface, I have one for 8 bit interface lying somewhere, but dont remember which computer. If you keep the HD44780 data sheet and the program code together you will understand how to send data over 8 bit interface instead of 4 bit.
while working with PICs configuration bits need to be properly programmed if you dont do it properly your micro will not work in the circuit for sure.
Ah I found another one, in Mikro C, tested this one too a while ago and it works.
 

Attachments

  • LCD 8 bit.rar
    3.9 KB · Views: 152
Last edited:
i want a code that i can use all the 8 bits...and RW...thanks is advance..
I think this is the solution.


/*
Date: 25-01-2011
Project name: 8bit LCD
Author: Denshil
MCU: PIC16F877A
LCD: Lcd 2x16
Compiler: mikroC PRO
*/

sbit LCD8_RS at RB2_bit;
sbit LCD8_RW at RB3_bit;
sbit LCD8_EN at RB4_bit;
sbit LCD8_D7 at RD7_bit;
sbit LCD8_D6 at RD6_bit;
sbit LCD8_D5 at RD5_bit;
sbit LCD8_D4 at RD4_bit;
sbit LCD8_D3 at RD3_bit;
sbit LCD8_D2 at RD2_bit;
sbit LCD8_D1 at RD1_bit;
sbit LCD8_D0 at RD0_bit;

sbit LCD8_RS_Direction at TRISB2_bit;
sbit LCD8_RW_Direction at TRISB3_bit;
sbit LCD8_EN_Direction at TRISB4_bit;
sbit LCD8_D7_Direction at TRISD7_bit;
sbit LCD8_D6_Direction at TRISD6_bit;
sbit LCD8_D5_Direction at TRISD5_bit;
sbit LCD8_D4_Direction at TRISD4_bit;
sbit LCD8_D3_Direction at TRISD3_bit;
sbit LCD8_D2_Direction at TRISD2_bit;
sbit LCD8_D1_Direction at TRISD1_bit;
sbit LCD8_D0_Direction at TRISD0_bit;

char firstRow[] = "8bit LCD Project";
char secondRow[] = "It's very simple";
void main(){
Lcd8_Init();
Lcd8_Cmd(_LCD_CLEAR);
Lcd8_Cmd(_LCD_CURSOR_OFF);
Lcd8_Out(1,1,firstRow);
Lcd8_Out(2,1,secondRow);

}
 
thnks abid ....i m using a tranier board in university but i dont still know what kind of crap is this borad..no manual for its internal connection..by the way i will try to use the code and and then give u feedback that who it worked ..thanks guys.

---------- Post added at 04:15 ---------- Previous post was at 04:13 ----------

I think this is the solution.


/*
Date: 25-01-2011
Project name: 8bit LCD
Author: Denshil
MCU: PIC16F877A
LCD: Lcd 2x16
Compiler: mikroC PRO
*/

sbit LCD8_RS at RB2_bit;
sbit LCD8_RW at RB3_bit;
sbit LCD8_EN at RB4_bit;
sbit LCD8_D7 at RD7_bit;
sbit LCD8_D6 at RD6_bit;
sbit LCD8_D5 at RD5_bit;
sbit LCD8_D4 at RD4_bit;
sbit LCD8_D3 at RD3_bit;
sbit LCD8_D2 at RD2_bit;
sbit LCD8_D1 at RD1_bit;
sbit LCD8_D0 at RD0_bit;

sbit LCD8_RS_Direction at TRISB2_bit;
sbit LCD8_RW_Direction at TRISB3_bit;
sbit LCD8_EN_Direction at TRISB4_bit;
sbit LCD8_D7_Direction at TRISD7_bit;
sbit LCD8_D6_Direction at TRISD6_bit;
sbit LCD8_D5_Direction at TRISD5_bit;
sbit LCD8_D4_Direction at TRISD4_bit;
sbit LCD8_D3_Direction at TRISD3_bit;
sbit LCD8_D2_Direction at TRISD2_bit;
sbit LCD8_D1_Direction at TRISD1_bit;
sbit LCD8_D0_Direction at TRISD0_bit;

char firstRow[] = "8bit LCD Project";
char secondRow[] = "It's very simple";
void main(){
Lcd8_Init();
Lcd8_Cmd(_LCD_CLEAR);
Lcd8_Cmd(_LCD_CURSOR_OFF);
Lcd8_Out(1,1,firstRow);
Lcd8_Out(2,1,secondRow);

}

thnks it really helped me.. i used your logic before but it was not implementing on the board i think the trainer board i just ...leave it ..:) ..by the way thanks
 

try proton or picbasic,don't bother with asm or C,too many bracket,lines, etc...,to print on lcd in basic ,simply do this :
print at 1,1,"Hello"

and check help file for other fonction,before in past,i programmed in ASm,now i dont waste my time
 

Here is a fully implemented code for the LCD display for PIC16877. This is programmed in assembly and actually says "Hello World!" lol
 

Attachments

  • LCD.zip
    6.3 KB · Views: 168

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top