-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmidi6.c
4502 lines (3831 loc) · 111 KB
/
midi6.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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
///////////////////////////////////////////////////////////////////
/* 6-Band QRP HF Transceiver "Midi6" */
/* ************************************************************ */
/* Mikrocontroller: ATMEL AVR ATmega128, 16 MHz */
/* LCD: CP11003 (8 bit parallel interface) */
/* DDS used: AD9951 (VFO), AD9834 (LO) */
/* */
/* Compiler: GCC (GNU AVR C-Compiler) */
/* Author: Peter Rachow (DK7IH) */
/* Last modification: 2020-26-11 */
///////////////////////////////////////////////////////////////////
//MIC connector from front (Mini DIN)
// [ ]
//
// (1) (2)
//
// (3) (4)
//
// 1=PTT
// 2=MIC
// 3,4=GND
// UART 3 pole connector for CAT (computer aided tuning)
// -----------
// <AAA|BBB|CCC
// ----------- A TX out|B RX in | C GND
//
// MUC: grey: RX, green: TX
///////////////////////
// MCU PORTS //
///////////////////////
///////////////
//O U T P U T//
///////////////
//LCD
// Data lines
//PC0 violet
//PC1 blue
//PC2 green
//PC3 brown
//PC4 yellow
//PC5 grey
//PC6 white
//PC7 pink / orange
// Ctrl lines
//PA4 blue RS
//PA5 brown WR
//PA6 violet RD
//PA7 green RES
//BCD driver for band relays
//PA0 white
//PA1 green
//PA2 grey
//PE3 LCD Backlight PWM
//PA3 TX/RX relay out
//DDS1 AD9951
// PD4: IO_UD //green
// PD5: SDIO //white
// PD6: SCLK //blue
// PD7: RESETPIN //violet
//PB3: RX ATT
//DDS2 AD9834
// PB4: FQ_UD //green
// PB5: SDATA //white
// PB6: W_CLK //blue
//PB7 Tone oscillator
//Tone
//PG3, PG4
//AGC
//PG0, PG1
/////////////
//I N P U T//
/////////////
//PD2 ROT ENC
//PD3
//ADC
//PF0/ADC0: Keys yellow
//PF1/ADC1: PWR-Meter violet
//PF2/ADC2: PA Temperature brown
//PF3/ADC3: Voltage green
//PF4/ADC4: S-Meter blue
//PG2 PTT in
///////////
// T W I //
///////////
//PD0: SCL yellow
//PD1: SDA green
///////////////////////
// E E P R O M //
///////////////////////
// Bytes
// 0:63: Memory frequencies 160m Formula: memplace = band * 64 + memory# * 4
// 64:127: Memory frequencies 80m
// 128:191: Memory frequencies 40m
// 192:255: Memory frequencies 20m
// 256:319: Memory frequencies 15m
// 320:383: Memory frequencies 10m
//VFO frequencies
// 384:387: Freq VFO A 160m memplace=96 Formula: memplace = band * 2 + 96
// 388:391: Freq VFO B 160m memplace=97
// 392:395: Freq VFO A 80m memplace=98
// 396:399: Freq VFO B 80m memplace=99
// 400:403: Freq VFO A 40m memplace=100
// 404:407: Freq VFO B 40m memplace=101
// 408:411: Freq VFO A 20m memplace=102
// 412:415: Freq VFO B 20m memplace=103
// 416:419: Freq VFO A 15m memplace=104
// 420:423: Freq VFO B 15m memplace=105
// 424:427: Freq VFO A 10m memplace=106
// 428:431: Freq VFO B 10m memplace=107
// 432:435: Reserved
// 436:439: Reserved
// 440: Last band used
// 441: Last VFO in use
// 442: Last memory selected
// 450: Scan threshold (0:80)
// 480: TONE set
// 481: AGC set
// 482: Backlight set
// 483: ATT set
// 484, 485: TX preset 160m
// 486, 487: TX preset 80m
// 488, 489: TX preset 40m
// 490, 491: TX preset 20m
// 492, 493: TX preset 15m
// 494, 495: TX preset 10m
//512:515: f.Lo.LSB
//516:519: f.Lo.USB
//Scan edge frquencies
/*
550 553 Scanfreq0: 160
554 557 Scanfreq1: 160
558 561 Scanfreq0: 80
562 565 Scanfreq1: 80
566 569 Scanfreq0: 40
570 573 Scanfreq1: 40
574 577 Scanfreq0: 20
578 581 Scanfreq1: 20
582 585 Scanfreq0: 15
586 589 Scanfreq1: 15
590 593 Scanfreq0: 10
594 597 Scanfreq1: 10
*/
#include <inttypes.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <avr/pgmspace.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>
#include <util/delay.h>
#include <avr/eeprom.h>
#define FOSC 16000000// Clock Speed
#define BAUD 2400
#define UARTBAUDSET FOSC/16/BAUD-1
#define MAXRXBUFLEN 24
///////////////////
// LCD-Display //
///////////////////
//LCD ILI9341
//Parallel output (8 bit) line defines
#define LCDDATAPORT PORTC
#define LCDDATADDR DDRC
#define LCDCTRLPORT PORTA
#define LCDCTRLDDR DDRA
#define LCDRS 16 //CMD (low) or DATA (high) blue
#define LCDWR 32 //Write operation indicator (actice low) brown
#define LCDRD 64 //Read indicator (actice low) vioelt
#define LCDRES 128 //Reset (active low) green
//Code defines for basic LCD write procedure
#define LCD_CMD 0
#define LCD_DATA 1
//LCD resolution
#define LCD_WIDTH 320
#define LCD_HEIGHT 240
//Menu
#define MENUITEMS 11
//Sample colors
#define WHITE 0xFFFF
#define SILVER1 0xC618
#define SILVER2 0xA510
#define BLACK0 0x0000
#define BLACK1 0x0004
#define GRAY 0x8410
#define LIGHT_GRAY 0xC618
#define DARK_GRAY 0x628A
#define LIGHT_GREEN 0x07E0
#define LIGHT_RED 0xF800
#define RED 0xF800
#define LIGHT_BLUE 0x03FF
#define BLUE 0x001F
#define DARK_BLUE1 0x0002
#define DARK_BLUE2 0x0008
#define MAROON1 0x8000
#define MAROON2 0x7800
#define FUCHSIA 0xF81F
#define PURPLE1 0x8010
#define PURPLE2 0x780F
#define LIME 0x07E0
#define GREEN 0x0400
#define YELLOW 0xFFE0
#define OLIVE1 0x8400
#define OLIVE2 0x7BE0
#define NAVY1 0x0010
#define NAVY2 0x000F
#define AQUA 0x07FF
#define TEAL 0x0410
#define MAGENTA 0xF81F
#define CYAN 0x07FF
#define DARK_CYAN 0x03EF
#define ORANGE 0xFCA0
#define BROWN 0x8200
#define LIGHT_BROWN 0xF5F0
#define VIOLET 0x9199
#define LIGHT_VIOLET 0xF00F
#define PINK 0xF97F
#define GOLD 0xA508
//Font dimensions
#define FONTWIDTH 12
#define FONTHEIGHT 16
//Font data 12x16 vert. MSB
//Based on work by Benedikt K. published on
//https://www.mikrocontroller.net/topic/54860 THANKS!
const char xchar[][24] PROGMEM={
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // 0x00
{0x00,0x00,0x03,0xF0,0x0C,0x0C,0x10,0x02,0x11,0x32,0x22,0x31,0x22,0x01,0x22,0x31,0x11,0x32,0x10,0x02,0x0C,0x0C,0x03,0xF0}, // 0x01
{0x00,0x00,0x03,0xF0,0x0F,0xFC,0x1F,0xFE,0x1E,0xCE,0x3D,0xCF,0x3D,0xFF,0x3D,0xCF,0x1E,0xCE,0x1F,0xFE,0x0F,0xFC,0x03,0xF0}, // 0x02
{0x00,0x00,0x00,0x00,0x00,0xF0,0x01,0xF8,0x03,0xF8,0x07,0xF0,0x0F,0xE0,0x07,0xF0,0x03,0xF8,0x01,0xF8,0x00,0xF0,0x00,0x00}, // 0x03
{0x00,0x00,0x00,0x00,0x00,0x80,0x01,0xC0,0x03,0xE0,0x07,0xF0,0x0F,0xF8,0x07,0xF0,0x03,0xE0,0x01,0xC0,0x00,0x80,0x00,0x00}, // 0x04
{0x00,0x00,0x03,0x80,0x07,0xC0,0x07,0xC0,0x13,0xB8,0x1B,0xFC,0x1F,0xFC,0x1B,0xFC,0x13,0xB8,0x07,0xC0,0x07,0xC0,0x03,0x80}, // 0x05
{0x00,0x00,0x00,0x00,0x03,0x80,0x07,0xC0,0x17,0xE0,0x1B,0xF0,0x1F,0xFC,0x1B,0xF0,0x17,0xE0,0x07,0xC0,0x03,0x80,0x00,0x00}, // 0x06
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // 0x07
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // 0x08
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // 0x09
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // 0x0A
{0x00,0x00,0x03,0x80,0x07,0xC0,0x0C,0x60,0x08,0x20,0x08,0x20,0x0C,0x60,0x07,0xC8,0x03,0xA8,0x00,0x18,0x00,0x78,0x00,0x00}, // 0x0B
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x08,0xF8,0x09,0x8C,0x3F,0x04,0x3F,0x04,0x09,0x8C,0x08,0xF8,0x00,0x70,0x00,0x00}, // 0x0C
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // 0x0D
{0x00,0x00,0x06,0x00,0x0F,0x00,0x0F,0x00,0x07,0xFF,0x00,0x33,0x30,0x66,0x78,0xCC,0x79,0x98,0x3F,0xF0,0x00,0x00,0x00,0x00}, // 0x0E
{0x00,0x00,0x00,0x80,0x09,0xC8,0x07,0xF0,0x06,0x30,0x0C,0x18,0x3C,0x1E,0x0C,0x18,0x06,0x30,0x07,0xF0,0x09,0xC8,0x00,0x80}, // 0x0F
{0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xFC,0x0F,0xF8,0x07,0xF0,0x03,0xE0,0x01,0xC0,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00}, // 0x10
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x01,0xC0,0x03,0xE0,0x07,0xF0,0x0F,0xF8,0x1F,0xFC,0x00,0x00,0x00,0x00,0x00,0x00}, // 0x11
{0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x10,0x0C,0x18,0x1C,0x1C,0x3F,0xFE,0x1C,0x1C,0x0C,0x18,0x04,0x10,0x00,0x00,0x00,0x00}, // 0x12
{0x00,0x00,0x00,0x00,0x00,0x00,0x37,0xFE,0x37,0xFE,0x00,0x00,0x00,0x00,0x37,0xFE,0x37,0xFE,0x00,0x00,0x00,0x00,0x00,0x00}, // 0x13
{0x00,0x00,0x00,0x38,0x00,0x7C,0x00,0xC6,0x00,0x82,0x3F,0xFE,0x3F,0xFE,0x00,0x02,0x3F,0xFE,0x3F,0xFE,0x00,0x02,0x00,0x00}, // 0x14
{0x00,0x00,0x00,0x00,0x08,0xDC,0x19,0xFE,0x11,0x22,0x11,0x22,0x11,0x22,0x11,0x22,0x1F,0xE6,0x0E,0xC4,0x00,0x00,0x00,0x00}, // 0x15
{0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x00,0x00}, // 0x16
{0x00,0x00,0x00,0x00,0x00,0x00,0x44,0x08,0x4C,0x0C,0x5C,0x0E,0x7F,0xFF,0x5C,0x0E,0x4C,0x0C,0x44,0x08,0x00,0x00,0x00,0x00}, // 0x17
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x18,0x00,0x1C,0x3F,0xFE,0x00,0x1C,0x00,0x18,0x00,0x10,0x00,0x00,0x00,0x00}, // 0x18
{0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x0C,0x00,0x1C,0x00,0x3F,0xFE,0x1C,0x00,0x0C,0x00,0x04,0x00,0x00,0x00,0x00,0x00}, // 0x19
{0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x07,0xF0,0x03,0xE0,0x01,0xC0,0x00,0x80,0x00,0x00}, // 0x1A
{0x00,0x00,0x00,0x00,0x00,0x80,0x01,0xC0,0x03,0xE0,0x07,0xF0,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x00}, // 0x1B
{0x00,0x00,0x3F,0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x00,0x00}, // 0x1C
{0x00,0x00,0x00,0x80,0x01,0xC0,0x03,0xE0,0x07,0xF0,0x00,0x80,0x00,0x80,0x00,0x80,0x07,0xF0,0x03,0xE0,0x01,0xC0,0x00,0x80}, // 0x1D
{0x00,0x00,0x04,0x00,0x06,0x00,0x07,0x00,0x07,0x80,0x07,0xC0,0x07,0xE0,0x07,0xC0,0x07,0x80,0x07,0x00,0x06,0x00,0x04,0x00}, // 0x1E
{0x00,0x00,0x00,0x20,0x00,0x60,0x00,0xE0,0x01,0xE0,0x03,0xE0,0x07,0xE0,0x03,0xE0,0x01,0xE0,0x00,0xE0,0x00,0x60,0x00,0x20}, // 0x1F
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // 0x20
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x33,0xFF,0x33,0xFF,0x00,0x7C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // 0x21
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x00,0x3C,0x00,0x00,0x00,0x00,0x00,0x3C,0x00,0x3C,0x00,0x00,0x00,0x00,0x00,0x00}, // 0x22
{0x00,0x00,0x02,0x00,0x1E,0x10,0x1F,0x90,0x03,0xF0,0x02,0x7E,0x1E,0x1E,0x1F,0x90,0x03,0xF0,0x02,0x7E,0x00,0x1E,0x00,0x10}, // 0x23
{0x00,0x00,0x00,0x00,0x04,0x78,0x0C,0xFC,0x0C,0xCC,0x3F,0xFF,0x3F,0xFF,0x0C,0xCC,0x0F,0xCC,0x07,0x88,0x00,0x00,0x00,0x00}, // 0x24
{0x00,0x00,0x30,0x00,0x38,0x38,0x1C,0x38,0x0E,0x38,0x07,0x00,0x03,0x80,0x01,0xC0,0x38,0xE0,0x38,0x70,0x38,0x38,0x00,0x1C}, // 0x25
{0x00,0x00,0x00,0x00,0x1F,0x00,0x3F,0xB8,0x31,0xFC,0x21,0xC6,0x37,0xE2,0x1E,0x3E,0x1C,0x1C,0x36,0x00,0x22,0x00,0x00,0x00}, // 0x26
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x27,0x00,0x3F,0x00,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // 0x27
{0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xF0,0x0F,0xFC,0x1F,0xFE,0x38,0x07,0x20,0x01,0x20,0x01,0x00,0x00,0x00,0x00,0x00,0x00}, // 0x28
{0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x01,0x20,0x01,0x38,0x07,0x1F,0xFE,0x0F,0xFC,0x03,0xF0,0x00,0x00,0x00,0x00,0x00,0x00}, // 0x29
{0x00,0x00,0x00,0x00,0x0C,0x98,0x0E,0xB8,0x03,0xE0,0x0F,0xF8,0x0F,0xF8,0x03,0xE0,0x0E,0xB8,0x0C,0x98,0x00,0x00,0x00,0x00}, // 0x2A
{0x00,0x00,0x00,0x00,0x01,0x80,0x01,0x80,0x01,0x80,0x0F,0xF0,0x0F,0xF0,0x01,0x80,0x01,0x80,0x01,0x80,0x00,0x00,0x00,0x00}, // 0x2B
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xB8,0x00,0xF8,0x00,0x78,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // 0x2C
{0x00,0x00,0x00,0x00,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x00,0x00,0x00,0x00}, // 0x2D
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // 0x2E
{0x00,0x00,0x18,0x00,0x1C,0x00,0x0E,0x00,0x07,0x00,0x03,0x80,0x01,0xC0,0x00,0xE0,0x00,0x70,0x00,0x38,0x00,0x1C,0x00,0x0E}, // 0x2F
{0x00,0x00,0x07,0xF8,0x1F,0xFE,0x1E,0x06,0x33,0x03,0x31,0x83,0x30,0xC3,0x30,0x63,0x30,0x33,0x18,0x1E,0x1F,0xFE,0x07,0xF8}, // 0x30
{0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x0C,0x30,0x0C,0x30,0x0E,0x3F,0xFF,0x3F,0xFF,0x30,0x00,0x30,0x00,0x30,0x00,0x00,0x00}, // 0x31
{0x00,0x00,0x30,0x1C,0x38,0x1E,0x3C,0x07,0x3E,0x03,0x37,0x03,0x33,0x83,0x31,0xC3,0x30,0xE3,0x30,0x77,0x30,0x3E,0x30,0x1C}, // 0x32
{0x00,0x00,0x0C,0x0C,0x1C,0x0E,0x38,0x07,0x30,0xC3,0x30,0xC3,0x30,0xC3,0x30,0xC3,0x30,0xC3,0x39,0xE7,0x1F,0x7E,0x0E,0x3C}, // 0x33
{0x00,0x00,0x03,0xC0,0x03,0xE0,0x03,0x70,0x03,0x38,0x03,0x1C,0x03,0x0E,0x03,0x07,0x3F,0xFF,0x3F,0xFF,0x03,0x00,0x03,0x00}, // 0x34
{0x00,0x00,0x0C,0x3F,0x1C,0x7F,0x38,0x63,0x30,0x63,0x30,0x63,0x30,0x63,0x30,0x63,0x30,0x63,0x38,0xE3,0x1F,0xC3,0x0F,0x83}, // 0x35
{0x00,0x00,0x0F,0xC0,0x1F,0xF0,0x39,0xF8,0x30,0xDC,0x30,0xCE,0x30,0xC7,0x30,0xC3,0x30,0xC3,0x39,0xC3,0x1F,0x80,0x0F,0x00}, // 0x36
{0x00,0x00,0x00,0x03,0x00,0x03,0x00,0x03,0x30,0x03,0x3C,0x03,0x0F,0x03,0x03,0xC3,0x00,0xF3,0x00,0x3F,0x00,0x0F,0x00,0x03}, // 0x37
{0x00,0x00,0x0F,0x00,0x1F,0xBC,0x39,0xFE,0x30,0xE7,0x30,0xC3,0x30,0xC3,0x30,0xC3,0x30,0xE7,0x39,0xFE,0x1F,0xBC,0x0F,0x00}, // 0x38
{0x00,0x00,0x00,0x3C,0x00,0x7E,0x30,0xE7,0x30,0xC3,0x30,0xC3,0x38,0xC3,0x1C,0xC3,0x0E,0xC3,0x07,0xE7,0x03,0xFE,0x00,0xFC}, // 0x39
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // 0x3A
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x9C,0x70,0xFC,0x70,0x7C,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // 0x3B
{0x00,0x00,0x00,0x00,0x00,0xC0,0x01,0xE0,0x03,0xF0,0x07,0x38,0x0E,0x1C,0x1C,0x0E,0x38,0x07,0x30,0x03,0x00,0x00,0x00,0x00}, // 0x3C
{0x00,0x00,0x00,0x00,0x06,0x60,0x06,0x60,0x06,0x60,0x06,0x60,0x06,0x60,0x06,0x60,0x06,0x60,0x06,0x60,0x06,0x60,0x00,0x00}, // 0x3D
{0x00,0x00,0x00,0x00,0x30,0x03,0x38,0x07,0x1C,0x0E,0x0E,0x1C,0x07,0x38,0x03,0xF0,0x01,0xE0,0x00,0xC0,0x00,0x00,0x00,0x00}, // 0x3E
{0x00,0x00,0x00,0x1C,0x00,0x1E,0x00,0x07,0x00,0x03,0x37,0x83,0x37,0xC3,0x00,0xE3,0x00,0x77,0x00,0x3E,0x00,0x1C,0x00,0x00}, // 0x3F
{0x00,0x00,0x0F,0xF8,0x1F,0xFE,0x18,0x07,0x33,0xF3,0x37,0xFB,0x36,0x1B,0x37,0xFB,0x37,0xFB,0x36,0x07,0x03,0xFE,0x01,0xF8}, // 0x40
{0x00,0x00,0x38,0x00,0x3F,0x00,0x07,0xE0,0x06,0xFC,0x06,0x1F,0x06,0x1F,0x06,0xFC,0x07,0xE0,0x3F,0x00,0x38,0x00,0x00,0x00}, // 0x41
{0x00,0x00,0x3F,0xFF,0x3F,0xFF,0x30,0xC3,0x30,0xC3,0x30,0xC3,0x30,0xC3,0x30,0xE7,0x39,0xFE,0x1F,0xBC,0x0F,0x00,0x00,0x00}, // 0x42
{0x00,0x00,0x03,0xF0,0x0F,0xFC,0x1C,0x0E,0x38,0x07,0x30,0x03,0x30,0x03,0x30,0x03,0x38,0x07,0x1C,0x0E,0x0C,0x0C,0x00,0x00}, // 0x43
{0x00,0x00,0x3F,0xFF,0x3F,0xFF,0x30,0x03,0x30,0x03,0x30,0x03,0x30,0x03,0x38,0x07,0x1C,0x0E,0x0F,0xFC,0x03,0xF0,0x00,0x00}, // 0x44
{0x00,0x00,0x3F,0xFF,0x3F,0xFF,0x30,0xC3,0x30,0xC3,0x30,0xC3,0x30,0xC3,0x30,0xC3,0x30,0xC3,0x30,0x03,0x30,0x03,0x00,0x00}, // 0x45
{0x00,0x00,0x3F,0xFF,0x3F,0xFF,0x00,0xC3,0x00,0xC3,0x00,0xC3,0x00,0xC3,0x00,0xC3,0x00,0xC3,0x00,0x03,0x00,0x03,0x00,0x00}, // 0x46
{0x00,0x00,0x03,0xF0,0x0F,0xFC,0x1C,0x0E,0x38,0x07,0x30,0x03,0x30,0xC3,0x30,0xC3,0x30,0xC3,0x3F,0xC7,0x3F,0xC6,0x00,0x00}, // 0x47
{0x00,0x00,0x3F,0xFF,0x3F,0xFF,0x00,0xC0,0x00,0xC0,0x00,0xC0,0x00,0xC0,0x00,0xC0,0x00,0xC0,0x3F,0xFF,0x3F,0xFF,0x00,0x00}, // 0x48
{0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x03,0x30,0x03,0x3F,0xFF,0x3F,0xFF,0x30,0x03,0x30,0x03,0x00,0x00,0x00,0x00,0x00,0x00}, // 0x49
{0x00,0x00,0x0E,0x00,0x1E,0x00,0x38,0x00,0x30,0x00,0x30,0x00,0x30,0x00,0x30,0x00,0x38,0x00,0x1F,0xFF,0x07,0xFF,0x00,0x00}, // 0x4A
{0x00,0x00,0x3F,0xFF,0x3F,0xFF,0x00,0xC0,0x01,0xE0,0x03,0xF0,0x07,0x38,0x0E,0x1C,0x1C,0x0E,0x38,0x07,0x30,0x03,0x00,0x00}, // 0x4B
{0x00,0x00,0x3F,0xFF,0x3F,0xFF,0x30,0x00,0x30,0x00,0x30,0x00,0x30,0x00,0x30,0x00,0x30,0x00,0x30,0x00,0x30,0x00,0x00,0x00}, // 0x4C
{0x00,0x00,0x3F,0xFF,0x3F,0xFF,0x00,0x1E,0x00,0x78,0x01,0xE0,0x01,0xE0,0x00,0x78,0x00,0x1E,0x3F,0xFF,0x3F,0xFF,0x00,0x00}, // 0x4D
{0x00,0x00,0x3F,0xFF,0x3F,0xFF,0x00,0x0E,0x00,0x38,0x00,0xF0,0x03,0xC0,0x07,0x00,0x1C,0x00,0x3F,0xFF,0x3F,0xFF,0x00,0x00}, // 0x4E
{0x00,0x00,0x03,0xF0,0x0F,0xFC,0x1C,0x0E,0x38,0x07,0x30,0x03,0x30,0x03,0x38,0x07,0x1C,0x0E,0x0F,0xFC,0x03,0xF0,0x00,0x00}, // 0x4F
{0x00,0x00,0x3F,0xFF,0x3F,0xFF,0x01,0x83,0x01,0x83,0x01,0x83,0x01,0x83,0x01,0x83,0x01,0xC7,0x00,0xFE,0x00,0x7C,0x00,0x00}, // 0x50
{0x00,0x00,0x03,0xF0,0x0F,0xFC,0x1C,0x0E,0x38,0x07,0x30,0x03,0x36,0x03,0x3E,0x07,0x1C,0x0E,0x3F,0xFC,0x33,0xF0,0x00,0x00}, // 0x51
{0x00,0x00,0x3F,0xFF,0x3F,0xFF,0x01,0x83,0x01,0x83,0x03,0x83,0x07,0x83,0x0F,0x83,0x1D,0xC7,0x38,0xFE,0x30,0x7C,0x00,0x00}, // 0x52
{0x00,0x00,0x0C,0x3C,0x1C,0x7E,0x38,0xE7,0x30,0xC3,0x30,0xC3,0x30,0xC3,0x30,0xC3,0x39,0xC7,0x1F,0x8E,0x0F,0x0C,0x00,0x00}, // 0x53
{0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x03,0x00,0x03,0x3F,0xFF,0x3F,0xFF,0x00,0x03,0x00,0x03,0x00,0x03,0x00,0x00,0x00,0x00}, // 0x54
{0x00,0x00,0x07,0xFF,0x1F,0xFF,0x38,0x00,0x30,0x00,0x30,0x00,0x30,0x00,0x30,0x00,0x38,0x00,0x1F,0xFF,0x07,0xFF,0x00,0x00}, // 0x55
{0x00,0x00,0x00,0x07,0x00,0x3F,0x01,0xF8,0x0F,0xC0,0x3E,0x00,0x3E,0x00,0x0F,0xC0,0x01,0xF8,0x00,0x3F,0x00,0x07,0x00,0x00}, // 0x56
{0x00,0x00,0x3F,0xFF,0x3F,0xFF,0x1C,0x00,0x06,0x00,0x03,0x80,0x03,0x80,0x06,0x00,0x1C,0x00,0x3F,0xFF,0x3F,0xFF,0x00,0x00}, // 0x57
{0x00,0x00,0x30,0x03,0x3C,0x0F,0x0E,0x1C,0x03,0x30,0x01,0xE0,0x01,0xE0,0x03,0x30,0x0E,0x1C,0x3C,0x0F,0x30,0x03,0x00,0x00}, // 0x58
{0x00,0x00,0x00,0x03,0x00,0x0F,0x00,0x3C,0x00,0xF0,0x3F,0xC0,0x3F,0xC0,0x00,0xF0,0x00,0x3C,0x00,0x0F,0x00,0x03,0x00,0x00}, // 0x59
{0x00,0x00,0x30,0x03,0x3C,0x03,0x3E,0x03,0x33,0x03,0x31,0xC3,0x30,0xE3,0x30,0x33,0x30,0x1F,0x30,0x0F,0x30,0x03,0x00,0x00}, // 0x5A
{0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xFF,0x3F,0xFF,0x30,0x03,0x30,0x03,0x30,0x03,0x30,0x03,0x00,0x00,0x00,0x00,0x00,0x00}, // 0x5B
{0x00,0x00,0x00,0x0E,0x00,0x1C,0x00,0x38,0x00,0x70,0x00,0xE0,0x01,0xC0,0x03,0x80,0x07,0x00,0x0E,0x00,0x1C,0x00,0x18,0x00}, // 0x5C
{0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x03,0x30,0x03,0x30,0x03,0x30,0x03,0x3F,0xFF,0x3F,0xFF,0x00,0x00,0x00,0x00,0x00,0x00}, // 0x5D
{0x00,0x00,0x00,0x60,0x00,0x70,0x00,0x38,0x00,0x1C,0x00,0x0E,0x00,0x07,0x00,0x0E,0x00,0x1C,0x00,0x38,0x00,0x70,0x00,0x60}, // 0x5E
{0x00,0x00,0xC0,0x00,0xC0,0x00,0xC0,0x00,0xC0,0x00,0xC0,0x00,0xC0,0x00,0xC0,0x00,0xC0,0x00,0xC0,0x00,0xC0,0x00,0xC0,0x00}, // 0x5F
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3E,0x00,0x7E,0x00,0x4E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // 0x60
{0x00,0x00,0x1C,0x00,0x3E,0x40,0x33,0x60,0x33,0x60,0x33,0x60,0x33,0x60,0x33,0x60,0x33,0x60,0x3F,0xE0,0x3F,0xC0,0x00,0x00}, // 0x61
{0x00,0x00,0x3F,0xFF,0x3F,0xFF,0x30,0xC0,0x30,0x60,0x30,0x60,0x30,0x60,0x30,0x60,0x38,0xE0,0x1F,0xC0,0x0F,0x80,0x00,0x00}, // 0x62
{0x00,0x00,0x0F,0x80,0x1F,0xC0,0x38,0xE0,0x30,0x60,0x30,0x60,0x30,0x60,0x30,0x60,0x30,0x60,0x18,0xC0,0x08,0x80,0x00,0x00}, // 0x63
{0x00,0x00,0x0F,0x80,0x1F,0xC0,0x38,0xE0,0x30,0x60,0x30,0x60,0x30,0x60,0x30,0xE0,0x30,0xC0,0x3F,0xFF,0x3F,0xFF,0x00,0x00}, // 0x64
{0x00,0x00,0x0F,0x80,0x1F,0xC0,0x3B,0xE0,0x33,0x60,0x33,0x60,0x33,0x60,0x33,0x60,0x33,0x60,0x13,0xC0,0x01,0x80,0x00,0x00}, // 0x65
{0x00,0x00,0x00,0xC0,0x00,0xC0,0x3F,0xFC,0x3F,0xFE,0x00,0xC7,0x00,0xC3,0x00,0xC3,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00}, // 0x66
{0x00,0x00,0x03,0x80,0xC7,0xC0,0xCE,0xE0,0xCC,0x60,0xCC,0x60,0xCC,0x60,0xCC,0x60,0xE6,0x60,0x7F,0xE0,0x3F,0xE0,0x00,0x00}, // 0x67
{0x00,0x00,0x3F,0xFF,0x3F,0xFF,0x00,0xC0,0x00,0x60,0x00,0x60,0x00,0x60,0x00,0xE0,0x3F,0xC0,0x3F,0x80,0x00,0x00,0x00,0x00}, // 0x68
{0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x30,0x60,0x3F,0xEC,0x3F,0xEC,0x30,0x00,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // 0x69
{0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x00,0xE0,0x00,0xC0,0x00,0xC0,0x60,0xFF,0xEC,0x7F,0xEC,0x00,0x00,0x00,0x00,0x00,0x00}, // 0x6A
{0x00,0x00,0x00,0x00,0x3F,0xFF,0x3F,0xFF,0x03,0x00,0x07,0x80,0x0F,0xC0,0x1C,0xE0,0x38,0x60,0x30,0x00,0x00,0x00,0x00,0x00}, // 0x6B
{0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x30,0x03,0x3F,0xFF,0x3F,0xFF,0x30,0x00,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // 0x6C
{0x00,0x00,0x3F,0xE0,0x3F,0xC0,0x00,0xE0,0x00,0xE0,0x3F,0xC0,0x3F,0xC0,0x00,0xE0,0x00,0xE0,0x3F,0xC0,0x3F,0x80,0x00,0x00}, // 0x6D
{0x00,0x00,0x00,0x00,0x3F,0xE0,0x3F,0xE0,0x00,0x60,0x00,0x60,0x00,0x60,0x00,0x60,0x00,0xE0,0x3F,0xC0,0x3F,0x80,0x00,0x00}, // 0x6E
{0x00,0x00,0x0F,0x80,0x1F,0xC0,0x38,0xE0,0x30,0x60,0x30,0x60,0x30,0x60,0x30,0x60,0x38,0xE0,0x1F,0xC0,0x0F,0x80,0x00,0x00}, // 0x6F
{0x00,0x00,0xFF,0xE0,0xFF,0xE0,0x0C,0x60,0x18,0x60,0x18,0x60,0x18,0x60,0x18,0x60,0x1C,0xE0,0x0F,0xC0,0x07,0x80,0x00,0x00}, // 0x70
{0x00,0x00,0x07,0x80,0x0F,0xC0,0x1C,0xE0,0x18,0x60,0x18,0x60,0x18,0x60,0x18,0x60,0x0C,0x60,0xFF,0xE0,0xFF,0xE0,0x00,0x00}, // 0x71
{0x00,0x00,0x00,0x00,0x3F,0xE0,0x3F,0xE0,0x00,0xC0,0x00,0x60,0x00,0x60,0x00,0x60,0x00,0x60,0x00,0xE0,0x00,0xC0,0x00,0x00}, // 0x72
{0x00,0x00,0x11,0xC0,0x33,0xE0,0x33,0x60,0x33,0x60,0x33,0x60,0x33,0x60,0x3F,0x60,0x1E,0x40,0x00,0x00,0x00,0x00,0x00,0x00}, // 0x73
{0x00,0x00,0x00,0x60,0x00,0x60,0x1F,0xFE,0x3F,0xFE,0x30,0x60,0x30,0x60,0x30,0x60,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // 0x74
{0x00,0x00,0x0F,0xE0,0x1F,0xE0,0x38,0x00,0x30,0x00,0x30,0x00,0x30,0x00,0x30,0x00,0x18,0x00,0x3F,0xE0,0x3F,0xE0,0x00,0x00}, // 0x75
{0x00,0x00,0x00,0x60,0x01,0xE0,0x07,0x80,0x1E,0x00,0x38,0x00,0x38,0x00,0x1E,0x00,0x07,0x80,0x01,0xE0,0x00,0x60,0x00,0x00}, // 0x76
{0x00,0x00,0x07,0xE0,0x1F,0xE0,0x38,0x00,0x1C,0x00,0x0F,0xE0,0x0F,0xE0,0x1C,0x00,0x38,0x00,0x1F,0xE0,0x07,0xE0,0x00,0x00}, // 0x77
{0x00,0x00,0x30,0x60,0x38,0xE0,0x1D,0xC0,0x0F,0x80,0x07,0x00,0x0F,0x80,0x1D,0xC0,0x38,0xE0,0x30,0x60,0x00,0x00,0x00,0x00}, // 0x78
{0x00,0x00,0x00,0x00,0x00,0x60,0x81,0xE0,0xE7,0x80,0x7E,0x00,0x1E,0x00,0x07,0x80,0x01,0xE0,0x00,0x60,0x00,0x00,0x00,0x00}, // 0x79
{0x00,0x00,0x30,0x60,0x38,0x60,0x3C,0x60,0x36,0x60,0x33,0x60,0x31,0xE0,0x30,0xE0,0x30,0x60,0x30,0x20,0x00,0x00,0x00,0x00}, // 0x7A
{0x00,0x00,0x00,0x00,0x00,0x80,0x01,0xC0,0x1F,0xFC,0x3F,0x7E,0x70,0x07,0x60,0x03,0x60,0x03,0x60,0x03,0x00,0x00,0x00,0x00}, // 0x7B
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xBF,0x3F,0xBF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // 0x7C
{0x00,0x00,0x00,0x00,0x60,0x03,0x60,0x03,0x60,0x03,0x70,0x07,0x3F,0x7E,0x1F,0xFC,0x01,0xC0,0x00,0x80,0x00,0x00,0x00,0x00}, // 0x7D
{0x00,0x00,0x00,0x10,0x00,0x18,0x00,0x0C,0x00,0x04,0x00,0x0C,0x00,0x18,0x00,0x10,0x00,0x18,0x00,0x0C,0x00,0x04,0x00,0x00}, // 0x7E
{0x00,0x00,0x0F,0x00,0x0F,0x80,0x0C,0xC0,0x0C,0x60,0x0C,0x30,0x0C,0x30,0x0C,0x60,0x0C,0xC0,0x0F,0x80,0x0F,0x00,0x00,0x00}, // 0x7F
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x78,0x00,0xFC,0x00,0xCC,0x00,0xCC,0x00,0xFC,0x00,0x78,0x00,0x00,0x00,0x00,0x00,0x00}, // 0x80 Degree-sign
};
//LCD additional data
int bcolor = BLACK0; //Standard Background Color
///////////
// ADC //
////////////
#define ADC_KEY_PORT PORTF
///////////
// DDS //
////////////
// SPI DDS1 (AD9951)
#define DDS1_PORT PORTD
#define DDS1_DDR DDRD
#define DDS1_IO_UD 16 //green
#define DDS1_SDIO 32 //white
#define DDS1_SCLK 64 //blue
#define DDS1_RESETPIN 128 //violet
///////////////////////
// SPI DDS2 AD9834 //
///////////////////////
#define DDS2_PORT PORTB
#define DDS2_DDR DDRB
#define DDS2_FSYNC 16 //green
#define DDS2_SDATA 32 //white
#define DDS2_SCLK 64 //blue
/////////////////////
// BAND RELAYS //
/////////////////////
#define RELAY_PORT PORTA
#define RELAY_0 PA0 //grey
#define RELAY_1 PA1 //green
#define RELAY_2 PA2 //white
//S-Meter
#define SMAX 240
#define SMETERPOSITION 62
int main(void);
/////////////////
// L C D //
/////////////////
//ILI9341 LCD Basic Functions
void lcd_send(int, int); //Write a byte of data via SPI
void lcd_set_xy(int, int);
void lcd_cls(int);
void lcd_draw_pixel(int);
void lcd_putchar(int, int, int, int, int, int);
void lcd_putstring(int, int, char*, int, int, int);
void lcd_putnumber(int, int, long, int, int, int, int);
void lcd_init(void);
void lcd_setbacklight(int);
//Extended LCD functions
void show_all_data(long, long, int, int, int, int, int, long, int, int, int, int);
void show_frequency1(long, int, int);
void show_frequency2(int, int, long, int, int, int);
void show_mem_number(int);
void show_mem_freq(long, int);
void show_sideband(int, int);
void show_voltage(int);
void show_band(int);
void show_temp(int);
void show_vfo(int, int);
void show_split(int, int);
void show_scan_status(int, int);
void show_tone(int, int);
void show_txrx(int);
void show_agc(int, int);
void show_att(int, int);
void draw_meter_scale(int, int);
void reset_smax(void);
void smeter(int, int);
void clear_smeter(int);
void show_msg(char*, int);
//STRING FUNCTIONS
int int2asc(long, int, char*, int);
long asc2long(char*);
void get_info_from_string(char*, char*, int);
//int strlen(char *s);
int calcx(int col);
int calcy(int row);
//Frequency generation
void dds1_send_bit(int);
void dds1_send_word(unsigned int);
void dds1_send_byte(unsigned int);
void set_frequency1(long frequency);
void dds1_send_bit(int);
void dds2_start(void);
void dds2_stop(void);
void dds2_send_bit(int sbit);
void set_frequency2(long fx);
void set_lo_freq(int);
//ADC
int get_s_value(void);
int get_keys(void);
int get_adc(int);
int get_ptt(void);
//MISC
int calc_tuningfactor(void);
void tx_test(void);
void tune(void);
void set_audio_tone_oscillator(int);
//Graphics
void drawbox(int, int, int, int, int);
void draw_hor_line(int, int, int, int);
void draw_vert_line(int, int, int, int);
//Menu
int menu0_get_xp(int);
int menu0_get_yp(int);
long menu0(long, int, int);
long menu1(int, long, int, int);
void print_menu_head(char*, int);
void print_menu_item(int, int, int);
void print_menu_item_list(int, int);
int navigate_thru_item_list(int, int, int, int, int);
void print_menu_help(int, int, int, int);
//Scanning & VFO
long scan(int);
void set_scan_threshold(void);
long set_scan_frequency(int, long);
//Tone and AGC
void set_tone(int);
void set_agc(int);
void set_att(int);
//VFO, Band etc.
void set_band(int, int);
int set_vfo(int);
//BAcklight
int adjustbacklight(void);
//TWI - I�C
void twi_init(void);
void twi_start(void);
void twi_stop(void);
void twi_write(uint8_t);
//DAC and TX preset
void mcp4725_set_value(int);
void tx_preset_adjust(void);
void store_tx_preset(int, int);
int load_tx_preset(int);
//EEPROM
//Loading
int load_last_band(void);
long load_frequency0(int);
long load_frequency1(int);
int load_last_mem(void);
int load_last_vfo(void);
long recall_mem_freq(int);
//Storing
void store_last_band(int);
void store_frequency0(long, int);
void store_frequency1(long, int);
void store_last_vfo(int);
void store_last_mem(int);
int save_mem_freq(long, int);
//MEM Data transfer
void rcv_mem_frequencies(void);
void txm_mem_frequencies(void);
//Checking
int is_mem_freq_ok(long,int);
//UART
void usart_init(int);
int usart_receive(void);
void usart_transmit(unsigned char);
void usart_sendstring(char*);
void usart_send_crlf(void);
/////////////
//Variables//
/////////////
//Seconds counting
long runseconds10 = 0;
//S-Meter temporary max. value
int smaxold = 0;
//Freq data
//LO
#define MAXMODES 2
//Radio basics
int txrx = 0;
//Interfrequency options
#define IFOPTION 0
#if (IFOPTION == 0) //9MHz Filter 9XMF24D (box73.de)
#define INTERFREQUENCY 9000000
#define F_LO_LSB 8998130
#define F_LO_USB 9001420
#endif
#if (IFOPTION == 1) //10.695MHz Filter 10M04DS (ex CB TRX "President Jackson")
#define INTERFREQUENCY 10695000 //fLSB 10692100, fUSB 10697700
#define F_LO_LSB 10691880
#define F_LO_USB 10697580
#endif
#if (IFOPTION == 2) //10.7MHz Filter 10MXF24D (box73.de)
#define INTERFREQUENCY 10700000
#define F_LO_LSB 10697630
#define F_LO_USB 10702000
#endif
#if (IFOPTION == 3) //Ladderfilter 9.830 MHz low profile xtals
#define INTERFREQUENCY 9830000
#define F_LO_LSB 9828320
#define F_LO_USB 9831000
#endif
#if (IFOPTION == 4) //Ladderfilter 9.832 MHz high profile xtals "NARVA"
#define INTERFREQUENCY 9830000
#define F_LO_LSB 9830960
#define F_LO_USB 9834930
#endif
#if (IFOPTION == 5) //Ladderfilter 10 MHz high profile xtals
#define INTERFREQUENCY 10000000
#define F_LO_LSB 9994720
#define F_LO_USB 9999840
#endif
long f_lo[] = {F_LO_LSB, F_LO_USB}; //LSB, USB
int sideband = 0; //Current sideband in use LSB=0, USB=1
int cur_band;
//VFO
#define MAXVFOS 10
long f_vfo[2];
int vfo_s[2];
int split = 0; //0=off, 1=TXA RXB, 2=TXB RXA
//Data for 6 bands
int std_sideband [] = {0, 0, 0, 1, 1, 1}; //Standard sideband for each rf band
long c_freq[] = {1950000, 3650000, 7120000, 14180000, 21290000, 28500000}; //Center frequency
long band_f0[] = {1810000, 3500000, 7000000, 14000000, 21000000, 28000000}; //Edge frequency I
long band_f1[] = {2000000, 3800000, 7200000, 14350000, 21450000, 29700000}; //Edge frequency II
//Frequency memories
#define MAXMEM 15
int last_memplace = 0;
//Scanning
int s_threshold = 30;
long scanfreq[2];
//Encoder & tuning
int laststate = 0; //Last state of rotary encoder
int tuningknob = 0;
int tuningcount = 0;
//Tone and AGC
int cur_tone;
int cur_agc;
int cur_att;
//TX amplifier preset values
int tx_preset[6] = {0, 0, 0, 0, 0, 0};
//METER
int smax = 0;
long runseconds10s = 0;
//Menu n=items-1
int menu_items[MENUITEMS] = {5, 1, 3, 1, 3, 3, 1, 3, 2, 1, 5};
//Backlight
int blight = 128;
/////////////////////////////////////
// Functions for ILI9341 control //
/////////////////////////////////////
//Parallel write data or command to LCD
void lcd_send(int dc, int val)
{
if(!dc) //Cmd (0) or Data(1)?
{
LCDCTRLPORT &= ~(LCDRS); //Cmd=0
}
else
{
LCDCTRLPORT |= LCDRS; //Data=1
}
LCDCTRLPORT |= LCDRD;
LCDDATAPORT = val;
LCDCTRLPORT &= ~(LCDWR); //Write operation
LCDCTRLPORT |= LCDWR;
}
//Init LCD to vertical alignement and 16-bit color mode
void lcd_init(void)
{
lcd_send(LCD_CMD, 0xCF);
lcd_send(LCD_DATA, 0x00);
lcd_send(LCD_DATA, 0xc1);
lcd_send(LCD_DATA, 0x30);
lcd_send(LCD_CMD, 0xed);
lcd_send(LCD_DATA, 0x64);
lcd_send(LCD_DATA, 0x03);
lcd_send(LCD_DATA, 0x12);
lcd_send(LCD_DATA, 0x81);
lcd_send(LCD_CMD, 0xcb);
lcd_send(LCD_DATA, 0x39);
lcd_send(LCD_DATA, 0x2c);
lcd_send(LCD_DATA, 0x00);
lcd_send(LCD_DATA, 0x34);
lcd_send(LCD_DATA, 0x02);
lcd_send(LCD_CMD, 0xea);
lcd_send(LCD_DATA, 0x00);
lcd_send(LCD_DATA, 0x00);
lcd_send(LCD_CMD, 0xe8);
lcd_send(LCD_DATA, 0x85);
lcd_send(LCD_DATA, 0x10);
lcd_send(LCD_DATA, 0x79);
lcd_send(LCD_CMD, 0xC0); // Power control
lcd_send(LCD_DATA, 0x23); // VRH[5:0]
lcd_send(LCD_CMD, 0xC1); // Power control
lcd_send(LCD_DATA, 0x10); // SAP[2:0];BT[3:0]
lcd_send(LCD_CMD, 0xC5); // VCM control
lcd_send(LCD_DATA, 0x3e);
lcd_send(LCD_DATA, 0x28);
lcd_send(LCD_CMD, 0xC7); // VCM control2
lcd_send(LCD_DATA, 0x86);
lcd_send(LCD_CMD, 0x36); // Memory Access Control
lcd_send(LCD_DATA, 0x88); // C8
lcd_send(LCD_CMD, 0x3A);
lcd_send(LCD_DATA, 0x55);
lcd_send(LCD_CMD, 0xB1);
lcd_send(LCD_DATA, 0x00);
lcd_send(LCD_DATA, 0x18);
lcd_send(LCD_CMD, 0xB6); // Display Function Control
lcd_send(LCD_DATA, 0x08);
lcd_send(LCD_DATA, 0x82);
lcd_send(LCD_DATA, 0x27);
lcd_send(LCD_CMD, 0xF2); // 3Gamma Function Disable
lcd_send(LCD_DATA, 0x00);
lcd_send(LCD_CMD, 0x26); // Gamma curve selected
lcd_send(LCD_DATA, 0x01);
lcd_send(LCD_CMD, 0xE0); // Set Gamma
lcd_send(LCD_DATA, 0x0F);
lcd_send(LCD_DATA, 0x31);
lcd_send(LCD_DATA, 0x2B);
lcd_send(LCD_DATA, 0x0C);
lcd_send(LCD_DATA, 0x0E);
lcd_send(LCD_DATA, 0x08);
lcd_send(LCD_DATA, 0x4E);
lcd_send(LCD_DATA, 0xF1);
lcd_send(LCD_DATA, 0x37);
lcd_send(LCD_DATA, 0x07);
lcd_send(LCD_DATA, 0x10);
lcd_send(LCD_DATA, 0x03);
lcd_send(LCD_DATA, 0x0E);
lcd_send(LCD_DATA, 0x09);
lcd_send(LCD_DATA, 0x00);
lcd_send(LCD_CMD, 0xE1); // Set Gamma
lcd_send(LCD_DATA, 0x00);
lcd_send(LCD_DATA, 0x0E);
lcd_send(LCD_DATA, 0x14);
lcd_send(LCD_DATA, 0x03);
lcd_send(LCD_DATA, 0x11);
lcd_send(LCD_DATA, 0x07);
lcd_send(LCD_DATA, 0x31);
lcd_send(LCD_DATA, 0xC1);
lcd_send(LCD_DATA, 0x48);
lcd_send(LCD_DATA, 0x08);
lcd_send(LCD_DATA, 0x0F);
lcd_send(LCD_DATA, 0x0C);
lcd_send(LCD_DATA, 0x31);
lcd_send(LCD_DATA, 0x36);
lcd_send(LCD_DATA, 0x0F);
lcd_send(LCD_CMD, 0x11); // Sleep out
_delay_ms(120);
lcd_send(LCD_CMD, 0x2c);
lcd_send(LCD_CMD, 0x29); // Display on
lcd_send(LCD_CMD, 0x2c);
}
void lcd_set_xy(int x, int y)
{
//X
lcd_send(LCD_CMD, 0x2B);
lcd_send(LCD_DATA, x >> 8);
lcd_send(LCD_DATA, x & 0xFF);
lcd_send(LCD_CMD, 0x2c);
//Y
lcd_send(LCD_CMD, 0x2A);
lcd_send(LCD_DATA, y >> 8);
lcd_send(LCD_DATA, y & 0xFF);
lcd_send(LCD_CMD, 0x2c);
}
void lcd_draw_pixel(int color)
{
lcd_send(LCD_DATA, color >> 8);
lcd_send(LCD_DATA, color & 0xFF);
}
void lcd_cls(int bcolor)
{
int x;
unsigned char y;
lcd_set_xy(0, 0);
for(x = 0; x < LCD_WIDTH; x++)
{
for(y = 0; y < LCD_HEIGHT; y++)
{
lcd_draw_pixel(bcolor);
}
}
}
//Write character from font set to destination on screen
void lcd_putchar(int x, int y, int c, int size, int fcolor, int bcolor)
{
int x0;
int t0, t1, t2, t3, u;
x0 = x;
for(t0 = 0; t0 < FONTWIDTH * 2; t0 += 2)
{
for(t1 = 0; t1 < size; t1++)
{
//u = xchar[c][t0 + 1] + (xchar[c][t0] << 8);
u = pgm_read_byte(&xchar[c][t0 + 1]) + (pgm_read_byte(&xchar[c][t0]) << 8);
lcd_set_xy(x0, y);
for(t2 = 16; t2 >= 0; t2--)
{
if(u & (1 << t2))
{
for(t3 = 0; t3 < size; t3++)
{
lcd_draw_pixel(fcolor);
}
}
else
{
for(t3 = 0; t3 < size; t3++)
{
lcd_draw_pixel(bcolor);
}
}
}
x0++;
}
}
}
//Print String to LCD
void lcd_putstring(int x, int y, char *text, int size, int fc, int bc)
{
int t1 = 0, x0;
x0 = x;
while(text[t1])
{
lcd_putchar(x0, y, text[t1], size, fc, bc);
x0 += (size * FONTWIDTH);
t1++;
}
}
//Convert a number to a string and print it
//col, row: Coordinates, Num: int or long to be displayed
//dec: Set position of decimal separator
//
//inv: Set to 1 if inverted charactor is required
void lcd_putnumber(int x, int y, long num, int dec, int lsize, int fc, int bc)
{
char *s = malloc(16);
if(s != NULL)
{
int2asc(num, dec, s, 16);
lcd_putstring(x, y, s, lsize, fc, bc);
free(s);
}
else
{
lcd_putstring(x, y, "Error", lsize, fc, bc);
}
}
//Set backlight
void lcd_setbacklight(int duty_cycle)
{
OCR3A = duty_cycle;
}
///////////////////////////////////////
// Data Display Functions for Radio //
///////////////////////////////////////
void show_all_data(long f0, long f1, int refresh, int s, int scan_s, int vfo, int splt, long splt_freq, int splt_invert, int mtr_scale, int memplace, int tr)
{
int linecolor = GRAY;
show_frequency1(f0, refresh, bcolor);
show_frequency2(8, 9, f1, bcolor, 100, 1);
show_sideband(s, 0);
//show_scan_status(scan_s);
show_mem_number(memplace);
show_vfo(vfo, 0);
show_voltage(bcolor);
show_temp(bcolor);
show_split(splt, bcolor);
//show_split_freq(splt_freq, splt_invert);
draw_meter_scale(mtr_scale, bcolor);
show_tone(cur_tone, bcolor);
show_agc(cur_agc, bcolor);
show_band(cur_band);
show_txrx(tr);
show_att(cur_att, bcolor);
load_tx_preset(cur_band);
draw_hor_line(0, LCD_WIDTH, 20, linecolor);
draw_hor_line(0, LCD_WIDTH, 75, linecolor);
draw_hor_line(0, LCD_WIDTH, 150, linecolor);
draw_hor_line(0, LCD_WIDTH, 200, linecolor);
draw_vert_line(65, 150, LCD_HEIGHT, linecolor);
draw_vert_line(140, 150, LCD_HEIGHT, linecolor);
draw_vert_line(240, 150, LCD_HEIGHT, linecolor);
draw_vert_line(260, 20, 75, linecolor);
}
//Calc x and y position of character
int calcx(int col)
{
return col * FONTWIDTH;
}
int calcy(int row)
{
return (14 - row) * FONTHEIGHT;
}
//Current frequency (double letter height)
void show_frequency1(long f, int refresh, int bc)
{
char *buf;
int t1, t2, x;
int x0 = 7, y0 = 8;
int fc = 0;
if(is_mem_freq_ok(f, cur_band))
{
fc = YELLOW;
}
else
{
fc = LIGHT_RED;
}
if(f < 10000000)
{
x0 = 8;
}
if(f <= 0)
{
for(x = 80; x < LCD_WIDTH; x++)
{
lcd_set_xy(x, calcy(y0));
for(t2 = 0; t2 < FONTHEIGHT * 2 + 2; t2++)
{
lcd_draw_pixel(bc);
}