PIC12F508 example code ?? - Page 1
Forum section: electronics / beginners

author: Vindhyachal.takniki
author_rank: Frequent Contributor
timestamp: November 11, 2014, 12:37:41 pm
content: 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 definitionsvolatile bit GP0 @ ((unsigned)&GPIO*+0;volatile bit GP1 @ ((unsigned)&GPIO*+1;volatile bit GP2 @ ((unsigned)&GPIO*+2;volatile bit GP3 @ ((unsigned)&GPIO*+3;volatile bit GP4 @ ((unsigned)&GPIO*+4;volatile bit GP5 @ ((unsigned)&GPIO*+5;

author: macboy
author_rank: Super Contributor
timestamp: November 11, 2014, 02:27:12 pm
content: To write to the GPIO port latch register, you load W with the desired contents, then issue a "MOVWF GPIO" instruction.To write to the GPIO Tristate register, you load W with the desired contents, then issue a "TRIS GPIO" instruction.This is one of the many idiosyncrasies of the old 12-bit instruction set PICs. Other weirdness includes the ability to GOTO any instruction, but ability to CALL only within the first 256 bytes of each 512 byte page. If you program in C, the compiler will take care of that; only assembly programmers (like me) need to worry about that nonsense. In C, you should usually not be directly writing to addresses anyway, you should use the compiler's pre-defined functions for I/O.If you want to know how to write to the TRIS register in C, then you need to look at your compiler's documentation. e.g. in PICC, you will find a header file 12f508.h containing the following comments:Code:// Discrete I/O Functions: SET_TRIS_x(), OUTPUT_x(), INPUT_x(),// PORT_x_PULLUPS(), INPUT(),// OUTPUT_LOW(), OUTPUT_HIGH(),// OUTPUT_FLOAT(), OUTPUT_BIT()

author: Flenser
author_rank: Regular Contributor
timestamp: November 13, 2014, 03:39:50 pm
content: Checkout the free "Baseline PIC" tutorials onhttp://gooligum.com.au/tutorials.htmlThese are written for the PIC10F200 and PIC12F508/509QuoteYes, this is correct. No interrupts and only a 2-Level Deep Hardware Stack, so you can only nest your subroutine calls two deep.

author: jlmoon
author_rank: Unknown
timestamp: November 13, 2014, 03:53:15 pm
content: Quote from: Flenser on November 13, 2014, 03:39:50 pmIf I had a uP part that only had a 2-level deep hardware stack, I would loose that one like a "bad date" .. time to move out of the 12F parts into something more up to date. That is if your working with a new design only.

author: Vindhyachal.takniki
author_rank: Frequent Contributor
timestamp: November 19, 2014, 05:21:50 am
content: @flenser: This site uou mentioned had good example for 12F.Solved my problemhttp://gooligum.com.au/tutorials.html