현재 세그먼트 과정
1 > 2 > 3 > 4 순서대로 킴
+
void send_port(unsigned char X, unsigned char port) {
send(X); // 첫 번째 데이터 전송
send(port);
HAL_GPIO_WritePin(FND_RCLK_GPIO_Port, FND_RCLK_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(FND_RCLK_GPIO_Port, FND_RCLK_Pin, GPIO_PIN_SET);
}
void digit4_temper(int n, int replay)
{
int n1, n2, n3, n4;
n1 = (int) n % 10;
n2 = (int) (n % 100)/10;
n3 = (int) (n % 1000) / 100;
n4 = (int) (n % 10000)/ 1000;
for(int i = 0; i<=replay; i++){
send_port(_LED_0F[n1], 0b0001); // 4
send_port(_LED_0F[n2] & 0x7F, 0b0010); // 2
if( n>99)send_port(_LED_0F[n3], 0b0100); // 1
if( n>999)send_port(_LED_0F[n4], 0b1000);
}
}
ex) 12.4
4 > 2 > 1.. 450번 반복 하다가
마지막 1에서 stop > 다시 4 > 2 > 1
>> 세그먼트에는 1은 계속 나오고 2 와 4가 깜빡거리는 증상 생김
// 동시에 실행을 못해서
현재 interrupt
main | systic | timer1 | timer2
timer3 :
prescaler : 71 // 현재 72MHz 클럭
counter period : 99
> 0~100 까지가 1us * 72 = 72 us // 총 시간
> 숫자 1 당 : 1us / 100 = 100us
NVIC : 우선순위 > timer3 : 10번 정도
> systick 1번정도 걸리면 timer3 100us라서 더 많이 걸림
// systick 내장 타이머 > cpu clock / 8 타이머
> timer 에서
digit4_temper(500); 실행
>> if( n>99)send_port(_LED_0F[n3], 0b0100); 여기서 5가 걸리고
timer 3 내에서 나머지도 실행중
> 00 이 조금 희미하게 보임
>> 5 가 되었을떄 다시 0으로 해서 실행중인 상태로 만들어야함
switch (m_tempercount){
case 0: send_port(_LED_0F[n1], 0b0001);
break;
case 1 : send_port(_LED_0F[n2] & 0x7F, 0b0010);
break;
case 2: if( temper>99)send_port(_LED_0F[n3], 0b0100);
break;
case 3: if( temper>999)send_port(_LED_0F[n4], 0b1000);
break;
default :
break;
}
m_tempercount++;
// 이렇게 하면 case 0부터 마지막 case 까지 다 거치게 되는 로직
ex) 512
n1 = 2, n2= 1, n3=5
case 0 > break > ++ > case 1 > break > ++ > case2 > break > ++ > case3 에서 if문X (sendport 못함) > ++
if(temper > 999 && m_tempercount>=4 ){
m_tempercount=0;
}else if( temper > 99 && m_tempercount>=3 ){
m_tempercount=0;
}else if( temper <= 99 && m_tempercount >=2 ){
m_tempercount=0;
}
>> temper = 512, count=4 이므로 두번째 else if 에 걸려서 > count =0 초기화
이제 온도정보를 가져와보자
timer3 // it ( interrupt )
digit4_temper((int) (getCurrentTemper() * 10));
> 이러면
main.c
Ds18b20_ManualConvert(); 이거 실행중에 충돌발생
// like , process 실행중 같은 값을 thread 에서 값 변경 > 충돌
> ManualConvert 가 끝난뒤 timer3에서 실행해야함
온도 정보가 안 올라온 이유