- This topic has 31 replies, 3 voices, and was last updated 13 years, 8 months ago by gana.
-
AuthorPosts
-
April 4, 2011 at 12:25 am #844ganaParticipant
hi i am making LCD 2×16 in my project i almost done my project but i can not understand LCD that how to use it … i tryed some codes in C but i doesnt work i do not know any ASM so i need some help for C with my LCD . i wonna display the words without flowing on it. and when the sensor(P1^1) senses the fire or other things the word should to display it with 2 lines and blink all words in while(1) loop . but in my code i works like flowing in loop and no w lines or not work. and i am showing you my codes pls help me!!! it’s written on MicroC pro for 8051 compiler. and project is on proteus7….
#define dt P1
sbit rs at P3_7_bit;
sbit r at P3_6_bit;
sbit e at P3_5_bit;
sbit gal at P2_1_bit;
sbit ut at P2_2_bit;
void delay()
{unsigned int i=0;
for(i=0;i<30;i++);}
void delay_ms()
{unsigned int i=0;
for(i=0;i<3000;i++);}
void init()
{rs=0;
r=0;
e=1;
dt=0x0f;
delay_ms();
e=0;}
void character()
{ int j;
unsigned char a[15]={“Xaalga”} ;rs=1;
r=0;
for(j=0;j<6;j++)
{e=1;
dt=a[j] ;
delay_ms() ;
e=0;} }void main()
{ init() ;
gal=0; ut=0;while(1) {
if(gal==1)
{
while(1){
character();
}}}
dt=0x38;rs=0;
r=0;
e=0;
e=1;}
April 4, 2011 at 2:30 am #5869romel emperadoParticipanthey gana..
reffer to this sample code.. it’s working.. I’ve using this code of my projects.. this is 4bit mode
// 4 bit example
#include<reg51.h>
#define LCD P1
#define LCD_EN 0x80
#define LCD_RS 0x20
//LCD Commands#define LCD_SETMODE 0x04
#define LCD_SETVISIBLE 0x08
#define LCD_SETFUNCTION 0x28
#define LCD_SETDDADDR 0x80void delayms(unsigned char);
void delayus(unsigned char);
void lcd_init();
void lcd_reset();
void lcd_cmd (char);
void lcd_data(unsigned char);
void lcd_str (unsigned char*);void main (void)
{
lcd_init();
lcd_cmd(0x80); // ist line address
lcd_str(” i love “);
lcd_cmd(0xC0); // 2nd line address
lcd_str(“Romel emperado”);
while(1);
}void delayus(unsigned char delay){
while(delay–);
}void delayms(unsigned char delay){
while(delay–)
delayus(149);
}void lcd_reset()
{
LCD = 0xFF;
delayms(40);
LCD = 0x03+LCD_EN;
LCD = 0x03;
delayms(40);
LCD = 0x03+LCD_EN;
LCD = 0x03;
delayms(5);
LCD = 0x03+LCD_EN;
LCD = 0x03;
delayms(5);
LCD = 0x02+LCD_EN;
LCD = 0x02;
delayms(5);
}void lcd_init ()
{
lcd_reset();
lcd_cmd(LCD_SETFUNCTION); // 4-bit mode – 1 line – 5×7 font.
lcd_cmd(LCD_SETVISIBLE+0x04); // Display no cursor – no blink.
lcd_cmd(LCD_SETMODE+0x02); // Automatic Increment – No Display shift.
lcd_cmd(LCD_SETDDADDR); // Address DDRAM with 0 offset 80h.
}void lcd_cmd (char cmd)
{
LCD = ((cmd >> 4) & 0x0F)|LCD_EN;
LCD = ((cmd >> 4) & 0x0F);LCD = (cmd & 0x0F)|LCD_EN;
LCD = (cmd & 0x0F);delayus(250);
delayus(250);
}void lcd_data (unsigned char dat)
{
LCD = (((dat >> 4) & 0x0F)|LCD_EN|LCD_RS);
LCD = (((dat >> 4) & 0x0F)|LCD_RS);
LCD = ((dat & 0x0F)|LCD_EN|LCD_RS);
LCD = ((dat & 0x0F)|LCD_RS);delayus(250);
delayus(250);
}void lcd_str (unsigned char *str)
{
while(*str){
lcd_data(*str++);
}
}April 4, 2011 at 2:32 am #5870romel emperadoParticipantthe above code is written in keil..
you said that you are using mickroC then that would be easy.. mikcroC has many builtin libraries .. just check the help file of the compiler..
April 4, 2011 at 5:03 am #5879dagakshayParticipantcheck out the links it might help you out
how to interface 16×2 LCD with 8051 conteroller
http://www.engineersgarage.com/microcontroller/8051projects/interface-lcd-at89c51-circuit
C code to asm code
http://www.engineersgarage.com/forums/8051/c-code-assembly-code
April 6, 2011 at 1:57 am #5907ganaParticipanthi there thank you a lot i check it out ..but it is not working on my project can you send me your project picture pls? and i tryed the examlpes from MicroC but every code i tryed that not working . when i compile it i having error . i think something is missing in the code written below:
// Lcd module connections
sbit LCD_RS at P2_0_bit;
sbit LCD_EN at P2_1_bit;
sbit LCD_D4 at P2_2_bit;
sbit LCD_D5 at P2_3_bit;
sbit LCD_D6 at P2_4_bit;
sbit LCD_D7 at P2_5_bit;
// End Lcd module connections
char txt1[] = "mikroElektronika";
char txt2[] = "Easy8051B";
char txt3[] = "Lcd4bit";
char txt4[] = "example";
char i; // Loop variable
void Move_Delay() { // Function used for text moving
Delay_ms(500); // You can change the moving speed here
}
void main(){
Lcd_Init(); // Initialize Lcd
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,6,txt3); // Write text in first row
Lcd_Out(2,6,txt4); // Write text in second row
Delay_ms(2000);
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Out(1,1,txt1); // Write text in first row
Lcd_Out(2,5,txt2); // Write text in second row
Delay_ms(2000);
// Moving text
for(i=0; i<4; i++) { // Move text to the right 4 times
Lcd_Cmd(_LCD_SHIFT_RIGHT);
Move_Delay();
}
while(1) { // Endless loop
for(i=0; i<8; i++) { // Move text to the left 7 times
Lcd_Cmd(_LCD_SHIFT_LEFT);
Move_Delay();
}
for(i=0; i<8; i++) { // Move text to the right 7 times
Lcd_Cmd(_LCD_SHIFT_RIGHT);
Move_Delay();
}
}
}
April 6, 2011 at 4:29 am #5908dagakshayParticipantgo for KEIL C instead of micro C…. the code you shown was written in Keil
April 6, 2011 at 5:19 am #5909romel emperadoParticipanthi gana,
the code example also in mickroC is working.. I’ve dont many projects using mikroC so i have no doubt with that code form mikroC..
how do you know that it is not working? can you pls post your exact problem ..
anyway how did you test your project?
this the code from mikroC.. and the LCD code is really working.
April 7, 2011 at 11:05 am #5920ganaParticipanthi guys i have almost done but the problem is i can not move the cursor to the second line . i wonna write on second line but i cant.in the lecture C0 Hex move cursor into second line but it doesnt how cani ? help?
April 7, 2011 at 11:10 am #5921romel emperadoParticipantif you think you are doing right and still you haven’t got the exact result then try this simple solution..
open your compiler and make another project..
are you using mikroC? I encountered that before.. just make another project with the same code… assumming your doing right buddy..
April 8, 2011 at 8:18 am #5931ganaParticipanthi can can you guys convert this code to MicroC? i am learnin Micro C but i can not convert it with my mind pls teach me the way how to changeit…
#include <REG51.h>
#define display P3
#define KEYPAD P1sbit doorclose = P1^7;
sbit correct = P3^5;
sbit wrong= P3^4;
sbit key = P3^7;
void DelayMs(unsigned int);
void save (unsigned char);
void compare (void);unsigned char keypad[4][3]= { ‘1’, ‘2’, ‘3’,
‘4’, ‘5’, ‘6’,
‘7’, ‘8’, ‘9’,
‘*’, ‘0’, ‘#’};unsigned char displayb[4][3]= { 1 , 2 , 3 ,
4 , 5 , 6 ,
7 , 8 , 9 ,
0, 0 , 0};unsigned char code password[5]= “12345”;
unsigned char user[30]; //user is allowed to press 30 keys without entering
unsigned char q,a=0,z=0;
char t=1;
bit true;
char d;void main(void)
{
unsigned char colloc,rowloc;while(1)
{
do
{
KEYPAD=0xF0;
colloc=KEYPAD & 0xF0;
}
while(colloc ==0xF0); // if any key pressed
DelayMs(1); // some delay
do
{
colloc=KEYPAD;
colloc &=0xF0;
}while(colloc==0xF0); // to verify is really key pressed
KEYPAD=0xFE;
colloc=KEYPAD & 0xF0;
if(colloc !=0xF0)
{
rowloc=0;
goto next;
}KEYPAD=0xFD;
colloc=KEYPAD & 0xF0;
if(colloc !=0xF0)
{
rowloc=1;
goto next;
}
KEYPAD=0xFB;
colloc=KEYPAD & 0xF0;
if(colloc !=0xF0)
{
rowloc=2;
goto next;
}
KEYPAD=0xF7;
colloc=KEYPAD & 0xF0;
rowloc=3;
goto next;next:
if (colloc==0xE0)
{
key=0; // verifying that key is pressed
DelayMs(145);
key=1;
display=((display & 0xf0) | (displayb[rowloc][0])); // display to 7 seg
save(keypad[rowloc][0]);
}
else if(colloc==0xD0)
{
key=0; // verifying that key is pressed
DelayMs(145);
key=1;
display=((display & 0xf0) | (displayb[rowloc][1]));
save(keypad[rowloc][1]);
}
else if(colloc==0xb0)
{
key=0; // verifying that key is pressed
DelayMs(145);
key=1;
display=((display & 0xf0) | (displayb[rowloc][2]));
save(keypad[rowloc][2]);
}
DelayMs(100); // here this delay is important if this is less than 100ms then
// controller understand 1 key as press 2 or 3 times becoz that
//is fast as compaer o our pressing if u want to remove delay from here
// then increse the above 1ms to 100 ms
}
}void save (unsigned char c)
{
if(c==’*’)
{
if(a!=0)
a–;
return;
}if(a==5 && c==’#’)
{
a=0;
compare();if(t==1)
{
if(true==1) // if match ok
{
DelayMs(800);
correct=0;
t=2;
for(d=0; d<7; d++) // on and after 10 sec off nw keypad can’t get data
DelayMs(1000); // max delay u can get is DelayMs(65535) otherwise need looping for big delay
correct=1;
z=0;
a=0; // start agian from 0 location of array
}
else if(true==0)
goto error;}
else if(t==2)
{
DelayMs(800);
doorclose=0;
t=1;
for(d=0; d<5; d++)
DelayMs(1000);
doorclose=1;
}
}
else if((a>5 && c==’#’) || (a<5 && c==’#’))
{
error:
for(q=0; q<5; q++)
{
wrong=0;
DelayMs(420);
wrong=1;
DelayMs(420);
a=0;
}
z=z+1;if(z==4)
{
for(q=0; q<10; q++)
{
wrong=0;
DelayMs(20000);
wrong=1;
z=0;
DelayMs(420);
}
}
a=0;
}
else
{
user[a]=c;
a++;if(a==30) // if the user press 31 keys without entering it will automatically indicate an error
{
display=((display & 0xf0) | (displayb[3][1])); //brings a zero display on the seven segment
goto error; //redirect to error code
}
}
} //end of savevoid compare (void)
{
unsigned char b;
for(b=0;b<5;b++)
{if(user==password)
true=1;
else
{
true=0;
break;
}
}
}//
// Delay mS function
//
void DelayMs(unsigned int count)
{ // mSec Delay 11.0592 Mhz
unsigned int i;
while(count) {
i = 115;
while(i>0) i–;
count–;
}
}April 11, 2011 at 12:59 am #5939romel emperadoParticipantgive it a try..
I know who is the author of this code gana
April 12, 2011 at 2:52 am #5946ganaParticipantit is from your site the guy who made project of home security gave it to me but the name is looks like your name!!!kkk
April 12, 2011 at 3:04 am #5947romel emperadoParticipanthaha.. it’s me gana.. use the above code for the lCD its working…
April 13, 2011 at 1:24 am #5951ganaParticipantkk i almost new that i have changed your project …added LCD and sensors with WIRELESS but i want to make the that code diffrent..like a…in this code we have password only 12345 but i wonna change it whenever i want, like holding (#,*) keys and then restore it what password i wanted . can you help me wth the code ?
April 13, 2011 at 2:14 am #5952romel emperadoParticipantthere are existing projects like that and make that as your refference project. give it a try and i will help you as you go through.
first you need to be done with that lcd thing first before you complicate everything
-
AuthorPosts
- You must be logged in to reply to this topic.