void Init(void) { //时钟配置 RCC_Configuration(); NVIC_Configuration(); delay_init(72); //串口配置 USART1_Configuration(); USART2_Configuration(); USART3_Configuration(); UART4_Configuration(); UART5_Configuration(); USART_ITEnable(); //PWM配置 PWMTIM_Configuration(72000/5,0); //不分频。PWM频率=Freq //指南针配置 COMPASS_Init(); //舵机配置 SERVOS_Init(); //设置到初始值 PWM_Configuration(MOTOR_Speed); s3010_SeTAngle(SERVOS_Angle); }
void BSP_Init(void) { RCC_Init(); Init_System_Timer(); TIM6_Configuration(); //10ms 主中断 LED_Init(); USART3_Configuration(); //上位机通信 CAN1_Mode_Init(CAN_SJW_1tq,CAN_BS1_6tq,CAN_BS2_7tq,6,CAN_Mode_Normal);//can1初始化500k波特率 CAN2_Mode_Init(CAN_SJW_1tq,CAN_BS2_6tq,CAN_BS1_7tq,3,CAN_Mode_Normal);//can2初始化500k波特率 USART1_IMU_Init(115200);//陀螺仪232通信 //USART4_IMU_Init(115200);//磁力计,卡尔曼滤波 }
/** * @brief Program entry point * @param None * @retval None */ int main(void) { RCC_ClocksTypeDef RCC_Clocks; __IO uint32_t i = 0; /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32fxxx_xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32fxxx.c file */ /* SysTick end of count event each 1ms */ RCC_GetClocksFreq(&RCC_Clocks); SysTick_Config(RCC_Clocks.HCLK_Frequency / 1000); USART3_Configuration(); // Debug via RS232 puts("T2 VCP Demo"); USART6_Configuration(Uart6); // Modem for USB Uart_ModemOn(Uart6, TELIT_TIME_ON); USBD_Init(&USB_OTG_dev, #ifdef USE_USB_OTG_HS USB_OTG_HS_CORE_ID, #else USB_OTG_FS_CORE_ID, #endif &USR_desc, &USBD_CDC_cb, &USR_cb); /* Main loop */ while (1) { if (i++ == 0x100000) { STM_EVAL_LEDToggle(LED1); STM_EVAL_LEDToggle(LED2); STM_EVAL_LEDToggle(LED3); i = 0; } } }
int main() { /* Initialize system */ SystemInit(); /* Initialize delay */ TM_DELAY_Init(); // Pin GPIO H4 for use by logic analyser. ConfigureDebugOutputPin(); USART3_Configuration(); printf("\r***************************************************************\r"); printf("* DS18B20 Temperature Controller *\r"); printf("***************************************************************\r"); // Setup the GPIO port and pin to talk to OneWire devices. DS18B20_Init(); //Search for devices and show their ROM codes. ShowROMCodesOfDevices(); printf(" \r"); char buffer[80]; while (1) { // Read the temperature. Blocks the processor for 700us or so. //BlockAndReadRawTemperature(); // Read the temperature. Non-blocking. DS18B20ReadTemperature(); if (DS18B20Status == TEMPERATURE_AVAILABLE) { //float celsius = (float)roundf(GetTemperatureCelsius() * 100) / 100; float celsius = GetTemperatureCelsius(); printf("Temp: %s\r", FormatFloatToString(celsius, buffer, 2)); } Delayms(500); } }
/************************************************************************************** Func: 使用DMA方式传输数据 Time: 2014-6-12 Ver.: V1.0 Note; **************************************************************************************/ void USART3_DMAConfiguration() { NVIC_InitTypeDef NVIC_InitStructure; DMA_InitTypeDef DMA_InitStructure; USART3_Configuration(); //启动DMA时钟 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE); //DMA发送中断设置 NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel6_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); //DMA1通道4配置 DMA_DeInit(DMA1_Channel6); //外设地址 DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)(&USART3->DR); //内存地址 DMA_InitStructure.DMA_MemoryBaseAddr =(uint32)USART3_TX_Buffer;//地址未设置请自行设置 //dma传输方向单向 DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST; //设置DMA在传输时缓冲区的长度 DMA_InitStructure.DMA_BufferSize =sizeof(USART3_TX_Buffer);//长度未设定请自行设置 //设置DMA的外设递增模式,一个外设 DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; //设置DMA的内存递增模式 DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; //外设数据字长 DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte; //内存数据字长 DMA_InitStructure.DMA_MemoryDataSize = DMA_PeripheralDataSize_Byte; //设置DMA的传输模式 DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; //设置DMA的优先级别 DMA_InitStructure.DMA_Priority = DMA_Priority_High; //设置DMA的2个memory中的变量互相访问 DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; DMA_Init(DMA1_Channel6,&DMA_InitStructure); DMA_ITConfig(DMA1_Channel6,DMA_IT_TC,ENABLE); USART_DMACmd(USART3,USART_DMAReq_Tx,ENABLE); }
void BSP_Init (void) { // Clock Config: HSE 72 MHz #if __RTC_ENABLE == ON RTC_Configuration(); #else RCC_Configuration(); #endif #if __USART1_ENABLE == ON // USART1 Config ==> FTDI USART1_Configuration(); #endif #if __USART3_ENABLE == ON // USART3 Config ==> Trypano support card USART3_Configuration(); #endif #if __SRAM_ENABLE == OFF && __LED_ENABLE == ON // LED Config LED_Configuration(); #endif #if __SWITCH_ENABLE == ON // SWITCH Config SWITCH_Configuration(); #endif // I2C Config #if __I2C_ENABLE == ON I2C_Configuration(); #endif #if __POT_ENABLE == ON // Pot / ADC Config ADC_POT_Configuration(); #endif #if __USB_ENABLE == ON //USB Config USB_Configuration(); #endif #if __DAC1_ENABLE == ON //DAC Config and start DAC1_Configuration(); #endif #if __SRAM_ENABLE == ON // RAM Config SRAM_Configuration(); #endif #if __SDCARD_ENABLE == ON // SDCard Config SDCARD_Configuration(); #endif #if __DAC2_ENABLE == ON DAC2_Configuration(); #endif #if __ADCe1_ENABLE == ON ADCe1_Configuration(); #endif }
void init(void) { SystemInit(); //Setup SystickTimer if (SysTick_Config(SystemCoreClock / 1000)){ColorfulRingOfDeath();} GPIO_Configuration(); #ifdef USE_MICROUSB USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_CDC_cb, &USR_cb); #endif #ifdef USE_SDIO UB_Fatfs_Init(); #endif #ifdef USE_ADC ADC_Configuration(); #endif #ifdef USE_I2C I2C_Configuration(); #endif #ifdef USE_SPI SPI_Configuration(); #endif #ifdef USE_ENCODER TIM_encoder_Configuration(); #endif #ifdef USE_USART1 USART1_Configuration(); #endif #ifdef USE_USART2 USART2_Configuration(); #endif #ifdef USE_USART3 USART3_Configuration(); #endif #ifdef USE_CAN CAN_Configuration(); #endif #ifdef USE_PWM TIM_pwm_Configuration(); #endif #ifdef USE_EXTI EXTI_Configuration(); #endif NVIC_Configuration(); }
/* *@功能 主函数入口 *@参数 空 *@返回 空 */ int main(void) { /*测试变量部分*/ /*******************************************/ uint8_t t=' '; uint8_t usb_code[6]={0x55,0x7A,0xBB,0x01,0x00,0x01};//下位机反复的向上位机发送此命令,用以建立初始化连接 uint8_t p[6]={0x30,0x31,0x32,0x33,0x34,0x35}; uint8_t hanzi[11]; uint8_t *phz; uint32_t flash_data; uint8_t flash_temp[4]; uint8_t status; uint32_t addr; uint8_t nChar; // uint8_t char_buf[50]; // uint8_t count; uint32_t batt_test=0; /*********************************************/ //设置中断向量表的位置在 0x5000,即内部flash的前20K NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x5000); SystemTick_Init(); NVIC_Configuration(); //按键初始化 Init_Sw_Key_Io(); Exit_Line_Init(); EXTILine_Mask(EXTI_Line5); EXTILine_Mask(EXTI_Line8); EXTILine_Mask(EXTI_Line15); //长按开机,如果长按不够3m则继续保持关机状态,如果长按3m,则退出停机模式,开机 WKUP_Init(); EXTILine_Unmask(EXTI_Line5); EXTILine_Unmask(EXTI_Line8); EXTILine_Unmask(EXTI_Line15); //如果没有进入停机模式,则开启显示 OLED_WR_Byte(0xAF,OLED_CMD); //开启显示 longpress=0; stop_flag=0; SPI_FLASH_Init(); //正常运行后,显示logo OLED_Init(); SPI_FLASH_Init(); OLED_Clear(); OLED_DrawBMP(32,2,48,4,hui); OLED_ShowUnite(48,2,"合科技"); //delay_ms(800); USB_BIT_Init(); //为降低功耗的控制位 /****************************************/ bluetooth_control_Init(); max232_control_Init(); oled_control_Init(); OLED_ON; buzzer_control_Init(); BUZZER_OFF; coil_control_Init(); COIL_NO_ACTUATE; /****************************************/ Init_Timer(); //实时时钟初始化 RTC_init(); //初始化并启动看门狗 //iwdg_init(); //串口1 USB初始化及配置 Uart1_Init(); USART1_Configuration(); //串口2 RFID初始化及配置 Uart2_Init(); USART2_Configuration(); //串口3 bluetooth初始化及配置 Uart3_Init(); USART3_Configuration(); bluetooth_Configuration(); //蓝牙的EN和BRST配置 CLR_BT_EN; //开启蓝牙 ADC_GPIO_Configuration(); ADC_Configuration(); //flash区域指针初始化 //SPI_FLASH_WriteWord(INIT_FLAG,1); //此次下载清flash SPI_FLASH_WriteWord(INIT_FLAG,0); //此次下载不清flash if(SPI_FLASH_ReadWord(INIT_FLAG) ==0x01) //当初始化标志等于1,就初始化POINT和ROW { mykey_init(); //初始化钥匙操作的头指针 ---如何设定在什么情况下重新设置 } // OLED_ClearArea(0,4,128,6); // OLED_ShowUnite(24,4,"初始化蓝牙"); // mac_query_result=bluetooth_mac(); /*延时函数测试*/ /**********************************************/ // GPIO_Configuration(); // while(1) // { // GPIO_SetBits(GPIOB,GPIO_Pin_0); // delay_ms(1000); // GPIO_ResetBits(GPIOB,GPIO_Pin_0); // delay_ms(3000); // } /**********************************************/ /*OLED测试*/ /**********************************************/ // while(1) // { // OLED_Clear(); // OLED_ShowChinese(0,0,0); //中 // OLED_ShowChinese(18,0,1); //景 // OLED_ShowChinese(36,0,2); //园 // OLED_ShowChinese(54,0,3); //电 // OLED_ShowChinese(72,0,4); //子 // OLED_ShowChinese(90,0,5); //科 // OLED_ShowChinese(108,0,6);//技 // OLED_ShowString(0,3,"1.3' OLED TEST"); // //OLED_ShowString(8,2,"ZHONGJINGYUAN"); // //OLED_ShowString(20,4,"2014/05/01"); // OLED_ShowString(0,6,"ASCII:"); // OLED_ShowString(63,6,"CODE:"); // OLED_ShowChar(48,6,t);//显示ASCII字符 // t++; // if(t>'~') // t=' '; // OLED_ShowNum(103,6,t,3,16);//显示ASCII字符的码值 // // delay_ms(8000); // //OLED_Clear(); // // OLED_DrawBMP(0,0,128,8,BMP1); //图片显示(图片显示慎用,生成的字表较大,会占用较多空间,FLASH空间8K以下慎用) // delay_ms(800); // // //OLED_Display_On(); // //delay_ms(800); // // OLED_DrawBMP(0,0,128,8,BMP2); // delay_ms(800); // // //OLED_Display_Off(); // //delay_ms(800); // } /**********************************************/ /*OLED+字库测试*/ /**********************************************/ // phz="字库"; // hanzi[0]=*phz; // hanzi[1]=*(phz+1); // hanzi[2]=*(phz+2); // hanzi[3]=*(phz+3); // hanzi[4]=*(phz+4); // // // OLED_ShowChinese(0,0,"汉"); // OLED_ShowChinese(16,0,"字"); // // OLED_ShowUnite(0,2,"你很不错"); // OLED_ShowUnite(0,4,"ABCDEF"); // OLED_ShowUnite(0,6,"123456"); /**********************************************/ /* STM32F103C8串口有3个 串口1通过USB接充电器,与上位机PC通信 串口2通过串口读RFID的数据 串口3通过蓝牙与PDA通信 */ /*串口1 USB测试*/ /**********************************************/ // while(1) // { // UART1nSendChar(1,"12345",5); // delay_ms(1000); // } //UART1nSendChar(1,usb_code,6); //USB_Cheak_init(); //Test_Usb_Data(); // UART1SendwordHex(1, 0x123456); // UART1nSendChar(1,"汉字",5); // while(1); /**********************************************/ /*串口2 RFID测试*/ /**********************************************/ // while(1) // { // OLED_ShowUnite(32,2,"RFID"); // delay_ms(1000); // UART1nSendChar(1,"12345",5); // //OLED_Clear(); //清屏 // nChar =Read_RfidData(2,Rfid_Buff,0xff); // m_UB2; // if(nChar ==5) // { // if(Rfid_Buff[0]==0&&Rfid_Buff[1]==0&&Rfid_Buff[2]==0&&Rfid_Buff[3]==0) // ; // else //至少有一个不为零 // { // UART1nSendChar(1,Rfid_Buff,5); // OLED_ShowNumHex(32,4,Rfid_Buff[0],2,16); // OLED_ShowNumHex(48,4,Rfid_Buff[1],2,16); // OLED_ShowNumHex(64,4,Rfid_Buff[2],2,16); // OLED_ShowNumHex(80,4,Rfid_Buff[3],2,16); // delay_ms(1000); // break; // } // } // } // while(1); /**********************************************/ /*串口3 bluetooth测试*/ /**********************************************/ // CLR_BT_EN; // CLR_BT_BRTS; // // while(1) // { // UART3nSendChar(3,"012345",6); // delay_ms(1000); // } // while(1) // { // UART3nSendChar(3,"TTM:MAC-?",9); // count=UART3GetCount(3); // UART3nReadChar(3,char_buf,count); // // // // // UART1nSendChar(1,char_buf,count); // delay_ms(1000); // } /**********************************************/ /*flash测试*/ /**********************************************/ // SPI_FLASH_WriteWord(AUTHOR_ROW,0x456789); // // SPI_FLASH_BufferRead(flash_temp,AUTHOR_ROW,4); // // flash_data=SPI_FLASH_ReadWord(AUTHOR_ROW); // UART1nSendChar(1,flash_temp,4); // // OLED_ShowNum(0,6,flash_data,8,16); // // //SPI_FLASH_WriteEnable(); // status=SPI_FLASH_ReadStatusReg(); // OLED_ShowNum(112,6,status,1,16); // SPI_FLASH_BulkErase(); // SPI_FLASH_BufferWrite("98765",0x100002,6); // SPI_FLASH_BufferRead(p,0x100002,6); // SPI_FLASH_Write("98765",0x1f0005,6); // SPI_FLASH_Read(p,0x1f0005,6); // while(1) // { // UART1nSendChar(1,p,6); // delay_ms(1000); // } /**********************************************/ //菜单测试 /**********************************************/ //Main_Lcd_Show(); //主界面显示 //Main_Lcd_Show2(); // mode=1; // // OLED_ShowChar(0,0,'A'); // // OLED_ShowChinese(0,2,"我"); // // OLED_ShowUnite(0,4,"你很不错"); // // while(1); // // mode=0; // delay_ms(1000); //ShowMenu(HsMenu); // Choose_MenuOp1(); // Choose_MenuOp4(); // Choose_MenuOp4_1(); // Choose_MenuOp4_2(); // Choose_MenuOp4_22(); // Choose_MenuOp4_3(); // Choose_MenuOp4_4(); // Choose_MenuOp5(); // Choose_MenuOp5_1(); // Choose_MenuOp5_3(); // Choose_MenuOp5_4(); // while(1) // { // Main_Oled_Time(); // Main_Oled_Power(); // delay_ms(1000); // } // while(1); /**********************************************/ //蜂鸣器测试 /**********************************************/ // while(1) // { // BUZZER_OFF; // delay_ms(1000); // // BUZZER_ON; // delay_ms(1500); // } /**********************************************/ //协议测试 /**********************************************/ //OLED_Clear(); // OLED_ShowUnite(32,2,"通信中.."); // OLED_ShowUnite(0,4,"你很不错"); // delay_ms(1000); // addr=0xFFFF; // OLED_ShowNumHex(0,6,addr,8,16); //USB_Cheak_init(); //USB_transmit(); // bluetooth_uart_switch=1; // Test_Usb_Data(); // while(1); // SPI_FLASH_WriteWord(AUTHOR_POINT,AUTHOR_START); // addr= SPI_FLASH_ReadWord(AUTHOR_POINT); // OLED_ShowNum(0,0,addr,8,16); /**********************************************/ //ADC测试 /**********************************************/ // while(1) // { // OLED_Clear(); // batt_test=ADC_GetConversionValue(ADC1); // OLED_ShowNum(24,2,batt_test,8,16); // delay_ms(1000); // } // /**********************************************/ //定时器2测试 /**********************************************/ // GPIO_Configuration(); // GPIO_ResetBits(GPIOB,GPIO_Pin_6); // delay_ms(10); // GPIO_SetBits(GPIOB,GPIO_Pin_6); // g_WaitTimeOut = 0; // SetTimer(TIMER_TIMEOUT,1,Do_TimeOut,THREE_MIN); // while(g_WaitTimeOut == 0) // { // GPIO_ResetBits(GPIOB,GPIO_Pin_6); // } // KillTimer(TIMER_TIMEOUT); // GPIO_SetBits(GPIOB,GPIO_Pin_6); // g_WaitTimeOut = 0; // SetTimer(TIMER_TIMEOUT,10,Do_TimeOut,THREE_MIN); // while(g_WaitTimeOut == 0) // { // nChar =Read_RfidData(2,Rfid_Buff,0xff); // if(nChar ==5) // { // OLED_ShowUnite(32,80,Rfid_Buff); // ++rfidrow; // delay_ms(1000); // for(i=0;i<4;i++) // { // for(k =0;k<40;k++) // msDelay(500); // WritEDAta(CAIMA_START+8*rfidrow+4+i,Rfid_Buff[i]); // } // break; // } // } // KillTimer(TIMER_TIMEOUT); /**********************************************/ // OLED_ClearArea(0,4,128,6); // OLED_ShowUnite(24,4,"初始化完成"); // delay_ms(100); //bluetooth_uart_switch=0; // for(int iter=0;iter<3;iter++) // Power_Cheak(); //主循环测试 g_State=ST_IDLE; while(1) { switch (g_State) //g_State是一个全局函数 { case ST_IDLE: //#define ST_IDLE 0XFF ST_Idle(); //空闲时做状态检测,可改变g_State break; case ST_USB: //#define ST_USB 0XFD USB_transmit(); //USB传输 break; // case ST_KEY: // Key_Trismit(); //读钥匙的RFID,判断是否已经连接上 // break; case ST_LCDMENU: //#define ST_LCDMENU 0XFA 多选择菜单操作 Choose_MenuOp1(); break; default:break; } } }
int main(void) { PWM_Initialization(); TIM1->CCR2 = 1000; TIM1->CCR3 = 1000; Delay_1us(500000); RCC_Configuration(); PushButton_Initialization(); LED_Initialization(); //LCD_Initialization(); //terminalBufferInitilization(); Delay_1us(100000); SPI_Initialization(); Delay_1us(100000); IMU_Initialization(); Delay_1us(100000); Timer5_Initialization(); //Filter Timer2_Initialization(); //Print Timer4_Initialization(); //Read IMU USART3_Configuration(); USART3_puts("\r\nHello World!\r\n"); while(1) { if(PushButton_Read()){ if(f.arm == 0){ f.arm = 1; Delay_1us(500000); } else if(f.arm == 1){ f.arm = 0; Delay_1us(500000); } } if(f.imu == 1){ //LED3_Toggle(); readIMU(gyroRaw, GYRO_DATA_REGISTER); gyro_remove_offset(gyroRaw); readIMU(accRaw, ACC_DATA_REGISTER); f.imu = 0; // } // if(f.filter == 1){ //LED4_Toggle(); Filter(gyroRaw, gyroAngle, accRaw, accAngle, Angle); if(f.arm == 1){ PID_control(Angle); } else{ TIM1->CCR2 = 1000; TIM1->CCR3 = 1000; errorI = 0; errorD = 0; previous_error = 0; } //f.filter = 0; } strcmd_main(); //if(f.print == 1){ // sprintf(lcd_text_main,"%.4f %.4f %d", Angle[0], Angle[1], f.arm); // //sprintf(lcd_text_main,"G: %.3f %.3f %.3f", EstV.G.X, EstV.G.Y, EstV.G.Z); // LCD_DisplayStringLine(LINE(1), lcd_text_main); // //sprintf(lcd_text_main,"A: %.3f %.3f %.3f", EstV.A.X, EstV.A.Y, EstV.A.Z); // //sprintf(lcd_text_main,"A: %.3f %.3f", sqX_sqZ, EstV.GA.X*EstV.GA.X + EstV.GA.Z*EstV.GA.Z); // // sprintf(lcd_text_main,"%.4f %.4f %.4f \n", gyroAngle[0], gyroAngle[1], gyroAngle[2]); // sprintf(lcd_text_main,"%d ", gyroRaw[2]); // LCD_DisplayStringLine(LINE(2), lcd_text_main); // sprintf(lcd_text_main,"GA: %.3f %.3f %.3f", EstV.GA.X, EstV.GA.Y, EstV.GA.Z); // LCD_DisplayStringLine(LINE(3), lcd_text_main); //sprintf(lcd_text_main,"%.3f %.3f %.3f\n", EstV.G.Z, EstV.A.Z, EstV.GA.Z); //LCD_DisplayStringLine(LINE(2), (uint8_t*)" Ming6842 @ github"); //terminalWrite(lcd_text_main); //PRINT_USART(); //f.print = 0; //} } while(1); // Don't want to exit }
void axu3init(void) { NVIC_Configuration(); USART3_Configuration(); }
int main(void) { u8 i, j, k; u8 addr, DATA_BUF; RCC_Configuration(); delay_Configuration(72); USART3_Configuration(9600); LED_OUT Set_LED //设置引脚方向,从单片机方向看过来 //5687的引脚方向 SCLK_OUT SDENB_OUT SDIO5687_OUT SDO_IN RESETB_OUT //4360的引脚方向 CE4360_OUT Set_CE4360; //芯片使能引脚拉高 delay_us(10); LE4360_OUT DATA4360_OUT CLK4360_OUT /**************************************************************/ /***********************配置DAC5687********************/ //写DAC5687 //复位DAC5687 Clr_RESETB delay_us(10); Set_RESETB /*指令字节数据组合*/ addr = 0x00; //起始地址0x00,I7='0',表示写模式;I6I5='00'',表示每次写一个字节 delay_us(10); /*配置DAC5687寄存器,32字节数据,分32次写入*/ for (i = 0; i < 32; i++) //循环配置32次,每次写一个字节 { /*初始化nCS和SCLK*/ Set_SDENB delay_us(10); Clr_SDENB delay_us(10); Clr_SCLK delay_us(10); /*写指令字节,配置地址*/ DATA_BUF = addr; for (j = 0; j < 8; j++) //指令周期,8bits数据 { delay_us(10); if (DATA_BUF & 0x80) Set_SDIO5687 else Clr_SDIO5687 delay_us(10); Clr_SCLK delay_us(10); Set_SCLK //时钟上升沿,写入数据 delay_us(10); DATA_BUF = DATA_BUF << 1; } DATA_BUF = config_5687_data[i]; //从config_5687_data数组相应位置,取要写的一字节数据,放到DATA_BUF delay_us(10); /*写寄存器数据*/ for (k = 0; k < 8; k++) //写一个字节 { if (DATA_BUF & 0x80) Set_SDIO5687 else Clr_SDIO5687 //时钟上升沿,写入数据 delay_us(10); Clr_SCLK delay_us(10); Set_SCLK delay_us(10); DATA_BUF = DATA_BUF << 1; } delay_us(10); /*结束一次写操作*/ Set_SDENB delay_us(10); addr = addr + 1; //配置完一个字节,寄存器地址加1 } //读DAC5687 for (i = 0; i < 32; i++) //读32字节,存入rec_buf { DATA_BUF = 0x00; /*初始化nCS和SCLK*/ delay_us(10); Set_SDENB delay_us(10); Clr_SDENB delay_us(10); Clr_SCLK delay_us(10); /*写指令字节,配置地址*/ DATA_BUF = config_addr1; for (j = 0; j < 8; j++) //指令周期,8bits数据 { if (DATA_BUF & 0x80) Set_SDIO5687 else Clr_SDIO5687 delay_us(10); Clr_SCLK delay_us(10); Set_SCLK //时钟上升沿,写入数据 delay_us(10); DATA_BUF = DATA_BUF << 1; } delay_us(10); config_addr1++; Set_SCLK delay_us(10); for (k = 0; k < 8; k++) { delay_us(10); DATA_BUF = DATA_BUF << 1; //时钟下降沿读出数据,高位在前 delay_us(10); Set_SCLK delay_us(10); Clr_SCLK delay_us(10); if (SDO == 1) DATA_BUF = DATA_BUF | 0x01; else DATA_BUF = DATA_BUF & 0xfe; delay_us(10); } delay_us(10); Set_SDENB delay_us(10); rec_buf[i] = DATA_BUF; } /***********************配置ADF4360********************/ //配置ADF4360 Set_LE4360 delay_ms(1); Clr_LE4360 // for (k = 1; k < 10; k++) { DATA_BUF = config_4360_data[k - 1]; for (i = 0; i < 8; i++) { if (DATA_BUF & 0x80) Set_DATA4360 else Clr_DATA4360 Clr_CLK4360 //上升沿写入数据 Set_CLK4360 DATA_BUF = DATA_BUF << 1; } if (k == 3) { Set_LE4360 delay_ms(4); Clr_LE4360 delay_ms(20); } if (k == 6) { Set_LE4360 delay_ms(4); Clr_LE4360 delay_ms(20); } if (k == 9) { Set_LE4360 delay_ms(4); Clr_LE4360 delay_ms(20); } } for (i = 0; i < 32; i++) printf(" %x", rec_buf[i]); }