BALKRISHNA TULSYAN
Junior Member level 3
- Joined
- Apr 19, 2013
- Messages
- 29
- Helped
- 2
- Reputation
- 4
- Reaction score
- 2
- Trophy points
- 1,283
- Location
- BANGALORE
- Activity points
- 1,522
hello experts...
I have written one simple program to control LED using PC but LED is not getting switched ON. May be there is some problem with code which in tern may be some ASCII related problem. PLEASE SOLVE
#include <REG51F.H>
#define LED P1 //4 LED'S are connected to port p1.0 ,p1.1, p1.2, p1.3
void serial_init();
void delay(unsigned int);
unsigned char data_key;
void int_ser(void) interrupt 4
{
if(RI)
{
RI =0;
data_key = SBUF;
delay(100);
switch(data_key)
{
case '1':
{
LED = 0x01;
delay(1000);
break;
}
case '2':
{
LED = 0x02;
delay(1000);
break;
}
case '3':
{
LED = 0x03;
delay(1000);
break;
}
default:
{
LED = 0xFF;
delay(1000);
LED = 0x0A;
delay(1000);
break;
}
}
}
if(TI)
TI =0;
}
void main()
{
LED = 0x00;
serial_init();
delay(100);
while(1)
{
}
}
void serial_init()
{
SCON = 0x50;
TMOD = 0x20;
TH1=0xFD;
TL1=0xFD;
TR1=1;
EA=1;
ES=1;
TI=1;
RI=0;
}
void delay(unsigned int X)
{
int i=0,j=100;
for(i=0;i<=X;i++)
{
for(j=100;j>=0;j--);
}
}
I have written one simple program to control LED using PC but LED is not getting switched ON. May be there is some problem with code which in tern may be some ASCII related problem. PLEASE SOLVE
#include <REG51F.H>
#define LED P1 //4 LED'S are connected to port p1.0 ,p1.1, p1.2, p1.3
void serial_init();
void delay(unsigned int);
unsigned char data_key;
void int_ser(void) interrupt 4
{
if(RI)
{
RI =0;
data_key = SBUF;
delay(100);
switch(data_key)
{
case '1':
{
LED = 0x01;
delay(1000);
break;
}
case '2':
{
LED = 0x02;
delay(1000);
break;
}
case '3':
{
LED = 0x03;
delay(1000);
break;
}
default:
{
LED = 0xFF;
delay(1000);
LED = 0x0A;
delay(1000);
break;
}
}
}
if(TI)
TI =0;
}
void main()
{
LED = 0x00;
serial_init();
delay(100);
while(1)
{
}
}
void serial_init()
{
SCON = 0x50;
TMOD = 0x20;
TH1=0xFD;
TL1=0xFD;
TR1=1;
EA=1;
ES=1;
TI=1;
RI=0;
}
void delay(unsigned int X)
{
int i=0,j=100;
for(i=0;i<=X;i++)
{
for(j=100;j>=0;j--);
}
}