/*
*******************************************************************************
* COPYRIGHT 2002 STMicroelectronics
* Source File Name : main.c                      
* Grou p           : IPSW,CMG-IPDF
* Author           : MCD Application Team
* Date First Issued: 11/3/2002      
********************************Documentation**********************************
* General Purpose - This file shows the application example for generation   
                     of PWM using AutoReload Timer in ST7LITE0 device.                                   
********************************RevisionHistory********************************
_______________________________________________________________________________
Date : 11/3/2002       Release:1.0 
Date : 23/9/2003       Release:2.0
       28/04/04        Release:2.1
                1.Changed for MISRA compliance		   
*******************************************************************************/
#include "ST7lib_config.h"                               /*  Select ST7FLITE0 */

/* prototype declaration */
void LART_OVF_IT_Routine(void);
void main(void);

static unsigned int count;

void main(void)                
{ 

    IO_Output(IO_PUSH_PULL,IO_PORT_B,IO_PIN_3);/* Port PB3 as pushpull output */
    /* Select Fcpu as counter clock & enable overflow interrupts              */ 
    LART_Init( ((unsigned char)LART_COUNTER_CLK_FCPU | 
                                          (unsigned char)LART_OVF_IT_ENABLE  )); 
    /* Clear I bit in CC register */
    EnableInterrupts
    /* Load ATR and DCR to get PWM signal of 10 KHz and duty cycle of 30%     */
    /* Generate PWM at PWM0 pin */
    LART_PWM_Mode((unsigned int)0xCE0, LART_POLARITY_0,(unsigned int)0xDD0);  

    while(1);                                                 
} 


/* ----------------------------------------------------------------------------
 ROUTINE NAME : LART_OVF_IT_Routine
 INPUT        : None
 OUTPUT       : None 
 DESCRIPTION  : Interrupt service routine for Overflow interrupt
 COMMENTS     : This gets automatically executed when OVF interrupt of the 
                LART is enabled. If  the same functions are called in the
                main Tree and the interrupt Tree, the function Re-entrant error 
                occurs in case COSMIC compiler is used with models other than 
                stack models.
                For configuring the port pins,I/O library is used. 
 -----------------------------------------------------------------------------*/
#ifdef _HIWARE_                               /* Test for Metrowerks 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 LART_OVF_IT_Routine(void)
{ 
    unsigned char Temp;

    LART_Clear_Flag(LART_FLAG_OVF);                    /*   Call to clear OVF */
    count++;
    if(count == 10000)
    {
        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***/        
