reading I/O state of pic12f675...


Closed Thread
Results 1 to 22 of 22
  1. #1
    Join Date
    Jun 2008
    Location
    Varese , Italy
    Posts
    326

    Default reading I/O state of pic12f675...

    Hi to all in this forum,
    I am using pic12f675 and the PICKIT_3 programmer.
    I would like to use all the six available pins as I/O and so I wrote this small program:

    @ __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _CP_OFF
    OSCCAL=64
    include "modedefs.bas"

    ' Set Debug pin port ________________________________________
    DEFINE DEBUG_REG PORTA
    ' Set Debug pin bit _________________________________________
    DEFINE DEBUG_BIT 0
    ' Set Debug baud rate _________________________________________
    DEFINE DEBUG_BAUD 9600
    ' Set Debug mode: 0 = true, 1 = inverted ______________________
    DEFINE DEBUG_MODE 1

    PAUSE 500 : DEBUG 13,10
    PU VAR GPIO.2

    MAIN: ' **************************************************

    IF PU=0 THEN
    DEBUG "low" ,13,10
    ENDIF

    IF PU=1 THEN
    DEBUG "high",13,10
    ENDIF

    GOTO MAIN ' **************************************************

    Debug works well but there is no way to read the GPIO.2 status since the terminal reports just LOW state.
    Any assistance please ?
    Thanks in advance .
    Regards,
    Ambrogio

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,517


    Did you find this post helpful? Yes | No

    Default Re: reading I/O state of pic12f675...

    Yes, read section 3.1 of the datasheet. They tell you exactly what you're seeing and what you need to do.

    /Henrik.

  3. #3
    Join Date
    May 2013
    Location
    australia
    Posts
    2,383


    Did you find this post helpful? Yes | No

    Default Re: reading I/O state of pic12f675...

    The most surprising thing is that it compiles and produces an output



    ' Set Debug pin port ________________________________________
    DEFINE DEBUG_REG PORTA
    since that chip has no PORTA

    debug must be a bit different
    Warning I'm not a teacher

  4. #4
    Join Date
    Jun 2008
    Location
    Varese , Italy
    Posts
    326


    Did you find this post helpful? Yes | No

    Default Re: reading I/O state of pic12f675...

    Thanks Richard,
    Could you please indicate tio me the correct syntax for the DEBUG ?
    ( I do not understand how to write the debug in case GPIO is involved ).
    Thanks for helping .
    regards,
    Ambrogio

  5. #5
    Join Date
    Jun 2008
    Location
    Varese , Italy
    Posts
    326


    Did you find this post helpful? Yes | No

    Default Re: reading I/O state of pic12f675...

    Thanks Henrik,
    I read the data sheet... but , to be sure : have you some sample to help in setting the register please ?
    I really need three input and three output pins.
    Thanks again
    regards,
    Ambrogio

  6. #6
    Join Date
    May 2013
    Location
    australia
    Posts
    2,383


    Did you find this post helpful? Yes | No

    Default Re: reading I/O state of pic12f675...

    Could you please indicate tio me the correct syntax for the DEBUG ?
    ( I do not understand how to write the debug in case GPIO is involved ).

    more properly would be

    DEFINE DEBUG_REG GPIO

    but it seems not to matter in this instance ,would also be wise to set the pin as digital too I think
    Warning I'm not a teacher

  7. #7
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,517


    Did you find this post helpful? Yes | No

    Default Re: reading I/O state of pic12f675...

    I read the data sheet... but , to be sure : have you some sample to help in setting the register please ?
    The datasheet says: The ANSEL (9Fh) and CMCON (19h) registers (9Fh) must be initialized to configure an analog channel as a digital input.
    So lets start with ANSEL (page 44 in the datasheet)where the lower four bits determines if AN0-AN3 should be analog (which they are by default) or digital. These bits needs to zero for the pins to be digital and since you're not using the ADC the state of the other bits doesn't matter, therefor ANSEL = 0 will do just fine.

    Next. CMCON, figure 6-2 (page 37) in the datasheet shows the various configurations, you don't want to use the comparator so it should be off, therefor CMCON = 7

    Finally you say that you need three inputs and three outputs but not which pins should be what so I can't tell you more than that you need to set TRISIO up with a '1' for each input and a '0' for each output. Remember that the MCLR-pin (GP3) can not be configured as an output.

    Code:
    ANSEL = 0
    CMCON = 7
    TRISIO = %00111000 ' GP0-GP2 outputs, GP3-GP5 inputs.
    /Henrik.
    Last edited by HenrikOlsson; - 9th May 2017 at 11:10.

  8. #8
    Join Date
    Jun 2008
    Location
    Varese , Italy
    Posts
    326


    Did you find this post helpful? Yes | No

    Default Re: reading I/O state of pic12f675...

    Thanks,
    I corrected the define debug as indicated and it OK too.

    I do not understand the data sheet as far as the GPIO setting is concerned:
    bit 5-0: GPIO<5:0>: General Purpose I/O pin.
    1 = Port pin is >VIH
    0 = Port pin is <VIL
    I have to read both states of the pin.
    Could you please clarify ?
    Thanks
    regards,
    Ambrogio

  9. #9
    Join Date
    Jun 2008
    Location
    Varese , Italy
    Posts
    326


    Did you find this post helpful? Yes | No

    Default Re: reading I/O state of pic12f675...

    thanks Henrik,
    I received your msg 7 just now. Now it is very clear to me ,.

    In my previous msg I refer to register 05h.
    rgds,
    Ambro

  10. #10
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,517


    Did you find this post helpful? Yes | No

    Default Re: reading I/O state of pic12f675...

    I wouldn't call the GPIO registers a "setting" (though it's really no different than any other register). It is the port register which is connected to the actual I/O pins.

    Write to GPIO and the bits will appear on the port pins configured as outputs. Read from GPIO and you'll get the state of the register. The state of each individual bit will properly reflect the state logic state of the actual pin provided that the pin IS set to digital, it IS set to input and the voltage is either less than VIL (for a logic zero) or more than VIH (for a logic one).

    In other words, if the voltage on GPIO.0 is less than VIL myVAR = GPIO.0 will be 0 and if the voltage is higher than VIH myVAR = GPIO.0 will be 1. If the voltage is somewhere in between VIL and VIH the result is unspecified.

    Your original problem was that the pin was not set to digital and as the datasheet says: I/O pins configured as analog inputs always read ‘0’.

    /Henrik.

  11. #11
    Join Date
    Jun 2008
    Location
    Varese , Italy
    Posts
    326


    Did you find this post helpful? Yes | No

    Default Re: reading I/O state of pic12f675...

    Hi,
    it is working for the first time. If I do reprogram the chip then I have the following message:


    017-05-09 12:13:19 +0200 - Programming...
    Target has invalid calibration data (0x00).

    Device Erased...

    Programming...

    The following memory area(s) will be programmed:
    program memory: start address = 0x0, end address = 0x45
    configuration memory
    program memory
    Address: 0 Expected Value: 2828 Received Value: 0
    Failed to program device
    2017-05-09 12:13:23 +0200 - Programming failed
    Pass Count: 49

    It is the first time I face with a so small PIC devices... Is it critical ?
    thanks
    Ambro

  12. #12
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,517


    Did you find this post helpful? Yes | No

    Default Re: reading I/O state of pic12f675...

    Not sure but I believe it might have something to do with the calibration value for the internal oscillator. I see you're manually setting OSCCAL to 64 at the top of the program but I'm wondering if what the error message is trying to say is that you've erased the factory calibration value originally stored in the PIC. Does the program work at all?

    If you want PBP to use the default calibration value add DEFINE OSCCAL_1K 1 but it will obviously not work on a device where you've erased the calibration value.

  13. #13
    Join Date
    Jun 2008
    Location
    Varese , Italy
    Posts
    326


    Did you find this post helpful? Yes | No

    Default Re: reading I/O state of pic12f675...

    yes, the program that I loaded before still runs.
    No other code can be loaded .
    I changed the micro : all OK at first programming. The same message comes out at the second programming.
    regards,
    Thanks
    Ambro

  14. #14
    Join Date
    Jun 2008
    Location
    Varese , Italy
    Posts
    326


    Did you find this post helpful? Yes | No

    Default Re: reading I/O state of pic12f675...

    Hi to all,
    I still have this message from PICKIT_3:

    Target Detected

    Programming...
    The following memory regions failed to program correctly:
    Program Memory
    Address: 00000000 Expected Value: 00002842 Received Value: 00000000
    Programming failed

    Any advice please ?
    Thanks in advance
    Ambrogio

  15. #15
    Join Date
    Jun 2008
    Location
    Varese , Italy
    Posts
    326


    Did you find this post helpful? Yes | No

    Default Re: reading I/O state of pic12f675...

    I forgot to tell that the PICKIT_3 works well when programming the pic18F252.

    >> it seems to me that the PICKIT_ 3 is loading the BOOTloader when the device is changed from PIC18 to PIC12F675...
    How to inhibit it ?
    Thanks
    Ambrogio

  16. #16
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,517


    Did you find this post helpful? Yes | No

    Default Re: reading I/O state of pic12f675...

    it seems to me that the PICKIT_ 3 is loading the BOOTloader when the device is changed from PIC18 to PIC12F675...
    How to inhibit it ?
    You can't. Different device families needs different things from the PICKit3 and it doesn't have enough memory on board to remember it all. So when you switch families (or switch software from which you "run" the PICKit3) it needs to have a different fimrware image loaded.

    There's an issue with using the internal oscillator AND GP3 as IO at the same time. The issue is that as soon as power is applied the internal oscillator starts and sets the IO pins up which now prevents the PK3 from "accessing" it in order to enter programming mode. IF you're supplying power to the device externally then try disconnecting that and power the device directly from the PICKit3, if you're running the standalone application for the PICKit3 look for the Vpp before Vdd setting and enable that (if there is one, I don't remember).

    If you spend 5 minutes with Google you'll find threads on several forums (including this one) which discusses the issue. For example, here's one

  17. #17
    Join Date
    Jun 2008
    Location
    Varese , Italy
    Posts
    326


    Did you find this post helpful? Yes | No

    Default Re: reading I/O state of pic12f675...

    ok, understood the reason of the problem.
    Thanks a lot to all.
    I did try to recover the chips that are no longer reconized by the programmer. I have a certain numbers dead here.
    I applied the indicated procedure but with no succes.
    Could anybody instruct about a proven recovery procedure please ?
    Thanks again.
    regards,
    Ambrogio

  18. #18
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    574


    Did you find this post helpful? Yes | No

    Default Re: reading I/O state of pic12f675...


  19. #19
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,588


    Did you find this post helpful? Yes | No

    Default Re: reading I/O state of pic12f675...

    I am impressed how well google translated that page to english.

    I expected it to look like the documentation I get from asia. (I admit that's better than mandarin or cantonese)

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  20. #20
    Join Date
    Jun 2008
    Location
    Varese , Italy
    Posts
    326


    Did you find this post helpful? Yes | No

    Default Re: reading I/O state of pic12f675...

    Thanks, but:
    I have a certain number of PIC12f675 that can not programmed anymore because some pin have been re_assigned in the running program.
    How to overcome this trouble please ?
    What procedure ?
    regards,
    Ambrogio

  21. #21
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    574


    Did you find this post helpful? Yes | No

    Default Re: reading I/O state of pic12f675...

    Read here : http://www.microchip.com/forums/tm.a...&mpage=2&key=&
    It's about 12F629 but ...maybe is useful !

  22. #22
    Join Date
    Jun 2008
    Location
    Varese , Italy
    Posts
    326


    Did you find this post helpful? Yes | No

    Default Re: reading I/O state of pic12f675...

    I did try all the suggestion found in the relevant link but no good result at all.
    My PICKIT_3 does not reconize the 675 anymore.
    Thanks
    Ambrogio

Similar Threads

  1. Knowledge of State Variable Filters
    By Lucy248 in forum General
    Replies: 1
    Last Post: - 9th September 2016, 09:56
  2. Changing output state after 2 minutes
    By carljbrooks in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 21st February 2014, 06:28
  3. DC - AC Solid State Relay
    By shahidali55 in forum General
    Replies: 6
    Last Post: - 10th November 2007, 17:01
  4. State machine programming
    By tjstevens in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 17th April 2007, 23:45
  5. Replies: 2
    Last Post: - 27th March 2007, 13:48

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts