// PIC16F886 Configuration Bit Settings // 'C' source line config statements // CONFIG1 #pragma config FOSC = HS // Oscillator Selection bits (HS oscillator: High-speed crystal/resonator on RA6/OSC2/CLKOUT and RA7/OSC1/CLKIN) #pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled and can be enabled by SWDTEN bit of the WDTCON register) #pragma config PWRTE = ON // Power-up Timer Enable bit (PWRT enabled) #pragma config MCLRE = ON // RE3/MCLR pin function select bit (RE3/MCLR pin function is MCLR) #pragma config CP = OFF // Code Protection bit (Program memory code protection is disabled) #pragma config CPD = OFF // Data Code Protection bit (Data memory code protection is disabled) #pragma config BOREN = OFF // Brown Out Reset Selection bits (BOR disabled) #pragma config IESO = OFF // Internal External Switchover bit (Internal/External Switchover mode is disabled) #pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enabled bit (Fail-Safe Clock Monitor is disabled) #pragma config LVP = OFF // Low Voltage Programming Enable bit (RB3 pin has digital I/O, HV on MCLR must be used for programming) // CONFIG2 #pragma config BOR4V = BOR21V // Brown-out Reset Selection bit (Brown-out Reset set to 2.1V) #pragma config WRT = OFF // Flash Program Memory Self Write Enable bits (Write protection off) #include #define _XTAL_FREQ 16000000 //周波数16MHz unsigned char reg_addres, data, tx_data, slv_addres; static void pic_init(); static void i2c_send(unsigned char, unsigned char); //Reg address, Data static void send_byte(unsigned char); //static void send_byte(unsigned char data); //static void send_byte(unsigned char tx_data); static void idlei2c(); //=============PICの初期化====================== static void pic_init() { ANSEL = 0x00; // Analog入力無し ANSELH = 0x00; TRISA = 0x00; // RA0-7:out TRISB = 0x00; // RB0-7:out TRISC = 0x18; // RC3,RC4 SDA/SCL:input PORTB = 0x00; PORTC = 0x00; SSPCON = 0x28; // SSP enable & I2C Master mode, 400kbps = Fosc / (4 * (SSPADD+1)) SSPADD = 0x09; // 0x00では動作せず return; } //===========I2C コマンド送信====================== static void i2c_send(unsigned char reg_addres, unsigned char data) { unsigned char slv_addres = 0xC0; //Si5351 0b1100 000_ idlei2c(); //アイドル待ち SSPCON2bits.SEN = 1; //スタート出力 while (SSPCON2bits.SEN); //スタート終了待ち send_byte(slv_addres); //Si5351 addres+マスタ送信 send_byte(reg_addres); //Si5351 Regster送信 send_byte(data); //Si5351 set data送信 SSPCON2bits.PEN = 1; //stop 出力 while (SSPCON2bits.PEN); //ストップ終了待ち } /**アイドル待ちサブ関数*/ static void idlei2c(void) { while (SSPCON2bits.SEN || SSPCON2bits.PEN || SSPCON2bits.RCEN || SSPCON2bits.ACKEN || SSPSTATbits.R_nW); } //===========I2C 1Byte送信======================= static void send_byte(unsigned char tx_data) { SSPBUF = tx_data; //データーセット送信開始 while (SSPSTATbits.BF); //送信終了待ち while (SSPCON2bits.ACKSTAT); //ACK返信待ち idlei2c(); //アイドル待ち } //==============メイン====================== void main() { pic_init(); //PIC初期設定 while(1) { /*Si5351A設定*/ i2c_send(3,0xFF); //OUT CONT Reg,OUT Disable i2c_send(16,0x80); //CLK0 CONT Reg,PWR DWN i2c_send(17,0x80); //CLK1 CONT Reg,PWR DWN i2c_send(18,0x80); //CLK2 CONT Reg,PWR DWN /*Si5351周波数設定レジスター26-31 パラメーターP1=4096 P2=0 P3=1 * PLL=900MHz Fout=36MHz*/ i2c_send(26,0x00); //MSNA_P3[15:8],P3=1 i2c_send(27,0x01); //MSNA_P3[7:0],P3=1 i2c_send(28,0x00); //MSNA_P1[17:16],P1=4096 i2c_send(29,0b00010000); //MSNA_P1[15:8],P1=4096 i2c_send(30,0x00); //MSNA_P1[7:0],P1=4096 i2c_send(31,0x00); //MSNA_P3[19:16],P3=1 //MSNA_P2[19:16],P2=0 i2c_send(32,0x00); //MSNA_P2[15:8],P2=0 i2c_send(33,0x00); //MSNA_P2[7:0],P2=0 /*Si5351Aマルチシンセ分周設定レジスター42-49 パラメーターP1=4096 P2=0 P3=1*/ i2c_send(42,0x00); //MSN0_P3[15:8],P3=1 i2c_send(43,0x01); //MSN0_P3[7:0],P3=1 i2c_send(44,0x00); //R0_DIV[6:4] MSN0_DIV[3:2] //MS0_P1[17:16],00 i2c_send(45,0b00001100); //MS0_P1[15:8],P1=3200 i2c_send(46,0b10000000); //MS0_P1[7:0],P1=3200 i2c_send(47,0x00); //MS0_P3[19:16],P3=1 //MS0_P2[19:16] P2=0 i2c_send(48,0x00); //MS0_P2[15:8],P2=0 i2c_send(49,0x00); //MS0_P2[7:0],P2=0 /*ここまでSi5351A周波数設定完了*/ i2c_send(177,0xA0); //PLL A b reset i2c_send(16,0x4F); //CLK0 POWER UP & 8mA i2c_send(3,0xFE); //OUT CONT reg,CLK0 Enable PORTA = 0b00000100; __delay_ms(500); PORTA = 0b00000000; __delay_ms(500); } return; }