hi to all
i'm programming a pic 16f84a
it was easy to set the port out wit the gcbasic an do some led flashing (i'm using it to drive the navigation light on my rc airplane model)
now i was wondering how to read a switch on input port and execute this problem
i tried many example but with no luck
any body can help me?
resume:
my problem is to read a state on a input port (previously declared) and run a program
thank you for your help
ciao
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Newbie should also be aware that there should be a resistor (value not critical, say 10K) to pull the pin voltage to a default state when the switch isn't closed. Normally, the resistor would pull up to the chip supply and the switch would pull the pin voltage down to ground when closed. There should also be a current limiting resistor between the output pin and the LED, say 1K. In this hardware configuration, the code would more properly and completely look like this:
#define Switch PORTB.0
#define Led PORTB.1
Dir Switch In
Dir Led Out
Set Led Off 'Start out with the Led off
Start:
If Switch = 1 Then
Set Led Off
End If
Goto start
.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
#define Switch PORTB.0
#define Led PORTB.1
Dir Switch In
Dir Led Out Start:
If Switch = 1 Then
Set Led On
End If
Goto start
circuit:
connect an xt 4Mhz between the osc in/osc out
a led connected anode to the portB1 and catode with a 470 ohm resistor to ground
on portB0 a pull up resistor of 1k and a switch to ground
i'm trying this program also with real pic simulator
everithing is set properly because i can run some other programs that does not have any switches or command to run.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Can you also post a description of the manner in which it "doesn't work"? What do you see when you reset the PIC? What happens when you then close the switch?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
on real pic simulator i give to the portb0 5V (1) and when i push the button
i can see the changing on oscilloscope portb0 channel,
but no change appear to portb1 (also monitored on oscilloscope in another channel)
after compiling gcbasic says that insys was not defined
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
i think the problem depend from some library not well set
gcbasi compile the file but does not recognize the status of the inpot portb0
wich library i need to load to run this simply programs?
thanks a lot for your help
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
hi to all
i'm programming a pic 16f84a
it was easy to set the port out wit the gcbasic an do some led flashing (i'm using it to drive the navigation light on my rc airplane model)
now i was wondering how to read a switch on input port and execute this problem
i tried many example but with no luck
any body can help me?
resume:
my problem is to read a state on a input port (previously declared) and run a program
thank you for your help
ciao
try something like this
Newbie should also be aware that there should be a resistor (value not critical, say 10K) to pull the pin voltage to a default state when the switch isn't closed. Normally, the resistor would pull up to the chip supply and the switch would pull the pin voltage down to ground when closed. There should also be a current limiting resistor between the output pin and the LED, say 1K. In this hardware configuration, the code would more properly and completely look like this:
#define Switch PORTB.0
#define Led PORTB.1
Dir Switch In
Dir Led Out
Set Led Off 'Start out with the Led off
Start:
If Switch = 1 Then
Set Led Off
End If
Goto start
.
Ooops…. Added reply before done
#define Switch PORTB.0
#define Led PORTB.1
Dir Switch In
Dir Led Out
Set Led Off 'Start out with the Led off
Start:
If Switch = 1 Then 'switch open, pin high
Set Led Off
Else 'switch closed, pin low
Set LED On
End If
Goto start
many thanks guys
i'm gona try
ciao
sorry to bother you but it doesn't work
any library to load befor? or some basical setting to do?
many thanks
Can you post entire code and description of circuit?
here i'm
;Chip Settings
#chip 16F84A,4
#define Switch PORTB.0
#define Led PORTB.1
Dir Switch In
Dir Led Out Start:
If Switch = 1 Then
Set Led On
End If
Goto start
circuit:
connect an xt 4Mhz between the osc in/osc out
a led connected anode to the portB1 and catode with a 470 ohm resistor to ground
on portB0 a pull up resistor of 1k and a switch to ground
i'm trying this program also with real pic simulator
everithing is set properly because i can run some other programs that does not have any switches or command to run.
Can you also post a description of the manner in which it "doesn't work"? What do you see when you reset the PIC? What happens when you then close the switch?
abosultely nthing
on real pic simulator i give to the portb0 5V (1) and when i push the button
i can see the changing on oscilloscope portb0 channel,
but no change appear to portb1 (also monitored on oscilloscope in another channel)
after compiling gcbasic says that insys was not defined
You also need 2 capacitors, around 20 - 33pf from each pin of the crystal to ground to make the oscillator start and run reliably.
sorry they are connected
i think the problem depend from some library not well set
gcbasi compile the file but does not recognize the status of the inpot portb0
wich library i need to load to run this simply programs?
thanks a lot for your help
it works now…
i just restart my computer and write again the software by copy and paste from this page
any way thank you to every body
ciao