프리마스터 LED 시프트 문제...
페이지 정보
작성자 miim 작성일21-10-13 09:16 조회3,222회 댓글1건본문
2초마다 LED를 오른쪽으로 시프트 시키는 문제인데
마지막 공란 부분에 코드를 추가시켜야한다고 해요...
되게 간단한 문제같은데 이상하게 계속 안되고 있어서 글 남겨봅니다...ㅠㅠ
제가 잘 몰라서 일단은 ,,, 코드 전문 첨부해봅니당...
#include "MPC5604P_M26V.h"
#include "freemaster.h"
#include "init_base.h"
void LED_Ctr(void);
void Init_GPIO(void);
void Switch(void);
void init_ADC1(void);
void ADCRead_1(void);
void ADC_LED_Ctr(void);
void init_PIT(void);
void PIT0ISR(void);
void PIT1ISR(void);
volatile int i = 0;
char LED1=1, LED2=1, LED3=1, LED4=1;
char SW1, SW2, SW3, SW4;
int R_adc = 0;
uint32_t Pit0cnt =0;
uint32_t Pit1cnt =0;
int main(void)
{
initModesAndClock();
disableWatchdog();
enableIrq();
initOutputClock();
FMSTR_Init();
init_INTC();
init_Linflex0();
Init_GPIO();
Switch();
init_ADC1();
init_PIT();
INTC_InstallINTCInterruptHandler(PIT0ISR, 59, 6);
//59=하드웨어 고유 넘버(이곳에서 인터럭트 발생), 6=우선순위
INTC_InstallINTCInterruptHandler(PIT1ISR, 60, 6);
/* Loop forever */
for (;;)
{
FMSTR_Recorder();
FMSTR_Poll();
LED_Ctr();
Switch();
ADCRead_1();
//ADC_LED_Ctr();
i++;
}
}
void Init_GPIO(void)
{
SIU.PCR[52].R = 0x0200; //LED1
SIU.PCR[53].B.PA = 0b00;
SIU.PCR[53].B.OBE = 0b1; //LED2
SIU.PCR[54].B.PA = 0b00;
SIU.PCR[54].B.OBE = 0b1; //LED3
SIU.PCR[55].R = 0b0000001000000000; //LED4
SIU.PCR[48].R = 0x0100;
SIU.PCR[49].R = 0x0100;
SIU.PCR[50].R = 0x0100;
SIU.PCR[51].R = 0x0100; //switch
}
void LED_Ctr(void)
{
SIU.GPDO[52].B.PDO = LED1;
SIU.GPDO[53].B.PDO = LED2;
SIU.GPDO[54].B.PDO = LED3;
SIU.GPDO[55].B.PDO = LED4;
}
void ADC_LED_Ctr(void)
{
if(R_adc > 250)
{
LED1 = 0;
}
else
{
LED1 = 1;
}
if(R_adc > 500)
{
LED2 = 0;
}
else
{
LED2 = 1;
}
if(R_adc > 750)
{
LED3 = 0;
}
else
{
LED3 = 1;
}
if(R_adc > 1000)
{
LED4 = 0;
}
else
{
LED4 = 1;
}
}
void Switch(void)
{
SW1 = SIU.GPDI[48].B.PDI;
SW2 = SIU.GPDI[49].B.PDI;
SW3 = SIU.GPDI[50].B.PDI;
SW4 = SIU.GPDI[51].B.PDI;
}
void init_ADC1(void)
{
ADC_1.MCR.B.ABORT = 1; //Abort ADC_1
ADC_1.MCR.B.OWREN = 0; //disable overwritting
ADC_1.MCR.B.WLSIDE = 0; //conversion data is written right_aligned
ADC_1.MCR.B.MODE = 0; //One Shot mode
ADC_1.MCR.B.CTUEN = 0; //disable CTU triggered
ADC_1.MCR.B.ADCLKSEL = 0; //Set ADClock 32MHz
// ADC_1.MCR.B.ADCLKSEL = 1; //Set ADClock 64MHz
ADC_1.MCR.B.ACK0 = 0; //disable auto clock off
ADC_1.MCR.B.PWDN = 0; //disable power down mode
ADC_1.CTR[0].R = 0x00008208;
ADC_1.NCMR[0].R = 0x00000020;
ADC_1.CDR[5].R = 0x00000000;
ADC_1.MCR.B.ABORT = 0; //clear ADC_1
SIU.PCR[64].R = 0x2400; //2000으로 설정해도 가능
}
void ADCRead_1(void) //변환결과를 읽어오는 함수
{
ADC_1.MCR.B.NSTART = 1;
asm("nop");
while(ADC_1.MCR.B.NSTART) asm("nop");
R_adc = ADC_1.CDR[5].B.CDATA;
}
void init_PIT(void)
{
PIT.PITMCR.R = 0x00000001; //타이머가 멈추고 디버그 모드로 설정
PIT.CH[0].LDVAL.R = 6400000; //64만을 16진수로 표현한 값(주기=100ms)
PIT.CH[0].TCTRL.R = 0x3; //둘 다 1이여야 하므로
PIT.CH[1].LDVAL.R = 64000000;
PIT.CH[1].TCTRL.R = 0x3; //예제 문제를 위한 추가 코드
}
void PIT0ISR(void) //interrupt가 잘 수행됐는지 확인 가능하게 해주는 함수
{
Pit0cnt ++;
//100ms 마다 해야할 일 추가 가능
PIT.CH[0].TFLG.B.TIF =1; //clear PIT0 flag
}
void PIT1ISR(void)
{
Pit1cnt++;
/////////////////////////////////////공란//////////////////////////////////////////////////
PIT.CH[1].TFLG.B.TIF =1;
}
댓글 : 1
조회수 : 3,222
master님의 댓글
master 작성일
PIT.CH[0].LDVAL.R=6400000; //64만을 16진수로 표현한 값(주기=100ms)
PIT.CH[1].LDVAL.R=64000000;
타이머0이 100ms면
타이머1은 1000ms 인가보죠?
2초마다 한번씩 쉬프트 해야하므로
void PIT1ISR(void){ // 1초
Pit1cnt++;
if(Pit1cnt>=2){ Pit1cnt=0; // 2초마다 <-- 추가
/////////////////////////////////////공란//////////////////////////////////////////////////
}
PIT.CH[1].TFLG.B.TIF=1;
}
나머지는 답글로 적어드리죠