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.
Hi,
i am a student and needs some help. Can someone help solve some of my doubts?
Hmm..may i know what does it means by SYSCLK/12/10? How can i go about calculating the timer values using the SYSCLK/12/10 if i want to use the codes below to make the LED blink at 1Hz?
Thanx=)
//------------------------------------------------------------------------------------ // MAIN Routine //------------------------------------------------------------------------------------ void main (void) { // disable watchdog timer WDTCN = 0xde; WDTCN = 0xad; SFRPAGE = CONFIG_PAGE; // Switch to configuration page PORT_Init (); SFRPAGE = TMR3_PAGE; // Switch to Timer 3 page Timer3_Init (SYSCLK /120/10); // Init Timer3 to generate interrupts // at a 10 Hz rate. EA = 1; // enable global interrupts SFRPAGE = LEGACY_PAGE; // Page to sit in for now while (1) { // spin forever } } //------------------------------------------------------------------------------------ // PORT_Init //------------------------------------------------------------------------------------ // // Configure the Crossbar and GPIO ports // void PORT_Init (void) { XBR2 = 0x40; // Enable crossbar and weak pull-ups P1MDOUT |= 0x40; // enable P1.6 (LED) as push-pull output } //------------------------------------------------------------------------------------ // Timer3_Init //------------------------------------------------------------------------------------ // // Configure Timer3 to auto-reload and generate an interrupt at interval // specified by <counts> using SYSCLK/12 as its time base. // // void Timer3_Init (int counts) { TMR3CN = 0x00; // Stop Timer3; Clear TF3; // use SYSCLK/12 as timebase RCAP3 = -counts; // Init reload values TMR3 = 0xffff; // set to reload immediately EIE2 |= 0x01; // enable Timer3 interrupts TR3 = 1; // start Timer3 } //------------------------------------------------------------------------------------ // Interrupt Service Routines //------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------ // Timer3_ISR //------------------------------------------------------------------------------------ // This routine changes the state of the LED whenever Timer3 overflows. // // NOTE: The SFRPAGE register will automatically be switched to the Timer 3 Page // When an interrupt occurs. SFRPAGE will return to its previous setting on exit // from this routine. // void Timer3_ISR (void) interrupt 14 { TF3 = 0; // clear TF3 LED = ~LED; // change state of LED }
Hmm..the SYSCLK is defined as 3062500Hz.. Thanx=)i will go and check that out..