View previous topic :: View next topic |
Author |
Message |
pickup
Joined: 22 Jun 2013 Posts: 9
|
Newbie question 12F675 accessing register port change int |
Posted: Sat Jun 22, 2013 12:54 pm |
|
|
Hello all,
Greetings. I am new and trying CCS as well as PIC microcontroller. I have a question about accessing register - "IOC" for port change interrupt of PIC-12F675. I have used this on PICbasic Pro. To enable interrupt on GPIO.2 and GPIO.3, the pins have to be declared as input. And, it is also needed to declare this in "IOC" register. On Picbasic Pro this can be done as bellow:
IOC = %00001100
I want to know, how is this declared on CCS for changing IOC register? Also, how to access other registers if needed? Any help regarding this is much appreciated.
Thank you. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Jun 22, 2013 1:20 pm |
|
|
See the post in this thread by Ttelmah:
http://www.ccsinfo.com/forum/viewtopic.php?t=48396
In his code in main(), when he does this,
Code: | enable_interrupts(INT_RA0 | INT_RA3); |
it writes to the IOC register and sets the appropriate bits.
In general, in CCS you don't have to write directly to registers.
There will be a built-in CCS function that does it for you.
If you want to see what the compiler is doing, set the List file format
to "Symbolic" in the compiler (or mplab) project options menu.
Then compile a program and look at the the .LST file. |
|
|
pickup
Joined: 22 Jun 2013 Posts: 9
|
|
Posted: Sat Jun 22, 2013 2:01 pm |
|
|
Thank you PCM programmer. I have read your link and understand that it is possible to set the desired pins for interrupt.
But, may be sometimes it may required to access the registers other than the mentioned "IOC". I have searched this forum and web for how to do this on CCS. But could not find or missed if it is possible.
For example on the link http://www.microchipc.com/reviews/CCS_C/ it is mentioned as:
Quote: | I have used the following method (example code provided) with success, removing the need to call the built in port manipulation functions in CCS:
"
#byte PORTC = 0x07 //PORTC is at SFR address 0x07
#define LED1 0x80 //LED1 on PORTC MSB
void main()
{
while(1)
{
PORTC|=LED1; //Turn off LED1
PORTC&=~LED1; //Turn off LED1
PORTC^=LED1; //Toggle LED1
}
}
" |
But I could not completely understand if it is possible to write/read to the register by the above way. If this can be done, what is the proper way to write to the IOC (SFR address 0x96) for example.
Best regards. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Jun 22, 2013 3:21 pm |
|
|
You can do it like this:
Code: |
#include <12F675.h>
#fuses INTRC_IO, NOWDT
#use delay(clock=4M)
#byte IOC = getenv("SFR:IOC")
//==========================================
void main()
{
IOC = 0x09;
while(1);
} |
This way, the compiler looks up the physical address of the IOC register
for that PIC (by using getenv). You don't have to do it. You can then
write (or read) the IOC register as shown in main(). |
|
|
pickup
Joined: 22 Jun 2013 Posts: 9
|
|
Posted: Sat Jun 22, 2013 5:54 pm |
|
|
Thanks a lot. This is really helpful . |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Sun Jun 23, 2013 3:21 am |
|
|
Also worth just adding, that getenv, also supports named bits.
So:
Code: |
#bit LED1=getenv("BIT:RC7")
//then your LED example, just becomes:
LED1=FALSE; //turn off the LED
LED1=TRUE; //turn on the LED
LED1=!LED1; //invert the LED
|
Bit advantage is that in the on/off cases, this codes as single bit set/reset instructions, instead of reading the port, masking the bit, and writing it.
Best Wishes |
|
|
pickup
Joined: 22 Jun 2013 Posts: 9
|
|
Posted: Sun Jun 23, 2013 4:19 pm |
|
|
That's great Ttelmah . Thank you very much.
Best regards. |
|
|
|