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 CCS Technical Support

SFR question

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








SFR question
PostPosted: Fri Aug 26, 2005 5:22 am     Reply with quote

I'm working with an 18f452.
I'm a little confused by the external interrupt flag address

#bit INTF_BIT = 0x0B.1

is that just for external interrupt 0, or is that for all portB?
what would the address for the other external interrupt flags be?
valemike
Guest







PostPosted: Fri Aug 26, 2005 9:17 am     Reply with quote

i haven't personally used #bit myself.

But from reading it, it looks like that it only refers to BIT 1 of the register at address 0x0B, not to the whole register.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Fri Aug 26, 2005 9:46 am     Reply with quote

Quote:
#bit INTF_BIT = 0x0B.1
This is a definition for accessing bit number 1 at address 0x0B. Address 0x0B is the address of the INTCON register in many of the PIC16 processors, the PIC18F452 has a whole different memory layout so you can't use this define !

In the PIC18F452 the same bit is called INT0IF and a similar define would look like:
Code:
#bit INT0IF_BIT = 0xFF2.1
.
Two complete include files with all these bit defines can be found in http://www.ccsinfo.com/forum/viewtopic.php?t=14755.

Quote:
is that just for external interrupt 0, or is that for all portB?
This define is just for the external interrupt.

Quote:
what would the address for the other external interrupt flags be?
Read the datasheet for the 18F452. I know this doesn't sound nice, but when writing programs for a low level processor like the PIC there are many small things that you as a programmer have to be aware of. So you won't escape from having to read the datasheet in the end.

Just one more remark, instead of all the low-level bit access stuff, the great thing about the CCS compiler is that they provide you with higher level functions that are easier to understand and makes it easy to convert your code to other PIC processors.
For example, to enable the external interrupt you can write:
Code:
#bit INT0IF_BIT = 0xFF2.1 // external interrupt enable bit
#bit GIE_BIT = 0xFF2.7    // Global interrupt enable bit
INTF_BIT = 1;
GIE_BIT =1;


or in CCS you write
Code:
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);

The latter is shorter and much easier to read, I advise you to use the CCS functions.
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Fri Aug 26, 2005 10:12 am     Reply with quote

I, personally, like to declare register assignments with the same name that are used in the spec. sheets. ie...

Code:

/////////////////////////
//    register definitions
/////////////////////////
#byte T0CON = 0xFD5
#byte T1CON = 0xFCD
#byte T2CON = 0xFCA
#byte T3CON = 0xFB1

/////////////////////////
//    word definitions
////////////////////////

// TOCON bits
#bit TMR0ON = T0CON.7
#bit T08BIT = T0CON.6
#bit TOPS2 = T0CON.2
#bit TOPS1 = T0CON.1
#bit TOPS0 = T0CON.0

// T1CON bits
#bit RD16 = T1CON.7// 16 bit write mode, 1 = 16 bit, 0 = 8 bit
#bit T1OSCEN = T1CON.3
#bit TMR1ON = T1CON.0

// T2CON bits
#bit TOUTPS3 = T2CON.6
#bit TOUTPS2 = T2CON.5
#bit TOUTPS1 = T2CON.4
#bit TOUTPS0 = T2CON.3
#bit TMR2ON = T2CON.2
#bit T2CKPS1 = T2CON.1
#bit T2CKPS0 = T2CON.0

// T3CON bits
#bit TMR3ON = T3CON.0


This makes it fairly easy to keep track of what register does what. You look one up, in the spec. sheet, and have the same name in your code. No need to convert from one naming standard to a custom one.

These, by-the-way, are for a PIC18F452.

Ronald
Guest








PostPosted: Fri Aug 26, 2005 12:08 pm     Reply with quote

I thought that definition was so you could use it later to clear the interrupt flag. does enabling and disabling the interrupt with

enable_interrupts(INT_EXT);

also clear the flag or is there another ccs function to do that?
Guest








PostPosted: Fri Aug 26, 2005 12:55 pm     Reply with quote

Anonymous wrote:
I thought that definition was so you could use it later to clear the interrupt flag. does enabling and disabling the interrupt with

enable_interrupts(INT_EXT);

also clear the flag or is there another ccs function to do that?


Code:

....................     /* Set up RB0 as an interrupt */ 
....................     ext_int_edge(H_TO_L);      // init interrupt triggering for limit switch 
044E:  BCF    FF1.6
....................     enable_interrupts(INT_EXT); 
0450:  BSF    FF2.4
....................   
....................     setup_timer_1(T1_INTERNAL | T1_DIV_BY_1); 


FYI, the enable_interrupts() instruction in the PIC18F458 'dis-assembles' into the above assembly. It looks efficient enough (1 assembly instruction), so if i were you, i'd just use the library call. Notice that you can implement the enable_interrupts(INT_EXT) function like:

Code:

#bit MY_BIT=0xFF1.6
...
MY_BIT = 1;


or

Code:

#byte MY_REG=0xFF1
...
MY_REG |= 0x40;  // 0100 0000 sets bit 6


-Mike

p.s. i'm pretty sure that the "|=" operation works, but you might have to verify "MY_BIT = 1"
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Aug 26, 2005 1:37 pm     Reply with quote

Quote:
also clear the flag or is there another ccs function to do that?

See the clear_interrupt() function in the CCS manual.
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