Menu

If Statements

2019-03-15
2019-05-29
  • Dermot Donnelly

    Dermot Donnelly - 2019-03-15

    Hi,

    I’m new to GCB and would appreciate a little help with some code please. The code is attached in a very simplified form. It is at end of this query as well.

    GCB version is SynWrite 6.22.2290 and Compiler Version (YYYY-MM-DD): 0.98.04 2018-10-20 (Windows 32 bit) Pickit OS firmware version 2.32.00. My OS is win7(64bit).

    I’ve hexed and flashed it to the 16F684 but it doesn’t work on my breadboard even though I’m not getting any error messages.

    I basically want different relays to be activated when pins PortA.1, PortA2 and PortC.0 are brought HIGH or LOW by 3 DIP switches on my breadboard.

    What happens is that the 3 if statements are ignored and the program operates from State000: no matter what position the DIP switches are in.

    Should these 3 pins be designated INPUTS or OUTPUTS. If they are inputs I presume they can’t be left floating and will need a 10k pulldown resistor?

    Thanks for any help.
    Regards
    Dermot

    '#chip 16F684,8
    '
    'if PortA.1=0 and PortA.2=0 and PortC.0=0 then goto State000
    'if PortA.1=0 and PortA.2=0 and PortC.0=1 then goto State001
    'if PortA.1=0 and PortA.2=1 and PortC.0=0 then goto State010
    '
    'State000:
    'PulseOut PortC.2, 5000 ms
    'pause 5000
    'goto State000
    '
    'State001:
    'Pulseout PortC.1, 5000 ms
    'pause 5000
    'goto State001
    '
    'State010:
    'PulseOut PortC.3, 5000 ms
    'pause 5000
    'goto State010

     
  • Anobium

    Anobium - 2019-03-16

    Welcome.

    The program is doing what it is intended to do. I have loaded into a simulator.

    The program is a one shot program, where the state of of the input ports is tested and the program jumps to one of the state00x loops. And, never exits that loop.

    Re the ports:
    Ports are being set as expected.

    ;Automatic pin direction setting
      banksel TRISC
      bcf TRISC,3
      bcf TRISC,2
      bcf TRISC,1
    

    If you wanted to.. you could add the following, but, this is not really needed but I provide to ensure you understand the syntax.

     DIR porta.1 in
    DIR porta.2 in
    DIR portc.0 in
    DIR portc.1 out
    DIR portc.2 out
    DIR portc.3 out
    

    So, the code is doing what is expected but you may need 10k pull-ups on the those input ports.

     
  • Dermot Donnelly

    Dermot Donnelly - 2019-03-16

    Thanks Anobium for the reply. You were right about the pulling the pins high (Ports A1,A2 and C.0). It's working now.

    I pulled the three pins high with 10k resistors as you suggested, it worked. I then pulled them low with the resistors and physically connected the appropriate pins to the V+ and it worked. So having floating input pins is the problem.

    I then decided to make the pins output pins in the code and again connected the appropriate pins to V+ and it also worked saving me the use of 3 resistors!

    By the way, what simulator do you use for checking the GCB code?

    Thanks again for going to so much trouble, especially at 6.52 am on a Saturday morning!
    Regards
    Dermot

     
    • Anobium

      Anobium - 2019-03-16

      Pleasure - the dog woke me up! at 5:55am

      I was using Real Simulator for you code.

      :-)

       
      • Dermot Donnelly

        Dermot Donnelly - 2019-03-16

        Thanks for that.

        "That best portion of a good man's life; His little, nameless,
        unremembered acts of kindness"

        William Wordsworth.

        On 16/03/2019 17:04, Anobium wrote:

        Pleasure - the dog woke me up! at 5:55am

        I was using Real Simulator for you code.

        :-)


        If Statements


        Sent from sourceforge.net because you indicated interest in https://sourceforge.net/p/gcbasic/discussion/579125/

        To unsubscribe from further messages, please visit https://sourceforge.net/auth/subscriptions/

         
        • Anobium

          Anobium - 2019-03-17

          Thank you.

          :-)

           
    • Dermot Donnelly

      Dermot Donnelly - 2019-05-29

      I just got back to completing my project and thought I should give a word of warning and a correction to what I wrote about making output pins high and connecting them to V+ and saving myself the use of three resistors. This doesn't work in the long term. I discoverd that although it worked fine the PIC began to get very hot and I'm sure would become damaged after a while.

       
      • Anobium

        Anobium - 2019-05-29

        Yes, good advice. I always look at the MCU and then use suitable resistors.

         
  • jackjames

    jackjames - 2019-05-29

    If we speak of pullup resistors, given that the micro absorb very little input current, it is enough to put them of adequate value, therefore generally also 10K.
    When the transistor output of the PIC door closes towards ground, therefore it goes to low value, the current flowing inside it is low and therefore the power (and obviously the heat) dissipated is low and not dangerous for the health of the micro.

     

Log in to post a comment.