/////////////////////////////////////////////////// // Direct Digital Synthesizer Control Program // Functions is below //  Communicate with PC thuru USART //  Communicate with DDS thuru special serial IF. /////////////////////////////////////////////////// #include <16f876.h> #include #use delay (CLOCK=10000000) //クロック10MHz #use fast_io(D) // コンフィギュレーションの設定 #FUSES HS,NOWDT,NOPROTECT,PUT,BROWNOUT // USARTの使用宣言 #use rs232(BAUD=9600,XMIT=PIN_C6, RCV=PIN_C7) #define sclk PIN_B2 //周波数設定用のクロック #define set PIN_B1 //周波数データラッチ用トリガ #define sdata PIN_B0 //周波数データ出力ピン #define rotal0 PIN_A0 //ロータリースイッチE0(将来用) #define rotal1 PIN_A1 //ロータリースイッチE1 //////// Prototyping shift_out(int byten); //周波数出力関数の宣言 ///////// メイン関数 ///////// main() { int byte3,byte2,byte1; char buffer[10]; long freq; set_tris_c(0xBF); //set port C set_tris_b(0); //set port B all output set_tris_a(0xFF); //set port A all input port_b_pullups(TRUE); //port B pull up on printf ("\r\nStart DDS Control!"); //スタートメッセージの送信 while(1) { printf ("\r\nSet Freqency = "); //メッセージ送信 gets(buffer); //上位2ビット分の受信 byte3 = atoi(buffer); //整数に変換 gets(buffer); //下位16ビット受信 freq = atol(buffer); byte2 = freq >> 8; //2バイトに分解 byte1 = freq; printf ("%2X %2X %2X\r\n",byte3,byte2,byte1); //設定データ確認 ////// 周波数データ出力 ///// shift_out(byte3); //上位2ビット分出力 shift_out(byte2); //下位16ビット分出力 shift_out(byte1); output_high(set); //set信号出力 output_low(set); } } //////// シフトレジスタ設定制御 ///// shift_out(int byten) { int i,temp; temp = byten; //退避 for (i=0; i<8; i++) { if (temp > 0x7F) output_high(sdata); //1の出力 else output_low(sdata); //0の出力 temp = temp << 1; output_high(sclk); //sclkの出力 output_low(sclk); } }