|
|
View previous topic :: View next topic |
Author |
Message |
luna
Joined: 11 Aug 2010 Posts: 3 Location: MALAYSIA
|
urgent..<<remote control>>... |
Posted: Fri Nov 26, 2010 6:49 am |
|
|
Hi Everyone,
I'm trying to make software UART work that received data from remote control through Zigbee (XBee OEM RF) wireless comm.
In my project, I have one remote control and one slave. …at the slave equipped lamp (at RB0) and motor (RB1). Besides at the slave also consist 2 manual switches to control ON/OFF for the device (lamp and motor)
the problem here:
when I send a command to on lamp, it will blink due to the switch at slave in off mode.
Anyone knows how to solve this problem? Plzz… I really appreciate who can help me..
Here I post my coding.
remote control:
Code: |
#include <18f2455.h>
#fuses HS,NOLVP,NOWDT,NOPROTECT
#use delay(clock=8000000) // 20 MHz crystal on PCB
#use rs232(baud=9600, UART1,ERRORS)
#include <stdlib.h>
#define LED_0 PIN_B4
void main()
{
set_tris_a(0b01111111);
set_tris_b(0b00000000);
while (TRUE)
{
if (input(PIN_A2)==1)
{
output_high(LED_0);
printf("x"); //sends signal x
}
if (input(PIN_A1)==1)
{
output_high(LED_0);
printf("y"); //sends signal x
}
if (input(PIN_A0)==1)
{
output_high(LED_0);
printf("z"); //sends signal z-off
}
}
}
|
program at slave
Code: |
#include <18F4550.h>
#fuses HS,NOLVP,NOWDT,NOPROTECT
#define use_portb_kbd TRUE
#use delay(clock=20000000) // 20 MHz crystal on PCB
#use rs232(baud=9600, UART1,ERRORS) // hardware uart much better; uses RC6/TX and RC7/RX
#include <stdlib.h>
#DEFINE lamp PIN_B0
#DEFINE motor PIN_B1
void manual_switch (void); //define a function
char x;
void main()
{
/*initialize*/
output_low(lamp);
output_low(motor);
delay_ms(100);
while (true)
{
manual_switch ();
if (kbhit())
{
x = getc();
if (x=='x')
{
output_high(lamp);
delay_ms(500);
}
if (x=='y')
{
output_high(motor);
delay_ms(500);
}
if (x=='z')
{
output_low(lamp);
output_low(motor);
delay_ms(500);
}
}
}
}
void manual_switch (void) //define a function
{
/////if button pressed(S1)/////
if(input(pin_a0)==1)
{
output_high(lamp);
delay_ms(500);
}
else if (input(pin_a0)==0)
{
output_low(lamp);
delay_ms(500);
}
/////if button pressed(S2)///////
if(input(pin_a1)==1)
{
output_high(motor);
delay_ms(500);
}
else if (input(pin_a1)==0)
{
output_low(motor);
delay_ms(500);
}
}
plz... help me.. :cry: |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19540
|
|
Posted: Fri Nov 26, 2010 8:51 am |
|
|
This is not really a remote control or programming problem, but a 'logic' problem.
You need to think 'who is master'. Your slave device has two possible control sources. Which one are you going to treat as 'ruling'. Currently, both have equal priority, so that when the master device turns the lamp 'on', the code then looks at the switch, and responds to this to turn it back 'off'.
A number of possible solutions (by no means all....):
Have the switch 'ignored' once a software control is received, until the software and switch are again in agreement.
Alternatively, change the hardware of the switch to be a 'momentary' type. then have the switch operation at the slave, instead of being on/off, become 'toggle' If the light is on, pushing the switch turns it off, and vice-versa. The master can switch the light on or off when required, and at any time, pushing the switch reverses the current setting.
Have a 'timer'. When the master operates the light, the switches are ignored for (say) 30 seconds. Have the master automatically send a command every 25 seconds. Then the switch only becomes useable if the master is _not_ talking to the slave.
Personally, I'd probably go for the 'toggle' option. Easy to implement, and effective.
Best Wishes |
|
|
Kerron
Joined: 16 Nov 2010 Posts: 5
|
|
Posted: Tue Dec 28, 2010 8:58 pm |
|
|
What are you trying to accomplish exactly? I have code that might help |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|