1
完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
刚开始接触adf4351的时候,发现不知道如何去下手去编写程序, 怎么通过按键去实现控制产生不同的正弦波, 同时通过OLED显示。代码如下: #include “delay.h” #include “sys.h” #include “lcd.h” #include “touch.h” #include “gui.h” #include “test.h” #include “MS5611.h” #include “24l01.h” #include “spi.h” #include “string.h” #include “usart.h” #include “key.h” #include “ADF4351.h” void KEY_Init(void); u8 KEY_Scan(void); u8 keycount=1; int sweeptime=0; int timebai=9; int timeshi=0; int timege=0; int timeyi=0; extern uint32_t Pressure; extern uint64_t dT,TEMP; void LCD_MS5611_DataShow(void); u8 T[9],P[13]; int key1_flag,key0_flg,keyup_flag; void ADF4351Init(void); void ReadToADF4351(u8 count, u8 *buf); void WriteToADF4351(u8 count, u8 *buf); void WriteOneRegToADF4351(u32 Regster); void ADF4351_Init_some(void); void ADF4351WriteFreq(float Fre); uint8_t data_buf[9]={0}; u8 tmp_buf[33]; float fre=80; float frequence=80; int main(void) { SystemInit(); key1_flag=0;key0_flg=0;keyup_flag=0; delay_init(72); //delay_ms(1000); IIC_Init(); delay_ms(100); KEY_Init(); delay_ms(100); LCD_Init(); LCD_Clear(WHITE); LCD_Clear(WHITE); ADF4351Init(); ADF4351_Init_some(); ADF4351WriteFreq(fre) ; while(1){ keycount=KEY_Scan(); switch(keycount) { case KEY0_PRES:{ LCD_Clear(WHITE); Gui_StrCenter(0,40,BLUE,YELLOW,“sweep frequence”,16,1); key0_flg=key0_flg+1; if(key0_flg==2) { LCD_Clear(WHITE); Gui_StrCenter(0,40,BLUE,YELLOW,"start sweep",16,1); while(key0_flg==2) { frequence=frequence+0.1; keycount=KEY_Scan(); delay_us(sweeptime); if(keycount==1) { key0_flg=key0_flg+1; } if(frequence>110) { frequence=80; } ADF4351WriteFreq(frequence) ; } key0_flg=0; } break;} case KEY1_PRES:{ LCD_Clear(WHITE); Gui_StrCenter(0,60,BLUE,YELLOW,"dop frequence",16,1); key1_flag=key1_flag+1; if(key1_flag==2){ LCD_Clear(WHITE); Gui_StrCenter(0,60,BLUE,YELLOW,"dop dop",16,1); while((key1_flag==2)) { //Gui_StrCenter(0,60,BLUE,YELLOW,"dop dop",16,1); keycount=KEY_Scan(); if(keycount==1) { LCD_Clear(WHITE); fre=fre+1; ADF4351WriteFreq(fre) ; Gui_StrCenter(0,20,BLUE,YELLOW,"frequence",16,1); LCD_ShowNum(30,50,fre,5,16) ; } else if(keycount==2) { key1_flag=key1_flag+1; LCD_Clear(WHITE); } else if(keycount==3) { LCD_Clear(WHITE); fre=fre-1; if(fre<35){ fre=35; ADF4351WriteFreq(fre) ; Gui_StrCenter(0,20,BLUE,YELLOW,"frequence",16,1); LCD_ShowNum(30,50,fre,5,16) ; } ADF4351WriteFreq(fre) ; Gui_StrCenter(0,20,BLUE,YELLOW,"frequence",16,1); LCD_ShowNum(30,50,fre,5,16) ; } } key1_flag=0; } break;} case WKUP_PRES:{ LCD_Clear(WHITE); Gui_StrCenter(0,60,BLUE,YELLOW,"step in",16,1); keyup_flag=keyup_flag+1; if(keyup_flag==2) { LCD_Clear(WHITE); Gui_StrCenter(0,60,BLUE,YELLOW,"step step",16,1); while(keyup_flag==2) { keycount=KEY_Scan(); if(keycount==2) { LCD_Clear(WHITE); timeyi=timeyi+1; if(timeyi>2) { timeyi=0; LCD_Clear(WHITE); Gui_StrCenter(0,20,BLUE,YELLOW,"bai wei",16,1); LCD_ShowNum(30,50,timebai,5,16) ; } else if(timeyi==0) { LCD_Clear(WHITE); Gui_StrCenter(0,20,BLUE,YELLOW,"bai wei",16,1); LCD_ShowNum(30,50,timebai,5,16) ; } else if(timeyi==1) { LCD_Clear(WHITE); Gui_StrCenter(0,20,BLUE,YELLOW,"shi wei",16,1); LCD_ShowNum(30,50,timeshi,5,16) ; } else if(timeyi==2) { LCD_Clear(WHITE); Gui_StrCenter(0,20,BLUE,YELLOW,"ge wei",16,1); LCD_ShowNum(30,50,timege,5,16) ; } sweeptime=sweeptime+timebai*100+timeshi*10+timege; } else if(keycount==1) { LCD_Clear(WHITE); if(timeyi==0){ timebai=timebai+1; if(timebai>9) { timebai=0; } LCD_Clear(WHITE); Gui_StrCenter(0,20,BLUE,YELLOW,"bai wei",16,1); LCD_ShowNum(30,50,timebai,5,16) ; } else if(timeyi==1){ timeshi=timeshi+1; if(timeshi>9) { timeshi=0; } LCD_Clear(WHITE); Gui_StrCenter(0,20,BLUE,YELLOW,"shi wei",16,1); LCD_ShowNum(30,50,timeshi,5,16) ; } else if(timeyi==2) { timege=timege+1; if(timege>9) { timege=0; } LCD_Clear(WHITE); Gui_StrCenter(0,20,BLUE,YELLOW,"ge wei",16,1); LCD_ShowNum(30,50,timege,5,16) ; } sweeptime=sweeptime+timebai*100+timeshi*10+timege; } else if(keycount==3) { keyup_flag=keyup_flag+1; } } keyup_flag=0; } break; } } } } void LCD_MS5611_DataShow(void) { //unsigned char T[9],P[13]; T[0] = 'T'; T[1] = ':'; T[2] = TEMP/1000 + 0x30; T[3] = TEMP%1000/100 + 0x30; T[4] = '.'; T[5] = TEMP%100/10 + 0x30; T[6] = TEMP%10 + 0x30; T[7]='C'; T[8] = ' |