View previous topic :: View next topic |
Author |
Message |
diehardfans
Joined: 23 Aug 2007 Posts: 3
|
beginner help |
Posted: Thu Aug 30, 2007 8:05 pm |
|
|
i try to simulate the code below using A1 as input if the input of A1 is high the pin A2 will blink once if A1 input is low A3 will blink once
here is the code:
#include <16F84a.h>
#use delay (clock=4000000)
#fuses HS,NOWDT,NOPROTECT
#use rs232(baud=9600, xmit=PIN_A3, rcv=PIN_A2)
void main()
{
while(1)
{
if ((input(PIN_A1)==1)
{output_high(PIN_A2);
delay_ms(50);
output_low(PIN_A2);
delay_ms(50);
}
else
{
output_high(PIN_A3);
delay_ms(50);
output_low(PIN_A3);
delay_ms(50);
}
}
}
i try to simulate using ISIS lite, but the only blink A3 no matter what input i insert...any idea what's happening ?
i insert the 16f84a, then i insert a logical input (0 or 1), then i run but the A2 condition never met ..why ?
[img]http://www.uploadimages.com/manage/MjM3NjQuMjU4MzI=
[/img]
[img]http://www.uploadimages.com/myalbum/23764[/img] |
|
|
Ken Johnson
Joined: 23 Mar 2006 Posts: 197 Location: Lewisburg, WV
|
|
Posted: Fri Aug 31, 2007 6:21 am |
|
|
maybe because pin_a2 is taken by the #use rs232?
Ken |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Fri Aug 31, 2007 7:19 am |
|
|
Ken Johnson wrote: | maybe because pin_a2 is taken by the #use rs232?
Ken |
Since the commands for A2 follow the #use rs232 statement they should take control of the pin.
Diehardfans, you should learn touse the "code" button when posting code to this BBS to make reading your code easier.
I would just use if ((input(PIN_A1)) instead of if ((input(PIN_A1)==1).
I haven't used a simulator in many years, so I think it is a simulator problem ;-) I don't see anything wrong with your code. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
umka
Joined: 28 Aug 2007 Posts: 99 Location: New Zealand
|
|
Posted: Fri Aug 31, 2007 4:10 pm |
|
|
i ran this on my 16f84a and it worked. you were missing a ) after the if statment coz you had 3 ( and only 2)
i tried something else because it was behaving strangly, like work fine but then stick on one for a little bit then work fine agin but it didnt help.
Code: | #include <16F84a.h>
#use delay (clock=4000000)
#fuses HS,NOWDT,NOPROTECT
void main()
{
while(1)
{
if ((input(PIN_A1)==1))
{
output_high(PIN_A2);
delay_ms(50);
output_low(PIN_A2);
delay_ms(50);
}
else if ((input(PIN_A1)==0))
{
output_high(PIN_A3);
delay_ms(50);
output_low(PIN_A3);
delay_ms(50);
}
}
} |
|
|
|
diehardfans
Joined: 23 Aug 2007 Posts: 3
|
|
Posted: Sun Sep 02, 2007 8:32 pm |
|
|
thanks for the viewing and the kindness of ur guys....
i will try again....
Keep it up... |
|
|
|