Bonjour,
Je me met à la programmation de PIC. J'essaie de maitriser les interruptions.
J'essaie de faire clignoter une led avec les interruptions du timer TMR0 du 12F683.
ça ne marche pas et j'ai un message qui me précise que la fonction interrupt n'est jamais appelée.
Quelqu'un saurait-il me dire ce qui cloche (j'ai essayé un tas de trucs en vain. D'avance merci.
Le programme:
#include <xc.h>
#include <pic12f683.h>
// Définition de la fréquence du crystal pour la fonction __delay_ms(x);
#define _XTAL_FREQ 31000
#define led GP4
// CONFIG
#pragma config FOSC = INTOSCIO // Oscillator Selection bits (INTOSCIO oscillator: I/O function on RA4/OSC2/CLKOUT pin, I/O function on RA5/OSC1/CLKIN)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = OFF // MCLR Pin Function Select bit (MCLR pin function is digital input, MCLR internally tied to VDD)
#pragma config CP = OFF // Code Protection bit (Program memory code protection is disabled)
#pragma config CPD = OFF // Data Code Protection bit (Data memory code protection is disabled)
#pragma config BOREN = OFF // Brown Out Detect (BOR disabled)
#pragma config IESO = OFF // Internal External Switchover bit (Internal External Switchover mode is disabled)
#pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enabled bit (Fail-Safe Clock Monitor is disabled)
#pragma interrupt
void interrupt () {
if ((INTCONbits.T0IF == 1) && (INTCONbits.T0IE == 1))
{
TMR0 = 16;
led =~ led;
INTCONbits.T0IF = 0;
}
}
void main() {
ANSEL = 0b00000000;
TRISIO = 0b00000000;
OSCCON = 0b00000111;
//interruptions
INTCON = 0b00100000;
// timer
OPTION_REGbits.T0CS = 0;
OPTION_REGbits.T0SE = 0;
OPTION_REGbits.PSA = 0;
OPTION_REGbits.PS2 = 1;
OPTION_REGbits.PS1 = 0;
OPTION_REGbits.PS0 = 0;
TMR0 = 16; // le timer0 doit contenir ce préchargement pour avoir 1s
while (1) {
}
}
Je me met à la programmation de PIC. J'essaie de maitriser les interruptions.
J'essaie de faire clignoter une led avec les interruptions du timer TMR0 du 12F683.
ça ne marche pas et j'ai un message qui me précise que la fonction interrupt n'est jamais appelée.
Quelqu'un saurait-il me dire ce qui cloche (j'ai essayé un tas de trucs en vain. D'avance merci.
Le programme:
#include <xc.h>
#include <pic12f683.h>
// Définition de la fréquence du crystal pour la fonction __delay_ms(x);
#define _XTAL_FREQ 31000
#define led GP4
// CONFIG
#pragma config FOSC = INTOSCIO // Oscillator Selection bits (INTOSCIO oscillator: I/O function on RA4/OSC2/CLKOUT pin, I/O function on RA5/OSC1/CLKIN)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = OFF // MCLR Pin Function Select bit (MCLR pin function is digital input, MCLR internally tied to VDD)
#pragma config CP = OFF // Code Protection bit (Program memory code protection is disabled)
#pragma config CPD = OFF // Data Code Protection bit (Data memory code protection is disabled)
#pragma config BOREN = OFF // Brown Out Detect (BOR disabled)
#pragma config IESO = OFF // Internal External Switchover bit (Internal External Switchover mode is disabled)
#pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enabled bit (Fail-Safe Clock Monitor is disabled)
#pragma interrupt
void interrupt () {
if ((INTCONbits.T0IF == 1) && (INTCONbits.T0IE == 1))
{
TMR0 = 16;
led =~ led;
INTCONbits.T0IF = 0;
}
}
void main() {
ANSEL = 0b00000000;
TRISIO = 0b00000000;
OSCCON = 0b00000111;
//interruptions
INTCON = 0b00100000;
// timer
OPTION_REGbits.T0CS = 0;
OPTION_REGbits.T0SE = 0;
OPTION_REGbits.PSA = 0;
OPTION_REGbits.PS2 = 1;
OPTION_REGbits.PS1 = 0;
OPTION_REGbits.PS0 = 0;
TMR0 = 16; // le timer0 doit contenir ce préchargement pour avoir 1s
while (1) {
}
}