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.

LED blinking and Displaying on LCD project in atmel 89c51

Status
Not open for further replies.

Hareesh Kumar

Junior Member level 2
Junior Member level 2
Joined
May 17, 2011
Messages
24
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,450
Hi,
I am new in the embodied world.I am going to develop a simple device which has 4 inputs 1 2 3 4.LED has to be blink while i give the input and also display in LCD which input i give like 1/2/3/4...I kindly request everybody to guide me..Any sort of help is appreciated.

Thanks and Regards
Hareesh Kumar
 

input is given by keypad or PC. if it is keypad then you have to write a program for keypad scan... if it is through PC then you have to write a serial communication program and blink the LED. Please tell how is the input given.... which IDE and compiler are you using????

---------- Post added at 10:49 ---------- Previous post was at 10:46 ----------

suppose led is connected to port 2

#inclue<at89c52.h>
void main(void)
{
TMOD = 0x20;
SCON = 0x50;
TH1 = -3;
while(1)
{
P2 = 0xFF;
SBUF = P2;
while(!TI);
TI = 0;
delay();
P2 = 0x00;
SBUF = P2;
while(!TI);
TI = 0;
}

}

Now it toggles continuously.
now you put the condition to check if the input is 1 2 3 or 4 and toggle that particular port pin.......
this program is for serial communication where input is given by PC to controller using UART.
 
Last edited:
using keyboard.I am using Keil and Ezd4 for this.

---------- Post added at 11:55 ---------- Previous post was at 11:43 ----------

My requirement is when i press 1/2/3/4 keys in the keyboard,the 4 LEDs connected to port1.1,1.2,1.3,1.4 should on and print the status in LCD also for off condition and in hyperterminal.
 

please write the keyboard program and check with hardware if it works.... then write a program to compare the inputs and use switch case for that......

you get the sample code for keyboard interface in 8052.com - The Online 8051/8052 Microcontroller Resource - 8052.com

keyboard is what type? PC keyboard or other external keypads... 3x3 or any configuration of keypads the code is seperate and PC keyboard will use serial communication program.. which one you use????????
 

when press 1 in keyboard the led connected with p1.1 pin should on.Then i press 2 in keyboard,first led should off and second led(p1.2)should on..These procedure should continoue for the 4th pin.and everytime led on,it should print on hyperterminal and LCD

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

I am using Pc keyboard
 

Dear Hareesh,
Please find the attached file
I have written one sample code for your application
considering that you have your LCD routines & UART, Timer initialization routines ready with you.
I haven't put any comment in the code, that is for your home work
Ping me if you want any further help.. :)
 

Attachments

  • KeySampleCode.txt
    1.2 KB · Views: 110

how can i send the 1 or 2 from keyboard to SBUF register?
 

the data you type is received by the SBUF and when you have to transmit the data is it stored in SBUF and then transmitted...

your loop will be like this

while(1)
{
while (!RI); //stay here till all 8 bits are received in SBUF
a= SBUF // storing the contents of SBUF to variable a
RI=0;

SBUF = a; // store the content of a into SBUF
while (!TI); //wait here till all 8 bits are transmitted from SBUF
TI=0;
}

---------- Post added at 15:04 ---------- Previous post was at 14:48 ----------

for sending the numbers 1 and 2 to SBUF, you have to define them as characters

unsigned char a;

main()
{
a='1';
SBUF = a;
while (!TI); //wait here till all 8 bits are transmitted from SBUF
TI=0;

}
 

#include <reg52.h>
void main(void)
{

TMOD=0x20; //use Timer 1, mode 2
TH1=0xFD; //9600 baud rate
SCON=0x50;
TR1=1; //start timer
while(1)
{
while (!RI);
a= SBUF
RI=0;

SBUF = a;
while (!TI);
TI=0;
}
}
}
i wrote this code for sending a value from keyboard to sbuf register through serial commnication.Is it right one??
 

yes it is correct... you can see the output in keil simulator window.... go to view in debug mode and open serial window1... then run the program... ( Not step by step) RUN it... come to the serial window and type from keyboard... you should see the letters typed on keyboard...

if not change the serial window
and try it.......
 

Actually i want to send the value 1 to sbuf when pres 1 in keyborad and at that time p1.1 pin get on .Then i will press 2 that time p1.1 should off.This is the basic step i want to do.
 

you need to modify the program that i have given... you have to compare the data and toggle the port pin... few lines of code you need to add...... Its more of a home work .... you are trying to get it done here....

you store the SBUF data in a variable and compare it with the number.. if it is same then do the needed operation............
 

#include <reg52.h>
sbit mybit=p1^3;
void main(void)
{
char a;
TMOD=0x20; //use Timer 1, mode 2
TH1=0xFD; //9600 baud rate
SCON=0x50;
TR1=1; //start timer
while(1)
{
while (!RI);
a='1';
SBUF = a;
RI=0;

SBUF = a;
while (!TI);
TI=0;
}
}
if(sbuf==1)
{
mybit=0xf0;
}
else if(sbuf==2)
{
mybit=0xf1;
}
Is this right one??
 

p1^3; P should be in capital letters....


remove this line a='1'; after while(!RI);
in the next line it is not SBUF = a;........ it is a=SBUF;

dont compare SBUF data... companre the value of a with 1 or 2........

make P1^3 = 1;

or P1^3 = 0;

you can simulate it on keil itself.... see when you type in serial window as one does the port pin in the peripherals pf port 2 change as per your typing of numbers.........
 

#include <reg52.h>
sbit mybit=p1^3;
void main(void)
{
char a;
TMOD=0x20; //use Timer 1, mode 2
TH1=0xFD; //9600 baud rate
SCON=0x50;
TR1=1; //start timer
while(1)
{
while (!RI);
a='1';
SBUF = a;
RI=0;

SBUF = a;
while (!TI);
TI=0;
}
}
if(sbuf==1)
{
mybit=0xf0;
}
else if(sbuf==2)
{
mybit=0xf1;
}
Is this right one??

From a brief look at your code, I see many lines of code are outside main function, give some concentration on brackets.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top