내장형하드웨어/일일보고서

2011년6월21일_8개의 LED를 키트자동차처럼 좌우로 시프트(AT91SAM7S256 Board)

배에고파아요오 2011. 6. 22. 08:41

 

 

image

상기의 회로도대로 브레드에 결선한다.


DSCN3456DSCN3457 

알록달록 LED의 색이 이쁘다.
점프선이 휘어진 모습이 귀엽다.

 

   1:  /***********************************************************************
   2:  
   3:      LED 8개를    좌로 시프트,
   4:                  우로 시프트, 반복
   5:                  
   6:      작 성 자: 김수만
   7:      작성일자: 2011년 6월 21일
   8:  
   9:  ***********************************************************************/
  10:  // I/O 정의
  11:  #define PIOA_PER    (*(volatile unsigned int *)0xFFFFF400)
  12:  #define PIOA_OER    (*(volatile unsigned int *)0xFFFFF410)
  13:  #define PIOA_PPUDR    (*(volatile unsigned int *)0xFFFFF460)
  14:  #define PIOA_CODR    (*(volatile unsigned int *)0xFFFFF434)
  15:  #define PIOA_SODR    (*(volatile unsigned int *)0xFFFFF430)
  16:   
  17:   
  18:  void LED_INIT(void);
  19:  void delay(unsigned int);
  20:   
  21:   
  22:  int main(void)
  23:  {
  24:      int iLoop;
  25:   
  26:      LED_INIT();
  27:      
  28:   
  29:      while(1)
  30:      {
  31:          //아래로 시프트 (우로 시프트)
  32:          for(iLoop = 0 ; 8 > iLoop ; ++iLoop)
  33:          {
  34:              PIOA_CODR = (1 << iLoop);
  35:   
  36:              delay(1000);
  37:              
  38:              PIOA_SODR = (1 << iLoop);
  39:          }
  40:          
  41:          //위로 시프트 (좌로 시프트)
  42:          for(iLoop = 6 ; 0 < iLoop ; --iLoop)
  43:          {
  44:              PIOA_CODR = (1 << iLoop);
  45:   
  46:              delay(1000);
  47:              
  48:              PIOA_SODR = (1 << iLoop);
  49:          }
  50:      }
  51:      
  52:      return 0;
  53:  }
  54:   
  55:  void LED_INIT(void)
  56:  {
  57:      // Configure the pin in output
  58:      PIOA_OER    = 0x000000FF;
  59:      // Set the PIO controller in PIO mode instead of peripheral mode
  60:      PIOA_PER    = 0x000000FF;
  61:      // Disable pull-up
  62:      PIOA_PPUDR    = 0x000000FF;
  63:      // 하위 1Byte set
  64:      PIOA_SODR = 0x000000FF;
  65:   
  66:      
  67:      return ;
  68:  }
  69:   
  70:   
  71:  void delay(unsigned int iTime)
  72:  {
  73:      volatile unsigned int iCount = 0;
  74:   
  75:      for(iCount=0; iTime * 1000 >= iCount; ++iCount);
  76:   
  77:      return ;
  78:  }