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

interrupt problem after migration 16f877 to 18f452
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
hydrogene



Joined: 23 May 2004
Posts: 11
Location: Montreal

View user's profile Send private message

interrupt problem after migration 16f877 to 18f452
PostPosted: Sun May 23, 2004 11:24 am     Reply with quote

Hi!
before to read a lot on this forum, I decide to do the migration and I changed the 16f877 for a 18f452. So when I put the code inside, the interrupt on RB0 doesn't work. (my code was working on the 16f). My compiller version is 3.2 (the last one).
When I saw that, I tried to put the simplest code, flash a led with the interrupt and it was not working to!!!!!

Here is the code :
#include <18f452.h>
#include <stdlib.h>

#fuses HS, NOWDT, NOLVP, PUT, NOBROWNOUT
#use delay (clock = 20000000)


/* Pin assignation */
#bit LED = 0xF81.7

/* function header */
#INT_EXT
void test();

void main()
{
SET_TRIS_B(0x00);

ext_int_edge(H_TO_L);

disable_interrupts(GLOBAL);
enable_interrupts(INT_EXT);

LED = 0;

while(1){}
}

#INT_EXT
void test()
{
LED = 1;
delay_ms(1000);
LED = 0;
}


It's working well with the 16f877 and not on the 18f452.... why Crying or Very sad

Sorry for my english Smile

Thanx a lot!!!!!!!!!!!!!!!!!!!!!!!!!!!

David
future



Joined: 14 May 2004
Posts: 330

View user's profile Send private message

PostPosted: Sun May 23, 2004 11:27 am     Reply with quote

Why do you have global interrupts disabled?
hydrogene



Joined: 23 May 2004
Posts: 11
Location: Montreal

View user's profile Send private message

PostPosted: Sun May 23, 2004 11:32 am     Reply with quote

I saw that on the forum, so I dont know!!!
hydrogene



Joined: 23 May 2004
Posts: 11
Location: Montreal

View user's profile Send private message

PostPosted: Sun May 23, 2004 11:42 am     Reply with quote

it's not working :'(

The code is stupid... why it's not simply work????
future



Joined: 14 May 2004
Posts: 330

View user's profile Send private message

PostPosted: Sun May 23, 2004 11:56 am     Reply with quote

change:

disable_interrupts(GLOBAL);
enable_interrupts(INT_EXT);

to:

enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
hydrogene



Joined: 23 May 2004
Posts: 11
Location: Montreal

View user's profile Send private message

PostPosted: Sun May 23, 2004 12:01 pm     Reply with quote

WOW, it's working!!!!!! Very Happy

thanx a lot Smile,

so why I must put all interrupts enabled ???
future



Joined: 14 May 2004
Posts: 330

View user's profile Send private message

PostPosted: Sun May 23, 2004 12:07 pm     Reply with quote

Global is not all interrupts, it enables interrupt generation.

if GIE=0 an interrupt will never happen.
hydrogene



Joined: 23 May 2004
Posts: 11
Location: Montreal

View user's profile Send private message

PostPosted: Sun May 23, 2004 12:32 pm     Reply with quote

it's good to know Smile

But...

It's not working on my real code... (it was only a test the old one) (I cut some innutil parts Smile)

Code :

#include <18F452.h>
#DEVICE ADC=10 *=16
#include <stdlib.h>

#fuses HS, NOWDT, NOLVP, PUT, NOBROWNOUT
#use delay (clock = 20000000)
#use RS232 (baud=9600, xmit=PIN_C6, rcv=PIN_C7)



/* Functions header */

#INT_RDA
void port(); //RS232
#INT_EXT
void ch_scr(); // Refresh LCD
#INT_TIMER1
void acq(); //acquisition timer


void main()
{

// Configuration des ports
SET_TRIS_A(0xFF);
SET_TRIS_B(0xFF);
SET_TRIS_C(0x08);
SET_TRIS_D(0x00);

// Configurations des ports analogiques
setup_port_a(ALL_ANALOG);
setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);

//Activer l'interruption du bouton sur un front montant
ext_int_edge(0, L_TO_H);

//Initialisation du LCD
init_lcd();

//Initialisation du timer
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);

//Activation des interruptions
enable_interrupts(GLOBAL);
enable_interrupts(INT_EXT);
enable_interrupts(INT_RDA);
enable_interrupts(INT_TIMER1);

//******** DEBUT DU CODE ****************

while(1)
{

delay_ms(100);
if(flag_acq) //Si le flag est à ON, on fait une acquisition
acquisition();

else if(flag_com) //Si le flag est à ON, on transmet les donnees
communication();

else if(flag_btn) //Si le flag est à ON, on change d'ecran du LCD
ecran_lcd();
}

}

/* Other Functions */

void communication()
{
if(!strcmp(string, id)) //est-ce que le data recu est km13?
{
creer_trame(); //on monte une trame pour envoyer les donnees
printf("%s", trame); //on envoie les donnees
}

SERIAL = 0; //LED de communication à off
ON = 1; //LED PowerON à ON
flag_com = 0; //fermeture du flag

}

//Cette fonction incremente le compteur d'ecrans et descend le flag a 0.
void ecran_lcd()
{
scr++; // next page
flag_btn = 0; // flag off
prints(); //Refresh screen
}


//Affichage des écrans sur le LCD. Incrémentation seulement du compteur.
void prints()
{
//Affichage des tensions
if(scr == 1)
{
sprintf(lcd, "Tension du 12: %2.1f", bt);
printl(lcd, 1,1);
sprintf(lcd, "Tension du 48: %2.1f", ht);
printl(lcd, 2,1);
}
//Affichage des courants
else if(scr == 2)
{
sprintf(lcd, "Courant du 12V:%2.1f", bt_courant);
printl(lcd, 1,1);
sprintf(lcd, "Courant du 48V:%2.1f", ht_courant);
printl(lcd, 2,1);
}
//Affichage de la température et du fonctionnement de la génératrice
else if(scr == 3)
{
if(gen)
strcpy(string, "en marche");
else
strcpy(string, "hors fonction");

sprintf(lcd, "Temperature:%2.1f", temperature);
printl(lcd, 1,1);
sprintf(lcd, "Generatrice %s", string);
printl(lcd, 2,1);
}
//Affichage des statistiques pour le 12V
else if(scr == 4)
{
sprintf(lcd, "Statistiques pour le 12V");
printl(lcd, 1,1);
sprintf(lcd, "Prct:%3.0f temps:%3.0f", prct_bt, temps_bt);
printl(lcd, 2,1);
}
//Affichage des statistiques pour le 48V
else if(scr == 5)
{
sprintf(lcd, "Statistiques pour le 48V");
printl(lcd, 1,1);
sprintf(lcd, "Prct:%3.0f temps:%3.0f", prct_ht, temps_ht);
printl(lcd, 2,1);
}
//Affichage complet
else if(scr == 6)
{
sprintf(lcd, "12:%2.0fV %2.0fA %3.0fpct T:%2.0fC", bt, bt_courant, prct_bt, temperature);
printl(lcd, 1,1);
sprintf(lcd, "48:%2.0fV %2.0fA %3.0fpct", ht, ht_courant, prct_ht);
printl(lcd, 2,1);
}
//Affichage complet 12V
if(scr == 7)
{
sprintf(lcd, "12=> %2.1fV %2.1fA", bt, bt_courant);
printl(lcd, 1,1);
sprintf(lcd, "Temps:%2.1fH Prct:%2.1f",temps_bt, prct_bt);
printl(lcd, 2,1);
}
//Affichage complet 48V
if(scr == 8)
{
sprintf(lcd, "48=> %2.1fV %2.1fA", ht, ht_courant);
printl(lcd, 1,1);
sprintf(lcd, "Temps:%2.1fH Prct:%2.1f",temps_ht, prct_ht);
printl(lcd, 2,1);
}
//Remsie à zéro du compteur d'écran
else
scr =0;
}


#INT_RDA
void port()
{
gets(string);
flag_com = 1;
}

//btn
#INT_EXT
void ch_scr()
{
flag_btn = 1;
}

//timer once per second
#INT_TIMER1
void acq()
{
flag_acq = 1;
}




Thanx!!!

DAvid
future



Joined: 14 May 2004
Posts: 330

View user's profile Send private message

PostPosted: Sun May 23, 2004 12:52 pm     Reply with quote

SET_TRIS_B(0xFF); set all as inputs.

change to:

SET_TRIS_B(0x00);
ckielstra



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

View user's profile Send private message

PostPosted: Sun May 23, 2004 3:51 pm     Reply with quote

How many times per second is your Timer1 generating an interrupt? If this is more then 10 times per second, than flag_acq will always be true and your communication or lcd-routines are never called....
hydrogene



Joined: 23 May 2004
Posts: 11
Location: Montreal

View user's profile Send private message

PostPosted: Sun May 23, 2004 4:29 pm     Reply with quote

Hello !!!
My button is on pin B0 (int0). So I can not put the TrisB at 00, at lease 01.
For the Timer1, I put // (comment) it and it's not working to...

I'm so disappointed :(

Tanks

David
future



Joined: 14 May 2004
Posts: 330

View user's profile Send private message

PostPosted: Sun May 23, 2004 5:52 pm     Reply with quote

I think you have to start reading the datasheet.
ckielstra



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

View user's profile Send private message

PostPosted: Mon May 24, 2004 3:14 am     Reply with quote

Where is the other code with flag_acq?
I don't see any initializations or resetting of this variable....
Guest








PostPosted: Tue May 25, 2004 1:53 am     Reply with quote

I very doubt the statement that this works on the 16f877 with
Code:

Disable_interrupts(GLOBAL);


Question Question Sad

Quote:

think you have to start reading the datasheet.

Take this hint serious, mr. Hydrogene!
ckielstra



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

View user's profile Send private message

PostPosted: Tue May 25, 2004 3:53 am     Reply with quote

Quote:
I very doubt the statement that this works on the 16f877 with
Code:

Disable_interrupts(GLOBAL);

Sorry Guest, this has already been solved in his later postings.

I still think his problem is with the Timer1, it looks too fast to me:
Code:
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);


In the Timer1 handler the flag_acq will be set. This combined with the delay_ms and the repeated if..else if...else construction will make sure he will only have time to execute the acquisition() function and nothing else.

Code:
while(1)
{

delay_ms(100);
if(flag_acq) //Si le flag est à ON, on fait une acquisition
acquisition();

else if(flag_com) //Si le flag est à ON, on transmet les donnees
communication();

else if(flag_btn) //Si le flag est à ON, on change d'ecran du LCD
ecran_lcd();
}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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