studysession
- 24th January 2009, 22:10
Hi -
I am new to PICBasic and to the forums. I have PICBasic Pro if that matters, I am unsure. I am having few problems.
I want to control few servos based on if this button is pressed etc... To start figure I would use either buttons or switches (same thing) and light up LED's based on if pressed then do kind of thing. Simple enough but for some reason my LED's blink and not just stay lit and trying to figure out why. Attached is an image of my electronics setup and here is my code. Also I am using a PIC16F84A chip and all the examples in books show an external crystal. If anyone knows how to do this without using the external crystal, that would be nice too.
Please tell me what I am doing wrong and how to do this better. Many thanks!
main
if portb.0 = 1 then gosub pressed0
if portb.0 = 0 then gosub npressed0
if portb.1 = 1 then gosub pressed1
if portb.1 = 0 then gosub npressed1
if portb.2 = 1 then gosub pressed2
if portb.2 = 0 then gosub npressed2
if portb.3 = 1 then gosub pressed3
if portb.3 = 0 then gosub npressed3
goto main
pressed0:
high portb.4
pause 200
return
npressed0:
low portb.4
pause 200
return
pressed1:
high portb.5
pause 200
return
npressed1:
low portb.5
pause 200
return
pressed2:
high portb.6
pause 200
return
npressed2:
low portb.6
pause 200
return
pressed3:
high portb.7
pause 200
return
npressed3:
low portb.7
pause 200
return
I am new to PICBasic and to the forums. I have PICBasic Pro if that matters, I am unsure. I am having few problems.
I want to control few servos based on if this button is pressed etc... To start figure I would use either buttons or switches (same thing) and light up LED's based on if pressed then do kind of thing. Simple enough but for some reason my LED's blink and not just stay lit and trying to figure out why. Attached is an image of my electronics setup and here is my code. Also I am using a PIC16F84A chip and all the examples in books show an external crystal. If anyone knows how to do this without using the external crystal, that would be nice too.
Please tell me what I am doing wrong and how to do this better. Many thanks!
main
if portb.0 = 1 then gosub pressed0
if portb.0 = 0 then gosub npressed0
if portb.1 = 1 then gosub pressed1
if portb.1 = 0 then gosub npressed1
if portb.2 = 1 then gosub pressed2
if portb.2 = 0 then gosub npressed2
if portb.3 = 1 then gosub pressed3
if portb.3 = 0 then gosub npressed3
goto main
pressed0:
high portb.4
pause 200
return
npressed0:
low portb.4
pause 200
return
pressed1:
high portb.5
pause 200
return
npressed1:
low portb.5
pause 200
return
pressed2:
high portb.6
pause 200
return
npressed2:
low portb.6
pause 200
return
pressed3:
high portb.7
pause 200
return
npressed3:
low portb.7
pause 200
return