반응형

* Dot Matrix

 

1. 하트를 그리고, 그 하트를 방향키를 이용하여 움직인다.

 

2. 불켜기 게임을 Dotmatrix로 구현한다. 25개를 다 켜면 HLED가 ON/OFF

 

3. 폭탄 피하기 게임

 

* Key Matrix

 

1. 핸드폰 영문자판 흉내내기

 - 키매트릭스를 핸드폰 자판이라 생각하고 LCD에 글을 써보자

 

* HLED 녹화하기

 - 타이머 인터럽트를 이용해서 구현하기

 

 

 

** 고난도 프로젝트

 

LCD에 Key입력을 받아 명령을 수행한다.

 

MTR RI 30 모터를 오른쪽으로 30도 이동 

MTR LE 15 모터를 왼쪽으로 15도 이동

 

...

반응형
반응형
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

 

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

반응형

+ Recent posts