Microcontroller › 8051 › programming 8×2 LCD (pc0802A)
- This topic has 5 replies, 2 voices, and was last updated 11 years ago by
Shailesh Tambe.
-
AuthorPosts
-
March 14, 2012 at 3:06 am #1579
werytretr
ParticipantHello! anyone know how to program a 8×2 LCD (8051) with silicon laboratories? I just need to display words on the LCD.. need help urgently! please help me!! (:
March 14, 2012 at 9:06 am #7298werytretr
Participanthow to edit from this.
#include <c8051f340.h>
#include <stdio.h>
#include <stdlib.h>#define cmdport P0
#define dataport P1
#define q 100
sbit rs = cmdport^4; //register select pin
sbit rw = cmdport^5; // read write pin
sbit e = cmdport^6; //enable pinvoid delay(unsigned int msec) // Function to provide time delay in msec.
{
int i,j ;
for(i=0;i<msec;i++)
for(j=0;j<1275;j++);
}void lcdcmd(unsigned char item) //Function to send command to LCD
{
dataport = item;
rs= 0;
rw=0;
e=1;
delay(1);
e=0;
}void lcddata(unsigned char item) //Function to send data to LCD
{
dataport = item;
rs= 1;
rw=0;
e=1;
delay(1);
e=0;
}void main()
{
lcdcmd(0x38); // for using 8-bit 2 row mode of LCD
delay(100);
lcdcmd(0x38);
delay(100);
lcdcmd(0x38);
delay(100);
lcdcmd(0x0E); // turn display ON for cursor blinking
delay(100);
lcdcmd(0x01); //clear screen
delay(100);
lcdcmd(0x06); //display ON
delay(100);
lcdcmd(0x86); // bring cursor to position 6 of line 1
delay(100);
lcddata(‘A’);
}March 14, 2012 at 9:38 am #7300Shailesh Tambe
ParticipantMay I know, do you want to use both the lines of LCD ?
March 14, 2012 at 10:12 am #7301Shailesh Tambe
ParticipantTry out this code……………… it should work
#include<reg51.h>#include<string.h>sbit rs = P2^0;sbit rw = P2^1;sbit en = P2^2;sbit b = P1^7;void writecmd(unsigned char a);void writedat(unsigned char b);void busy();void writestr(unsigned char *s);void delay(unsigned int msec);void writecmd(unsigned char a){busy();rs=0;rw=0;P1=a;en=1;en=0;}void writedat(unsigned char b){busy();rs=1;rw=0;P1=b;en=1;en=0;}void busy(){en=0;P1=0xFF;rs=0;rw=1;while(b==1){en=0;en=1;}en=0;}void writestr(unsigned char *s){unsigned char i,len;len=strlen(s);for(i=0;i<len;i++){writedat(*s);s++;}}void delay(unsigned int msec){int count1,count2;for(count1=0;count1<msec;count1++)for(count2=0;count2<1275;count2++);}void main(){P1=0x00;P2=0x00;writecmd(0x3C); // Initialize the LCDdelay(50);writecmd(0x0E); // turn display ON for cursor blinkingdelay(50);writecmd(0x01); //Clear the LCD Screendelay(50);writecmd(0x06);delay(50);writestr(“HAPPY”);delay(50);writecmd(0xC0);delay(50);writestr(“BIRTHDAY”);delay(50);while(1);}March 15, 2012 at 1:28 am #7303werytretr
Participanterms, it still don’t work.. im using port 1 for PB0~PB7, P0.2 for EN, P0.1 for R/W, P0.0 for RS.. what does your b define as? is it PB0~PB7? im using this lcd, with datasheet inside.. http://singapore.rs-online.com/web/p/lcd-displays-alphanumeric/2143288/?searchTerm=214+3288&relevancy-data=636F3D3126696E3D4931384E525353746F636B4E756D6265724D504E266C753D656E266D6D3D6D61746368616C6C26706D3D5E5C647B337D5B5C732D2F255C2E5D5C647B332C347D2426706F3D313426736E3D592673743D52535F53544F434B5F4E554D424552267573743D32313420333238382677633D4E4F4E4526
guess i need to add #include < c8051f340.h> as header for sure because im using silicon lab. (:
March 16, 2012 at 12:13 pm #7306Shailesh Tambe
ParticipantYou have to do some necessary changes in the program as per the microcontroller, the connections and the LCD that you might be using. This program is for 16×2 LCD using P89V51RD2 Microcontroller. ‘b’ in this program is defined as PB7 to check the LCD status.
-
AuthorPosts
- You must be logged in to reply to this topic.