Realiser une tempo sur microcontrolleur
Bonjour,
Est ce que quelqu'un a du code pour realiser une tempo sur microcontrolleur hc12.
genre:
/* permet d'attendre n secondes */
void Attendre (int n);
j'ai un code mais il marche pas et me fait bugger mon micro, mais je sais pas pkoi! :?
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| void CycleWait(unsigned int delay)
{
int Endt;
Endt = TCNT+delay; /* Time (125ns cycles) to wait */
while((Endt-(int)TCNT)>0); /* wait */
}
//******** SecWait ***************
// wait 1 second, using TCNT
void SecWait(unsigned int sec)
{
unsigned int i,j;
for(i=0; i<sec; i++){
for(j=0; j<1000; j++){
CycleWait(8000); // 1ms wait
}
}
} |
Merci a tous