Bonjour,
J'ai du mal à modifier le programme en y réintégrant une instruction qu'il fasse les chose suivante :
Quand l'état actuel est différent de l'état précédent, et le latA 0 = 1 :
--> Lancer la durée X2
Quand l'état actuel est différent de l'état précédent, et le latA 0 = 0 :
--> Lancer la durée X2
J'ai commencé à traduire cela en C : (j : l'état)
--------------------------------------------------------
if (j = j-1) i =0;
else I = 1;
---------------------------------------------------------
Le programme est le suivant :
Code:#include <p18cxxx.h> #ifndef _XTAL_FREQ #define _XTAL_FREQ 4000000 /*4MHz*/ //#pragma config SOSCSEL = DIG /* Digital (SCLKI) mode*/ #pragma config FOSC = XT #pragma config PLLCFG = ON #pragma config PWRTEN = OFF #pragma config WDTEN = OFF unsigned char var[4] = {0x69,0x9B}; /*******************************/ void Int_Hight(void); #pragma code HighVector=0x08 void HighVector(void) { _asm goto Int_Hight _endasm } /*ooooooooooooooooooooooooooooo oooooo*/ #pragma code LowVector=0x18 void LowVector(void) { } #pragma code #pragma interrupt Int_Hight void Int_Hight(void){ static unsigned char i = 0; if(INTCONbits.TMR0IF){ /*==1*/ INTCONbits.TMR0IF=0; /*: Clr Overflow Interrupt Flag bit*/ LATB=LATB^0x01; TMR0L = var[i]; if (i <= 4) i++; else i = 0; } } void main (void){ TRISB=0b11111110; /* Bit 0 out*/ /**********************TIMER 0 INIT*******************************************/ T0CONbits.TMR0ON=1; /*: Timer0 On/Off Control bit 1 = Enables Timer0*/ T0CONbits.T08BIT=1; /*: Timer0 8-Bit/16-Bit Control bit 1 = Timer0 is configured as an 8-bit timer/counter 0 = Timer0 is configured as a 16-bit timer/counter*/ T0CONbits.T0CS=0; /*Timer0 Clock Source Select bit 1 = Transition on T0CKI pin input edge 0 = Interna clock (FOSC/4)*/ T0CONbits.PSA=0; /* Timer0 Prescaler Assignment bit 1 = Timer0 prescaler is not assigned; Timer0 clock input bypasses the prescaler 0 = Timer0 prescaler is assigned; Timer0 clock input comes from the prescaler output*/ T0CONbits.T0PS=0x100; /*<2:0>: Timer0 Prescaler Select bits 111 = 1:256 Prescale value 110 = 1:128 Prescale value 101 = 1:64 Prescale value 100 = 1:32 Prescale value 011 = 1:16 Prescale value 010 = 1:8 Prescale value 001 = 1:4 Prescale value 000 = 1:2 Prescale value*/ /*******************************************************************************/ INTCON2bits.TMR0IP=1; /*TMR0 Overflow Interrupt Priority bit 1 = High priority 0 = Low priority*/ INTCONbits.TMR0IF=0; /*: TMR0 Overflow Interrupt Flag bit 1 = TMR0 register has overflowed (must be cleared in software) 0 = TMR0 register did not overflow*/ INTCONbits.TMR0IE=1; /*: TMR0 Overflow Interrupt Enable bit 1 = Enables the TMR0 overflow interrupt 0 = Disables the TMR0 overflow interrupt*/ RCONbits.IPEN = 1; /*When IPEN = 1: 1 = Enables all high-priority interrupts 0 = Disables all interrupts*/ INTCONbits.GIE=1; /*Global Interrupt Enable bit When IPEN = 0: 1 = Enables all unmasked interrupts 0 = Disables all interrupts*/ TMR0L=0x00; /*Timer0 Register Low Byte*/ while(1){ /**************************************/ } }
-----