PIC12F508 example code ??

Discussion in 'Embedded Systems and Microcontrollers' started by Vindhyachal Takniki, Nov 11, 2014.

  1. Vindhyachal Takniki

    Thread Starter Member

    Nov 3, 2014
    349
    6
    1. Do anyone have link for example codes on PIC12F508. I searched but didn't find example codes specific to PIC12F508.

    2. From datasheet what I can understand, there are no interrupts in this PIC. Not even Timer0 have interrupt.
    Am I right?

    3. In datasheet of PIC12F508, there is register TRISGPIO mentioned. But in its address N/A is written.
    And in pic12f508.h file for hi-tech c compiler , both TRISGPIO & GPIO register have same address.
    Why is that so, aren't both of them are different registers??

    Code (Text):
    1.  
    2.  
    3. volatile         unsigned char           GPIO                @ 0x006;
    4. volatile control unsigned char           TRIS                @ 0x006;
    5. volatile control unsigned char           TRISGPIO            @ 0x006;
    6. // bit and bitfield definitions
    7. volatile bit GP0                 @ ((unsigned)&GPIO*8)+0;
    8. volatile bit GP1                 @ ((unsigned)&GPIO*8)+1;
    9. volatile bit GP2                 @ ((unsigned)&GPIO*8)+2;
    10. volatile bit GP3                 @ ((unsigned)&GPIO*8)+3;
    11. volatile bit GP4                 @ ((unsigned)&GPIO*8)+4;
    12. volatile bit GP5                 @ ((unsigned)&GPIO*8)+5;
    13.  
    14.  
     
  2. ericgibbs

    AAC Fanatic!

    Jan 29, 2010
    2,503
    380
    hi,
    This pdf has some information on programs for the base line PIC's inc. 12F508. [ Google for 12C508 the OTP version]
    No interrupts, TRISGPIO means tristate Reg GPIO, so it will be the same address.
    E
     
  3. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    1. Did you see the tutorial over on TalkingElectronics/Googlium?
    2. Nope, doesn't seem like it.
    3. This is a bit odd, and probably a result of the original design being so old that they hadn't yet standardized the design of the processors. As such, the TRIS register is accessed through a special instruction "tris f" (page 64), where f is the address of the port to set I/O directions for. Page 31 gives a little bit of information regarding the matter.
    I'd suggest a new part, as there are more Microchip self-standardized parts out there...

    Edit: Updated Link
     
    Last edited: Nov 12, 2014
  4. jpanhalt

    AAC Fanatic!

    Jan 18, 2008
    5,699
    907
    Eric has provided a link to a good tutorial with code examples.
    If you want interrupts in the 12F chips you need a 12F6xx or an enhanced midrange, such as the 12F1840.
    TRIS is write only:

    upload_2014-11-11_8-29-54.png

    It controls the pin directions, i.e., input (high- impedance) or output (low-impedance). In Assembly, the usual way is to move a literal to w, then put that into GPIO:
    Code (ASM):
    1.  
    2.     MOVLW    B'11101000'    ; Set pins 4,6 as inputs, 2,3,5,7 as outputs
    3.     TRIS    GPIO        ; Configure pins as either I or O
    4.  
    Your compiler may give a warning for using TRIS like that, but it works. Section 5 (about page 29) of the datasheet explains setting the pins and ports in greater detail.

    John
     
  5. Vindhyachal Takniki

    Thread Starter Member

    Nov 3, 2014
    349
    6
    1. @tshuck , link provided by you don't open, its 404
    1. Did you see the tutorial over on TalkingElectronics/Googlium?
    2. I have tried below code for making pin input or output. In MPSLAB SIM it is working, but I will test it on real board after assembling:

    Code (Text):
    1.  
    2.     GPIO = 0x20U;       /* all output pins be low on power up */
    3.     TRIS = 0x08U;       /* GP3 as input rest output */
    4.  
    3. Is there any GUI based real time simulator like Proteus for PIC12F508.
    Proteus don't have support for this. I have searched internet & tried Real Pic simualtor.
    It do not allow using generic components like LED, res, cap etc.
     
  6. ericgibbs

    AAC Fanatic!

    Jan 29, 2010
    2,503
    380
  7. Vindhyachal Takniki

    Thread Starter Member

    Nov 3, 2014
    349
    6
    I have build code for PIC12F508 & output is 294 bytes program memory & 13 bytes RAM.
    I am writing code in C.
    I am woried about stack overflow since PIC12F508 have only 2 level stack.
    Maximum function depth in C in mu code is 3 level.

    Is there any check that if my code have violated stack limit.
    No local variables in my code.
     
  8. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,394
    1,606
    C inside PICs does not use the stack in the same way as other processors, such as trading RAM for stack and other tricks. Local variables do not get stored on the stack but inside RAM; curiously persistent locals are essentially global, but their names are only defined inside the routine.

    If you restrict your function calls from main() to one or two you should be good. See if your C user manual gives this limit.

    A good way to check is to run it inside the simulator and see what happens. A stack error WILL be reported as an error.
     
  9. ericgibbs

    AAC Fanatic!

    Jan 29, 2010
    2,503
    380
    hi VT,
    If you get the Oshonsoft IDE trial version, set up the simulator for 12F508 PIC, in the Options , set the clock frequency as used by your hardware, then you can Load the Hex file your C compiler creates into the sim and Run it.

    If you post your hex file I could try it for you.

    E
     
  10. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,394
    1,606
    Assuming you are running hi-tech C inside MPLAB you need not go any further then MPLAB itself. It has an awesome simulator with will work directly with the C code itself, or if you wish you can instead watch the assembly statements go by as these will be commented with the C code that generated them.

    If you are not are running hi-tech C inside MPLAB I would have to ask "why not?"
     
  11. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    I updated the link: http://www.talkingelectronics.com/projects/Elektor/Gooligum PIC Tutorials/PIC_Base_A_1.pdf

    One thing to check is that your disassembled code uses the tris instruction as follows:
    Screenshot_2014-11-12-07-17-23~2.jpg
    Note that this means the TRIS register is loaded with the contents of W and stored in the location associated with the port address specified.

    3. You will not be finding a real time simulator for a whole circuit anytime soon, probably not in this lifetime, anyway, there are a lots of calculations involved with a simulation and those take time to do. That said, there are some decent simulators out there that do a pretty good job.
     
  12. Vindhyachal Takniki

    Thread Starter Member

    Nov 3, 2014
    349
    6
    1. Example code on googlium are sufficient.
    2. in proteus, I had simulated PIC12C508.

    tested code on hardware & working. Thanks @all for help
     
Loading...