Author Topic: PIC12F508 example code ??  (Read 6772 times)

0 Members and 1 Guest are viewing this topic.

Offline Vindhyachal.taknikiTopic starter

  • Frequent Contributor
  • **
  • Posts: 488
PIC12F508 example code ??
« on: November 11, 2014, 12:37:41 pm »
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;
 

Offline macboy

  • Super Contributor
  • ***
  • Posts: 2287
  • Country: ca
Re: PIC12F508 example code ??
« Reply #1 on: November 11, 2014, 02:27:12 pm »
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: [Select]
// Discrete I/O Functions: SET_TRIS_x(), OUTPUT_x(), INPUT_x(),
//                         PORT_x_PULLUPS(), INPUT(),
//                         OUTPUT_LOW(), OUTPUT_HIGH(),
//                         OUTPUT_FLOAT(), OUTPUT_BIT()

 

Offline Flenser

  • Regular Contributor
  • *
  • Posts: 60
Re: PIC12F508 example code ??
« Reply #2 on: November 13, 2014, 03:39:50 pm »
Checkout the free "Baseline PIC" tutorials on http://gooligum.com.au/tutorials.html

These are written for the PIC10F200 and PIC12F508/509

Quote
2. From datasheet what I can understand, there are no interrupts in this PIC. Not even Timer0 have interrupt.
Yes, this is correct. No interrupts and only a 2-Level Deep Hardware Stack, so you can only nest your subroutine calls two deep.
« Last Edit: November 13, 2014, 03:44:15 pm by Flenser »
 

Offline jlmoon

  • Supporter
  • ****
  • Posts: 609
  • Country: us
  • If you fail the first time, keep trying!
Re: PIC12F508 example code ??
« Reply #3 on: November 13, 2014, 03:53:15 pm »
Checkout the free "Baseline PIC" tutorials on http://gooligum.com.au/tutorials.html

These are written for the PIC10F200 and PIC12F508/509

Quote
2. From datasheet what I can understand, there are no interrupts in this PIC. Not even Timer0 have interrupt.
Yes, this is correct. No interrupts and only a 2-Level Deep Hardware Stack, so you can only nest your subroutine calls two deep.

If 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.
Recharged Volt-Nut
 

Offline Vindhyachal.taknikiTopic starter

  • Frequent Contributor
  • **
  • Posts: 488
Re: PIC12F508 example code ??
« Reply #4 on: November 19, 2014, 05:21:50 am »
@flenser: This site uou mentioned had good example for 12F.
Solved my problem

http://gooligum.com.au/tutorials.html
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf