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.

Control led by writing a string serially into microcontroller

Status
Not open for further replies.

shubham156

Newbie level 4
Joined
Oct 20, 2014
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
39
Sir, i want to control room devices by transmitting serially from virtual terminal to microcontroller.
That means if i write BULB ON in virtual terminal, the bulb connected to p0.0 glows
I have written a code but that is not working fine.
Please can you tell me the errors in this.
I am attaching the code and circuit diagram.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include<reg51.h>
sfr ldata=0x90;
sbit rs=P2^0;
sbit rw=P2^1;
sbit en=P2^2;
void delay();
void lcdcmd(char value);
void lcddata(char value);
void main()
{
unsigned char p[40]="BULBON";
unsigned char q[40];
unsigned int i=0;
unsigned int flag=0;
unsigned char mybyte;
P1=0;
lcdcmd(0x81);
delay();
lcdcmd(0x0E);
delay();
lcdcmd(0x01);
delay();
lcdcmd(0x06);
delay();
TMOD=0x20;
TH1=0xFd;
SCON=0x51;
TR1=1;
while(1)
{
while(RI==0);
mybyte=SBUF;
while(mybyte!=0x20)
{
q[i]=mybyte;
if(p[i]==q[i])
{
    flag=1;
}
i++;
if((mybyte==0x08)||(mybyte==0x7f))
lcdcmd(0x01);
lcddata(mybyte);
}
 
if(flag==1)
P0=1;
 
RI=0;
delay();
}
}
void lcdcmd(char value)
{
ldata=value;
rs=0;
rw=0;
en=1;
delay();
en=0;
}
void lcddata(char value)
{
ldata=value;
rs=1;
rw=0;
en=1;
delay();
en=0;
}
void delay()
{
int i,j;
for(i=0;i<256;i++);
for(j=0;j<256;j++);
}



Circuit diagram:

hvjcv.jpg
 
Last edited by a moderator:

That is extremely tedious. A far better solution is to copy your incoming characters to a buffer then 'strcmp' them with the commands.

You can then add more commands, for example "BULBOFF" easily.

Brian.
 

Hi,
Store the characters from the Serial buffer into an array or using a pointer. And then use the strcmp commands or strncmp (if you intend to compare particular length of character)
Based on the comparison result go for toggling the I/O pins.
 

Hi,
I have attached the code for your concept. Check this. I haven't compiled the code. If you find any errors, post it.
 

Attachments

  • 8051-lcd.txt
    1 KB · Views: 46

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top