CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Newbie question 12F675 accessing register port change int

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
pickup



Joined: 22 Jun 2013
Posts: 9

View user's profile Send private message

Newbie question 12F675 accessing register port change int
PostPosted: Sat Jun 22, 2013 12:54 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Jun 22, 2013 1:20 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Jun 22, 2013 2:01 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Jun 22, 2013 3:21 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Jun 22, 2013 5:54 pm     Reply with quote

Thanks a lot. This is really helpful Smile.
Ttelmah



Joined: 11 Mar 2010
Posts: 19260

View user's profile Send private message

PostPosted: Sun Jun 23, 2013 3:21 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Jun 23, 2013 4:19 pm     Reply with quote

That's great Ttelmah Very Happy . Thank you very much.

Best regards.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group