Menu

beginner problem

Help
salvo
2011-11-07
2013-05-30
  • salvo

    salvo - 2011-11-07

    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

     
  • Vaclav

    Vaclav - 2011-11-07

    try something like this

    #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
    
     
  • Nobody/Anonymous

    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

    .

     
  • Nobody/Anonymous

    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

     
  • salvo

    salvo - 2011-11-08

    many thanks guys
    i'm gona try

    ciao

     
  • salvo

    salvo - 2011-11-08

    sorry to bother you but it doesn't work
    any library to load befor? or some basical setting to do?

    many thanks

     
  • Nobody/Anonymous

    Can you post entire code and description of circuit?

     
  • salvo

    salvo - 2011-11-08

    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.

     
  • Nobody/Anonymous

    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?

     
  • salvo

    salvo - 2011-11-08

    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

     
  • Nobody/Anonymous

    You also need 2 capacitors, around 20 - 33pf from each pin of the crystal to ground to make the oscillator start and run reliably.

     
  • salvo

    salvo - 2011-11-09

    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

     
  • salvo

    salvo - 2011-11-09

    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

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.