int main() { long int savedfreq = 0; int s, c; unsigned char sw=0; // PORTB output for LCD DDRB = 0xff; PORTB = 0xff; #ifdef BOARD2 // PORTC PC0-4 output, PC5 input DDRC = 0x1f; PORTC = 0x00; sbi(PORTC, MUTE); #endif #ifdef BOARD1 // PORTC PC0,2-5 output, PC1 input DDRC = 0x3d; PORTC = 0x00; sbi(PORTC, MUTE); #endif // PORTD is input with pullup DDRD = 0x00; PORTD = 0xff; initLcd(); initADC(); // set reference freq fref = eeprom_read_word((unsigned int *)0x00); if (fref < 2000 || (fref % 100) != 0) { fref = 12000; eeprom_write_word((unsigned int *)0x00, fref); } // read squelch level from eeprom muteval = eeprom_read_word((unsigned int *)0x0c); if (muteval < 0 || muteval > 100) { muteval = 0; eeprom_write_word((unsigned int *)0x0c, muteval); } // read last frequency from eeprom freq = eeprom_read_dword((unsigned long int *)0x10); if (freq < 1240000UL || freq > 1300000UL) { freq = 1298375UL; eeprom_write_dword((unsigned long int *)0x10, freq); } // read shift from eeprom shift = eeprom_read_word((unsigned int *)0x18); if (shift < 60000UL || shift > 60000UL) { shift = -28000UL; eeprom_write_word((unsigned int *)0x18, shift); } // read tone (*10) from eeprom tone = eeprom_read_word((unsigned int *)0x1c); if (tone < 650 || tone > 1500) { tone = 650; eeprom_write_word((unsigned int *)0x1c, tone); } initInterrupts(); initPLL(freq - IF); update(); sprintf(str, "JPD 23cm v%s", version); lcdCmd(0x80); lcdStr(str); _delay_ms(500); for (;;) { lcdCmd(0x80); lcdStr("VFO "); lcdCmd(0xc0); lcdStr(" "); update(); for (;;) { // read switches on PORTD sw = PIND; // switch from tx to rx?? if (tx && (sw & (1<<PTT) )) { cbi(PORTC, TXON); // switch TX off tx = FALSE; // TCCR2A &= ~(1<<COM2A1); update(); } // switch from rx to tx? else if (!tx && !(sw & (1<<PTT) )) { tx = TRUE; displaySmeter(0); // switch TX on sbi(PORTC, TXON); sbi(PORTC, MUTE); // if (tone > 650) { // TCCR2A |= (1<<COM2A1); // } update(); } if (!tx) { s = readSmeter(); displaySmeter(s); if (s > muteval) cbi(PORTC, MUTE); else sbi(PORTC, MUTE); } // switch shift off if ( (shiftSwitch == TRUE) && (sw & (1<<SHIFTKEY) )) { shiftSwitch = FALSE; update(); } // switch shift on else if ( (shiftSwitch == FALSE) && !(sw & (1<<SHIFTKEY) )) { shiftSwitch = TRUE; update(); } // save vfo frequency in eeprom after ~2 secs inactivity if (tick > 200) { if (freq != savedfreq) { eeprom_write_dword((unsigned long int *)0x10, freq); savedfreq = freq; } } // handle encoder pulses c = handleRotary(); if (c!=0) { if (c>0) { freq += step; } else { freq -= step; } tick = 0; update(); } if (rotaryPushed()) { doMenu(); break; } } } }
int rxtx() { int s; // read ptt on PORTD int c = PIND; // listen reverse? if (rv) { if (c & (1<<REVERSE)) { lastFreq = 0; rv = FALSE; } } else { if (!(c & (1<<REVERSE))) { lastFreq = 0; rv = TRUE; } } if (tx) { //keep smeter clear s = 0; // switch from tx to rx?? if (c & (1<<PTT) ) { cbi(PORTC, TXON); lastFreq = 0; tx = FALSE; } } else { s = readRSSI(); displaySmeter(s); // switch from rx to tx? if (!(c & (1<<PTT) )) { // clear smeter s = 0; displaySmeter(s); sbi(PORTC, MUTE); sbi(PORTC, TXON); // force update pll lastFreq = 0; tx = TRUE; } } // calc value for ISR toneCount = 5*F_CPU/tone; // freq change or update needed? if (freq != lastFreq) { long int f = freq; if (tx) { f += (long int) shift*1000; setFrequency(f); } else { if (rv) f += (long int)shift*1000; setFrequency(f - IF); } displayFrequency(f); lastFreq = freq; lcdCursor(15,0); if (tx) lcdChar('T'); else lcdChar('R'); } return s; }