Discussion in "8051 Discussion Forum" started by    wounder    Feb 10, 2020.
Mon Feb 10 2020, 02:02 pm
#1
From below sample code for nuvoton 8051 timer0 mode 0, the isr interval is calculated is 1ms,
its work. but how can I calculate the minimum isr timer interval for 16mhZ frequency.?

#define TH0_INIT 0x1A //1.0ms@XTAL=16MH
#define TL0_INIT 0xEC

while loading these hex values gets 1ms Isr interval. I was tried 5-microsecond calculation for timer 0, but not get the correct 5uS interval.

#include "N76E003.h"
#include "Common.h"
#include "Delay.h"
#include "SFR_Macro.h"
#include "Function_define.h"



#define TH0_INIT        0x1A //1.0ms@XTAL=16MH
#define TL0_INIT        0xEC
#define TH1_INIT        0xD7 
#define TL1_INIT        0x0C


/************************************************************************************************************
*    TIMER 0 interrupt subroutine
************************************************************************************************************/
void Timer0_ISR (void) interrupt 1          //interrupt address is 0x000B
{
    TH0 = TH0_INIT;
    TL0 = TL0_INIT;    
   											// GPIO toggle when interrupt
}
/************************************************************************************************************
*    TIMER 1 interrupt subroutine
************************************************************************************************************/
//void Timer1_ISR (void) interrupt 3          //interrupt address is 0x001B
//{
//    TH1 = TH1_INIT;
//    TL1 = TL1_INIT;   
//  P12 = ~P12;																	// GPIO toggle when interrupt
//}
/************************************************************************************************************
*    Main function 
************************************************************************************************************/
void main (void)
{
	//TMOD = 0XFF;
	Set_All_GPIO_Quasi_Mode;
	TIMER0_MODE0_ENABLE;                        //Timer 0 and Timer 1 mode configuration
//	TIMER1_MODE0_ENABLE;
    
	clr_T0M;
	clr_T1M;
    
	TH0 = TH0_INIT;
	TL0 = TL0_INIT;
//	TH1 = TH1_INIT;
//	TL1 = TL1_INIT;
    
	set_ET0;                                    //enable Timer0 interrupt
	//set_ET1;                                    //enable Timer1 interrupt
	set_EA;                                     //enable interrupts
	
	set_TR0;                                    //Timer0 run
	//set_TR1;                                    //Timer1 run

  while(1)
	{
		
	
}
}


[ Edited Mon Feb 10 2020, 02:13 pm ]
Sat Feb 22 2020, 03:35 am
#2
Did you sort out your problem?

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

Bobbyerilar
Thu Mar 28 2024, 08:08 am
pb58
Thu Mar 28 2024, 05:54 am
Clarazkafup
Thu Mar 28 2024, 02:24 am
Walterkic
Thu Mar 28 2024, 01:19 am
Davidusawn
Wed Mar 27 2024, 08:30 pm
Richardsop
Tue Mar 26 2024, 10:33 pm
Stevencog
Tue Mar 26 2024, 04:26 pm
Bernardwarge
Tue Mar 26 2024, 11:15 am