|
|
View previous topic :: View next topic |
Author |
Message |
hydrogene
Joined: 23 May 2004 Posts: 11 Location: Montreal
|
int_rda problem with 3.202 version?? |
Posted: Thu Jun 10, 2004 5:48 am |
|
|
Hi,
I want help, because on the demo version (3.17), it was working well, but now, it's not working (3.202)
The interrupt on RX pin (RC7) seems not work. Also, I saw an other problem, the edge detector (ext_int_edge) not working to!!
Tanks All!!!!!!!
David
Here is my code :
#include <16f877.h>
#DEVICE ADC=10
#include <stdlib.h>
#fuses HS, NOWDT, NOLVP, PUT, NOBROWNOUT
#use delay (clock = 20000000)
#use RS232 (baud=9600, xmit=PIN_C6, rcv=PIN_C7, BITS=8, PARITY=N, errors)
#byte TEXTE = 0x08
#bit LCD_RS = 0x07.5
#bit LCD_E = 0x07.4
#bit COM = 0x06.6
#bit ON = 0x06.5
#bit SERIAL = 0x06.4
//Flag interruptions:
int1 flag_com=0;
int1 flag_acq=0;
int1 flag_btn=0;
int8 sec=0;
int8 min=0;
int8 hr=0;
int compteur_int = 0;
int8 scr=0;
float tension;
float tension1;
float courant;
char string[40];
char string2[25];
char station_id[5] = "km13";
float temporaire;
signed int32 lecture;
int i;
#separate
void init_lcd();
#separate
void eclk();
#separate
void printl(char string[], int line, int pos);
#separate
void prints();
#separate
void creer_trame();
#INT_RDA
void communication();
#INT_EXT
void bouton();
#INT_TIMER1
void acq();
void main()
{
ON = 0;
// Configuration des ports
SET_TRIS_A(0XFF); //Ports analog, tous en lecture
SET_TRIS_B(0x81); //Seulement B7 en lecture, bouton.
SET_TRIS_C(0x80); //Rx en entrée
SET_TRIS_D(0x00); //Port pour le LCD, tous en sortie
//Activation des ports analogiques
setup_port_a(ALL_ANALOG);
setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
ext_int_edge(L_TO_H);
//Desactivation des Interupt
//disable_interrupts(GLOBAL);
//Initialisation du LCD
init_lcd();
//Initialisation du timer
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1); //65536/(0.01/(4/20M)) où 0.01=overflow aux 10 millisecondes
//Activation des interruptions
enable_interrupts(INT_EXT);
enable_interrupts(INT_RDA);
enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);
//Pour le fun
strcpy(string, " Project ");
printl(string, 1,1);
printf("\f");
printf("%s\n\r", string);
while(1)
{
if(flag_acq)
{
compteur_int++;
if (compteur_int==38)
COM=1;
if (compteur_int==76)
{
sec++; //incrementer les secondes
if(sec == 60)
{ min ++;
sec = 0;
}
else if(min == 60)
{ hr++;
min = 0;
}
COM=0;
set_adc_channel(0);
delay_ms(1);
lecture = read_adc(); //0.0554865
tension1 = lecture * 0.055486;
set_adc_channel(1);
delay_ms(1);
lecture = read_adc();
courant = 512-lecture;
courant = courant * .0554863;
set_adc_channel(2);
delay_ms(1);
lecture = read_adc();
tension = lecture * 0.488281;
set_adc_channel(3);
delay_ms(1);
temporaire = read_adc()*0.027832; //5*5.7/1024
compteur_int=0;
}
prints();
flag_acq=0;
}
//Si le flag de communication est à 1
else if(flag_com)
{
if(!strcmp(string, station_id))
{
creer_trame();
printf("%s", string);
}
else
printf("identification non reconnue!!\n\r");
SERIAL = 0;
ON = 1;
flag_com=0;
}
else if(flag_btn)
{
printf("bouton\n\r");
scr++;
flag_btn=0;
}
}
}
//Secondary functions
#separate
void init_lcd()
{
delay_ms(20);
LCD_RS = 0;
delay_us(120);
TEXTE = 0b00001100;
eclk();
delay_us(120);
TEXTE = 0b00111000; //2 lignes, 5X7, 8bits
eclk();
}
#separate
void eclk()
{
int i;
delay_us(1);
LCD_E =1 ;
delay_us(1);
LCD_E = 0;
}
#separate
void printl(char stringa[], int line, int pos)
{
int DD_RAM;
int k;
int lenght;
lenght = strlen(stringa);
if (line == 1)
DD_RAM = pos - 1;
else
DD_RAM = 0x40 + pos-1;
//Setter la position
LCD_RS = 0;
TEXTE = 0b10000000 | DD_RAM; //ou binaire
eclk();
//Ecriture de la string
LCD_RS = 1;
for (k=0; k<25-pos; k++)
{
if(k<lenght)
{
TEXTE = stringa[k];
delay_us(30);
}
else
{
TEXTE = ' ';
delay_us(30);
}
eclk();
}
}
#separate
void prints()
{
sprintf(string2, " %d:%d:%d ", hr, min, sec);
printl(string2, 1,1);
if(scr == 1)
{
sprintf(string2, "Temp1 %2.0fC Temp2 %2.0fC", tension, tension1);
printl(string2, 2,1);
}
else if(scr == 2)
{
sprintf(string2, "Courant:%2.1fA", courant);
printl(string2, 2,1);
}
else if(scr == 3)
{
sprintf(string2, "Tension: +/- %2.1f Volts", temporaire);
printl(string2, 2,1);
}
/* else if(scr == 4)
{
sprintf(string2, " Station %s ", station_id);
printl(string2, 2,1);
}*/
else
scr=0;
}
#separate
void creer_trame()
{
sprintf(string, "'%2.1f', '%2.1f', '%2.1f', '%2.1f'", tension, tension1, courant, temporaire);
}
/*****************************************************************************
******************************************************************************
*** INTERRUPTIONS ***
******************************************************************************
*****************************************************************************/
#INT_RDA
void communication()
{
gets(string);
SERIAL = 1;
ON = 0;
flag_com=1;
}
#INT_EXT
void bouton()
{
SERIAL = 1;
flag_btn=1;
delay_ms(10);
SERIAL = 0;
}
#INT_TIMER1
void acq()
{
flag_acq=1;
} |
|
|
Ttelmah Guest
|
|
Posted: Thu Jun 10, 2004 7:00 am |
|
|
Lots of little 'comments', that could cause problems.
1) SETUP_ADC_PORTS, and SETUP_PORT_A, are different names for the _same_ function. You are duplicating the initialisation here.
2) You are setting TRIS for all the ports, but not using FAST_IO. The compiler will be overriding your TRIS settings.
3) Use getc, not gets in the RDA handler. You are effectively 'hanging' the code inside the RDA handler, till the EOS character comes. Use getc, store the character into a string, and return. Set your flag when the 'end' character is seen. As it stands, when data starts to be received, the timer interrupt will be stopped, until the string is complete...
4) The timer interrupt is not at 10mSec intervals. With a 20MHz clock, you are interrupting at 20000000/(4*65536) times/sec = 76 times per second (approx) = 13mSec.
5) Clear the edge interrupt, after setting which edge you want to use, and before enabling the interrupt. Otherwise, changing the edge, can lead to a spurious interrupt.
I suspect the main problem is using gets, which is probably hanging the whole code inside the seral receive handler.
Best Wishes |
|
|
|
|
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
|