/********************************************************************** AVR PLL-VFO control PLL device : TC9256P (Toshiba Co.) 7.200MHz(Xtal) / 720(preset prescaler) = 10KHz(minimam step) **********************************************************************/ #include #include #include #include #include #include #include "lcd.h" #define cbi(addr, bit) addr &= ~(1<> i) & 0x00000001; // 最下位ビットから if(tmp % 2) sbi(PLL_PORT, PLL_DATA); else cbi(PLL_PORT, PLL_DATA); _delay_us(2); cbi(PLL_PORT, PLL_CLOCK); // クロック信号Low _delay_us(2); sbi(PLL_PORT, PLL_CLOCK); // クロック信号High _delay_us(2); if(i == 2) // クロック信号8回以内にピリオド信号をHigh sbi(PLL_PORT, PLL_LE); } _delay_us(2); cbi(PLL_PORT, PLL_LE); // ピリオド信号Low ・・これでデータ終了 _delay_us(2); sbi(PLL_PORT, PLL_LE); // ピリオド信号Highに戻しておく } /********************************************************************** Pin change interrupt Frequency Up & Down by Rotary encorder input **********************************************************************/ ISR(SIG_PIN_CHANGE1) { if(bit_is_set(PINC, PC4)){ if(bit_is_clear(PINC, PC5)) renc_now = 0; else renc_now = 1; } else { if(bit_is_set(PINC, PC5)) renc_now = 2; else renc_now = 3; } if((renc_now + 3 + 1) % 3 == renc_old) { if(pcd > 6500) { pcd -= diff; } } if((renc_now + 3 - 1) % 3 == renc_old) { if(pcd < 9000) { pcd += diff; } } renc_old = renc_now; pll_dataset(0xd0 + ((unsigned long)pcd<<8) + ((unsigned long)0x9a<<24), 32); } /********************************************************************** main routine **********************************************************************/ void main(void) { unsigned char sw1_state; unsigned long freq; DDRB = 0b11111111; // LCD DDRC = 0b00000000; // PC3 sw input, PC4,5 routary encoder input DDRD = 0b11111111; // PD0-2 PLL serial output PORTC = 0b00111000; // PC3,4,5 pull up PCICR = _BV(PCIE1); PCMSK1 = _BV(PCINT12)|_BV(PCINT13); sbi(PLL_PORT, PLL_LE); sbi(PLL_PORT, PLL_CLOCK); sbi(PLL_PORT, PLL_DATA); lcd_init(); lcd_cls(); fp = fdevopen(lcd_putch, NULL); // Open File descriptor for LCD sw1_state = 0; pcd = 8000; // default frequency 80.00MHz diff = 1; pll_dataset(0xd0 + ((unsigned long)pcd<<8) + ((unsigned long)0x9a<<24), 32); sei(); while(1) { if(bit_is_clear(PINC, PC3)) { // frequency step change sw1_state = 1; delay_ms(15); } if(sw1_state && bit_is_set(PINC, PC3)) { sw1_state = 0; if(diff == 1) { diff = 10; // 100kHz step pcd = pcd / 10 * 10; } else { diff = 1; // 10kHz step } } freq = pcd; lcd_goto(0, 0); if(diff == 1) fprintf(fp, "%2d.%02dMHz", (unsigned int)(freq * 0.01), freq - (unsigned int)(freq * 0.01) * 100); else { freq = freq * 0.1; fprintf(fp, "%2d.%01d MHz", (unsigned int)(freq * 0.1), freq - (unsigned int)(freq * 0.1) * 10); } } }