/*   
*******************************************************************************
COPYRIGHT 2002 STMicroelectronics
Source File Name : main.c
Group            : IPSW, CMG - IPDF
Author           : MCD Application Team
Date First Issued: 21/03/2002
********************************Documentation**********************************
General Purpose -Top Level file.This file calls the functions, written in 
     different source directories of ST7 Library.
     -This will run an application including TBU and ADC conversion on channel0
     Both applications will run simultaneously.
     -IO library is also called.
*******************************************************************************     
********************************RevisionHistory********************************
_______________________________________________________________________________
Date : 21/03/2002              	Release:  1.0
Date : 22/09/2003              	Release:  2.0
******************************************************************************/     
#include "ST7lib_config.h"                               /*Configuration File*/ 

/******************************************************************************
                          MAIN APPLICATION BEGINS
******************************************************************************/
void TBU_IT_Routine(void);
void main (void);
void main (void)                    
{                                    
    /*Declaration of variables*/
    int ADC_Data;               
    unsigned char Channel_No = 0;
    /*IO library is called to change the staus of the perticualr port pin and
    set Port A, pin 0 as floating input for ADC*/
    IO_Init(); 
    IO_Output (IO_PUSH_PULL, IO_PORT_B, (unsigned char)IO_PIN_0 |((unsigned 
                                     char)IO_PIN_6 | (unsigned char)IO_PIN_7));
    IO_Write(IO_PORT_B, (unsigned char)IO_PIN_0 |((unsigned char) IO_PIN_6 | 
                                       (unsigned char)IO_PIN_7), IO_DATA_HIGH);
    IO_Input (IO_FLOATING,IO_PORT_A,IO_PIN_0);

    /*TBU library called with interrupt initialization with clock fcpu/16*/            
    TBU_Init((unsigned char)TBU_DEFAULT | (unsigned char)TBU_IT_ENABLE);
    TBU_SetPrescCount8(TBU_Prescvalue_16,(unsigned char)224);
    TBU_Enable();
    EnableInterrupts;

    /*ADC library is called with channel0, ADC will run continuously with TBU*/
    while(1)
    {    
        ADC_Init(ADC_SPEED);
        ADC_Select_Channel(Channel_No);
        ADC_Enable();
        
        while (!(ADC_Test_Conversn_Complete()));
        ADC_Data = ADC_Conversn_Read();
    }	 	
}

/******************************************************************************\
                                  END OF MAIN
******************************************************************************/

/******************************************************************************
Interrupt Subroutine for EI2
******************************************************************************/
#ifdef _HIWARE_                                  /* test for HIWARE Compiler */
#pragma TRAP_PROC SAVE_REGS            /* additional registers will be saved */
#else
#ifdef _COSMIC_                                  /* test for Cosmic Compiler */
@interrupt                                      /* Cosmic interrupt handling */
#else
#error"Unsupported Compiler!"                 /* Compiler Defines not found! */
#endif
#endif

void TBU_IT_Routine (void)
{
    TBU_ClearOverflow();      
    PBDR ^= 0x01;     /* To check the Delay in caling the interrupt          */
} 
	

/**** (c) 2002   STMicroelectronics *************************** END OF FILE **/











