English
Language : 

VMX1C1020 Datasheet, PDF (28/80 Pages) List of Unclassifed Manufacturers – Versa Mix 8051 Mixed-Signal MCU
VMX51C1020
The following table provides a summary of the
Interrupt control and Flag bits associated with
the Timer0 and Timer1 interrupts.
Bit Name
EA
T0IE
T1IE
TF0
TF1
Location
IEN0.7
IEN0.1
IEN0.3
TCON.5
TCON.7
Description
General interrupt control bit
0, Interrupt Disabled
1, Enabled Interrupt active
Timer 0 Overflow Interrupt
1 = Enable
0 = Disable
Timer 1 Overflow Interrupt
1 = Enable
0 = Disable
TF0 Flag is set when Timer 0
Overflow occurs.
Automatically cleared when
Timer 0 interrupt is serviced.
This flag can also be cleared
by software
TF1 Flag is set when Timer 1
Overflow occurs.
Automatically cleared when
Timer 1 interrupt is serviced.
This flag can also be cleared
by software
Setting Up Timer0 Example
In order to use Timer0, the first step is to setup
the interrupt and then configure the module and
this is described in the following code example.
Sample C code to set up Timer 0:
//---------------------------------------------------------------------------
// Sample C code to setup Timer 0
//---------------------------------------------------------------------------
// (…) PROGRAM INITIALIZATION OMITTED
AT 0X0100 VOID MAIN(VOID){
// INTERRUPT + TIMER 0 SETUP
IEN0 |= 0X80;
IEN0 |= 0X02;
TMOD = 0X02;
TCON = 0X10;
// ENABLE ALL INTERRUPTS
// ENABLE INTERRUPT TIMER 0
// TIMER 0 MODE 2
// START TIMER 0
DO{}WHILE(1);
//WAIT FOR TIMER 0 INTERRUPT
}//END OF MAIN()
//---------------------------------------------------------------------------
// INTERRUPT FUNCTION
VOID INT_TIMER_0 (VOID) INTERRUPT 1
{
IEN0 &= 0X7F;
// DISABLE ALL INTERRUPTS
/*------------------------*/
/*Put Interrupt code here*/
/*------------------------*/
IEN0 |= 0x80;
// Enable all interrupts
}
//---------------------------------------------------------------------------
Setting Up Timer1 Example
The following code provides an example of how
to configure Timer1 (first part of the code is the
interrupt setup and module configuration
whereas the second part is the interrupt
function).
Example1: Delay function
//-------------------------------------------------------------------------
// Sample C code using the Timer 1: Delay function
//-------------------------------------------------------------------------
VOID DELAY1MS(UNSIGNED CHAR DLAIS) {
IDATA UNSIGNED CHAR X=0;
TMOD = 0X10;
TL1 = 0X33;
TH1 = 0XFB;
;//TIMER1 RELOAD VALUE FOR
TCON = 0X40;
WHILE (DLAIS > 0)
{
DO{
X=TCON;
X= X&0X80;
}WHILE(X==0);
TCON = TCON&0X7F;
TL1 = 0X33;
TH1 = 0XFB;
;//TIMER1 RELOAD VALUE FOR
DLAIS = DLAIS-1;
}
}//END OF DELAY 1MS
Example 2: Timer1 interrupt example
//-------------------------------------------------------------------------
// Sample C code using the Timer 1: Interrupt
//-------------------------------------------------------------------------
// (…) PROGRAM INITIALIZATION OMITTED
at 0xo100 void main(void){
// TIMER 1 setup
IEN0 |= 0x80;
IEN0 |= 0x08;
TMOD = 0x20;
TCON = 0x40;
TL1 = 0xFC;
// Enable all interrupts
// Enable interrupt Timer1
// Timer 1 mode 2
// Start Timer 1
// Timer1 offset
do {
}while(1);
//Wait Timer 1 interrupt
}//end of main() function
//----------------------------------------
// Timer 1 Interrupt function
//----------------------------------------
void int_timer_1 (void) interrupt 3
{
IEN0 &= 0x7F;
// Disable all interrupts
/* Put Interrupt code here*/
IEN0 |= 0x80;
}
// Enable all interrupts
_________________________________________________________________________________________________
www.ramtron.com
page 28 of 80