Hi,
Firstly sorry for my English.
I discover pic programing with PIC18F4520
I would like to make an USART receive interruption, but I have a problem, my code is:
int Bf3_Gestion_Etat_Bouton(void) // gestion allumage led
{
if (PortA.RA0 == 0)
{
LATA.LATA4=1;
return 1;
}
else
{
LATA.LATA4=0;
return 0;
}
}
int Ash3_Gestion_Etat_Bouton(void) // gestion allumage led
{
if (PortA.RA1 == 0)
{
LATA.LATA5=1;
return 1;
}
else
{
LATA.LATA5=0;
return 0;
}
}
int Ph3_Gestion_Etat_Bouton(void) // gestion allumage led
{
if (PortA.RA2 == 0)
{
LATE.LATE0=1;
return 1;
}
else
{
LATE.LATE0=0;
return 0;
}
}
int Aux_Gestion_Etat_Bouton(void) // gestion allumage led
{
if (PortA.RA3 == 0)
{
LATE.LATE1=1;
return 1;
}
else
{
LATE.LATE1=0;
return 0;
}
}
int BouttonControl(void) // gestion allumage led
{
int a,b,c,d,sum;
if(PORTA.RA0 == 0)a=1;
else a=0;
if(PORTA.RA1 == 0)b=10;
else b=0;
if(PORTA.RA2 == 0)c=100;
else c=0;
if(PORTA.RA3 == 0)d=1000;
else d=0;
sum= a+b+c+d;
return sum;
}
void Interrupt() iv 0x000008 ics ICS_AUTO {
PIE1.RCIE=0;
LATE.RE2 = 1 ; // to turn on indicator led
delay_ms(1000);
PIR1.RCIF=0;
RCSTA.RCIE=1;
}
void main() {
int a, b, c, d ;
char *text = "v";
ADCON0 = 0b00111100;
ADCON1 = 0b00001111;
TRISA = 0b11001111;
LATA = 0b00000000;
TRISB = 0b11000000;
TRISC = 0b10010100;
TRISD = 0b11111111;
TRISE = 0b000;
LATE = 0b000;
LATC = 0b01000011;
UART1_Init(9600);
delay_ms(500) ;
OSCCON.SCS1 =0;
OSCCON.SCS0= 0;
PIE1.RCIE= 1;
PIE1.TXIE= 0;
RCON.IPEN= 0;
INTCON.GIE= 1;
INTCON.PEIE= 1;
TXSTA.TXEN= 1;
RCSTA.SPEN = 1;
RCSTA.CREN= 1;
RCSTA.CREN= 1;
while(1)
{
LATE.RE2 = 0 ; // led d'indication interruption
a= Bf3_Gestion_Etat_Bouton();
b= Ash3_Gestion_Etat_Bouton();
c= Ph3_Gestion_Etat_Bouton();
d= Aux_Gestion_Etat_Bouton();
if(a == 1)
UART1_Write_Text(text);
}
}
when I execute the code, the interruption occurs correctly, the led turn on, after the interruption turns off correctly and the routine in the while continues its correct functioning. But it is impossible to contact another interruption. I read the datasheet and think that I understand the functioning of the interruption procedure, but it seems that I forget something. if someone can help me it will be cool.
Firstly sorry for my English.
I discover pic programing with PIC18F4520
I would like to make an USART receive interruption, but I have a problem, my code is:
int Bf3_Gestion_Etat_Bouton(void) // gestion allumage led
{
if (PortA.RA0 == 0)
{
LATA.LATA4=1;
return 1;
}
else
{
LATA.LATA4=0;
return 0;
}
}
int Ash3_Gestion_Etat_Bouton(void) // gestion allumage led
{
if (PortA.RA1 == 0)
{
LATA.LATA5=1;
return 1;
}
else
{
LATA.LATA5=0;
return 0;
}
}
int Ph3_Gestion_Etat_Bouton(void) // gestion allumage led
{
if (PortA.RA2 == 0)
{
LATE.LATE0=1;
return 1;
}
else
{
LATE.LATE0=0;
return 0;
}
}
int Aux_Gestion_Etat_Bouton(void) // gestion allumage led
{
if (PortA.RA3 == 0)
{
LATE.LATE1=1;
return 1;
}
else
{
LATE.LATE1=0;
return 0;
}
}
int BouttonControl(void) // gestion allumage led
{
int a,b,c,d,sum;
if(PORTA.RA0 == 0)a=1;
else a=0;
if(PORTA.RA1 == 0)b=10;
else b=0;
if(PORTA.RA2 == 0)c=100;
else c=0;
if(PORTA.RA3 == 0)d=1000;
else d=0;
sum= a+b+c+d;
return sum;
}
void Interrupt() iv 0x000008 ics ICS_AUTO {
PIE1.RCIE=0;
LATE.RE2 = 1 ; // to turn on indicator led
delay_ms(1000);
PIR1.RCIF=0;
RCSTA.RCIE=1;
}
void main() {
int a, b, c, d ;
char *text = "v";
ADCON0 = 0b00111100;
ADCON1 = 0b00001111;
TRISA = 0b11001111;
LATA = 0b00000000;
TRISB = 0b11000000;
TRISC = 0b10010100;
TRISD = 0b11111111;
TRISE = 0b000;
LATE = 0b000;
LATC = 0b01000011;
UART1_Init(9600);
delay_ms(500) ;
OSCCON.SCS1 =0;
OSCCON.SCS0= 0;
PIE1.RCIE= 1;
PIE1.TXIE= 0;
RCON.IPEN= 0;
INTCON.GIE= 1;
INTCON.PEIE= 1;
TXSTA.TXEN= 1;
RCSTA.SPEN = 1;
RCSTA.CREN= 1;
RCSTA.CREN= 1;
while(1)
{
LATE.RE2 = 0 ; // led d'indication interruption
a= Bf3_Gestion_Etat_Bouton();
b= Ash3_Gestion_Etat_Bouton();
c= Ph3_Gestion_Etat_Bouton();
d= Aux_Gestion_Etat_Bouton();
if(a == 1)
UART1_Write_Text(text);
}
}
when I execute the code, the interruption occurs correctly, the led turn on, after the interruption turns off correctly and the routine in the while continues its correct functioning. But it is impossible to contact another interruption. I read the datasheet and think that I understand the functioning of the interruption procedure, but it seems that I forget something. if someone can help me it will be cool.