This repository has been archived by the owner on Apr 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathC8051F410.c
189 lines (155 loc) · 2.66 KB
/
C8051F410.c
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
#include "C8051F410.h"
#define uchar unsigned char
#define uint unsigned int
sbit RS=P1^3;
sbit RW=P1^4;
sbit EN=P1^5;
sbit PSB=P1^6;
sbit RET=P0^7;
unsigned char opinion[]={"Worked?"};
unsigned char yes_no[]={" YES No "};
unsigned char number[]={" "};
int yesCount=0;
int noCount=0;
int no[10]={48,49,50,51,52,53,54,55,56,57};
void PCA_Init(){
PCA0MD&=~0x40; //WDTE = 0 (clear watchdog timer enable)
}
void SYSCLK_Init(){
OSCICN=0x84;;
}
void GPIO_Init(){
XBR1=0x40;
P2MDOUT=0xff;
}
void Interrupt_Init(){
IT01CF=0x10;
TCON=0x05; //trigger mode
EX0=1;
EX1=1;
EA=1; // Enable global interrupts
}
void Ext_Interrupt_Configuration(){
PCA_Init();
SYSCLK_Init();
GPIO_Init();
Interrupt_Init();
}
void Port_IO_Init()
{
XBR1 = 0x40;
}
void Oscillator_Init()
{
OSCICN = 0x86;
}
void Init_Device(void)
{
PCA_Init();
Port_IO_Init();
Oscillator_Init();
}
void delay_50us(uint t)
{
uchar i=2;
while(t--)
while(i--);
}
void delay_50ms(uint t)
{
uint i,j,k;
for (i=t;i>0;i--)
for (j=57;j>0;j--)
for(k=100;k>0;k--);
}
void wr_command(uchar com)
{
RS=0;
RW=0;
delay_50us(1);
P2=com;
EN=1;
delay_50us(1);
EN=0;
delay_50us(1);
}
void wr_data(uchar dat)
{
RS=1;
RW=0;
delay_50us(1);
P2=dat;
EN=1;
delay_50us(1);
EN=0;
delay_50us(1);
}
void re_data(uchar *dat)
{
while(*dat != '\0')
wr_data(*dat++);
}
void wr_address(uchar x,uchar y)
{
uchar temp = 0;
switch(x)
{
case 1:
temp = 0x7f;
break;
case 2:
temp = 0x8f;
break;
case 3:
temp = 0x87;
break;
case 4:
temp = 0x97;
break;
}
temp = temp + y;
wr_command(temp);
}
void display(char q[],int x,int y)
{
wr_address(x,y);
delay_50us(3);
re_data(q);
delay_50us(4);
}
void init_12864( )
{
PSB=1;
wr_command(0x30);
delay_50us(2);
wr_command(0x30);
delay_50us(2);
wr_command(0x0c);
delay_50us(1);
wr_command(0x01);
delay_50us(20);
wr_command(0x06);
delay_50us(2);
}
void INT0_ISR() interrupt 0
{
yesCount++;
number[2]=no[(yesCount/10)%10];
number[3 ]=no[yesCount%10];
display(number,3,1);
}
void INT1_ISR() interrupt 2
{
noCount++;
number[9]=no[(noCount/10)%10];
number[10]=no[noCount%10];
display(number,3,1);
}
void main(){
Init_Device();
init_12864();
Ext_Interrupt_Configuration();
display(opinion,1,4);
display(yes_no,2,1);
while(1); // Wait forever
}