Can you repair this.. plz..

Discussion about projects that used PIC Microcontroller, Hardware Interface, Programming Algorithm and etc......

Can you repair this.. plz..

Postby mayai » Fri Oct 16, 2009 8:38 pm

i have a source code, i'm using PICC compiler.. the problem is the code is suppose to work as a remote control.. ok that part is working well.. but i cannot seems to remove the latching function.. when i inserted the data the PIC will kept hold of that current condition even though we did not put any data anymore.. let me get this simple k.. exp: if i put letter 'w' the motor will operate but it will operate even if i release the 'w' key, i want the motor to stop running as soon as i release the key... if u understand plz help me.. thanks in advance..

here's the code:

void main()
{
byte status=0;
char data;
set_tris_b(0x00);
output_b(0);
do{
if(kbhit())
{data=getch();
status=1;}
if(status==1)
output_b(0);
{
if(data=='w')
{OUTPUT_B(0b00001001);}
else if(data=='s')
{OUTPUT_B(0b00000110);}
else if(data=='a')
{output_high(PIN_B0);}
else if(data=='d')
{output_high(PIN_B3);}
else if(data=='e')
{output_high(PIN_B6);}
delay_ms(100);
status=0;

}}
while(1);}
mayai
Greenhorn
 
Posts: 2
Joined: Fri Oct 16, 2009 8:29 pm

Re: Can you repair this.. plz..

Postby robosang » Sun Oct 18, 2009 12:01 am

I thought there are "Forum Rules and Regulations".....

Disappointment!
robosang
Expert
 
Posts: 1239
Joined: Wed Jun 10, 2009 5:37 pm

Re: Can you repair this.. plz..

Postby sich » Sun Oct 18, 2009 2:50 pm

I see that u don't have a default value for ur if-else statement where the program goes when non of the keyboard key is pressed or when other keys are pressed instead of the defined ones. Add an else at the end of ur if-else and define an output for it, for example stop the motor. Another thing is i wonder ur program will enter the while loop forever. Please revise the do-while statement.
~> How to ask QUESTIONS the SMART way in FORUM? <~
User avatar
sich
Moderator
 
Posts: 603
Joined: Tue Apr 21, 2009 2:15 pm


Return to PIC Microcontroller

Who is online

Users browsing this forum: No registered users and 27 guests