PIC12F508 example code ??

Thread Starter

Vindhyachal Takniki

Joined Nov 3, 2014
594
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:
volatile         unsigned char           GPIO                @ 0x006;
volatile control unsigned char           TRIS                @ 0x006;
volatile control unsigned char           TRISGPIO            @ 0x006;
// bit and bitfield definitions
volatile bit GP0                 @ ((unsigned)&GPIO*8)+0;
volatile bit GP1                 @ ((unsigned)&GPIO*8)+1;
volatile bit GP2                 @ ((unsigned)&GPIO*8)+2;
volatile bit GP3                 @ ((unsigned)&GPIO*8)+3;
volatile bit GP4                 @ ((unsigned)&GPIO*8)+4;
volatile bit GP5                 @ ((unsigned)&GPIO*8)+5;
 

ericgibbs

Joined Jan 29, 2010
18,849
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
 

Attachments

tshuck

Joined Oct 18, 2012
3,534
  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:

jpanhalt

Joined Jan 18, 2008
11,087
1. Do anyone have link for example codes on PIC12F508. I searched but didn't find example codes specific to PIC12F508.
Eric has provided a link to a good tutorial with code examples.
2. From datasheet what I can understand, there are no interrupts in this PIC. Not even Timer0 have interrupt.
Am I right?
If you want interrupts in the 12F chips you need a 12F6xx or an enhanced midrange, such as the 12F1840.
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??
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:
    MOVLW    B'11101000'    ; Set pins 4,6 as inputs, 2,3,5,7 as outputs
    TRIS    GPIO        ; Configure pins as either I or O
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
 

Thread Starter

Vindhyachal Takniki

Joined Nov 3, 2014
594
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:
    GPIO = 0x20U;       /* all output pins be low on power up */
    TRIS = 0x08U;       /* GP3 as input rest output */
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.
 

Thread Starter

Vindhyachal Takniki

Joined Nov 3, 2014
594
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.
 

ErnieM

Joined Apr 24, 2011
8,377
Is there any check that if my code have violated stack limit.
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.
 

ericgibbs

Joined Jan 29, 2010
18,849
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
 

ErnieM

Joined Apr 24, 2011
8,377
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?"
 

tshuck

Joined Oct 18, 2012
3,534
1. @tshuck , link provided by you don't open, its 404
  1. Did you see the tutorial over on TalkingElectronics/Googlium?
I updated the link: http://www.talkingelectronics.com/projects/Elektor/Gooligum PIC Tutorials/PIC_Base_A_1.pdf

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:
[...]
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.
 
Top