uday mehta
Advanced Member level 4
- Joined
- Dec 30, 2011
- Messages
- 104
- Helped
- 6
- Reputation
- 12
- Reaction score
- 6
- Trophy points
- 1,298
- Activity points
- 1,979
in my simulation i am using 12 Mhz. frequency. then it works nicely but when i want to double its speed change the value to 24 Mhz. it shows message "controller receive message while busy".
code is:
when it print "please set your head at middle" it gives busy message. and on hardware LCD shows nothing...
code is:
Code:
#include<reg51.h>
/* function declaration start */
void delay(int);
void initlcd(void);
void w_cmd(int);
void w_data(char);
void Rotate(void);
void op_a(int);
void op_b(int);
/* function declaration stop */
/* pin declaration start */
sbit l = P3^5; // pin declaration for sensors
sbit m = P3^6;
sbit r = P3^7;
sbit rs = P1^2; // pin declaration for lcd
sbit en = P1^1;
sbit sw1 = P1^0; // pin declaration for switch
sbit out = P1^5; // pin declaration for output to another uc
/*function definatio start */
void delay(int c) // function for delay
{
int i,j;
for(i=0;i<c;i++)
for(j=0;j<100;j++);
}
void initlcd(void) // function for initializing the lcd
{
w_cmd(0x38);
delay(50);
w_cmd(0x0c);
delay(50);
w_cmd(0x01);
delay(50);
w_cmd(0x06);
delay(50);
}
void w_cmd(int z) // function for sending command to lcd
{
rs = 0;
P2 = z;
en = 1;
delay(1);
en = 0;
delay(1);
}
void w_data(char y) // function for sending data to lcd
{
rs = 1;
P2 = y;
en = 1;
delay(1);
en = 0;
delay(1);
}
lcd_data(unsigned char *disp) // function for sending string to lcd
{
int x;
for(x=0;disp[x]!=0;x++)
{
w_data(disp[x]);
}
}
void Return(void) // function for returning the cursor at home positon
{
w_cmd(0x01);
delay(2);
w_cmd(0x80);
delay(2);
}
void Return2(void) // function for move cursor at second line
{
w_cmd(0xc0);
delay(2);
}
void Rotate(void) // function for measurement of rotation
{
int a,b;
while(l==0&&r==0); // check the status of left and right sensor
while(l==1)
{
b=0;
while(l==1);
while(l==0);
while(m==0) // start measurement when left sensor sense beam second time
{
delay(1);
b=b+1;
}
while(r==0)
{
delay(1);
b=b+1;
}
op_b(b);
}
while(r==1)
{
a=0;
while(r==1);
while(r==0);
while(m==0) // start measurement when right sensor sense beam second time
{
delay(1);
a=a+1;
}
while(l==0)
{
delay(1);
a=a+1;
}
op_a(a);
}
}
void op_b(int h) // function for calculation the rotation from left to right
{
int f,d4,d5,d6,r2,r4;
f=90000/h; // conveting into degree per second
d4=f/100;
if(d4>=1)
{
out=0;
} // saperating the digits for ASCII conversion
r2=f%100;
d5=r2/10;
r4=r2%10;
d6=r4%10;
d4=d4+48; // converting from decimal to ASCII
d5=d5+48;
d6=d6+48;
Return();
w_data(d4);
w_data(d5);
w_data(d6);
Rotate();
}
void op_a(int g) // function for calculation the rotation from left to right
{
int e,d1,d2,d3,r1,r3;
e=90000/g;
d1=e/100;
if(d1>=1)
{
out=0;
}
r1=e%100;
d2=r1/10;
r3=r1%10;
d3=r3%10;
d1=d1+48;
d2=d2+48;
d3=d3+48;
Return();
w_data(d1);
w_data(d2);
w_data(d3);
Rotate();
}
void main() // start main program
{
P1=0xff; // set the port 1 as input
sw1=1; // set the switch as input
initlcd();
w_cmd(0x80);
delay(1);
lcd_data(" WELL-COME");
delay(1000);
w_cmd(0x01);
delay(1);
while(m==0)
{
lcd_data("please set your");
Return2();
lcd_data("head at middle ");
delay(100);
while(m==1)
{
Return();
lcd_data("start rotation ");
delay(100);
while(1)
{
Rotate();
}
}
}
}
when it print "please set your head at middle" it gives busy message. and on hardware LCD shows nothing...