|
发表于 2012-2-18 19:49:06
|
显示全部楼层
usually, you don't need that precise of a delay: something in the rough neighbor would typically work.
plus, if you have interrupt, your delay routines will produce different actual delays.
"num1 = Fcy/40322; "
I would redefine 40322 so that it can be easily changed when you move the routine to a different chip / architecture.
" while(--num1); "
this will create a problem when num1 is calculated to be 0 - from very low Fcy for example. I would use "while (num1--) continue;" instead.
I use a similar approach, except that mine was built up, from delay(cycles); to delay_us(us) which calls delay() and then delay_ms(ms) which calls delay_us(), all of which is based on pre-defined F_CPU.
this allows the code to be fairly easily ported. |
|