Je veux créé une fonction DELAY() qui créé simplement un retard comme son nom l'indique.
Pour ça, j'utilise le TIMER0 d'un PIC18LF2620. Mais mon timer à un comportement bizarre. Enfaite il marche de temps en temps. Et quand il marche pas il fait ce genre de chose :
J'ai réduit le programme au maximum pour le poster ici. Ce que fait donc le bout de code ci dessous est qu'il inverse mes 2 DELAYs. J'ai l'impression que'il fait en premier DELAY(165, 171) ; puis AFF7SEG('1') ; puis DELAY(254, 199) ; puis AFF7SEG(' ') ; etc....
Je suis sur qu'il s'agit encore d'un problème évident, un oubli quelque part, mais là j'ai passé toute la soirée et je ne trouve pas.
Code : Tout sélectionner
#include <XC.h>
#include <stdio.h>
#include <stdlib.h>
#pragma config OSC = ECIO6
#pragma config FCMEN = OFF
#pragma config IESO = OFF
#pragma config BOREN = OFF
#pragma config MCLRE = OFF
#pragma config PBADEN = OFF
#pragma config WDT = OFF
#pragma config LVP = OFF
#pragma config STVREN = OFF
#define _XTAL_FREQ 8000000
void DELAY(unsigned char, unsigned char) ;
void AFF7SEG(unsigned char) ;
int main(int argc, char** argv)
{
TRISA = 0b10000000 ;
TRISB = 0b00111100 ;
TRISC = 0b00011000 ;
PORTA = 0b00000000 ;
PORTB = 0b00000000 ;
PORTC = 0b00000000 ;
T0CON = 0b00000101 ; // EN:0(pour l'instant) , 16bits:0 , F=CLK/4:0 , low-to-high_transition:0 , Prescalar:OUI:0 , PRE=1/64:101
PORTBbits.RB0=1 ; PORTBbits.RB1=1 ;
AFF7SEG('1') ; DELAY(165, 171) ; AFF7SEG(' ') ; DELAY(254, 199) ;
AFF7SEG('2') ; DELAY(165, 171) ; AFF7SEG(' ') ; DELAY(254, 199) ;
AFF7SEG('3') ; DELAY(165, 171) ; AFF7SEG(' ') ; DELAY(254, 199) ;
return (EXIT_SUCCESS);
}
void AFF7SEG(unsigned char n)
{
switch(n)
{
case '1' : PORTA = 0b01000001 ;
break ;
case '2' : PORTA = 0b00111011 ;
break ;
case '3' : PORTA = 0b01101011 ;
break ;
default : PORTA = 0b00000000 ;
}
}
void DELAY(unsigned char TMRH, unsigned char TMRL)
{
TMR0L = TMRL ;
TMR0H = TMRH ;
T0CONbits.TMR0ON = 1 ;
while(INTCONbits.TMR0IF==0) ;
T0CONbits.TMR0ON = 0 ;
INTCONbits.TMR0IF = 0 ;
}
/*
DELAY(254, 199) ; // 10ms +0,1600%
DELAY(165, 171) ; // 740ms +0,0000%
*/

