/* =========================================================================== */
/* Project:        Ex1 */
/* File:           Ex1main.c */
/* Organization:   Raisonance */
/* Author:         Lionel  (initial version generated by RBuilder) */
/* Date:           4/12/2006 */
/* =========================================================================== */

#include "ST7lib_config.h"
#include <stdio.h>


/* --------------------------------------------------------------------------- */
/* Function:       PeriphInit */
/* Purpose:        Periph configuration at RESET */
/* Date:           4/12/2006 */
/* --------------------------------------------------------------------------- */
void PeriphInit ( void ) {
   
   /* I/O Port initialization */
   IO_Init();
   IO_Input(IO_PULL_UP_IT, IO_PORT_A, 0x55);
   IO_Input(IO_PULL_UP_IT, IO_PORT_B, 0x05);
   IO_Input(IO_FLOATING_IT, IO_PORT_B, 0xFA);
   IO_Output(IO_PUSH_PULL, IO_PORT_F, 0xFF);  
   
}/* end of  PeriphInit */

/* --------------------------------------------------------------------------- */
/* Function:       main() */
/* Purpose:        main routine */
/* Date:           4/12/2006 */
/* --------------------------------------------------------------------------- */
void main ( void ) {
   
   unsigned char readval=0;
   /* Configure the internal peripherals */
   PeriphInit();

   while ( 1 )
   {
   	/* read SW1 to SW4 */
		readval  = IO_Read(IO_PORT_A);     
		readval &= 0x55;
		if(readval&0x04)
		{
			readval |= 0x02;
			readval &= 0xFB;
		}
		if(readval&0x10)
		{
			readval |= 0x04;
			readval &= 0xEF;
		}
		if(readval&0x40)
		{
			readval |= 0x08;
			readval &= 0xBF;
		}	
		
		/* read BT5 and BT6 */
		readval |= ( (IO_Read(IO_PORT_B)<<4) & 0x50 );
		
		if(readval&0x40)
		{
			readval |= 0x20;
			readval &= 0xBF;
		}			
		
		readval |= 0xC0;
   	IO_ByteWrite(IO_PORT_F, readval );   /* Write Port F */
	}
	
}/* end of main */

