keyin_now.byte[i] = 0x00;
}
latchvar = _KEY_SENDPORT;
- latchvar &= ~_KEY_GRP1MASK;
+ latchvar |= _KEY_SENDPORTMASK;
_KEY_SENDPORT = latchvar; // Group1 DOWN.
break;
case 1:
+ latchvar = _KEY_SENDPORT;
+ latchvar &= ~_KEY_GRP1MASK;
+ _KEY_SENDPORT = latchvar; // Group1 DOWN.
+ break;
+ case 2:
portvar = _KEY_RECVPORT;
if((portvar & _KEY_POS1MASK) == 0) {
keyin_now.BIT0A = 1;
keyin_now.BIT3A = 0;
}
latchvar = _KEY_SENDPORT;
- latchvar |= _KEY_GRP1MASK;
+ latchvar |= _KEY_SENDPORTMASK;
_KEY_SENDPORT = latchvar; // Group1 UP.
break;
- case 2:
+ case 3:
latchvar = _KEY_SENDPORT;
latchvar &= ~_KEY_GRP2MASK;
_KEY_SENDPORT = latchvar; // Group2 DOWN.
break;
- case 3:
+ case 4:
portvar = _KEY_RECVPORT;
if((portvar & _KEY_POS1MASK) == 0) {
keyin_now.BIT0B = 1;
keyin_now.BIT3B = 0;
}
latchvar = _KEY_SENDPORT;
- latchvar |= _KEY_GRP2MASK;
+ latchvar |= _KEY_SENDPORTMASK;
_KEY_SENDPORT = latchvar; // Group1 UP.
break;
- case 4:
+ case 5:
latchvar = _KEY_SENDPORT;
latchvar &= ~_KEY_GRP3MASK;
_KEY_SENDPORT = latchvar; // Group2 DOWN.
break;
- case 5:
+ case 6:
portvar = _KEY_RECVPORT;
if((portvar & _KEY_POS1MASK) == 0) {
keyin_now.BIT0C = 1;
keyin_now.BIT3C = 0;
}
latchvar = _KEY_SENDPORT;
- latchvar |= _KEY_GRP3MASK;
+ latchvar |= _KEY_SENDPORTMASK;
_KEY_SENDPORT = latchvar; // Group1 UP.
break;
- case 6:
+ case 7:
latchvar = _KEY_SENDPORT;
latchvar &= ~_KEY_GRP4MASK;
_KEY_SENDPORT = latchvar; // Group2 DOWN.
break;
- case 7:
+ case 8:
portvar = _KEY_RECVPORT;
if((portvar & _KEY_POS1MASK) == 0) {
keyin_now.BIT0D = 1;
keyin_now.BIT3D = 0;
}
latchvar = _KEY_SENDPORT;
- latchvar |= _KEY_GRP4MASK;
+ latchvar |= _KEY_SENDPORTMASK;
_KEY_SENDPORT = latchvar; // Group4 UP.
break;
void setfreq_updown(unsigned char ctlword)
{
-#ifndef _LCD_DEBUG
switch(ctlword){
case charcode_8: // Change band
if(fm != 0){
amband++;
if(amband > 18) amband = 0;
// amfreq = akc6955_setfreq(amfreq)
- akc6955_set_amband(amband);
+// akc6955_set_amband(amband);
_AKC6955_WAIT_62_5MS(); // 62.5ms
- amband = akc6955_get_amband();
- amfreq = akc6955_get_freq();
+// amband = akc6955_get_amband();
+// amfreq = akc6955_get_freq();
} else {
fmband++;
if(fmband > 7) fmband = 0;
// amfreq = akc6955_setfreq(amfreq)
- akc6955_set_fmband(fmband);
+// akc6955_set_fmband(fmband);
_AKC6955_WAIT_62_5MS(); // 62.5ms
- fmband = akc6955_get_fmband();
- fmfreq = akc6955_get_freq();
+// fmband = akc6955_get_fmband();
+// fmfreq = akc6955_get_freq();
}
break;
case charcode_2: // Change band
if(amband == 0) amband = 18;
if(amband >= 18) amband = 18;
// amfreq = akc6955_setfreq(amfreq)
- akc6955_set_amband(amband);
+// akc6955_set_amband(amband);
_AKC6955_WAIT_62_5MS(); // 62.5ms
- amband = akc6955_get_amband();
- amfreq = akc6955_get_freq();
+// amband = akc6955_get_amband();
+// amfreq = akc6955_get_freq();
} else {
fmband--;
if(fmband == 0) fmband = 7;
if(fmband >= 7) fmband = 7;
// amfreq = akc6955_setfreq(amfreq)
- akc6955_set_fmband(fmband);
+// akc6955_set_fmband(fmband);
_AKC6955_WAIT_62_5MS(); // 62.5ms
- fmband = akc6955_get_fmband();
- fmfreq = akc6955_get_freq();
+// fmband = akc6955_get_fmband();
+// fmfreq = akc6955_get_freq();
}
break;
case charcode_4: // Down Freq;
if(fm != 0){
- fmfreq = akc6955_down_freq(10); // DOWN 100KHz
+ // fmfreq = akc6955_down_freq(10); // DOWN 100KHz
} else {
- amfreq = akc6955_down_freq(10); // DOWN 10KHz
+ // amfreq = akc6955_down_freq(10); // DOWN 10KHz
}
break;
case charcode_6: // Down Freq;
if(fm != 0){
- fmfreq = akc6955_up_freq(10); // UP 100KHz
+ // fmfreq = akc6955_up_freq(10); // UP 100KHz
} else {
- amfreq = akc6955_up_freq(10); // UP 10KHz
+ // amfreq = akc6955_up_freq(10); // UP 10KHz
}
break;
case charcode_7: // Down Fast;
if(fm != 0){
- fmfreq = akc6955_down_freq(50); // DOWN 500KHz
+ // fmfreq = akc6955_down_freq(50); // DOWN 500KHz
} else {
- amfreq = akc6955_down_freq(50); // DOWN 50KHz
+ // amfreq = akc6955_down_freq(50); // DOWN 50KHz
}
break;
case charcode_9: // Down Fast;
if(fm != 0){
- fmfreq = akc6955_up_freq(50); // UP 100KHz
+ // fmfreq = akc6955_up_freq(50); // UP 100KHz
} else {
- amfreq = akc6955_up_freq(50); // UP 10KHz
+ // amfreq = akc6955_up_freq(50); // UP 10KHz
}
break;
case charcode_1: // Down Slow;
if(fm != 0){
- fmfreq = akc6955_down_freq(5); // DOWN 50KHz
+ // fmfreq = akc6955_down_freq(5); // DOWN 50KHz
} else {
- amfreq = akc6955_down_freq(5); // DOWN 50KHz
+ // amfreq = akc6955_down_freq(5); // DOWN 50KHz
}
break;
case charcode_3: // Down Slow;
if(fm != 0){
- fmfreq = akc6955_up_freq(5); // UP 50KHz
+ // fmfreq = akc6955_up_freq(5); // UP 50KHz
} else {
- amfreq = akc6955_up_freq(5); // UP 5KHz
+ // amfreq = akc6955_up_freq(5); // UP 5KHz
}
break;
case charcode_0: // Step
} else {
am_mode3k = 0;
}
- amfreq = akc6955_mode3k(am_mode3k);
+ // amfreq = akc6955_mode3k(am_mode3k);
}
break;
case charcode_a: // Toggle FM
toggle_amfm();
break;
case charcode_b:
- input_userband();
+ //input_userband();
break;
case charcode_c:
- set_userband();
+ //set_userband();
break;
case charcode_d:
- set_volume();
+ //set_volume();
break;
case charcode_e: // Backlight ON/OFF
if(backlight_counter > 0) {
}
break;
case charcode_f:
- main_menu();
+ //main_menu();
break;
default:
break;
}
-#endif
}
/*
*
printstr("Hello;-)");
lcd_setbacklight(0xff, 100);
// PORTD |= _LCDPORT_CONT_RS;
-#if 1
+#if 0
i = 10001;
do {
ClrWdt();
set_amlamp(i & 1);
set_powerlamp(i & 1);
i = i + 1;
- c = pollkeys(pollkeybuf, 30); // Poll about 600ms
+// idle(65536 - 7182/10 + 1);
+ c = pollkeys(pollkeybuf, 60, 1); // Poll about 600ms
if(c != 0) {
unsigned char sp;
- _LOCATE(0,0);
+// _LOCATE(0,0);
for(sp = 0; sp < c; sp++) _PUTCHAR(pollkeybuf[sp] + '0');
} else {
_CLS();
printstr("EEPROM FORMATTING");
_LOCATE(0,1);
printstr("Press any key");
- c = charcode_null;
- do {
- c = readkey();
- idle(ui_idlecount);
-// _CLS();
- _LOCATE(0,0);
- _PUTCHAR(c + '0');
- ClrWdt();
- } while(c == charcode_null);
+ c = pollkey_single();
_CLS();
_LOCATE(0,0);
printstr("Formatting...");
save_eeprom();
break;
case 0x00: // Checksum error
- idle(0xff80);
+ idle(65535-7128*2+1);
_CLS();
_LOCATE(0,0);
printstr("X-) Sum Error");
_LOCATE(0,1);
printstr("Press any key to format");
- c = charcode_null;
- do {
- _CLS();
- c = readkey();
- idle(ui_idlecount);
- _PUTCHAR(c + '0');
- ClrWdt();
- } while(c == charcode_null);
+ c = pollkey_single();
_CLS();
_LOCATE(0,0);
printstr("Formatting...");
printstr("OK");
do {
/* Main routine*/
- c = readkey();
- if(c != charcode_null){
- if((c >= charcode_1) && (c <= charcode_0)) {
+ c = pollkeys(pollkeybuf, 60, 1);
+ if(c != 0){
+ if((pollkeybuf[0] >= charcode_1) && (pollkeybuf[0] <= charcode_0)) {
// setfreq_updown(readchar);
} else {
// Other is skip
// update_status();
// Putstring to LCD.
-// update_display();
+ update_display();
if(backlight_counter > 0) {
backlight_counter--;
lcd_setbacklight(0xff, backlight_level); // Turn ON
char keyin_readp;
char keyin_counter;
+unsigned char cold;
+
void keyin_init(void)
{
char i;
keyin_nowp = 0;
keyin_readp = 0;
keyin_counter = 0;
-
+ cold = charcode_null;
}
/*
* Push to keyin fifo; not used atomic-writing.
{
if(keyin_counter >= 31) {
keyin_counter = 31;
- return;
+ keyin_readp++; // Discard data
+// return;
+ if((keyin_readp > 31) || (keyin_readp < 0)) keyin_readp = 0;
}
keyin_fifo[keyin_nowp] = b;
keyin_nowp++;
- if((keyin_nowp > 31) || (keyin_nowp < 0))keyin_nowp = 0;
keyin_counter++;
+ if((keyin_nowp > 31) || (keyin_nowp < 0))keyin_nowp = 0;
}
/*
return charcode_null ;
}
c = keyin_fifo[keyin_readp];
- if(keyin_readp > 31) keyin_readp = 0;
keyin_readp++;
keyin_counter--;
- if(keyin_counter < 0) keyin_counter = 0;
+ if((keyin_readp > 31) || (keyin_readp < 0)) keyin_readp = 0;
return c;
}
unsigned char readkey(void)
{
unsigned char i;
- for(i = 0; i < 8; i++) {
- idle(0xfffe); // 1.5ms?
+ for(i = 0; i < 9; i++) {
+ idle(0xfffc); // 3ms?
readkey_io(i);
}
readkey_compare();
* 1~32 = Received.
* if((limit * 19.6ms) elapsed), break;
*/
-unsigned char pollkeys(unsigned char *p, unsigned int limit)
+unsigned char pollkeys(unsigned char *p, unsigned int limit, unsigned char repeat)
{
unsigned int count = 0;
unsigned int lifetime = 0;
+ unsigned int penalty = 0;
unsigned char c;
- unsigned char cold;
do {
- idle(65535 - 100 + 1); // 0.78*256 = 78ms.
+ idle(65535 - 20 + 1); // 0.78*20 = 15.6ms.
+// idle(65535 - 2000 + 1); // 0.78*2000 = 1560ms.
c = readkey(); // 0.78*2*8 = 11.2ms
+ ClrWdt();
if(c != charcode_null) {
- cold = c;
- p[count++] = c;
- }
- do {
- c = pop_keyinfifo();
- if(c == charcode_null) break;
- if(c != cold) {
- p[count++] = c;
- cold = c;
+ push_keyinfifo(c);
+ do {
+ c = pop_keyinfifo();
+ if(c == charcode_null) {
+ break;
+ }
+ if(c != cold) {
+ p[count++] = c;
+ cold = c;
+ }
+ } while(count < 32);
+ penalty = 0;
+ } else {
+ penalty++;
+ if((limit > 3) && (penalty > limit / 4)){
+ penalty = 0;
+ cold = charcode_null;
}
- } while(count < 32);
+ }
if(limit != 0) lifetime++;
- if(lifetime >= limit) break;
+ if(lifetime > limit) break;
} while(count < 32);
+ if(repeat != 0) cold = charcode_null;
return count;
}
+
+unsigned char pollkey_single(void)
+{
+ unsigned int count = 0;
+ unsigned int lifetime = 0;
+ unsigned int penalty = 0;
+ unsigned char c;
+
+ do {
+ idle(65535 - 20 + 1); // 0.78*20 = 15.6ms.
+// idle(65535 - 2000 + 1); // 0.78*2000 = 1560ms.
+ c = readkey(); // 0.78*2*8 = 11.2ms
+ ClrWdt();
+ if(c != charcode_null) {
+ if(cold != c){
+ cold = c;
+ return c;
+ }
+ }
+ penalty++;
+ if(penalty > 20) cold = charcode_null;
+ } while(1);
+}
+
/*
* Notes:
* Initialize sequence: