• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Aucun tag

Frequently used words (click to add to your profile)

javac++androidlinuxc#objective-cqt誰得cocoawindowspythonrubyphpgameguibathyscaphec翻訳omegat計画中(planning stage)frameworktwittertestdombtronvb.netdirectxarduinopreviewerゲームエンジン

Commit MetaInfo

Révisionea36e7b26496155f65cc0177798be7288ad4f507 (tree)
l'heure2013-06-11 14:37:41
AuteurK.Ohta <whatisthis.sowhat@gmai...>
CommiterK.Ohta

Message de Log

[UI] Add simple(?) UI with ten-key.

Change Summary

Modification

--- a/akc6955.c
+++ b/akc6955.c
@@ -37,6 +37,18 @@ unsigned char akc6955_readcmd(unsigned char reg)
3737 }
3838
3939
40+void akc6955_chg_fm(unsigned char fm)
41+{
42+ unsigned char b;
43+ b = akc6955_readcmd(AKC6955_POWER);
44+ if(fm != 0){
45+ b |= 0x40;
46+ } else {
47+ b &= 0xbf;
48+ }
49+ akc6955_writecmd(AKC6955_POWER, b);
50+}
51+
4052 void akc6955_set_amband(unsigned char band)
4153 {
4254 unsigned char b;
@@ -105,6 +117,20 @@ unsigned char akc6955_tune(void)
105117 }
106118 }
107119
120+unsigned int akc6955_mode3k(unsigned char flag)
121+{
122+ unsigned char b;
123+ b = akc6955_readcmd(AKC6955_CH_HI);
124+ if(flag != 0){
125+ b |= 0x20;
126+ } else {
127+ b &= 0xdf;
128+ }
129+ akc6955_writecmd(AKC6955_CH_HI, b);
130+// akc6955_do_tune();
131+ delay1ktcy(500); // Wait 62.5ms
132+ return akc6955_get_freq();
133+}
108134
109135 void akc6955_set_tune(unsigned char mode_3k, unsigned int ch)
110136 {
--- a/akc6955.h
+++ b/akc6955.h
@@ -44,6 +44,48 @@ extern "C" {
4444 #define AKC6955_RSSI 27
4545
4646 /*
47+ * BAND DEFINES
48+ */
49+
50+ enum {
51+ AKC6955_BAND_LW = 0, // 150~285KHz, 3KHz order
52+ AKC6955_BAND_MW1, // 520~1710KHz, 5KHz order
53+ AKC6955_BAND_MW2, // 522~1620KHz, 9KHz order
54+ AKC6955_BAND_MW3, // 520~1710KHz, 10KHz order
55+
56+ AKC6955_BAND_SW1, // 4700~10000KHz, 5KHz order
57+ AKC6955_BAND_SW2, // 3200~4100KHz, 5KHz order
58+ AKC6955_BAND_SW3, // 4700~5600KHz, 5KHz order
59+ AKC6955_BAND_SW4, // 5700~6400KHz, 5KHz order
60+
61+ AKC6955_BAND_SW5, // 6800~7600KHz, 5KHz order
62+ AKC6955_BAND_SW6, // 9200~10000KHz, 5KHz order
63+ AKC6955_BAND_SW7, // 11400~12200KHz, 5KHz order
64+ AKC6955_BAND_SW8, // 13500~14300KHz, 5KHz order
65+
66+ AKC6955_BAND_SW9, // 15000~15900KHz, 5KHz order
67+ AKC6955_BAND_SW10, // 17400~17900KHz, 5KHz order
68+ AKC6955_BAND_SW11, // 18900~19700KHz, 5KHz order
69+ AKC6955_BAND_SW12, // 21400~21900KHz, 5KHz order
70+
71+ AKC6955_BAND_SW13, // 11400~17900KHz, 5KHz order
72+ AKC6955_BAND_AMUSER, // User Setting
73+ AKC6955_BAND_MW4, // 520~1730KHz, 5KHz order
74+ };
75+
76+
77+ enum {
78+ AKC6955_BAND_FM1 = 0, // 87.0~108.0MHz
79+ AKC6955_BAND_FM2, // 76.0~108.0MHz
80+ AKC6955_BAND_FM3, // 70.0~93.0MHz
81+ AKC6955_BAND_FM4, // 76.0~90.0MHz
82+ AKC6955_BAND_FM5, // 64.0~88.0MHz
83+ AKC6955_BAND_TV1, // 56.25~91.75MHz
84+ AKC6955_BAND_TV2, // 174.75~222.25MHz
85+ AKC6955_BAND_FMUSER, // User Setting
86+ };
87+
88+/*
4789 * Resister definitions
4890 */
4991 typedef union{
@@ -60,6 +102,35 @@ extern "C" {
60102 } AKC6955_Reg0;
61103
62104
105+extern void akc6955_writecmd(unsigned char reg, unsigned char data);
106+extern unsigned char akc6955_readcmd(unsigned char reg);
107+extern void akc6955_chg_fm(unsigned char fm);
108+
109+extern void akc6955_set_amband(unsigned char band);
110+extern void akc6955_set_fmband(unsigned char band);
111+
112+
113+extern unsigned char akc6955_get_amband(void);
114+extern unsigned char akc6955_get_fmband(void);
115+extern void akc6955_set_power(unsigned char on);
116+extern void akc6955_do_tune(void);
117+extern unsigned char akc6955_tune(void);
118+
119+extern unsigned int akc6955_mode3k(unsigned char flag);
120+extern void akc6955_set_tune(unsigned char mode_3k, unsigned int ch);
121+extern void akc6955_do_scan(unsigned char up);
122+
123+extern unsigned char akc6955_chk_donescan(void);
124+extern unsigned int akc6955_get_freq(void);
125+extern void akc6955_set_freq(unsigned int freq);
126+extern unsigned char akc6955_get_cnr(void);
127+
128+extern int akc6955_read_level(void);
129+extern unsigned int akc6955_up_freq(unsigned int step);
130+extern unsigned int akc6955_down_freq(unsigned int step);
131+
132+
133+
63134 #ifdef __cplusplus
64135 }
65136 #endif
--- a/i2c_io.c
+++ b/i2c_io.c
@@ -10,3 +10,21 @@
1010
1111 #include "i2c_io.h"
1212
13+void i2c1_init(void)
14+{
15+ unsigned char b;
16+ b = SSP1CON1;
17+ b &= ~(_WCOL | _SSPOV);
18+ b = b | _SSPEN | _SSPM3;
19+ SSP1CON1 = b;
20+}
21+
22+void i2c2_init(void)
23+{
24+ unsigned char b;
25+ b = SSP2CON1;
26+ b &= ~(_WCOL | _SSPOV);
27+ b = b | _SSPEN | _SSPM3;
28+ SSP2CON1 = b;
29+
30+}
--- a/i2c_io.h
+++ b/i2c_io.h
@@ -24,7 +24,8 @@ extern "C" {
2424
2525 #define OPENASMASTER() i2c_open(I2C_DEFAULT_MODE, I2C_SLEW_DEFAULT, I2C_CLOCK_PARAM)
2626 #define CLOSEASMASTER() i2c_close()
27-
27+extern void i2c1_init(void);
28+extern void i2c2_init(void);
2829
2930 #ifdef __cplusplus
3031 }
--- a/iodef.h
+++ b/iodef.h
@@ -103,20 +103,6 @@ enum {
103103 charcode_s3, // Reserve
104104 };
105105
106-extern keyin_defs keyin_old[2];
107-extern keyin_defs keyin_now;
108-extern char keyin_fifo[16];
109-extern char keyin_nowp;
110-extern char keyin_counter;
111-
112-extern unsigned char readkey_compare(void);
113-extern void readkey_io(void);
114-extern void push_keyinfifo(char b);
115-extern char pop_keyinfifo(void);
116-extern void keyin_ioinit(void);
117-extern void keyin_init(void);
118-
119-
120106
121107 #ifdef __cplusplus
122108 }
--- a/lcd_acm1602.c
+++ b/lcd_acm1602.c
@@ -5,13 +5,7 @@
55 * License: GPL2
66 */
77
8-#include <stdarg.h>
9-#include <stdio.h>
10-#include <delay.h>
11-#include <string.h>
12-
13-#include "i2c_io.h"
14-
8+#include "lcd_acm1602.h"
159
1610 static void sendcmd(unsigned char addr, unsigned char cmd)
1711 {
--- /dev/null
+++ b/lcd_acm1602.h
@@ -0,0 +1,38 @@
1+/*
2+ * OpenI2CRADIO
3+ * I2C-LCD ACM1602 Handler
4+ * (C) 2013-06-10 K.Ohta <whatisthis.sowhat ai gmail.com>
5+ * License: GPL2
6+ */
7+
8+#ifndef LCD_ACM1602_H
9+#define LCD_ACM1602_H
10+
11+#include <stdarg.h>
12+#include <stdio.h>
13+#include <delay.h>
14+#include <string.h>
15+
16+#include "i2c_io.h"
17+
18+
19+#ifdef __cplusplus
20+extern "C" {
21+#endif
22+
23+void acm1602_cls(unsigned char addr);
24+void acm1602_putchar(unsigned char addr, unsigned char c);
25+void acm1602_locate(unsigned char addr, char x, char y);
26+void acm1602_home(unsigned char addr);
27+void acm1602_printf(unsigned char addr, const char *fmt, ...);
28+void acm1602_cursordir(unsigned char addr, unsigned char right);
29+void acm1602_init(unsigned char addr, unsigned char cls);
30+
31+
32+
33+#ifdef __cplusplus
34+}
35+#endif
36+
37+#endif /* LCD_ACM1602_H */
38+
--- a/main.c
+++ b/main.c
@@ -5,14 +5,21 @@
55 * License: GPL2
66 */
77
8+#include <stdarg.h>
89 #include <stdio.h>
910 #include <stdlib.h>
11+#include <string.h>
1012 #include <sdcc-lib.h>
1113 #include <pic18fregs.h> /* ONLY FOR PIC18x */
1214 #include <signal.h>
15+#include <delay.h>
1316
1417 #include "iodef.h"
1518 #include "idle.h"
19+#include "i2c_io.h"
20+#include "akc6955.h"
21+#include "lcd_acm1602.h"
22+#include "ui.h"
1623
1724 /*
1825 * Config words.
@@ -34,8 +41,17 @@ __at(__CONFIG7H) _config7h = _EBTRB_OFF_7H;
3441 SIGHANDLER(TMR0_handler)
3542 {
3643 unsigned char tmr0f;
44+ unsigned char t0con;
3745
46+ // Stop timer0
47+ t0con = T0CON;
48+ t0con &= ~_IDLEN;
49+ T0CON = t0con;
50+
51+ // Read IOKEYS
3852 readkey_io();
53+
54+ // Clear interrupt flag
3955 tmr0f = INTCON;
4056 tmr0f &= ~(_TMR0IF);
4157 INTCON = tmr0f;
@@ -49,6 +65,169 @@ DEF_INTLOW(intlow_handler)
4965 END_DEF
5066
5167
68+unsigned int amfreq;
69+unsigned int fmfreq;
70+unsigned char amband;
71+unsigned char fmband;
72+unsigned char fm;
73+unsigned char am_mode3k;
74+int recv_signal;
75+
76+
77+
78+
79+static void update_display(void)
80+{
81+ if(fm != 0){ // FM
82+ _LOCATE(0,0);
83+ if(fmband < AKC6955_BAND_TV1) {
84+ printstr("FM");
85+ _PUTCHAR('1' + (fmband & 7));
86+ } else if(fmband < AKC6955_BAND_FMUSER){
87+ printstr("TV");
88+ _PUTCHAR('1' + fmband - AKC6955_BAND_TV1);
89+ } else { // USER
90+ printstr("FMUSR");
91+ }
92+ } else { // AM
93+ _LOCATE(0,1);
94+ if(amband == AKC6955_BAND_LW) {
95+ printstr("LW");
96+ } else if(amband <AKC6955_BAND_SW1) { //MW
97+ printstr("MW");
98+ _PUTCHAR('1' + amband - AKC6955_BAND_MW1);
99+ } else if(amband < AKC6955_BAND_AMUSER) { //MW
100+ printstr("SW");
101+ _PUTCHAR('1' + amband - AKC6955_BAND_SW1);
102+ } else if(amband == AKC6955_BAND_MW4){
103+ printstr("MW4");
104+ } else {
105+ printstr("AMUSR");
106+ }
107+ }
108+ _LOCATE(16-4 ,1);
109+ if(fm != 0){
110+ printstr("MHz");
111+ } else {
112+ printstr("KHz");
113+ }
114+ _LOCATE(16-5, 1);
115+ if(fm != 0){
116+ int freq_lo = fmfreq % 100;
117+ int freq_hi = fmfreq / 100;
118+ print_numeric(freq_hi);
119+ _PUTCHAR('.');
120+ print_numeric(freq_lo);
121+ } else {
122+ int freq = amfreq;
123+ print_numeric(freq);
124+ }
125+ // Signal
126+ _LOCATE(0, 0);
127+ printstr("S=");
128+ print_numeric(recv_signal);
129+}
130+
131+
132+static void setfreq_updown(unsigned char ctlword)
133+{
134+ switch(ctlword){
135+ case charcode_8: // Change band
136+ if(fm != 0){
137+ amband++;
138+ if(amband > 18) amband = 0;
139+// amfreq = akc6955_setfreq(amfreq)
140+ akc6955_set_amband(amband);
141+ delay1ktcy(500); // 62.5ms
142+ amband = akc6955_get_amband();
143+ amfreq = akc6955_get_freq();
144+ } else {
145+ fmband++;
146+ if(fmband > 7) fmband = 0;
147+// amfreq = akc6955_setfreq(amfreq)
148+ akc6955_set_fmband(fmband);
149+ delay1ktcy(500); // 62.5ms
150+ fmband = akc6955_get_fmband();
151+ fmfreq = akc6955_get_freq();
152+ }
153+ break;
154+ case charcode_2: // Change band
155+ if(fm != 0){
156+ amband--;
157+ if(amband == 0) amband = 18;
158+ if(amband >= 18) amband = 18;
159+// amfreq = akc6955_setfreq(amfreq)
160+ akc6955_set_amband(amband);
161+ delay1ktcy(500); // 62.5ms
162+ amband = akc6955_get_amband();
163+ amfreq = akc6955_get_freq();
164+ } else {
165+ fmband--;
166+ if(fmband == 0) fmband = 7;
167+ if(fmband >= 7) fmband = 7;
168+// amfreq = akc6955_setfreq(amfreq)
169+ akc6955_set_fmband(fmband);
170+ delay1ktcy(500); // 62.5ms
171+ fmband = akc6955_get_fmband();
172+ fmfreq = akc6955_get_freq();
173+ }
174+ break;
175+ case charcode_4: // Down Freq;
176+ if(fm != 0){
177+ fmfreq = akc6955_down_freq(10); // DOWN 100KHz
178+ } else {
179+ amfreq = akc6955_down_freq(10); // DOWN 10KHz
180+ }
181+ break;
182+ case charcode_6: // Down Freq;
183+ if(fm != 0){
184+ fmfreq = akc6955_up_freq(10); // UP 100KHz
185+ } else {
186+ amfreq = akc6955_up_freq(10); // UP 10KHz
187+ }
188+ break;
189+ case charcode_7: // Down Fast;
190+ if(fm != 0){
191+ fmfreq = akc6955_down_freq(50); // DOWN 500KHz
192+ } else {
193+ amfreq = akc6955_down_freq(50); // DOWN 50KHz
194+ }
195+ break;
196+ case charcode_9: // Down Fast;
197+ if(fm != 0){
198+ fmfreq = akc6955_up_freq(50); // UP 100KHz
199+ } else {
200+ amfreq = akc6955_up_freq(50); // UP 10KHz
201+ }
202+ break;
203+ case charcode_1: // Down Slow;
204+ if(fm != 0){
205+ fmfreq = akc6955_down_freq(5); // DOWN 50KHz
206+ } else {
207+ amfreq = akc6955_down_freq(5); // DOWN 50KHz
208+ }
209+ break;
210+ case charcode_3: // Down Slow;
211+ if(fm != 0){
212+ fmfreq = akc6955_up_freq(5); // UP 50KHz
213+ } else {
214+ amfreq = akc6955_up_freq(5); // UP 5KHz
215+ }
216+ break;
217+ case charcode_0: // Step
218+ if(fm == 0){
219+ if(am_mode3k == 0) {
220+ am_mode3k = 0xff;
221+ } else {
222+ am_mode3k = 0;
223+ }
224+ amfreq = akc6955_mode3k(am_mode3k);
225+ }
226+ break;
227+ default:
228+ break;
229+ }
230+}
52231 /*
53232 *
54233 */
@@ -61,11 +240,32 @@ int main(void)
61240 keyin_ioinit();
62241 idle_init();
63242
64- /* Init I2C*/
65- /* Init LCD */
243+ i2c1_init();
244+
245+ delay1ktcy(1000); // Wait 125ms
246+
247+ acm1602_init(0xa0, 1); //Init LCD
248+
249+ delay1ktcy(1000); // Wait 125ms
250+
251+
252+ // Init AKC6955
253+ amfreq = 954;
254+ fmfreq = 8000; // 10KHz order.
255+ amband = AKC6955_BAND_MW2;
256+ fmband = AKC6955_BAND_FM2;
257+ am_mode3k = 0xff;
258+ fm = 0;
259+ recv_signal = 0;
260+
66261 /* Check EEPROM */
67262 /* Push default parameters to AKC6955*/
68- /* Power on AKC6955 */
263+
264+ akc6955_chg_fm(fm); // Set to AM
265+ akc6955_set_amband(amband);
266+ akc6955_set_freq(amfreq); // Dummy, TBS (954KHz)
267+ akc6955_set_power(0xff); // Power ON
268+ idle(0xff00);
69269 do {
70270 /* Main routine*/
71271 input_flag = readkey_compare();
@@ -74,10 +274,21 @@ int main(void)
74274 switch(readchar) {
75275 // Top of input-tree.
76276 case charcode_s0:
77- // Change band
277+ // Change FM/AM
278+ if(fm != 0){
279+ fm = 0;
280+ akc6955_chg_fm(fm);
281+ akc6955_set_amband(amband);
282+ akc6955_set_freq(amfreq);
283+ } else {
284+ fm = 0xff;
285+ akc6955_chg_fm(fm);
286+ akc6955_set_fmband(fmband);
287+ akc6955_set_freq(fmfreq);
288+ }
78289 break;
79290 case charcode_s1:
80- // MODE
291+ //
81292 break;
82293 case charcode_s2:
83294 // ENTER
@@ -89,15 +300,17 @@ int main(void)
89300 break;
90301 default:
91302 // Numeric 0to9, or a to f.
303+ setfreq_updown(readchar);
92304 break;
93305 }
94306 }
307+ recv_signal = akc6955_read_level();
95308 // Check battery (include idle?)
96309 // Read AKJC6955's status
97310 // Putstring to LCD.
311+ update_display();
98312 idle(0xff00);
99313 } while(1);
100314
101-
102315 }
103316
--- a/nbproject/Makefile-genesis.properties
+++ b/nbproject/Makefile-genesis.properties
@@ -1,5 +1,5 @@
11 #
2-#Tue Jun 11 10:35:42 JST 2013
2+#Tue Jun 11 14:34:36 JST 2013
33 default.languagetoolchain.dir=/usr/local/bin
44 default.br-unifei-rmaalmeida-toolchainSDCC-SDCCtoolchain.md5=b67cce1ad75b450308d7806e430931b3
55 com-microchip-mplab-nbide-embedded-makeproject-MakeProject.md5=8fe1589514540343a5279c082104bce0
--- a/nbproject/configurations.xml
+++ b/nbproject/configurations.xml
@@ -36,6 +36,8 @@
3636 <itemPath>lcd_acm1602.c</itemPath>
3737 <itemPath>akc6955.c</itemPath>
3838 <itemPath>akc6955.h</itemPath>
39+ <itemPath>lcd_acm1602.h</itemPath>
40+ <itemPath>ui.h</itemPath>
3941 </logicalFolder>
4042 <sourceRootList>
4143 <Elem>/usr/local/share/sdcc/lib/src/pic16/libc</Elem>
@@ -80,8 +82,6 @@
8082 <property key="pk2settings.userpgmexec" value="true"/>
8183 <property key="pk2settings.usetargetpower" value="false"/>
8284 </PICkit2PlatformTool>
83- <SDCCToolchain>
84- </SDCCToolchain>
8585 <sdcc>
8686 <property key="V-show-commands-compiler" value="true"/>
8787 <property key="Werror" value="false"/>
--- a/ui.c
+++ b/ui.c
@@ -5,10 +5,7 @@
55 * License: GPL2
66 */
77
8-#include <sdcc-lib.h>
9-#include <pic18fregs.h> /* ONLY FOR PIC18x */
10-
11-#include "iodef.h"
8+#include "ui.h"
129
1310 keyin_defs keyin_old[2];
1411 keyin_defs keyin_now;
@@ -83,6 +80,72 @@ char pop_keyinfifo(void)
8380 return c;
8481 }
8582
83+void print_numeric(int i)
84+{
85+ if(i == 0){
86+ unsigned char c;
87+ c = '0';
88+ _CURSOR_LEFT();
89+ _PUTCHAR(c);
90+ _CURSOR_RIGHT();
91+ } else {
92+ int l;
93+ unsigned char supress = 0;
94+ _CURSOR_LEFT();
95+ if(i < 0){
96+ _PUTCHAR('-');
97+ i = -i;
98+ }
99+ l = i / 10000;
100+ i = i % 10000;
101+ if(l != 0) {
102+ _PUTCHAR((l & 0x0f)+ '0');
103+ supress = 1;
104+ }
105+ l = i / 1000;
106+ i = i % 1000;
107+ if(supress != 0){
108+ _PUTCHAR((l & 0x0f)+ '0');
109+ } else if(l != 0){
110+ _PUTCHAR((l & 0x0f)+ '0');
111+ supress = 1;
112+
113+ }
114+ l = i / 100;
115+ i = i % 100;
116+ if(supress != 0){
117+ _PUTCHAR((l & 0x0f)+ '0');
118+ } else if(l != 0){
119+ _PUTCHAR((l & 0x0f)+ '0');
120+ supress = 1;
121+
122+ }
123+ l = i / 10;
124+ i = i % 10;
125+ if(supress != 0){
126+ _PUTCHAR((l & 0x0f)+ '0');
127+ } else if(l != 0){
128+ _PUTCHAR((l & 0x0f)+ '0');
129+ supress = 1;
130+
131+ }
132+ _PUTCHAR((i & 0x0f) + '0');
133+ _CURSOR_RIGHT();
134+ }
135+
136+}
137+
138+void printstr(char *s)
139+{
140+ int p = 0;
141+ _CURSOR_RIGHT();
142+ if(s == NULL) return;
143+ do {
144+ if(s[p] == '\0') break;
145+ _PUTCHAR(s[p]);
146+ p++;
147+ } while(p < 255);
148+}
86149
87150 /*
88151 * Read IOPORTS for KEY.
--- /dev/null
+++ b/ui.h
@@ -0,0 +1,48 @@
1+/*
2+ * OpenI2CRADIO
3+ * UI Handler
4+ * (C) 2013-06-10 K.Ohta <whatisthis.sowhat ai gmail.com>
5+ * License: GPL2
6+ */
7+
8+#ifndef UI_H
9+#define UI_H
10+
11+#include <sdcc-lib.h>
12+#include <pic18fregs.h> /* ONLY FOR PIC18x */
13+
14+#include "lcd_acm1602.h"
15+#include "iodef.h"
16+
17+#ifdef __cplusplus
18+extern "C" {
19+#endif
20+
21+extern keyin_defs keyin_old[2];
22+extern keyin_defs keyin_now;
23+extern char keyin_fifo[16];
24+extern char keyin_nowp;
25+extern char keyin_counter;
26+
27+#define _LOCATE(x,y) acm1602_locate(0xa0, x, y)
28+#define _PUTCHAR(c) acm1602_putchar(0xa0, c)
29+#define _CURSOR_LEFT() acm1602_cursordir(0xa0, 0x00);
30+#define _CURSOR_RIGHT() acm1602_cursordir(0xa0, 0xff);
31+
32+extern void keyin_init(void);
33+extern void keyin_ioinit(void);
34+extern void push_keyinfifo(char b);
35+extern char pop_keyinfifo(void);
36+extern void readkey_io(void);
37+extern unsigned char readkey_compare(void);
38+
39+extern void printstr(char *s);
40+extern void print_numeric(int i);
41+
42+
43+#ifdef __cplusplus
44+}
45+#endif
46+
47+#endif /* UI_H */
48+