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

Printing control register bits does not work

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



Joined: 17 Sep 2003
Posts: 97
Location: Atlanta, GA, USA

View user's profile Send private message

Printing control register bits does not work
PostPosted: Wed Oct 04, 2006 8:55 am     Reply with quote

I am trying to print interrupt status bits and it is not working.

I am trying to print all of the bits (INTCON, PIE, PIR, IPR, RCON) on a PIC18F8722 using 3.249. The code to do this is rather lengthy so, below, I will abbreviate it down to one part that I know for a fact is not working correctly.

The interrupt we will concentrate on is INT1, pin 57 of the device. It is an external interrupt. It is connected to a push button on my PCB, and the interrupt handles the button press and [i]works as it should whenever the button is pressed[i].

However, according to what CCS is printing out, INT1 is turned off. I considered that perhaps the print routine was turning off the interrupt while it was printing, so I changed the code to copy interrupt bits into RAM before printing and got the same erroneous result. Since that didn't work, I then turned off global interrupts for the duration of the control register to RAM copy routine and the data CCS is giving me is still invalid.

Here is the code. I removed all the code and #bit declarations for all of the other interrupts and just left it with INT1 for us to concentrate on. Once we fix this problem, I'm sure the same work-around will apply to all of the other interrupts.

Code:
void Print10(int8 val, int8 mask) {
   if(val & mask) fprintf(TERM,"1"); else fprintf(TERM,"0");
}

void PrintAddressBinary(int16 loc) {
   char c;
   int8 i;
   c = 0x80;
   for(i=0;i<8>>=1; }
   fprintf(TERM,"\n\r");
}

void PrintEdgeInterrupt(int1 bIE,int1 bIF, int1 bEdge,int8 iIP) {
   if(bIF) fprintf(TERM,"SET");
   fprintf(TERM,"\t");
   if(bIE) fprintf(TERM,"ENABLED "); else fprintf(TERM,"disabled");
   fprintf(TERM,"\t");
   if(iIP == 1) fprintf(TERM,"HIGH"); elsif(iIP == 0) fprintf(TERM,"low"); else fprintf(TERM,"   ");
   fprintf(TERM,"\t");
   if(bEdge) fprintf(TERM,"risING"); else fprintf(TERM,"FALLing");
   fprintf(TERM,"\t");

}

void PrintInterrupts() {
   char   c;
   int8   i,INTCON,INTCON2,INTCON3,PIE1,PIE2,PIE3,PIR1,PIR2,PIR3,IPR1,IPR2,IPR3,RCON;
   
#byte _INTCON = 0xFF2              // INTCON address
#bit GIE = INTCON.7               // Global Interrupt Enable
#bit PEIE = INTCON.6               // Peripheral Interrupt Enable
#bit INT0IE = INTCON.4            // INT0 External Interrupt Enable

#byte _INTCON2 = 0xFF3            // INTCON2 address
#bit INTEDG1 = INTCON2.5         // External Interrupt 1 Edge

#byte _INTCON3 = 0xFF4            // INTCON3 address
#bit INT1IP = INTCON3.6            // INT1 External Interrupt Priority
#bit INT1IE = INTCON3.3            // INT1 External Interrupt Enable
#bit INT1IF = INTCON3.0            // INT1 External Flag

#byte _PIE1 = 0xF9D               // PIE1 address
#byte _PIE2 = 0xFA0               // PIE2 address
#byte _PIE3 = 0xFA3               // PIE3 address
#byte _PIR1 = 0xF9E               // PIR1 address
#byte _PIR2 = 0xFA1               // PIR2 address
#byte _PIR3 = 0xFA4               // PIR3 address
#byte _IPR1 = 0xF9F
#byte _IPR2 = 0xFA2
#byte _IPR3 = 0xFA5

#byte _RCON = 0xFD0
#bit IPEN = RCON.7               // Interrupt Priority Feature

disable_interrupts(GLOBAL);
INTCON = _INTCON;
INTCON2 = _INTCON2;
INTCON3 = _INTCON3;
PIE1 = _PIE1;
PIE2 = _PIE2;
PIE3 = _PIE3;
PIR1 = _PIR1;
PIR2 = _PIR2;
PIR3 = _PIR3;
IPR1 = _IPR1;
IPR2 = _IPR2;
IPR3 = _IPR3;
RCON = _RCON;
enable_interrupts(GLOBAL);

fprintf(TERM,"Interrupt Status Dump:\n\r");
fprintf(TERM,"INTCON\t"); PrintAddressBinary(INTCON);
fprintf(TERM,"INTCON2\t"); PrintAddressBinary(INTCON2);
fprintf(TERM,"INTCON3\t"); PrintAddressBinary(INTCON3);
fprintf(TERM,"PIE1\t"); PrintAddressBinary(PIE1);
fprintf(TERM,"PIE2\t"); PrintAddressBinary(PIE2);
fprintf(TERM,"PIE3\t"); PrintAddressBinary(PIE3);
fprintf(TERM,"IPR1\t"); PrintAddressBinary(IPR1);
fprintf(TERM,"IPR2\t"); PrintAddressBinary(IPR2);
fprintf(TERM,"IPR3\t"); PrintAddressBinary(IPR3);
fprintf(TERM,"PIR1\t"); PrintAddressBinary(PIR1);
fprintf(TERM,"PIR2\t"); PrintAddressBinary(PIR2);
fprintf(TERM,"PIR3\t"); PrintAddressBinary(PIR3);

fprintf(TERM,"\n\rGIE All Interrupts\t\t\t");
if(GIE) fprintf(TERM,"ENABLED "); else fprintf(TERM,"disabled");
fprintf(TERM,"\n\rPEIE Peripheral Interrupt\t\t");
if(PEIE) fprintf(TERM,"ENABLED "); else fprintf(TERM,"disabled");
fprintf(TERM,"\n\rInterrupt Priority Feature\t\t");
if(IPEN) fprintf(TERM,"ENABLED "); else fprintf(TERM,"disabled");

fprintf(TERM,"\n\n\rExternal Interrupt 1\t\t");   PrintEdgeInterrupt(INT1IE,INT1IF,INTEDG1,INT1IP);
}


Which produces this output when called:

Code:
Interrupt Status Dump:
INTCON  00100110
INTCON2 00010111
INTCON3 00000000
PIE1    00000000
PIE2    00000000
PIE3    01000100                                                                                                             
IPR1    10001100
IPR2    00000000
IPR3    10100000
PIR1    00101010
PIR2    00100110
PIR3    00100110
                                                                                                                             
GIE All Interrupts                      disabled
PEIE Peripheral Interrupt               disabled
Interrupt Priority Feature              ENABLED

External Interrupt 1                    disabled        low     FALLing


Note that when the global interrupts are not disabled, it shows the same data and GIE and PEIE both say "ENABLED".

As you can see, INTCON3, bit 3 is clear which means, "0 = Disables the INT1 external interrupt". YET, INT1 is clearly working.

Finally, in the list file, I can see that it is copying the correct register addresses to RAM addresses, and that the RAM addresses are the same ones being used for printing.

What am I doing wrong? What do I have to do to print out these control registers?

Thanks,
Kyle
Ttelmah
Guest







PostPosted: Wed Oct 04, 2006 9:21 am     Reply with quote

Without looking too far. 0xFF4, is _not_ the address of INTCON3. INTCON3 is 0xFF0.....

Best Wishes
kda406



Joined: 17 Sep 2003
Posts: 97
Location: Atlanta, GA, USA

View user's profile Send private message

PostPosted: Wed Oct 04, 2006 10:01 am     Reply with quote

Embarassed Yes, in my two man-days of typing in all the #bytes and #bits I needed, I did make a typo on that register and one other.

I fixed them, and much of the data looks right, but some is still wrong. I will dig deeper and report back if I cannot fix the rest of the problems myself.

Using the right addresses, should we be able to print the actual register values in a chip with hardware EUSARTs without copying the registers to RAM? Are we sure the EUSART transmit buffer won't mess with the results?

Thanks,
Kyle
Ttelmah
Guest







PostPosted: Wed Oct 04, 2006 10:08 am     Reply with quote

In general, yes. However you are never going to see anything except zeros on the PIR registers, unless you disable the interrupts (since if they set, the handler will be called). The only effect of the USART, will be on it's interrupt flag(s) RDA, and TXE.
The big advantage of copying them to memory, is that it allows a 'timeshot' to be taken. Given the duration needed to print the sort of message scale you are shoing, some of the interrupts, could easily have gone through a hundred cycles in this time...

Best Wishes
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