반응형
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85 |
/*
* avr_test.cpp
*
* Created: 2018-09-03 오전 10:56:46
* Author : USER
*/
#include <avr/io.h>
#define F_CPU 16000000
#include <util/delay.h>
#define LED_SEL1 (*(volatile unsigned char *)0xA000)
#define LED_SEL2 (*(volatile unsigned char *)0xB000)
#define FND (*(volatile unsigned char *)0x8000)
void io_init(void)
{
MCUCR|=(1<<SRE) | (1<<SRW10);
XMCRA=(1<<SRL2) | (0<<SRL1) | (0<<SRL0) | (1<<SRW01) | (1<<SRW00) | (1<<SRW11);
XMCRB |= 0x00;
}
void fndController (char loc , char number){
FND = (number <<3)|loc;
}
int main(void)
{
io_init();
int count =0;
int num2 =0;
int num3 =0;
int num4 =0;
int num5 =0;
int num6 =0;
while (1)
{
count++;
if (count %10 == 0){
num6 ++;
count =0;
}
if (num6 >=10){
num5 ++;
num6=0;
}
if (num5>=10){ num4 ++;
num5=0;
}
if (num4>=10){
num3++;
num4=0;
}
if ( num3>=10){
num2++;
num3=0;
}
for (int i =0; i<166;i++){
fndController(5,count);
_delay_ms(1);
fndController(4,num6);
_delay_ms(1);
fndController(3,num5);
_delay_ms(1);
fndController(2,num4);
_delay_ms(1);
fndController(1,num3);
_delay_ms(1);
fndController(0,num2);
_delay_ms(1);
}
}
}
|
cs |
// 1ms 6번 출력함으로 1초를 만들기위해 166회 for 문을 돌리면 1초에 근접한 시간이 만들어 진다.
// 6*166 = 996 ms
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49 |
/*
* avr_test.cpp
*
* Created: 2018-09-03 오전 10:56:46
* Author : USER
*/
#include <avr/io.h>
#define F_CPU 16000000
#include <util/delay.h>
#define LED_SEL1 (*(volatile unsigned char *)0xA000)
#define LED_SEL2 (*(volatile unsigned char *)0xB000)
#define FND (*(volatile unsigned char *)0x8000)
void io_init(void)
{
MCUCR|=(1<<SRE) | (1<<SRW10);
XMCRA=(1<<SRL2) | (0<<SRL1) | (0<<SRL0) | (1<<SRW01) | (1<<SRW00) | (1<<SRW11);
XMCRB |= 0x00;
}
void fndController (char loc , char number){
FND = (number <<3)|loc;
}
void fndDisplay (unsigned long long number){
fndController(0,number%10);_delay_ms(1);
fndController(1,(number%100)/10);_delay_ms(1);
fndController(2,(number%1000)/100);_delay_ms(1);
fndController(3,(number%10000)/1000);_delay_ms(1);
fndController(4,(number%100000)/10000);_delay_ms(1);
fndController(5,number/100000);_delay_ms(1);
}
int main(void)
{
io_init();
DDRE = 0x00;
PORTE = 0xff;
while (1)
{
if (PINE == 0b11101111) fndDisplay(999999);
else fndDisplay(0);
}
}
|
cs |
// FND 출력 함수를 만들어 놓으면 나중에 확인할 때 유용하다.
// SW4입력시 999999를 출력한다.
반응형
'Study > 8-bit MCUs' 카테고리의 다른 글
[NPAVR Board] AVR - Atmega128 (Character LCD) (0) | 2018.09.04 |
---|---|
[NPAVR Board] AVR -Atmega128 (FND, Switch) (0) | 2018.09.03 |
Atmgea8 FND 시계 (0) | 2018.02.21 |
B/T LED 부품 선정 및 견적서 (1) | 2017.04.10 |
B/T LED Control circuit (0) | 2017.04.10 |