Elektronique - Cours d'électronique

Interruption pour le PIC 16F628

avatar par défaut
Editer Supprimer
# Le 14/11/2014 à 20h26
Bonjour,
Je tente de faire marcher les interruptions sur un PIC 16F628, mais pour l'instant sans succès.
J'utilise MPLAB et un PICKIT 3.
J'ai tenté tout d'abord d'adapter à un 16F628 l'exemple donné ici :
http://microchip.wikidot.com/faq:31
Mais sans succès : ça compile, et programme, mais le PIC ne semble pas allumer la pin en fonction.
J'ai ensuite tenté d'utiliser le programme proposé ici en exemple 1 :
http://picguides.com/beginner/timers.php
Mais le résultat est le même : ça compile, ça programme, mais le PIC n'a pas de signal sur les PINs.
Avec le même montage, j'ai fait plusieurs HELLO WORD donc je suis sûr d'avoir tout branché comme il se doit. L'alimentation est fait avec un régulateur de tension, dont je contrôle la sortie avec un voltmètre, donc je suis sûr qu'elle est correcte.

Je vous met ici le code de la deuxième version adaptée :
<code>


//#define _XTAL_FREQ 4000000
//set the configuration bits: internal OSC, everything off except MCLR
#pragma config FOSC = INTOSCIO // Oscillator Selection bits (INTOSC oscillator: I/O function on RA6/OSC2/CLKOUT pin, I/O function on RA7/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 = ON // RA5/MCLR/VPP Pin Function Select bit (RA5/MCLR/VPP pin function is MCLR)
#pragma config BOREN = OFF // Brown-out Detect Enable bit (BOD enabled)
#pragma config LVP = ON // Low-Voltage Programming Enable bit (RB4/PGM pin has PGM function, low-voltage programming enabled)
#pragma config CPD = OFF // Data EE Memory Code Protection bit (Data memory code protection off)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)

#include <xc.h>

int main(int argc, char** argv) {
TRISA = 0xFF; //set all digital I/O to inputs
TRISB = 0xFF;

TRISBbits.TRISB7 = 0; //set RB7 as an output


///////////////////
// Timer 0 Setup //
///////////////////
OPTION_REGbits.PSA = 0; //Prescaler assigned to Timer 0 (other option is to
//the Watchdog timer (WDT))

OPTION_REGbits.PS = 0b111; //Set the prescaler to 1:256
OPTION_REGbits.T0CS = 0; //Use the instruction clock (Fcy/4) as the timer
//clock. Other option is an external oscillator
//or clock on the T0CKI pin.
PORTBbits.RB3 = 0;
PORTBbits.RB3 = 1;
PORTB = 0x0F;//1111 => RB0 à RB3

///////////////////////
// Main Program Loop //
///////////////////////
while(1)
{
INTCONbits.T0IF = 0; //Clear the Timer 0 interrupt flag
TMR0 = 0; //Load a value of 0 into the timer
INTCONbits.T0IE = 1; //Enable the Timer 0 interrupt

while(INTCONbits.T0IF == 0) //Wait for the interrupt to occur. This
{ //happens when the TMR0 register rolls over.
NOP();
}

PORTBbits.RB3 = -PORTBbits.RB3; //Toggle the LED
}

return 0;
}

</code>

Je vous remercie par avance de vos réponses, même si ce ne sont que des idées sans solutions à proprement parler :)

Cordialement,
Willy
Modifié le 24/04/2024 à 19h27
avatar par défaut
Editer Supprimer
# Le 15/11/2014 à 08h13
Pas d'idée ? :´(