■LED + keypad 회로도 (비트필드 구조체 사용)■

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
#include "2450addr.h"
typedef struct    
{
    unsigned gpg0 : 2;
    unsigned gpg1 : 2;
    unsigned gpg2 : 2;
    unsigned gpg3 : 2;
    unsigned gpg4 : 2;
    unsigned gpg5 : 2;
    unsigned gpg6 : 2;
    unsigned gpg7 : 2;
 
}gpgcon_t;
typedef struct 
{
    unsigned gpg0 : 1;
    unsigned gpg1 : 1;
    unsigned gpg2 : 1;
    unsigned gpg3 : 1;
    unsigned gpg4 : 1;
    unsigned gpg5 : 1;
    unsigned gpg6 : 1;
    unsigned gpg7 : 1;
}gpgdat_t;
 
typedef struct 
{
    unsigned gpf0 : 2;
    unsigned gpf1 : 2;
    unsigned gpf2 : 2;
    unsigned gpf3 : 2;
    unsigned gpf4 : 2;
    unsigned gpf5 : 2;
    unsigned gpf6 : 2;
    unsigned gpf7 : 2;
}gpfcon_t;
typedef struct 
{
    unsigned gpf0 : 1;
    unsigned gpf1 : 1;
    unsigned gpf2 : 1;
    unsigned gpf3 : 1;
    unsigned gpf4 : 1;
    unsigned gpf5 : 1;
    unsigned gpf6 : 1;
    unsigned gpf7 : 1;
}gpfdat_t;
 
#define GPGCON  (*(volatile gpgcon_t *)0x56000060)
#define GPGDAT  (*(volatile gpgdat_t *)0x56000064)
#define GPFCON  (*(volatile gpfcon_t *)0x56000050)
#define GPFDAT  (*(volatile gpfdat_t *)0x56000054)
void LED_Port_Init(void);
void LED_ON_Off(int num);
int Get_Key_byPolling(void);
 
void Main()
{
    int key;
    LED_Port_Init();
    while(1)
    {
 
    GPGDAT.gpg0 = 0x1;
    GPFDAT.gpf7 = 0x0;
    key = Get_Key_byPolling();    
    LED_ON_Off(key);
 
    GPGDAT.gpg0 =0x0;
    GPFDAT.gpf7 = 0x1;
    key = Get_Key_byPolling();    
    LED_ON_Off(key+1);
 
    }
}
 
void LED_Port_Init() 
{    
    GPGCON.gpg0 = 0x1;
    GPGCON.gpg4 = 0x1;
    GPGCON.gpg5 = 0x1;
    GPGCON.gpg6 = 0x1;
    GPGCON.gpg7 = 0x1;
 
    GPGDAT.gpg4 = 0x1;
    GPGDAT.gpg5 = 0x1;
    GPGDAT.gpg6 = 0x1;
    GPGDAT.gpg7 = 0x1;
    
    GPFCON.gpf2 = 0x0;
    GPFCON.gpf3 = 0x0;
    GPFCON.gpf4 = 0x0;
    GPFCON.gpf5 = 0x0;
    GPFCON.gpf6 = 0x0
    GPFCON.gpf7 = 0x1;
    
 
    GPFDAT.gpf0= 0x0;
    GPFDAT.gpf1= 0x0;
    GPFDAT.gpf2= 0x0;
    GPFDAT.gpf3= 0x0;
    GPFDAT.gpf4= 0x0;
    GPFDAT.gpf5= 0x0;
    GPFDAT.gpf6= 0x0;
    GPFDAT.gpf7= 0x0;
}
 
 
void LED_ON_Off(int num)
{
    switch(num)
    {
    case 0:
    GPGDAT.gpg4 = 0x1;
    GPGDAT.gpg5 = 0x1;
    GPGDAT.gpg6 = 0x1;
    GPGDAT.gpg7 = 0x1;
    break;
    case 1:
    GPGDAT.gpg4 = 0x0;
    GPGDAT.gpg5 = 0x1;
    GPGDAT.gpg6 = 0x1;
    GPGDAT.gpg7 = 0x1;
    break;
    case 2:
    GPGDAT.gpg4 = 0x1;
    GPGDAT.gpg5 = 0x0;
    GPGDAT.gpg6 = 0x1;
    GPGDAT.gpg7 = 0x1;
    break;
    case 3:
    GPGDAT.gpg4 = 0x1;
    GPGDAT.gpg5 = 0x1;
    GPGDAT.gpg6 = 0x0;
    GPGDAT.gpg7 = 0x1;
    break;
    case 4:
    GPGDAT.gpg4 = 0x1;
    GPGDAT.gpg5 = 0x1;
    GPGDAT.gpg6 = 0x1;
    GPGDAT.gpg7 = 0x0;
    break;
    case 5:
    GPGDAT.gpg4 = 0x1;
    GPGDAT.gpg5 = 0x1;
    GPGDAT.gpg6 = 0x0;
    GPGDAT.gpg7 = 0x0;
    break;
    case 6:
    GPGDAT.gpg4 = 0x0;
    GPGDAT.gpg5 = 0x0;
    GPGDAT.gpg6 = 0x1;
    GPGDAT.gpg7 = 0x1;
    break;
    }
}
 
int Get_Key_byPolling(void)
{        
    unsigned char key=(GPFDAT.gpf2)|(GPFDAT.gpf3<<1)|(GPFDAT.gpf4<<2)|(GPFDAT.gpf5<<3)|(GPFDAT.gpf6<<4);
    if(key==0x1e)     
        {return 1;}
    if(key==0x1d)
        {return 2;}
    if(key==0x1b)
        {return 3;}
    if(key==0x17)
        {return 4;}
    if(key==0xf)
        {return 5;}
}
cs


+ Recent posts