You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
2.6 KiB

2 weeks ago
#include "delay.h"
/**
* : delay
* : (delay)
*
* :
* - d : .
*
* :
* - while(d--) CPU를
* -
* - CPU
*
* :
* - CPU
* -
*/
void delay(long d){
while(d--);
}
/**
* : delay_us
* : (us) (delay)
*
* :
* - us : ( )
*
* :
* 1. us count
* - us <= 150 : count = (us * 100 + 50) / 100
* - us > 150 : count = (us * 106 + 50) / 100
* - +50
* 2. for count만큼 __nop()
* - __nop() "No Operation" , CPU
* 3.
*
* :
* - CPU
* -
*/
void delay_us(volatile uint32_t us)
{
volatile uint32_t i;
volatile uint32_t count;
if (us <= 150) {
count = (us * 100 + 50) / 100; // 소수점 올림 효과를 위해 +50 추가
} else {
count = (us * 106 + 50) / 100;
}
for (i = 0; i < count; i++) {
__nop();
}
}
/**
* : delay_ms
* : (ms) (delay)
*
* :
* - ms : ( )
*
* :
* 1. for (i) ms만큼
* 2. for (j) 0~799
* - 800 CPU
* - CPU
* 3.
*
* :
* - (CPU , )
* -
* - delay_ms와 delay_us를
*/
void delay_ms(unsigned int ms)
{
volatile unsigned int i, j;
for (i = 0; i < ms; i++)
for (j = 0; j < 800; j++); // 내부 루프 조정 필요 (클럭에 따라 조정)
}