// PIC18F serie : il faut timer0 sur 16 bits
// delais pour FOSC=16Mhz
void Delay_uS(unsigned int x);
void Delay_mS(unsigned int cnt);
void Delay_1S(void);
void Delay_uS(unsigned int x)
{unsigned int y;
y=x;
while(--y != 0);
}
void Delay_mS(unsigned int cnt)
{
#ifdef DEBUG
return;
#else
INTCONbits.TMR0IE=0; // no interrupt
T0CON=0b00000001; // Timer OFF, 16bits, internal, prescaler=1:4
TMR0H=0xFC; //hi(64537); // 1.0mS avec 1:4
TMR0L=0x19; //lo (65537);
while(cnt>0)
{
T0CONbits.TMR0ON=1;
while(INTCONbits.TMR0IF == 0); // wait over
INTCONbits.T0IF=0;
cnt--;
TMR0H=0xFC; //hi(64537); // 1.0mS avec 1:4
TMR0L=0x19; //lo (65537);
}
T0CON=0;
#endif
}
void Delay_1S(void)
{
INTCONbits.TMR0IE=0; // no interrupt
T0CON=0b00000111; // Timer OFF, 16bits, internal, prescaler=1:256
TMR0H=0xC2; //hi(49911); // 1.0 S avec 1:256
TMR0L=0xF7; //lo (49911);
T0CONbits.TMR0ON=1;
while(INTCONbits.TMR0IF == 0); // wait over
INTCONbits.T0IF=0;
T0CON=0;
TMR0H=0xC2; //hi(49911); // 1.0 S avec 1:256
TMR0L=0xF7; //lo (49911);
}