
/*@Title:    AVR-GCC test program for at90s2313
    Author:   eto
    Mail-to:  esoc@sfc.keio.ac.jp
    Date:     4/2001
    Purpose:  LED and SW
    Software: AVR-GCC  needed
    Hardware: ATS90S2313 

    PortD 3LED and PortB 2SW

    PB0=SW0
    PD0=LED0,PD1=LED1,PD2=LED2,PD3=LED3

*/

#include <io2313.h>
#include <iomacros.h>
#define  nop() asm volatile ("nop" ::)
typedef unsigned char  io8bit;

int main( void )
	{
	io8bit nowled, nowsw, i, j, k;

	outp(0xff,DDRD);					/* PD1-PD6 PortD for output */
	outp(0xfc,DDRB);					/* PB0-PB1 PortB for input 	*/

   	nowled = 0x00;						/* LED init all Low 		*/
	nowsw = 0x00;						/* Switch init all Low		*/

	for (;;)  
		{
   		outp(nowled, PORTD);			/* LED on					*/

		if((inp(PINB) & 0x01) != 0x00) 	/* check switch	 on			*/
			nowsw = 1 ;					/* up						*/
		if((inp(PINB) & 0x01) == 0x00)	/* check switch	off			*/
			{
			if(nowsw == 1) 
				{
				nowsw = 0;
				nowled++;
				}
			}
   		}
	}

