sakaidanny
Newbie level 1
thx for ur great help!
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
#include <REGX51.H>
#include<string.h>
sbit SW = P1^7;
void SerTx(unsigned char);
void SerTx_Str(unsigned char[]);
void Delay(unsigned int itime);
void serial_int();
unsigned int delay;
unsigned char mybyte;
void main()
{
delay = 100;
SW = 1; //Making this as Input Pin
TMOD = 0x20; //Timer-1, 8-Bit Auto Reload Mode
TH1 = 0xFD; //9600 Baud Rate When Crystal Used is 11.0592MHZ
SCON = 0x50;
RI = 0;
TI = 0;
TR1 = 1; //Start Timer
while(1)
{
if(SW == 0)
{ SerTx_Str("Anti-Clockwise Moving");
SerTx(13);
while(RI == 0)
{
P2 = 0x66;
Delay(delay);
P2 = 0xCC;
Delay(delay);
P2 = 0x99;
Delay(delay);
P2 = 0x33;
Delay(delay);
}
mybyte = SBUF;
SerTx(mybyte);
RI = 0;
SerTx(13);
switch(mybyte)
{
case '1': delay = 100;
break;
case '2': delay = 10;
break;
case '3': delay = 1;
break;
default: delay =10 ;
break;
}
RI = 0;
}
else if(SW == 1)
{
SerTx_Str("Clockwise Moving");
SerTx(13);
while(RI == 0)
{
P2 = 0x66;
Delay(delay);
P2 = 0x33;
Delay(delay);
P2 = 0x99;
Delay(delay);
P2 = 0xCC;
Delay(delay);
}
mybyte = SBUF;
SerTx(mybyte);
RI = 0;
SerTx(13);
switch(mybyte)
{
case '1': delay = 100;
break;
case '2': delay = 10;
break;
case '3': delay = 1;
break;
default: delay =10 ;
break;
}
}
}
}
void Delay(unsigned int itime)
{
unsigned int j,i;
for(i=0;i<1275;i++)
for(j=0;j<itime;j++);
}
void SerTx(unsigned char x)
{
SBUF = x;
while(TI==0);
TI = 0;
}
void SerTx_Str(unsigned char str[])
{
unsigned int len,i;
len = strlen(str);
for(i=0;i<len;i++)
{
SerTx(str[i]);
}
}