/* ******************************************************************************* * COPYRIGHT 2002 STMicroelectronics * Source File Name : main.c * Group : IPSW,CMG-IPDF * Author : MCD Application Team * Date First Issued: 8/3/2002 ********************************Documentation********************************** * General Purpose - This file gives an example application programme for LITE Timer. ********************************RevisionHistory******************************** _______________________________________________________________________________ Date : 8/3/2002 Release : 1.0 Date :28/04/04 MISRA changes ******************************************************************************/ #include "ST7lib_config.h" /* select ST7FLITE0 */ #define LT_WDG
volatile unsigned int count; void main (void) { /* PB3 and PB1 as pushpull output */ IO_Output(IO_PUSH_PULL,IO_PORT_B,((unsigned char)IO_PIN_3 | (unsigned char)IO_PIN_1 )); /*Set Time base to 1ms,Input capture and Timebase interrupts enabled */ LT_Init(((unsigned char)LT_ICAP_IT_ENABLE|(unsigned char)LT_TB_IT_ENABLE)); /* Clear I bit in CC register */ EnableInterrupts /* Micro defined in the st7lib_config.h */ #ifdef LT_WDG /* Use of force watchdog reset */ LT_WDG_Enable(); LT_WDG_Reset(LT_FORCD_WDG_RESET); #endif /* LT_WDG_ */ while(1); /* For Testing only */ } /* Program end */
/****************************************************************************** Use of Input capture Interrupt service routine - User has to write this function and map the interrupt vector in .prm file in case of HIWARE or in vector_xxx.c in case of COSMIC. - An example of LED toggles at port PB1 is given, which will be executed when capture occurs. - This gets automatically executed if the ICAP interrupt of the LT is enabled. If the same functions are called in the main Tree and the interrupt Tree, the function Reentrant error occurs in case COSMIC compiler is used with models other than stack models. Functions description - The lt_hr.h is to be included when the actual hardware register are read to clear the flags.For configuring the port pins, I/O library is used. ******************************************************************************/
#ifdef _HIWARE_ /* Test for HIWARE Compiler */ #pragma TRAP_PROC SAVE_REGS /* Additional registers will be saved */ #else #ifdef _COSMIC_ /* Test for Cosmic Compiler */ @interrupt @nostack #else #error "Unsupported Compiler!" /* Compiler Defines not found! */ #endif #endif void LT_IC_IT_Routine(void) { unsigned char ICAP_Value, i; /* i = LTICR; Clear ICF */ LT_Clear_Flag(LT_FLAG_ICF); /* Call only to clear ICF */ ICAP_Value = LT_ICAP_Getvalue(); /* Get capture value and also clear ICF */ IO_Write (IO_PORT_B,IO_PIN_1,IO_DATA_HIGH); /* Turn ON LED at PB1 */ for ( i=0;i<=100;i++) /* Delay */ { Nop } IO_Write (IO_PORT_B,IO_PIN_1,IO_DATA_LOW); /* Turn OFF LED at PB1 */ }
/****************************************************************************** Use of TimebaseInterrupt service routine - User has to write this function and map the interrupt vector in .prm file in case of HIWARE or in vector_xxx.c in case of COSMIC. - An example of LED toggles after every 5 seconds is given.This routine is executed when overflow occurs (TBF=1). - This gets automatically executed when TBF interrupt of the LT is enabled. If the same functions are called in the main Tree and the interrupt Tree, the function Reentrant error occurs in case COSMIC compiler is used with models other than stack models. Functions description - The lt_hr.h is to be included when the actual hardware register are read to clear the flags.For configuring the port pins, I/O library is used. ******************************************************************************/ #ifdef _HIWARE_ /* Test for HIWARE Compiler */ #pragma TRAP_PROC SAVE_REGS /* Additional registers will be saved */ #else #ifdef _COSMIC_ /* Test for Cosmic Compiler */ @interrupt @nostack #else #error "Unsupported Compiler!" /* Compiler Defines not found! */ #endif #endif void LT_TB_IT_Routine(void) { unsigned char Temp; /* i = LTCSR; Clear ICF */ LT_Clear_Flag(LT_FLAG_TBF); /* Call only to clear TBF */ /* Routine up to the user */ count++; if(count == 5000) { Temp = IO_Read (IO_PORT_B ); /* TO Toggle PB3 */ if (Temp & 0x08) { IO_Write (IO_PORT_B,IO_PIN_3,IO_DATA_LOW);/* Turn OFF LED at PB3 */ } else { IO_Write (IO_PORT_B,IO_PIN_3,IO_DATA_HIGH);/* Turn ON LED at PB3 */ } count = 0; } } /******************** (c) 2002 ST Microelectronics *************END OF FILE**/