|
|
View previous topic :: View next topic |
Author |
Message |
hydrogene
Joined: 23 May 2004 Posts: 11 Location: Montreal
|
interrupt problem after migration 16f877 to 18f452 |
Posted: Sun May 23, 2004 11:24 am |
|
|
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
Sorry for my english
Thanx a lot!!!!!!!!!!!!!!!!!!!!!!!!!!!
David |
|
|
future
Joined: 14 May 2004 Posts: 330
|
|
Posted: Sun May 23, 2004 11:27 am |
|
|
Why do you have global interrupts disabled? |
|
|
hydrogene
Joined: 23 May 2004 Posts: 11 Location: Montreal
|
|
Posted: Sun May 23, 2004 11:32 am |
|
|
I saw that on the forum, so I dont know!!! |
|
|
hydrogene
Joined: 23 May 2004 Posts: 11 Location: Montreal
|
|
Posted: Sun May 23, 2004 11:42 am |
|
|
it's not working :'(
The code is stupid... why it's not simply work???? |
|
|
future
Joined: 14 May 2004 Posts: 330
|
|
Posted: Sun May 23, 2004 11:56 am |
|
|
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
|
|
Posted: Sun May 23, 2004 12:01 pm |
|
|
WOW, it's working!!!!!!
thanx a lot ,
so why I must put all interrupts enabled ??? |
|
|
future
Joined: 14 May 2004 Posts: 330
|
|
Posted: Sun May 23, 2004 12:07 pm |
|
|
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
|
|
Posted: Sun May 23, 2004 12:32 pm |
|
|
it's good to know
But...
It's not working on my real code... (it was only a test the old one) (I cut some innutil parts )
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
|
|
Posted: Sun May 23, 2004 12:52 pm |
|
|
SET_TRIS_B(0xFF); set all as inputs.
change to:
SET_TRIS_B(0x00); |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sun May 23, 2004 3:51 pm |
|
|
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
|
|
Posted: Sun May 23, 2004 4:29 pm |
|
|
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
|
|
Posted: Sun May 23, 2004 5:52 pm |
|
|
I think you have to start reading the datasheet. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Mon May 24, 2004 3:14 am |
|
|
Where is the other code with flag_acq?
I don't see any initializations or resetting of this variable.... |
|
|
Guest
|
|
Posted: Tue May 25, 2004 1:53 am |
|
|
I very doubt the statement that this works on the 16f877 with
Code: |
Disable_interrupts(GLOBAL);
|
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
|
|
Posted: Tue May 25, 2004 3:53 am |
|
|
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();
} |
|
|
|
|
|
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
|