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

Conflict between Lookup table with interrupt and ICD2

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







Conflict between Lookup table with interrupt and ICD2
PostPosted: Wed Jan 16, 2008 4:24 pm     Reply with quote

Hi,

I am using PIC16F877 to control a LCD module. I found when I tried to use lookup table in the code. It will cause Timer interrupt disabled and ICD2 debugger working improperly. My C compiler is CCS (it may be 2005 version). I am wondering whether CCS doesn’t support what I am doing.
The code looks like as follows:

const unsigned int Sampl_TableH[100]={1,2,3…}

void main() {

while (TRUE){

x = Sampl_TableL[i];

}

#int_timer2

void timer2_isr() {

}



Your help will be quite appreciated.

Thank,

Peter
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jan 16, 2008 7:18 pm     Reply with quote

You can find the compiler version by looking at the top of the .LST file.
The .LST file will be in your project directory.

Post a complete test program that shows the problem. It should be
compilable without errors, and without having to make any changes
or additions, if we paste it into MPLAB. But make it as short as possible.
For example, don't put in code to setup the A/D, etc. Only put in code
that demonstrates the problem.
yyc027
Guest







Complete code
PostPosted: Thu Jan 17, 2008 10:34 am     Reply with quote

As per "PCM programmer" suggestion, I attach my complete code as follows.

If I add code "j=Table[i];" (marked as * Note), the timer2 won't get interrupted as expected. The CCS version is "CCS PCW C Compiler, Version 3.110, 15982"

I really don't know what happned here.
Your help will be quite appreciated.

Thank,

Peter


Complete code attached

Code:
#define _ICD2_ 0

#if defined _ICD2_
#include <16F877_ICD2.h>
#else
#include <16F877.h>
#endif

#fuses HS,NOPROTECT,NOLVP,NOWDT
#BYTE RCSTA = 0x18
#BYTE RCREG = 0x1A
#bit TMR2IF = 0x0C.1
#use delay (clock=16000000)
//#use rs232(baud=9600,xmit=PIN_C6, rcv=PIN_C7)

Boolean fT50us;

//-----------------------------------------------------------------------------
// Name: main()
//

const unsigned int Table[3]={
32,16,11
};


void main() {
byte i,j;
//delay_ms(100);
OUTPUT_A(0x0f); // A0,A1,A2,A3=1,A4,A5=0
OUTPUT_B(0x00); // PORTB=0
OUTPUT_C(0x80); // PORTC=0
OUTPUT_D(0x00); // PORTD=0
OUTPUT_E(0x04); // E0,E1=0,E2=1

SET_TRIS_A(0x0f); // A0,A1,A2,A3=IN, A4,A5=OUT
SET_TRIS_B(0x00); // PORTB=OUT
SET_TRIS_C(0x80); // C0,C1,C2,C3,C4,C5,C6=OUT,C7=IN
SET_TRIS_D(0x00); // PORTD=OUT
SET_TRIS_E(0x00); // PORTE=OUT

//////// initializing LCD /////////
//lcd_init();
//printf(lcd_putc,"\fOZOPTICS\n EPC-V1");


//////// initializing Timer /////////

setup_timer_2(T2_DIV_BY_1,200,1); // 200*(4/16MHz))=50us

enable_interrupts(int_timer2);
enable_interrupts(global);


//////////// main loop //////////////

while (TRUE){
i++;
j--;

if (!fT50us) continue;
fT50us = 0;

if (i>3) i=0;
j=Table[i]; // * Note

}
}


#int_timer2

void timer2_isr() {
static byte i;

if (i==1){
i=0;
OUTPUT_LOW(PIN_C5);
}else{
i=1;
OUTPUT_HIGH(PIN_C5);
}

fT50us = 1;
TMR2IF = 0;
}
[/code]
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Fri Jan 18, 2008 2:36 am     Reply with quote

For a start you array Table[3] has 3 indexes [0],[1] and [2]. Your code has a check

if (i>3) i=0;

This means that i can be 3 and j=Table[3]; Is wrong.

j--; isn't required!
yyc027
Guest







PostPosted: Fri Jan 18, 2008 7:50 am     Reply with quote

I posted the code "if (i>3) i=0; " by mistake. it should be "if (i>2) i=0; "

I just tried again. If "if (i>2) i=0; " added, the timer interrupt won't be generated. It looks like something wrong with the compiler.

Thanks.

Peter
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Fri Jan 18, 2008 8:09 am     Reply with quote

You should set your TRIS before setting any outputs!
SET



Joined: 15 Nov 2005
Posts: 161
Location: Glasgow, UK

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Fri Jan 18, 2008 8:16 am     Reply with quote

What happens if you change the name of the static (in the ISR) from i to something else? Maybe the compiler is getting the variables mixed up..
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