/***
  ATMEGA8のデジタル入力の練習。
  もっとも単純な形。
  PB0のデジタル入力を、PB1のデジタル出力へつなげる。
  
  CPU: ATMEGA8
  Compiler: WinAVR20050214(AVR-GCC3.4.3)
  Date: 2005/05/11
  Author: Yoshiro Sugano
  WebSite: http://web.sfc.keio.ac.jp/~yoshiro/weblog/archives/2005/05/atmega8.html
  ***/


#include <avr/io.h>

#define TRUE 1
#define FALSE 0

/* No Operation */
void nop(int count){
  int i;
  for(i = 0; i < count*100; i++){
  }
}

/* PORT設定 */
//DDR-でピンの入力(0)と出力(1)の役割を決める
//PORT-で出力に指定されたピンから実際に出力する(1)、しない(0)を決める。
void port_init(void){
  DDRB = 0xfe; //PB0だけ入力。DDRB = 0b11111110　と同じ意味。
}

//char mode;

int main(void){
  port_init(); // PORT設定
  
  for(;;){
    if(PINB&1){// PIN-は入力の判定　&は、この場合、PB0がhighならばtureということ。他のピンからの入力は関係ない。
      PORTB = 0b00000010; // PB1を出力。
    }else{
      PORTB = 0b00000000; // PB1を出力しない。
    }
  }
}

