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.

Help with 8051 Code!!!

Status
Not open for further replies.

hsuri

Newbie level 5
Joined
Jun 26, 2010
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,329
I am new to Microcontrollers..need urgent help with the code..

Follwing is the code to display a single message on the sound of a clap using 8051

Code:
#include<reg51.h>
#define port P1
#define dataport P2  //Data port for LCD
#define sec 1000
//CONTROL PINS
sbit rs = port^0;
sbit rw = port^1;
sbit e = port^2;
sbit sensor_input=P0^0;

void delay(unsigned int msec) //Time delay function
{
int i,j ;
for(i=0;i<msec;i++)
 for(j=0;j<1275;j++);
}

void lcd_cmd(unsigned char item) //Function to send command to LCD
{
dataport = item;
rs= 0;
rw=0;
e=1;
delay(1);
e=0;
return;
}

void lcd_data(unsigned char item) // Function to send data to LCD
{
dataport = item;
rs= 1;
rw=0;
e=1;
delay(1);
e=0;
return;
}

void lcd_data_string(unsigned char *str)  //Function to send string to LCD
{
int i=0;
while(str[i]!='\0')
{
 lcd_data(str[i]);
 i++;
 delay(10);
}
return;
}

void main()
{
unsigned char str1[] ="HELLO";
unsigned char str2[] =" WORLD";
sensor_input=1;
sensor_input=0;
lcd_cmd(0x38);
lcd_cmd(0x0e);
lcd_cmd(0x01);
while(1)
{
 if(sensor_input==1)
 {
  lcd_cmd(0x82);
  lcd_data_string(str1);
  lcd_cmd(0xc6);
  lcd_data_string(str2);
  delay(sec);
  lcd_cmd(0x01);
  delay(100);
 }
}
}


---------- Post added at 12:03 ---------- Previous post was at 12:02 ----------

Urgent help required...plzz:-?
 

keil is the good compiler

---------- Post added at 12:53 ---------- Previous post was at 12:47 ----------

yes code is correct
no errors and no warnings i have checked
 

what is your problem?
no display in lcd?
try to give more delay while command 0x38
some lcd's need to write the 0x38 three times first give 15ms delay and 5ms delay and 1ms delay

still error
 

You can also use a simulator, ( Proteus, for example ) to check if program behave like expected.
 

@hsuri : thats the same code given at EngineersGarage website.. i have made this project and it is working fine. Use Keil for compiling the code.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top