unsigned char digit[10] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7c, 0x07, 0x7f, 0x67};
unsigned char fnd_sel[4] = {0x08, 0x04, 0x02, 0x01};
unsigned char fnd[4];
int main()
{
DDRC = 0xff; // led출력 설정
DDRG = 0x0f; // TR 출력 설정
int i=0, count=0;
while(1){
count++;
if (count == 10000)
count = 0;
fnd[3] = (count/1000)%10;
fnd[2] = (count/100)%10;
fnd[1] = (count/10)%10;
fnd[0] = count%10;
for (i=0; i<4; i++)
{ PORTC = digit[fnd[i]];
PORTG = fnd_sel[i];
_delay_ms(2); }
}
}
// 오른쪽 1의자리 부터 count
unsigned char digit[10] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7c, 0x07, 0x7f, 0x67};
unsigned char fnd_sel[4] = {0x08, 0x04, 0x02, 0x01};
unsigned char fnd[4];
int main()
{
DDRC = 0xff; // led출력 설정
DDRG = 0x0f; // TR 출력 설정
int i=0, count=0;
while(1){
count++;
if (count == 10000)
count = 0;
fnd[0] = (count/1000)%10;
fnd[1] = (count/100)%10;
fnd[2] = (count/10)%10;
fnd[3] = count%10;
for (i=0; i<4; i++)
{ PORTC = digit[fnd[i]];
PORTG = fnd_sel[i];
_delay_ms(2); }
}
}
1의자리 숫자는 컨트롤러 속도가 워낙 빨라서 변하는 값이 보이질 않네..
여기까지는 실습 예제가 있어서 쉽게 풀 수 있었다.
하지만 24시간 디지털 시계 만들기는 조금 까다로웠다.
unsigned char digit[10] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7c, 0x07, 0x7f, 0x67};
unsigned char fnd_sel[4] = {0x08, 0x04, 0x02, 0x01};
unsigned char fnd[4];
int main()
{
DDRC = 0xff; // led출력 설정
DDRG = 0x0f; // TR 출력 설정
int i=0, count=0, j=0;
while(1){
count++;
if (count == 1440 )
count = 0;
fnd[0] = (count/600)%3;
fnd[1] = (count/60)%10;
fnd[2] = (count/10)%6;
fnd[3] = count%10;
for(j=0; j<2800;j++){
for (i=0; i<4; i++)
{ PORTC = digit[fnd[i]];
PORTG = fnd_sel[i];
_delay_ms(5); }}
}
}
시간은 정확하지 않지만 2800 부분 수정하여 정확한 시간을 맞출 수 있을 것 같다.
'Project > j-kit-128-1실습' 카테고리의 다른 글
FND_Display with Timer/Counter (0) | 2018.10.01 |
---|---|
LED 제어 (0) | 2016.02.26 |
FND 실습 (0) | 2016.02.26 |
회로도 참고 (0) | 2016.02.26 |
jkit switch 제어/ 인터럽트사용 (0) | 2016.02.26 |