반응형
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 |
// 키를 누를 경우 알파벳 출력.
반응형
'Study > 8-bit MCUs' 카테고리의 다른 글
[NPAVR Board] AVR - Atemga128(Timer/Counter0)- OVF (0) | 2018.09.10 |
---|---|
[NPAVR Board] AVR - Atmega128 (Dot Matrix) (0) | 2018.09.04 |
[NPAVR Board] AVR - Atemga128 (ADC, CDS) (0) | 2018.09.04 |
[NPAVR Board] AVR - Atmega128 (Character LCD, Switch) (0) | 2018.09.04 |
[NPAVR Board] AVR - Atmega128 (Character LCD) (0) | 2018.09.04 |