-
Notifications
You must be signed in to change notification settings - Fork 0
/
bk4802noledstc8.c
262 lines (247 loc) · 5.27 KB
/
bk4802noledstc8.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
#include "STC8F.h"
#include "intrins.h"
#include "IICANDDELAY.h"
#include "codetab.h"
sbit set=P3^7;//must connect not more than 8.2K resistor to GND
//MCU and BK4802N share 3.3v VCC(STC8MCU must using 3.3v VCC)
//BK4802N pin19-pin22 must connect to 3.3v.
sbit ppt=P5^4;//ppt must be connected to BK4802N pin23.
sbit test=P5^5;//test(p5.5) connect a LED to GND to indict 4802n IIC RUN.
//DEFAULT FERQ:TX=RX=439.725mh.uSING "BK4802NCalc.exe to calculate.
int rxfreq[]={
0x52BE,0xF850,0x0000};
int txfreq[]={
0x52C5,0x925F,0x0000};
char txinf[]="TX...";
char rxinf[]="RX...";
char blankinf[]=" ";
char newtxfreq[6];
char newrxfreq[6];
unsigned char newtxfreqinf[6];
//char newrxfreqinf[6];
int rxreg[]={ //rx setting for register
0x0300,
0x8e04,
0xF140,
0xED00,
0x17E0,
0xe0e0,
0x8543,
0x0700,
0xA066,
0xFFFF,
0xFFE0,
0x07a0,
0x9E3C,
0x1F00,
0xD1D1,
0x200F,
0x01FF,
0xE000,
0x0340
};
int txreg[]={//tx setting for register
0x7C00,
0x0c04,
0xF140,
0xED00,
0x3fE0,
0xe0e0,
0x8543,
0x0700,
0xA066,
0xFFFF,
0xffe0,
0x061f,
0x9e3c,
0x1f00,
0xd1C1,
0x200f,
0x01FF,
0xE000,
0x0c00
};
void setchannel(char k)//setting new trx freq from EEPROM in MCU
{
int i;
for(i=0;i<6;i++)
{
newrxfreq[i]=IapRead(i+6+k*32);
newtxfreq[i]=IapRead(i+k*32);
}
}
void setchannelinf(char k)//setting new trx freq information display on OLED from EEPROM in MCU
{
int i;
for(i=0;i<6;i++)
{
newtxfreqinf[i]=IapRead(i+16+k*32);
}
}
void main()
{
unsigned char i,f;// i do for 'for',f do for store channel No.
unsigned char k=0;//k is do for trx
//Start
test=1;
Delay50ms();
OLED_Init(); //OLED初始化
for(i=0; i<8; i++)//通过点整显示汉字 -- i表示字表数组的位置
{
OLED_P16x16Ch(i*16,0,i);//In the name of the Moon ,I will punish you.
OLED_P16x16Ch(i*16,2,i+8); //Moon promise power, make up!
}
OLED_P8x16Str(0,6,"BG7QKU");
delay(10000);
OLED_CLS();//清屏
test=0;
OLED_P8x16Str(0,0,"BG7QKU");
for(i=0; i<8; i++)
{
OLED_P16x16Ch(i*16,6,i);
}
writing(0x90,23,0xa8,0XD0);//Init rx reg23.
if(P11==0)//if default or not?
{
for(i=4;i<=22;i++)
{
writing(0x90,i,HIGHBYTE(rxreg[i-4]),LOWBYTE(rxreg[i-4]));//init default reg. ro rx
}
for(i=5;i>2;i--)
{
writing(0x90,i-3,HIGHBYTE(rxfreq[i-3]),LOWBYTE(rxfreq[i-3]));//init default reg. to rx freq
}
OLED_P8x16Str(0,4,"439.725");
OLED_P8x16Str(0,2,rxinf);
}
else
{
f=IapRead(0x0200);//read store channel No.
if (f>3)
f=0;
setchannel(f);
setchannelinf(f);
OLED_P8x16Str(0,4,newtxfreqinf);
k=1;
}
test=1;
while(1)
{
if(set==1)//teat channel change key
{
Delay30ms();//kill swim
if(set==1)
{
Delay30ms();//down to LOW to set channel
if(set==0)
{
f++;
if(f>3)
f=0;
IapErase(0x0200);//erase EEPROM before write
IapProgram(0x0200,f);//write EEPORM
setchannel(f);
setchannelinf(f);
OLED_P8x16Str(0,4,newtxfreqinf);
k=1;
}
}
}
//Only using default freq
if(ppt==1&&k==0&&P11==0)//Set to TX if PTT =HIGH.
{
test=0;
Delay30ms();
if(ppt==1)
{
Delay30ms();
for(i=4;i<=22;i++)
{
writing(0x90,i,HIGHBYTE(txreg[i-4]),LOWBYTE(txreg[i-4]));
}
for(i=5;i>2;i--)
{
writing(0x90,i-3,HIGHBYTE(txfreq[i-3]),LOWBYTE(txfreq[i-3]));
}
Delay30ms();
OLED_P8x16Str(0,2,blankinf);
OLED_P8x16Str(0,2,"439.725");
test=1;
k=1;
}
}
if(ppt==0&&k==1&&P11==0)//Set to RX.
{
test=0;
Delay30ms();
if(ppt==0)
{
Delay30ms();
writing(0x90,23,0xa8,0XD0);
for(i=4;i<=22;i++)
{
writing(0x90,i,HIGHBYTE(rxreg[i-4]),LOWBYTE(rxreg[i-4]));
}
for(i=5;i>2;i--)
{
writing(0x90,i-3,HIGHBYTE(rxfreq[i-3]),LOWBYTE(rxfreq[i-3]));
}
Delay30ms();
OLED_P8x16Str(0,2,blankinf);
OLED_P8x16Str(0,2,"439.725");
test=1;
k=0;
}
}
//Using pre-set freq
if(ppt==1&&k==0&&P11==1)//Set to TX if PTT =HIGH.
{
test=0;
Delay30ms();
if(ppt==1)
{
setchannel(f);
setchannelinf(f);
test=0;
OLED_P8x16Str(0,4,newtxfreqinf);
Delay30ms();
for(i=4;i<=22;i++)
{
writing(0x90,i,HIGHBYTE(txreg[i-4]),LOWBYTE(txreg[i-4]));
}
for(i=5;i>2;i--)
{
writing(0x90,i-3,newtxfreq[2*(i-3)],newtxfreq[2*(i-3)+1]);
}
Delay30ms();
OLED_P8x16Str(0,2,blankinf);
OLED_P8x16Str(0,2,txinf);
test=1;
k=1;
}
}
if(ppt==0&&k==1&&P11==1)//Set to RX.
{
Delay30ms();
if(ppt==0)
{
test=0;
Delay30ms();
writing(0x90,23,0xa8,0XD0);
for(i=4;i<=22;i++)
{
writing(0x90,i,HIGHBYTE(rxreg[i-4]),LOWBYTE(rxreg[i-4]));
}
for(i=5;i>2;i--)
{
writing(0x90,i-3,newrxfreq[2*(i-3)],newrxfreq[2*(i-3)+1]);
}
Delay30ms();
OLED_P8x16Str(0,2,blankinf);
OLED_P8x16Str(0,2,rxinf);
test=1;
k=0;
}
}
}
}