
VMX51C1020
_________________________________________________________________________________________________
www.ramtron.com
page 28 of 80
The following table provides a summary of the
Interrupt control and Flag bits associated with
the Timer0 and Timer1 interrupts.
Bit Name
Location
Description
EA
IEN0.7
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
T0IE
IEN0.1
T1IE
IEN0.3
TF0
TCON.5
TF1
TCON.7
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
0
X
0100
VOID MAIN
(
VOID
){
//
I
NTERRUPT
+
TIMER
0
SETUP
IEN0
|=
0
X
80;
//
E
NABLE ALL INTERRUPTS
IEN0
|=
0
X
02;
//
E
NABLE INTERRUPT
T
IMER
0
TMOD
=
0
X
02;
//
T
IMER
0
M
ODE
2
TCON
=
0
X
10;
//
START
T
IMER
0
DO
{}
WHILE
(1);
//
WAIT FOR TIMER
0
INTERRUPT
}//
END OF MAIN
()
//---------------------------------------------------------------------------
//
I
NTERRUPT FUNCTION
VOID INT
_
TIMER
_0
(
VOID
)
I
NTERRUPT
1
{
IEN0
&=
0
X
7F;
//
D
ISABLE 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
whereas the second part is the interrupt
function).
Example1: Delay function
//-------------------------------------------------------------------------
// Sample C code using the Timer 1: Delay function
//-------------------------------------------------------------------------
VOID DELAY
1
MS
(
UNSIGNED CHAR DLAIS
)
{
IDATA UNSIGNED CHAR X
=0;
TMOD
=
0
X
10;
TL1
=
0
X
33;
TH1
=
0
X
FB;
;//
TIMER
1
RELOAD VALUE FOR
TCON
=
0
X
40;
WHILE
(
DLAIS
>
0)
{
DO
{
X
=TCON;
X
=
X
&0
X
80;
}
WHILE
(
X
==0);
TCON
=
TCON&0
X
7F;
TL1
=
0
X
33;
TH1
=
0
X
FB;
;//
TIMER
1
RELOAD VALUE FOR
DLAIS
=
DLAIS
-1;
}
}//
END OF DELAY
1
MS
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;
// Enable all interrupts
IEN0 |= 0x08;
// Enable interrupt Timer1
TMOD = 0x20;
// Timer 1 mode 2
TCON = 0x40;
// Start Timer 1
TL1 = 0xFC;
// 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
}
module
configuration