/**************************************** * FT-101Z VFO CONT * 2015.12.25 ver1.0 ***************************************/ #include <16f88.h> #fuses HS,NOWDT,NOPROTECT,PUT,BROWNOUT,NOLVP,NOIESO,NOFCMEN,NODEBUG,NOMCLR #use fixed_io(a_outputs=PIN_A0,PIN_A1,PIN_A2,PIN_A3,PIN_A4) #use fixed_io(b_outputs=PIN_B0,PIN_B4,PIN_B5,PIN_B7) #use delay(clock=16000000) int timer_loop, gate_flag, counter_H, counter_M, counter_L, address; int valu,dds_cmd, i; long counter_ML; int32 freq_data; #int_timer2 void isr2() { timer_loop++; //loop count up if (timer_loop > 9) { timer_loop = 0; //loop_count reset setup_timer_1(T1_DISABLED); //T1 Gate close setup_timer_2(T2_DISABLED,0xFA,10); //T2 Gate close gate_flag = 1; //gate close flag ON } } /// Timer1関数 #int_timer1 void isr1() { counter_H++; } //VFO FREQ COUNT FUNCTION int32 vfo_count() { timer_loop = 0; counter_H = 0; counter_ML = 0; gate_flag = 0; setup_timer_1(T1_EXTERNAL_SYNC | T1_DIV_BY_2); // setup_timer_1(T1_INTERNAL | T1_DIV_BY_1); set_timer1(0); set_timer2(0); setup_timer_2(T2_DIV_BY_16,0xF9,10); enable_interrupts(INT_TIMER1); enable_interrupts(INT_TIMER2); enable_interrupts(GLOBAL); while(1) { if(gate_flag == 1) //gate close then { counter_ML = get_timer1(); freq_data = counter_H*0x10000 + counter_ML; return(freq_data); } } } //EEPROM WRITE FUNCTION void write_memo(int adress,int32 freq_data) { counter_H = (freq_data&0xFF0000)/0x10000; //counter_H picup counter_M = (freq_data&0xFF00)/0x100; //counter_M picup counter_L = freq_data&0x00FF; //counter_L picup write_eeprom(address++,counter_H); write_eeprom(address++,counter_M); write_eeprom(address++,counter_L); } //EEPROM READ FUNCTION int32 read_memo(int adress) { counter_H = read_eeprom(address++); counter_M = read_eeprom(address++); counter_L = read_eeprom(address++); freq_data = counter_H*0x10000 + counter_M*0x100 + counter_L; return(freq_data); } //DDS_DATA FUNCTION void dds_send(int dds_cmd,int32 freq_data) { int32 dds_data; //DDS START output_low(PIN_A3); //PIN_A3=dds_data output_low(PIN_A2); //PIN_A2=dds_clock output_high(PIN_A4); //PIN_A4=dds_stb //DDS CMD & CS CS=*111 & dds Comand=1(on) data for (i=1; i<=7; i+=1) { if (bit_test(dds_cmd,i)) { output_high(PIN_A3); //PIN_A3=dds_data output_high(PIN_A2); //PIN_A2=dds_clock delay_us(50); output_low(PIN_A2); delay_us(50); } else { output_low(PIN_A3); output_high(PIN_A2); delay_us(50); output_low(PIN_A2); delay_us(50); } } //DDS_DATA dds_data = freq_data * 0x14; //gate 0.1sec to 1sec for (i=0; i<=25; i+=1) { if (bit_test(dds_data,i)) { output_high(PIN_A3); //PIN_A3=dds_data output_high(PIN_A2); //PIN_A2=dds_clock delay_us(50); output_low(PIN_A2); delay_us(50); } else { output_low(PIN_A3); output_high(PIN_A2); delay_us(50); output_low(PIN_A2); delay_us(50); } } //DDS_STB SEND output_low(PIN_A4); //dds_stb H to L delay_us(50); output_high(PIN_A4); delay_ms(10); } //// メイン関数 void main() { int vfo_on_flag; int rxext_on_flag; set_tris_a(0x20); //RA5=input set_tris_b(0x4E); //RB1,2,3,6 input setup_adc_ports(NO_ANALOGS); //initial mode set output_low(PIN_A0); //ch1 LED off output_low(PIN_A1); //ch2 LED off output_low(PIN_B7); //K1 off output_low(PIN_B5); //K2 off output_low(PIN_B4); //K3 off while(1) { //VFO SW ON/OFF DETECT delay_ms(50); output_low(PIN_B0); //74HC240 1G=L VFO,CH1,CH2 SELECT if (input(PIN_B1)) { delay_ms(20); if (input(PIN_B1)) // if (vfo_on_flag == 0) //vfo sw off { dds_cmd = 0x0F; //dds cmd 0(off) & CS*111 freq_data = 0x00000000; //dds_off all 0 dummy data dds_send(dds_cmd,freq_data); //send to dds vfo_on_flag = 1; output_low(PIN_A0); //ch1 LED off output_low(PIN_A1); //ch2 LED off output_low(PIN_B7); //K1 off output_low(PIN_B5); //K2 off output_low(PIN_B4); //K3 off } } do { valu = input(PIN_B1); //detect VFO neutral } while(valu); //CH1 SW DETECT if (input(PIN_B2)) { address = 0; //set EEPROM adress delay_ms(700); //700ms wait if (input(PIN_B2)) //CH1 write mode { freq_data = vfo_count(); //counter function // freq_data = 0x07A120; //debug only write_memo(address,freq_data); //EEPROM write function } else { freq_data = read_memo(address); //EEPROM read function } do { valu = input(PIN_B2); //detect CH1 neutral postion } while(valu); dds_cmd = 0x1F; //dds on dds_send(dds_cmd,freq_data); //freq dummy dds_cmd = 0xCF; //dds cmd=C(dds on) & CS=*111 dds_send(dds_cmd,freq_data); //dds function output_high(PIN_A0); //ch1 LED on output_low(PIN_A1); //ch2 LED off output_low(PIN_B7); //K1 off output_high(PIN_B5); //K2 on output_high(PIN_B4); //K3 off } //CH2 SW DETECT if (input(PIN_B3)) { address = 3; //set EEPROM adress delay_ms(700); //700ms wait if (input(PIN_B3)) //CH2 write mode { freq_data = vfo_count(); //counter function // freq_data = 0x86470; //debug only write_memo(address,freq_data); //EEPROM write function } else { freq_data = read_memo(address); //EEPROM read function } do { valu = input(PIN_B3); //detect CH2 neutral } while(valu); dds_cmd = 0x1F; //dds on dds_send(dds_cmd,freq_data); //freq dummy dds_cmd = 0xCF; //dds cmd=C(dds on) & CS=*111 dds_send(dds_cmd,freq_data); //dds function output_low(PIN_A0); //ch1 LED off output_high(PIN_A1); //ch2 LED on output_low(PIN_B7); //K1 off output_high(PIN_B5); //K2 on output_high(PIN_B4); //K3 off } //EXT SW DETECT output_high(PIN_B0); //74HC240 2G=L EXT,TX EXT,RX EXT SELECT delay_ms(50); if (input(PIN_B1)) { delay_ms(20); // if (ext_on_flag == 0) //EXT sw off then if (input(PIN_B1)) { // ext_on_flag = 1; //EXT SW on output_low(PIN_A0); //ch1 LED off output_low(PIN_A1); //ch2 LED off output_high(PIN_B7); //K1 on output_low(PIN_B5); //K2 off output_low(PIN_B4); //K3 off } } do { valu = input(PIN_B1); //detect EXT neutral } while(valu); //TX EXT SW DETECT if (input(PIN_B2)) { delay_ms(50); if (input(PIN_B2)) //TX EXT sw on { // txext_on_flag = 1; output_low(PIN_A0); //ch1 LED off output_low(PIN_A1); //ch2 LED off output_low(PIN_B7); //K1 off output_low(PIN_B5); //K2 off output_high(PIN_B4); //K3 on freq_data = vfo_count(); //counter function dds_cmd = 0x1F; //dds on dds_send(dds_cmd,freq_data); //freq dummy dds_cmd = 0xCF; //dds cmd=C(dds on) & CS=*111 dds_send(dds_cmd,freq_data); //dds function } } do { valu = input(PIN_B2); //detect SW neutral } while(valu); //RX EXT SW DETECT if (input(PIN_B3)) { delay_ms(50); if (input(PIN_B3)) //RX EXT sw on { freq_data = vfo_count(); //counter function output_low(PIN_A0); //ch1 LED off output_low(PIN_A1); //ch2 LED off output_low(PIN_B7); //K1 off output_high(PIN_B5); //K2 on output_low(PIN_B4); //K3 off // freq_data = vfo_count(); //counter function dds_cmd = 0x1F; //dds on dds_send(dds_cmd,freq_data); //freq dummy dds_cmd = 0xCF; //dds cmd=C(dds on) & CS=*111 dds_send(dds_cmd,freq_data); //dds function } } do { valu = input(PIN_B3); //detect SW neutral } while(valu); } }