Menu

Pull-ups not working PIC12F1501

2024-12-27
2024-12-29
  • Roger Jönsson

    Roger Jönsson - 2024-12-27

    Solved. (see message below)

    Is pull-up not supported for PIC12F105 in GC-basic?
    Or am I doing it wrong?
    (I use pickit2plus to write the hex to the chip. The program runs as it should, but there are no pull-ups)

    #chip 12F1501,16
    DIR PORTA.2 in
    DIR PORTA.4 in
    DIR PORTA.5 out
    Set RAPU = 0 'enabling Port A pullups in general.
    Set WPUA2 = 1 ' Weak pullup resistor)
    Set WPUA4 = 1 ' Weak pullup resistor)
    

    (Some examples I've seen does not use the RAPU line and other does not use SET at all, I've tried all kinds of combinations with the same, no pull-ups result)

     

    Last edit: Roger Jönsson 2024-12-28
  • Anobium

    Anobium - 2024-12-28

    Roger - here are some pointers.

    Always add #option explicit. This would shown you that RAPU is not a valid register. The compiler would have told you that the variable/register does not exist.

    From this you should go to the next pointer.

    #chip 12F1501,16
    #option Explicit
    
    DIR PORTA.2 in
    DIR PORTA.4 in
    DIR PORTA.5 out
    Set RAPU = 0 'enabling Port A pullups in general.
    Set WPUA2 = 1 ' Weak pullup resistor)
    Set WPUA4 = 1 ' Weak pullup resistor)
    

    Open PICINFO. Search the REGISTERs and BITs. Does RAPU exist ? No. So, this proves that.

    Next, in PICINFO open the datasheet. This will take you to a datasheet where you have to select the correct datasheet ( Microchip madness not ours ). Search for weak. BiT7 of OPTION_REG.

    Back to PICINFO. Look up BiT7 of OPTION_REG. It i called NOT_WPUEN. Change the code.
    Check WPUA2 exists - it does.

    Compiles OK.

    #chip 12F1501,16
    #option Explicit
    
    DIR PORTA.2 in
    DIR PORTA.4 in
    DIR PORTA.5 out
    Set NOT_WPUEN = 0 'enabling Port A pullups in general.
    Set WPUA2 = 1 ' Weak pullup resistor)
    Set WPUA4 = 1 ' Weak pullup resistor)
    

    I may do a video on this. As the moment I saw this post I knew the diagnostic route to take - the route described above. :-)


    SET is not required. The assignments work with or without. I do not use SET as a general rule.

    The use of the SET command in GCBASIC is not strictly mandated. The SET command simplifies configuring various settings and parameters for the microcontroller, making your code more readable and easier to write. The lax

    For example, you might use SET to configure I/O pins, communication protocols, or other hardware features. Here's a typical use case:

    SET porta.3 ON
    
    Dim baudrate as Word
    SET baudrate = 9600
    

    While you can often achieve the same results using lower-level commands or direct manipulation of registers, SET provides a higher-level abstraction that can save time and reduce the risk of errors. It helps streamline your code and makes it more accessible, especially for those new to programming microcontrollers.

    Is it lax to not use SET ?

    Not necessarily. In GCBASIC, using the SET command is a matter of convenience and clarity rather than a strict requirement. The SET command is designed to make your code more readable and easier to manage, particularly for tasks like configuring I/O pins, setting up communication protocols, and other hardware-related settings.

    However, if you prefer to use lower-level commands or direct register manipulation to achieve the same results, that's perfectly valid. It all depends on your comfort level and the specific requirements of your project. The SET command is there to simplify things, but opting for a different method doesn't imply laxness—it's just a different approach.

    BBCBASIC ( circa 1980 ) introduced the concept of optionally using SET and I am a child of the Computer Literacy Project. This was an ambitious project aimed to educate the British public about the emerging world of computing. The project was a response to the growing importance of microelectronics and the need for computer literacy in both industry and everyday life.

    The important thing is that your code is functional, maintainable, and meets the needs of your project.

     
    • Roger Jönsson

      Roger Jönsson - 2024-12-28

      The BBC B computer was my favourite in the early 80s (odd choice for a Swede, but I'm odd so...).
      To me it was just confusing with the SET-thingy, not making any difference here. To me SET is pointless (unless required).
      You wrote that SET is not required. Never required? -Did I get that right? Then why would I use SET to configure I/O pins etc. I just don't get it. How is it more readable? How does SET 'baudrate = 9600' , simplify things or makes things clearer compared to just 'baudrate = 9600 '?

      In the datasheet it says WPUEN with a line on top. Does that mean the when I find a command with a line on top (in the PIC data sheet) I can always use that name like; NOT_XXXXX (in this case: NOT_WPUEN)?

      "Open PICINFO" -Where do I find PICINFO?

       
      • Anobium

        Anobium - 2024-12-28

        The BBC B computer was my favourite in the early 80s (odd choice for a Swede, but I'm odd so...)

        I have a few in the lab. All used at schools to show them Technology. "From little Acorns do grow" is my session. I show them that inside a BBC microcomputer from 1983 there is an ARM processor. And, that ARM processors are everywhere today. Mostly focused on gaming but it is real fun.

        To me it was just confusing with the SET-thingy, not making any difference here. To me SET is pointless (unless required).

        There is no case where SET is mandated in GCBASIC. The compiler removes a leading 'SET' if line contains '='.

        The cases I gave where SET works. Just to show the use case. SET could be easier to read for a novice to read code. As I wrote - I do not use SET.


        Re NOT_WPUEN

        As you stated the line on top. Could mean NOT Register.bit if the information we are provided by Microchip.

        The following section from the chip specific.INC file.

        ;----- OPTION_REG Bits -----------------------------------------------------
        PSA              EQU  H'0003'
        TMR0SE           EQU  H'0004'
        TMR0CS           EQU  H'0005'
        INTEDG           EQU  H'0006'
        NOT_WPUEN        EQU  H'0007'
        
        PS0              EQU  H'0000'
        PS1              EQU  H'0001'
        PS2              EQU  H'0002'
        T0SE             EQU  H'0004'
        T0CS             EQU  H'0005'
        

        In this case NOT_WPUENis OPTION_REG.7.

        The easy way to find out is to look in PICINFO - it was one of main reasons the software was written.

        I always check in PICINFO and use #option explicit.


        "Open PICINFO" -Where do I find PICINFO?

        When using GCCODE IDE, press function key <f4> and select or type PICINFO. ( One of benefits of GCCODE is that we add all the new tools in the <f4> menu.</f4></f4>

        When using the legacy SynWrite IDE or any other code editor then you will find it your installation directory \GSTUDIO\PICINFO\PICINFO.EXE

         
        • Roger Jönsson

          Roger Jönsson - 2024-12-29

          Thank you for confirming and explaining. I didn't find PICINFO when scrolling through the list earlier and thought that I was looking in the wrong place. It appeared now after using the search field.
          I just moved from an old Win XP installation (which I haven't used for some time) to windows 11 and 1.76.2, which I run on a Macbook. So far it has been a very pleasant experience. The programming is faster than I remembered using Microchip Pickit 2 and 3 software to "burn" the hexfiles.

           
          • Anobium

            Anobium - 2024-12-29

            Great feedback! Thank you

             

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.