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

 

 

 

반응형

+ Recent posts