반응형
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
86
87
88
89
90
91
92
93
94
95
96
97
// Prob_01.cpp: 콘솔 응용 프로그램의 진입점을 정의합니다.
//
 
#include "stdafx.h"
int park[100= { 0 };
int way[100= { 0 };
int park_top = 0;
int way_top = 0;
int num = 0;
int num_out = 0;
int mode = 0;
int out_car = 0;
 
int push(int value) {
    park[park_top] = value;
    park_top++;
    way_top--;
    return park_top;
}
int push_way(int value) {
    way[way_top] = value;
    way_top++;
    return way_top;
}
int pop() {
    park_top--;
    way_top++;
    way[way_top] = park[park_top];
    return park[park_top];
}
 
int main()
{
    while (1) {
        printf("동작을 선택하세요 (1. 입차 2.출차 3.주차장 상태보기 ) : ");
        scanf_s("%d"&mode);
        if (mode == 1) {
            printf("1. 자동차 번호를 입력해 주세요 : ");
            scanf_s("%d"&num);
            push(num);
            printf("자동차가 주차되었습니다. 차량번호 : %d \n", park[park_top - 1]);
            way_top = 0;
        }
        else if (mode == 2) {
            printf("2. 출차 할 자동차 번호를 입력 해 주세요 :");
            scanf_s("%d"&num_out);
            for (int i = 0; i < park_top; i++) {
                if (num_out == park[i]) out_car = 1;
            }
            if (out_car == 1) {
                printf("출차 할 차량이 있습니다. 출차를 위해 다른 차량을 출차합니다.\n");
                while (num_out != park[park_top]) {
                    if (num_out == park[park_top]) { park_top--break; }
                    else if (num_out != park[park_top]) {
                        pop();
                    }
                    printf("출차 : %d\n", park[park_top]);
                    printf("막다른길 : ");
                    for (int i = 1; i < way_top; i++) {
                        printf("%d   ", way[i]);
                    }
                    printf("\n주차장 : ");
                    for (int i = 0; i < park_top; i++) {
                        printf("%d  ", park[i]);
                    }
                    printf("\n");
                }
                printf("%d 차량이 출차 되었습니다.\n", park[park_top]);
                printf("막다른길의 차들을 다시 주차장에 주차합니다.\n");
                
                while (way_top >= 1) {
                    push(way[way_top-1]);
                    printf("입차 : %d\n", way[way_top]);
                    printf("막다른길 : %d ");
                    for(int i = 0; i < way_top-1; i++) {
                        printf("%d   " ,way[i]);
                    }
                    printf("\n주차장 : ");
                    for (int i = 0; i < park_top-1; i++) {
                        printf("%d   ", park[i]);
                    }
                    printf("\n");
                }
            }
            else
                printf("출차 할 차량이 없습니다.\n");
        }
        else if (mode == 3) {
 
            for (int i = 0; i < park_top; i++) {
                printf("%d  \n", park[i]);
            }
        }
    }
    return 0;
}
 
cs

 

 

반응형

'Study > C' 카테고리의 다른 글

C언어 - 학생 Table(총점, 평균, 석차)  (0) 2018.09.07
C언어 - 탐색, 정렬, 순위  (0) 2018.09.07
C언어(자료구조) - Stack 구현  (0) 2018.09.06
C언어 - goto문  (0) 2018.08.29
C언어 - 구조체(학생 성적 구조체 만들기)  (0) 2018.08.29
반응형

 

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
 
#include "stdafx.h"
int stack[100];
int top = 0;
 
int push(int value) {
    stack[top] = value; // 스택에 값을 저장
    top++// top 증가
    return top; // top 반환
}
int pop() {
    top--// top 감소
    return stack[top];  //값 반환
}
int main()
{
    push(100);
    push(200);
    push(300);
    printf("%d\n"pop());
    printf("%d\n"pop());
    printf("%d\n"pop());
 
    return 0;
}
 
cs

 

 

반응형
반응형
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
 * GccApplication1.cpp
 *
 * Created: 2018-09-04 오전 11:21:22
 * Author : USER
 */ 
 
#include <avr/io.h>
#define F_CPU 16000000
#include <util/delay.h>
#include "lcd.h"
#include <stdio.h>
#include <stdlib.h>
 
#define LED_SEL1 (*(volatile unsigned char *)0xA000)
#define LED_SEL2 (*(volatile unsigned char *)0xB000)
#define FND (*(volatile unsigned char *)0x8000)
#define DOTMATRIX (*(volatile unsigned char *)0x9000)
 
void DotMatrix(char rdata, char addr)
{
    char data = 0;
    DOTMATRIX = 0x00;
    for (int i=0; i<8; i++)
    {
        data = 0;
        if (rdata & 0x80) data |= 0x01;
        DOTMATRIX = data;
        DOTMATRIX = 0x04;
        DOTMATRIX = 0x00;
        rdata <<= 1;
    }
    DOTMATRIX = (addr << 4| 0x88;
}
 
 
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(5,number%10);_delay_ms(1);
    fndController(4,(number%100)/10);_delay_ms(1);
    fndController(3,(number%1000)/100);_delay_ms(1);
    fndController(2,(number%10000)/1000);_delay_ms(1);
    fndController(1,(number%100000)/10000);_delay_ms(1);
    fndController(0,number/100000);_delay_ms(1);
    
}
 
int keyMatrix(){
    unsigned char key =0, ret_val =0;
    for (int i =0; i<4;i++){
        if(i==0) PORTD = 0b11101111;
        if(i==1) PORTD = 0b11011111;
        if(i==2) PORTD = 0b10111111;
        if(i==3) PORTD = 0b01111111;
        _delay_ms(5);
        
        key = ~PINF &0xf0;
        if(key){
            ret_val = key|(PORTD >>4);
            return ret_val;
            }
    }
    return 0;
}
int main(void)
{
    io_init();
    unsigned char data = 0b00000001;
    while (1
    {
        
        DotMatrix(0b01100110,0);
        _delay_ms(1);
        DotMatrix(0b10011001,1);
        _delay_ms(1);
        DotMatrix(0b10000001,2);
        _delay_ms(1);
        DotMatrix(0b10000001,3);
        _delay_ms(1);
        DotMatrix(0b01100110,4);
        _delay_ms(1);
        DotMatrix(0b00100100,5);
        _delay_ms(1);
        DotMatrix(0b00011000,6);
        _delay_ms(1);
        
    }
}
 
 
cs

 

 

 

반응형
반응형
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
/*
 * GccApplication1.cpp
 *
 * Created: 2018-09-04 오전 11:21:22
 * Author : USER
 */ 
 
#include <avr/io.h>
#define F_CPU 16000000
#include <util/delay.h>
#include "lcd.h"
#include <stdio.h>
#include <stdlib.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(5,number%10);_delay_ms(1);
    fndController(4,(number%100)/10);_delay_ms(1);
    fndController(3,(number%1000)/100);_delay_ms(1);
    fndController(2,(number%10000)/1000);_delay_ms(1);
    fndController(1,(number%100000)/10000);_delay_ms(1);
    fndController(0,number/100000);_delay_ms(1);
    
}
 
int keyMatrix(){
    unsigned char key =0, ret_val =0;
    for (int i =0; i<4;i++){
        if(i==0) PORTD = 0b11101111;
        if(i==1) PORTD = 0b11011111;
        if(i==2) PORTD = 0b10111111;
        if(i==3) PORTD = 0b01111111;
        _delay_ms(5);
        
        key = ~PINF &0xf0;
        if(key){
            ret_val = key|(PORTD >>4);
            return ret_val;
            }
    }
    return 0;
}
int main(void)
{
    io_init();
    lcd_init();
    lcd_clear();
    
    DDRF = 0x0f;
    DDRD = 0xf0;
    
    PORTF = 0x0f;
    PORTD = 0x00;
    char str[16];
    
    while (1
    {    
        lcd_clear();
        itoa (keyMatrix(),str,2);
        lcd_putsf(0,0,str);_delay_ms(5);
        lcd_clear();
        
    }
}
 
 
cs

 

// 키를 입력할 경우 키값을 반환한다.

 

 

2. keyMatrix - 알파벳 출력

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
#include <avr/io.h>
#define F_CPU 16000000
#include <util/delay.h>
#include <stdio.h>
#include <stdlib.h>
#include "lcd.h"
 
void io_init(void)
{
    MCUCR|=(1<<SRE) | (1<<SRW10);
    XMCRA=(1<<SRL2) | (0<<SRL1) | (0<<SRL0) | (1<<SRW01) | (1<<SRW00) | (1<<SRW11);
    XMCRB |= 0x00;
}
 
unsigned int getKey()
{
    unsigned char key = 0, ret_val = 0;
    for (int i=0; i<4; i++)
    {
        PORTD = ~(0b00010000 << i);
        _delay_ms(5);        
        key = ~PINF & 0xf0;
        if (key) 
        {
            ret_val = key | (PORTD >> 4);                    
            return ret_val;
        }        
    }
    return 0;
}
void inputChar(char array[16], char data, int *count)
{
    array[*count] = data;
    array[*count + 1= 0;
    *count = *count + 1;
}
 
int main(void)
{
    io_init();
    lcd_init();
    lcd_clear();    
    
    DDRF = 0x00;        
    DDRD = 0xff;
    PORTF = 0xff;
    PORTD = 0x00;
    char str[16];
    int count = 0;
    while (1
    {    
        if (getKey() == 0b00011110) inputChar(str, 'a'&count);
        if (getKey() == 0b00011101) inputChar(str, 'b'&count);
        if (getKey() == 0b00011011) inputChar(str, 'c'&count);
        if (getKey() == 0b00010111) inputChar(str, 'd'&count);
        
        lcd_putsf(0,0,str);
        _delay_ms(10);
    }
}
 
cs

 

// 키를 누를 경우 알파벳 출력. 

반응형
반응형

 

 

Analog to Digital Converter

ADC 레지스터

ADMUX

ADCSRA

 

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
/*
 * GccApplication1.cpp
 *
 * Created: 2018-09-04 오전 11:21:22
 * Author : USER
 */ 
 
#include <avr/io.h>
#define F_CPU 16000000
#include <util/delay.h>
#include "lcd.h"
#include <stdio.h>
#include <stdlib.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(5,number%10);_delay_ms(1);
    fndController(4,(number%100)/10);_delay_ms(1);
    fndController(3,(number%1000)/100);_delay_ms(1);
    fndController(2,(number%10000)/1000);_delay_ms(1);
    fndController(1,(number%100000)/10000);_delay_ms(1);
    fndController(0,number/100000);_delay_ms(1);
    
}
 
 
int main(void)
{
    io_init();
    lcd_init();
    lcd_clear();
    
    ADCSRA = 0xe7;
    ADMUX = 0x01;
    
    char str[16];
    
    while (1
    {    
        unsigned int sum = ADC ;
        itoa(sum,str,10);
        lcd_putsf(0,0,str);
        _delay_ms(1);
    }
}
 
 
cs

 

// 가변저항을 돌리면 LCD 에 값이 출력된다.

 

http://tackbro.tistory.com/entry/AVR-%EA%B0%80%EB%B3%80%EC%A0%80%ED%95%AD%EC%9C%BC%EB%A1%9C-atmega-128%EC%97%90%EC%84%9C-ADC-%EC%82%AC%EC%9A%A9-%EC%98%88%EC%A0%9C

 

 

반응형
반응형
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
#include <avr/io.h>
#define F_CPU 16000000
#include <util/delay.h>
#include "lcd.h"
#include <stdio.h>
#include <stdlib.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(5,number%10);_delay_ms(1);
    fndController(4,(number%100)/10);_delay_ms(1);
    fndController(3,(number%1000)/100);_delay_ms(1);
    fndController(2,(number%10000)/1000);_delay_ms(1);
    fndController(1,(number%100000)/10000);_delay_ms(1);
    fndController(0,number/100000);_delay_ms(1);
    
}
 
 
int main(void)
{
    io_init();
    lcd_init();
    lcd_clear();
    
    DDRE = 0x00;
    PORTE = 0xff;
    
    int count=0;
    char str[16];
    
    while (1
    {    
        itoa(PINE,str,2);
        sprintf(str,"C:%d",count);
    }
}
 
cs

 

 

 

// 스위치를 입력할 경우 LCD 2진수가 출력된다.

//디버깅에 용이하다

반응형
반응형
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
/*
 * GccApplication1.cpp
 *
 * Created: 2018-09-04 오전 11:21:22
 * Author : USER
 */ 
 
#include <avr/io.h>
#define F_CPU 16000000
#include <util/delay.h>
#include "lcd.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(5,number%10);_delay_ms(1);
    fndController(4,(number%100)/10);_delay_ms(1);
    fndController(3,(number%1000)/100);_delay_ms(1);
    fndController(2,(number%10000)/1000);_delay_ms(1);
    fndController(1,(number%100000)/10000);_delay_ms(1);
    fndController(0,number/100000);_delay_ms(1);
    
}
 
 
int main(void)
{
    io_init();
    lcd_init();
    lcd_clear();
    
    int flag = 0;
    while (1
    {    
        if (flag == 0){
            for (int i = 0;i<16;i++){
            lcd_putsf(0,0,"             ");
            lcd_putsf(i,0,"A");
            _delay_ms(100);
            
                if (i==15){flag =1; lcd_putsf(15,0,"   ");
                }
            }
        }
            
        else if (flag == 1){
            for (int i = 15; i>=0;i--){
                lcd_putsf(0,1,"                     ");
                lcd_putsf(i,1,"A");    
                _delay_ms(100);
                if (i==0){flag=0;lcd_putsf(0,1,"   ");}
            }
        }
    }
}
 
 
cs

lcd.h

 

 

 

 

반응형
반응형

AVR

io레지스터

DDRA = 0b1111 1111; //출력설정

PORTA = 0b1111 1111; // 포트를 출력한다.

DDRA = 0b0000 0000; // 입력설정

PORTA = 0b11111111; // Software pull-up

//

if(PINA == 0b0111 1111) // PIN 레지스터는 Read-Only 읽기만 가능.

{

PORTA = 0b0000 0000; // PORT 레지스터읽기 쓰기 둘다 가능하다.

}

 

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
/*
 * 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(5,number%10);_delay_ms(1);
    fndController(4,(number%100)/10);_delay_ms(1);
    fndController(3,(number%1000)/100);_delay_ms(1);
    fndController(2,(number%10000)/1000);_delay_ms(1);
    fndController(1,(number%100000)/10000);_delay_ms(1);
    fndController(0,number/100000);_delay_ms(1);
    
}
int main(void)
{
    io_init();
    DDRE = 0x00;
    PORTE = 0xff;
    //int count =0;
    
    bool state = false;
    int randnum =0, dispnum =0;
    while (1)
    {
        
        /* //눌렀을 때 증가하는 소스
        if (PINE == 0b11101111 && state ==false){ count ++;state =true;}
        else if (PINE ==0b11111111&& state==true){ state =false;}
        fndDisplay(count);
        */
        // 0~100 사이의 랜덤수 출력하는 소스
        randnum++;
        if (randnum>100) randnum=0;
        if (PINE == 0b11101111 && state ==false){  dispnum= randnum;state =true;}
        else if (PINE ==0b11111111&& state==true){ state =false;}
        fndDisplay(dispnum);
        
    }
}
 
cs

 

 

반응형
반응형
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
반응형
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace WindowsFormsApp1
{
    struct s_watch
    {
        public int milisec;
        public bool status;
    }
    public partial class Form1 : Form
    {
        int board_x = 0;
        int board_y = 0;
        int board_size_x = 0;
        int board_size_y = 0;
 
        int arrow_x = 0;
        int arrow_y = 0;
        int arrow_size_x = 0;
        int arrow_size_y = 0;
 
        int gagebar_x = 0;
        int gagebar_y = 0;
        int gagebar_size_x = 0;
        int gagebar_size_y = 0;
 
        int gagepoint_x = 0;
        int gagepoint_y = 0;
        int gagepoint_size_x = 0;
        int gagepoint_size_y = 0;
 
       
        int powerCount = 0;
        int power = 0;
        bool powermax = false;
        bool gamestate = false;
 
        int highlow_x = 0;
        int highlow_y = 0;
        int highlow_size_x = 0;
        int highlow_size_y = 0;
 
        bool resultState = false;
        s_watch Watch;
        
        public Form1()
        {
            InitializeComponent();
            board_x = (pictureBox1.Width/2 -100- board_size_x;
            board_y = (pictureBox1.Height*(1/17)) - board_size_y;
            board_size_x = 200;
            board_size_y = 200;
 
            arrow_x = (pictureBox1.Width / 2 - 30);
            arrow_y = (pictureBox1.Height -100- arrow_size_y;
            arrow_size_x = 50;
            arrow_size_y = 100;
 
            gagebar_x = pictureBox1.Width - 100;
            gagebar_y = pictureBox1.Height - 500;
            gagebar_size_x = 50;
            gagebar_size_y = 500;
 
            gagepoint_x = pictureBox1.Width - 160;
            gagepoint_y = pictureBox1.Height- 30;
            gagepoint_size_x = 60;
            gagepoint_size_y = 30;
 
        }
 
        
 
        private void Form1_Load(object sender, EventArgs e)
        {
 
        }
 
        private void pictureBox1_Paint(object sender, PaintEventArgs e)
        {
            Image board = Bitmap.FromFile("board.png"); // 이미지로 가져오는 소스
            e.Graphics.DrawImage(board, board_x, board_y, board_size_x, board_size_y);
 
            Image arrow = Bitmap.FromFile("arrow2.png"); // 이미지로 가져오는 소스
            e.Graphics.DrawImage(arrow, arrow_x, arrow_y, arrow_size_x, arrow_size_y);
 
            Image gagebar = Bitmap.FromFile("gagebar.png"); // 이미지로 가져오는 소스
            e.Graphics.DrawImage(gagebar, gagebar_x, gagebar_y, gagebar_size_x, gagebar_size_y);
            
            Image gagepoint = Bitmap.FromFile("gagepoint4.png"); // 이미지로 가져오는 소스
            e.Graphics.DrawImage(gagepoint, gagepoint_x, gagepoint_y , gagepoint_size_x, gagepoint_size_y);
 
            Image highlow = Bitmap.FromFile("highlow.png"); // 이미지로 가져오는 소스
            e.Graphics.DrawImage(highlow, highlow_x, highlow_y, highlow_size_x, highlow_size_y);
 
        }
 
        private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
        {
            if (Watch.status == false)
            {
                timer1.Enabled = true;
                power = 0;
                powerCount = 0;
                Watch.status = true;
                
            }
            timer2.Enabled = true;
            arrow_y = (pictureBox1.Height) - arrow_size_y;
            gamestate = false;
        }
 
 
 
        private void timer1_Tick(object sender, EventArgs e)
        {
            
            Watch.milisec++;
            if (Watch.milisec > 2)
            {
                Watch.milisec = 0;
                powerCount++;
                power = powerCount * 20;
                if (power > 460) { 
                powerCount = 0;
                powermax = true;
                }
            }
         
            gagepoint_y = pictureBox1.Height -30 - power;
            
            pictureBox1.Invalidate();
 
        }
 
        private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
        {
            arrow_y = (pictureBox1.Height-350- arrow_size_y;
            pictureBox1.Invalidate();
            if (Watch.status == true)
            {
                timer1.Enabled=false;
                Watch.milisec = 0;
                power = powerCount ;
                
                Watch.status = false;
                
            }
            textBox1.Text = "Power = " + power;
            if (resultState == true)
            {
                resultState = false;
                timer2.Enabled = false;
                if (power == 11 && gamestate == false)
                {
                    gamestate = true;
                    MessageBox.Show("10점");       
                }
                else if ((power == 9 || power == 10 || power == 12 || power == 13&& gamestate == false)
                {
                    gamestate = true;
                    MessageBox.Show("8점");
                }
                else if ((power == 7 || power == 8 || power == 14 || power == 15&& gamestate == false)
                {
                    gamestate = true;
                    MessageBox.Show("6점");
                }
                else if ((power == 5 || power == 6 || power == 16 || power == 17&& gamestate == false)
                {
                    gamestate = true;
                    MessageBox.Show("4점");
                }
                else if ((power == 3 || power == 4 || power == 18 || power == 19&& gamestate == false)
                {
                    gamestate = true;
                    MessageBox.Show("2점");
                }
                else  
                {
                    gamestate = true;
                    MessageBox.Show("장외");
                }
                
            }
 
        }
 
        private void textBox1_TextChanged(object sender, EventArgs e)
        {
           
        }
 
        private void timer2_Tick(object sender, EventArgs e)
        {
          
            resultState = true;
            pictureBox1.Invalidate();
 
        }
    }
}
 
cs

 

// 마우스를 누르면 power 게이지가 올라가며, 뗄경우 화살이 날라가며 점수가 출력 된다.

 

 

반응형

'Study > C#' 카테고리의 다른 글

C# 메모장 프로그램  (0) 2021.01.22
C# - 닷지 게임 만들기 결과  (2) 2018.08.31
C# - 닷지 게임 만들기  (0) 2018.08.30
C# - 비행기 자유롭게 움직이기  (0) 2018.08.30
C# - 공튀기기 (particles.js)  (0) 2018.08.30

+ Recent posts