We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I'm trying to generate a square frequency with C51. After playing around for some hours with the debuger I Know which line is giving me a headacke. The important lines (in bold) of the algorithm are as follows
new_timer_reload = 0xfe9b; new_timer_reload_high = new_timer_reload >>8; TR0=1; //run timer 0 divisions=38; //The high poti is chossen to be divided in 7 steps (rough tunning) //not like the low poti low_poti=0x32; high_poti=0x39; } void main() { init(); while(1) { add_high=high_poti/divisions; //According to the value in high poti (0 to 255) //gives me the value I should add to TL0 (0 to 6) add_high=add_high<<8; // times 256 new_timer_reload = 0xfe9b+low_poti+add_high; new_timer_reload_high = new_timer_reload >> 8; } } #pragma RB(1) timer0() interrupt 1 using 1 { TR0=0; //stop the timer EAL=0; //disable all interrupts frequen_1=~frequen_1; //invert the signal TL0 = new_timer_reload; //load the new values TH0 = new_timer_reload_high; TR0=1; EAL=1; }
Using a union is quick & simple, but non-portable - as it relies upon the Compiler's internal data representation. Not necessarily bad, but you should be aware.