View previous topic :: View next topic |
Author |
Message |
Guest
|
SFR question |
Posted: Fri Aug 26, 2005 5:22 am |
|
|
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
|
|
Posted: Fri Aug 26, 2005 9:17 am |
|
|
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
|
|
Posted: Fri Aug 26, 2005 9:46 am |
|
|
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
|
|
Posted: Fri Aug 26, 2005 10:12 am |
|
|
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
|
|
Posted: Fri Aug 26, 2005 12:08 pm |
|
|
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
|
|
Posted: Fri Aug 26, 2005 12:55 pm |
|
|
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
|
|
Posted: Fri Aug 26, 2005 1:37 pm |
|
|
Quote: | also clear the flag or is there another ccs function to do that? |
See the clear_interrupt() function in the CCS manual. |
|
|
|