본문 바로가기

ARM7

타이머 카운터 파형발생 모드 WAVESELL=01 0x8989A402=>1010(바이너리) 10=(A)16진수 LED서서히점멸


/* 타이머 카운터 파형발생 모드 WAVESELL=01 0x8989A402=>1010(바이너리)  10=(A)16진수      LED점점 밝아 지기 */
#include "AT91SAM7S256.h"
#include "lib_AT91SAM7S256.h"
#include "OK7S256ads.h"

#define DBGU_SR (*(volatile unsigned int *) 0xFFFFF214)
#define DBGU_RHR (*(volatile unsigned int *) 0xFFFFF218)
#define DBGU_THR (*(volatile unsigned int *) 0xFFFFF21C)
#define DBGU_MR (*(volatile unsigned int *) 0xFFFFF204)
#define DBGU_BRGR (*(volatile unsigned int *) 0xFFFFF220)
#define DBGU_CR (*(volatile unsigned int *) 0xFFFFF200)
#define PIO_ASR (*(volatile unsigned int *) 0xFFFFF470)
#define PIO_BSR (*(volatile unsigned int *) 0xFFFFF474)
#define PIO_PDR (*(volatile unsigned int *) 0xFFFFF404)
#define PIO_SODR (*(volatile unsigned int *) 0xFFFFF430)
#define PIO_CODR (*(volatile unsigned int *) 0xFFFFF434)
#define PIO_OER (*(volatile unsigned int *) 0xFFFFF410)
#define PIT_MR (*(volatile unsigned int *) 0xFFFFFD30)
#define AIC_SVR ((volatile unsigned int *) 0xFFFFF080)
#define AIC_SMR ((volatile unsigned int *) 0xFFFFF000)
#define AIC_IDCR (*(volatile unsigned int *) 0xFFFFF124)
#define AIC_ICCR (*(volatile unsigned int *) 0xFFFFF128)
#define AIC_IECR (*(volatile unsigned int *) 0xFFFFF120)
#define PMC_PCER (*(volatile unsigned int *) 0xFFFFFC10)
#define PIT_PIVR (*(volatile unsigned int *) 0xFFFFFD38)

void Delayms(unsigned int ms) //딜레이 함수..
{
  volatile unsigned int count, countmax = (48000000 / 10000) * ms;

  for(count = 0; count < countmax; count++);
}

int main(void)
{
  unsigned int TC0_RA =65000;   // initial register value
  //unsigned int TC0_RB = 1000;
  unsigned int TC0_RC =65000;// 도착점?

  unsigned int FLAG=0;

  PIO_OER = 0x00000FFF;
  //PIO_CODR = 0x0000FFFF;
  PMC_PCER =(unsigned int)1 << (unsigned int)12;
 
 
  AT91F_TC0_CfgPMC();    // enable clock of TC0
  AT91F_PIO_CfgPeriph(AT91C_BASE_PIOA, 0, AT91C_PA1_TIOB0 | AT91C_PA0_TIOA0);
        // TIOA0,TIOB0 output(Peripheral B)

  *AT91C_TC0_CMR = 0x8989C402;   // TC0 Channel Control Register WAVESELL=10
  *AT91C_TC0_CCR = 0x0005;   // TC0 clock enable and start

  *AT91C_TC0_RA = TC0_RA;   // set TC0 register
  //*AT91C_TC0_RB = TC0_RB;
  *AT91C_TC0_RC = TC0_RC;

  while(1)
  {
    if(FLAG==0)   //0일때
    {
     TC0_RA-=100;  // RC초기값 65000==>>0까지 에서 점점 전위차가 발생 함으로 LED 가 밝아진다.
     *AT91C_TC0_RA =TC0_RA;
     Delayms(5);
     if(TC0_RA==0)
      {FLAG=1;}
  } 
    else if(FLAG==1)
    {
   TC0_RA+=100;// 다시 0에서 ===> 65000(초기값 RC) LED  가까워짐으로 전위차가 줄어듬으로 LED 가 어두워진다
     *AT91C_TC0_RA =TC0_RA;
     Delayms(5);
     if(TC0_RA == TC0_RC)
     {FLAG=0;}
    }
 }
  
}