#include "main.h" static uint16_t buffer[BufferSizeMax]; // 320*8 = 2560 static uint16_t zero[32]; uint16_t BufferSize=BufferSizeMax; uint16_t PointSync=0; // synchronization point uint8_t Band = 4; // 0=3.75mks, 1=10mks, 2=20mks, 3=50mks, 4=0.1ms, 5=0.2ms, 6=0.5ms, 7=1ms uint8_t Sync = 1; // 0=None, 1=Fall, 2=Increase, 3=Up, 4=Down, 5=Wait uint8_t Mode=0; // 0=OSC, 1=OSC+miniOSC, 2=FFT uint8_t KeyStatus=0; uint16_t KeyAntiBug =0; uint8_t Freez=0; // 0=norm; 1=Freez; 2=Freez+slide uint16_t Vbat=15; // battery voltage uint16_t Uin; // Input voltage uint32_t SumUin=0; // SUM input voltage uint8_t Umin; uint8_t Umax; uint8_t Umidl; uint8_t Ddown; uint8_t CursorRED=255; uint8_t CursorBLUE=255; uint32_t Frequence; uint32_t Frequence_OUT=12; uint8_t amount=0; // amount point zerro uint16_t Draw_Uin_Time_Counter=0; uint16_t Draw_Freq_Time_Counter=0; uint16_t Draw_Bat_Time_Counter=0; uint16_t Draw_F_Out_Time_Counter=0; uint8_t Bright=1; uint16_t position = 1; uint16_t counter_buffer=0; uint8_t beam_new; uint8_t beam_old; //============================================================================== int main(void) { GPIOinit(); SPIinit(); ADCinit(); TIMERinit(); LCDinit(); DMAinit((uint32_t)&buffer[0], BufferSize); EXTI_init(); Usart_init(); DrawOSD(Band, Sync, Vbat, Mode); TIM1->ARR = Frequence_OUT_Period[Frequence_OUT]-1; TIM1->PSC = Frequence_OUT_Prescaler[Frequence_OUT]-1; TIM1->CNT = 0; if (Band<2) {ADC_SoftwareStartConvCmd(ADC1, ENABLE);} for (uint16_t j = 1; j < 800; j++) { SetBright(0); Delay(800-j); SetBright(1); Delay(j); } SetBright(Bright); ADC_SoftwareStartConvCmd(ADC2, ENABLE); //============================================================================== //============================================================================== //============================================================================== while(1) { if (KeyStatus>0) {HandlingStatus();} //============================================================================== // <= 5ms ====================================================================== if (Band <= 10) { if (Freez==0) { if (Band<3) { __disable_irq(); __disable_fiq(); ReadADC((uint32_t)&buffer[0], Band); __enable_irq(); __enable_fiq(); } else { // >= 20mks if (Band<6) {__disable_irq(); __disable_fiq();} ADC_SoftwareStartConvCmd(ADC1, ENABLE); uint32_t timeout = 1000000; while (!DMA_GetITStatus(DMA1_FLAG_TC1) && timeout) {timeout--;} if (timeout==0) {DrawString("T OUT", 247, 3, WHITE, BLUE);} __enable_irq(); __enable_fiq(); ADC_SoftwareStartConvCmd(ADC1, DISABLE); DMA_ClearFlag(DMA1_FLAG_GL1); } for (uint16_t j = 0; j < BufferSize; j++) { buffer[j]=buffer[j]>>4; } // Sinchronization==================================================== if (Mode!=2) { // != FFT Umidl=(Umax/2)+(Umin/2); // CursorRED=45+Umax/2; // CursorGREEN=45+Umin/2; // CursorCYAN=45+Umidl/2; Umin=255; // min voltage in buffer uint16_t Nmin=0; // number min voltage in buffer Umax=0; // max voltage in buffer uint16_t Nmax=0; // number min voltage in buffer uint8_t Dup=0; // Delta when changing up uint8_t Ddown=0; // Delta when changing down amount=0; for (uint16_t j = 16; j < BufferSizeMax-320; j++) { if((((buffer[j-1]Umidl)) | ((buffer[j-1]>Umidl)&(buffer[j] Ddown)) { PointSync=j; Ddown=buffer[j]-buffer[j+1]; } } if (Sync == 2) { if ((buffer[j+1]-buffer[j] > Dup)) { PointSync=j; Dup=buffer[j+1]-buffer[j]; } } if ((buffer[j] > Umax)) { Nmax=j; Umax=buffer[j]; } if ((buffer[j] < Umin)) { Nmin=j; Umin=buffer[j]; } } if (Sync == 3) { PointSync=Nmax; } if (Sync == 4) { PointSync=Nmin; } } // END Sinchronization==================================================== if (Mode ==0) { Draw320x216(buffer, PointSync, CursorRED, CursorBLUE); } if (Mode ==1) { Draw320x184(buffer, PointSync, CursorRED, CursorBLUE); Draw320x32(buffer, PointSync, Freez); } if (Mode ==2) { FFT(buffer); } } // freez } // END Band <= 12 //============================================================================== //============================================================================== // 10ms =< Band >= 0.1S ================================== //======================================================== if (Band >= 11 && Band <= 14) { if (Freez==0) { ADC_SoftwareStartConvCmd(ADC1, ENABLE); // BufferSize=BufferSizeMax; // Sinchronization==================================================== beam_old=beam_new; uint16_t delta=512; if (Sync==1||Sync==3) { while ((beam_old-beam_new) < delta/4) { while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC)) {} ADC_ClearFlag(ADC1, ADC_FLAG_EOC); buffer[counter_buffer] = 45+((ADC1->DR)>>5); beam_old=beam_new; beam_new=buffer[counter_buffer]; counter_buffer++; if (counter_buffer>=BufferSizeMax) {counter_buffer=0;} delta--; } } //---------------------------------- if (Sync==2||Sync==4) { while ((beam_new-beam_old) < delta/4) { // while ((beam_old-beam_new) < delta/16) { while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC)) {} ADC_ClearFlag(ADC1, ADC_FLAG_EOC); buffer[counter_buffer] = (ADC1->DR)>>4; beam_old=beam_new; beam_new=buffer[counter_buffer]; counter_buffer++; if (counter_buffer>=BufferSizeMax) {counter_buffer=0;} delta--; } } //---------------------------------- // TIM2->ARR = TIM2_ADC_Period[Band]; // TIM2->CNT = 0; amount=0; SendCMD(ILI9341_MAC); SendDAT(Orient_Land); Umax=0; Umin=255; Draw_Uin_Time_Counter=Draw_Uin_Time; for (uint16_t j = 1; j < 319; j++) { DrawColumn(beam_new*216/256, beam_old*216/256, j); Umidl=127; if((((beam_oldUmidl)) | ((beam_old>Umidl)&(beam_newDR)>>4; if (temp>Umax) {Umax=temp;} if (temp=BufferSizeMax) {counter_buffer=0;} } } // Freez if (KeyStatus>0) {HandlingStatus();} // Draw Batty, Uin, Frequence ======================================================== // if (Draw_Bat_Time_Counter==0) { DrawBat(Vbat); Draw_Bat_Time_Counter=Draw_Bat_Time;} // if (Draw_F_Out_Time_Counter) { DrawString(Frequence_OUT_String[Frequence_OUT], 172, 3, GREEN, BLUE); } // else { if (Draw_Freq_Time_Counter==0) { DrawFreq(); } } // if (Draw_Uin_Time_Counter==0) { DrawUin(Uin); } } // 10ms =< Band >= 0.1S // Band >= 0.2S ========================================= //======================================================== if (Band >= 15) { if (KeyStatus>0) {HandlingStatus();} if (!Freez) { position++; // position begin draw if(position>318) { position = 1; Umax=0; Umin=255; Draw_Uin_Time_Counter=Draw_Uin_Time; } while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC)) {} ADC_ClearFlag(ADC1, ADC_FLAG_EOC); uint8_t temp=(ADC1->DR)>>4; if (temp>Umax) {Umax=temp;} if (tempDR)>>7; DrawBat(Vbat); Draw_Bat_Time_Counter=Draw_Bat_Time; // ADC_SoftwareStartConvCmd(ADC2, ENABLE); } //---------------------------------------- if (!(GPIOB->IDR & Key1)) { // IF SHIFT display FrequenceOUT DrawString(Frequence_OUT_String[Frequence_OUT], 140, 3, GREEN, BLUE); } else { if (Draw_Freq_Time_Counter==0 && !Freez) { Frequence =0; if (amount>1) { for (uint8_t f = 0; f < amount-1; f++) { Frequence=Frequence+zero[f+1]-zero[f]; } Frequence = 1000*Freq_KF[Band]*(amount-1)/Frequence; } DrawFreq(Frequence); amount=0; Draw_Freq_Time_Counter=Draw_Freq_Time; } } } // END while(1) } // END main //============================================================================== //============================================================================== //============================================================================== void Delay(uint32_t delayTime) // ~ 1mks 72mHz { for (uint32_t i = 0; i < delayTime*9; i++); } // IRQ TIM3 ============================================================================= void TIM3_IRQHandler(void) { if (KeyAntiBug>0) {KeyAntiBug--;} if (Draw_F_Out_Time_Counter>0) {Draw_F_Out_Time_Counter--;} if (Draw_Uin_Time_Counter>0) {Draw_Uin_Time_Counter--;} if (Draw_Freq_Time_Counter>0) {Draw_Freq_Time_Counter--;} if (Draw_Bat_Time_Counter>0) {Draw_Bat_Time_Counter--;} TIM_ClearFlag(TIM3, TIM_FLAG_Update); } // IRQ Key ============================================================================= void EXTI9_5_IRQHandler(void) { //------------------------------------------- if (EXTI_GetITStatus(EXTI_Line6) != RESET) { if (!KeyAntiBug) { if (!(GPIOB->IDR & Key2)) { if (!Freez) { KeyStatus=2; } // Key2 else { KeyStatus=20; } // IF FREEZ if (!(GPIOB->IDR & Key1)) { KeyStatus=12; } // IF SHIFT + Key2 } KeyAntiBug=KeyAntiBug_Time; } EXTI_ClearITPendingBit(EXTI_Line6); } //------------------------------------------- if (EXTI_GetITStatus(EXTI_Line7) != RESET) { if (!KeyAntiBug) { if (!(GPIOB->IDR & Key3)) { if (!Freez) { KeyStatus=3; } // Key3 else { KeyStatus=30; } // IF FREEZ if (!(GPIOB->IDR & Key1)) { KeyStatus=13; } // IF SHIFT + Key3 } KeyAntiBug=KeyAntiBug_Time; } EXTI_ClearITPendingBit(EXTI_Line7); } //------------------------------------------- if (EXTI_GetITStatus(EXTI_Line8) != RESET) { if (!KeyAntiBug) { if (!(GPIOB->IDR & Key4)) { if (!Freez) { KeyStatus=4; } // Key4 else { KeyStatus=40; } // IF FREEZ if (!(GPIOB->IDR & Key1)) { KeyStatus=14; } // IF SHIFT + Key4 } KeyAntiBug=KeyAntiBug_Time; } EXTI_ClearITPendingBit(EXTI_Line8); } //------------------------------------------- if (EXTI_GetITStatus(EXTI_Line9) != RESET) { if (!KeyAntiBug) { if (!(GPIOB->IDR & Key5)) { if (!Freez) { KeyStatus=5; } // Key5 else { KeyStatus=50; } // IF FREEZ if (!(GPIOB->IDR & Key1)) { KeyStatus=15; } // IF SHIFT + Key5 } KeyAntiBug=KeyAntiBug_Time; } EXTI_ClearITPendingBit(EXTI_Line9); } } //------------------------------------------------------------------------------ // IF SHIFT IF FREEZ // Key1 SHIFT // Key2 Mode+ FREEZ // Key3 Sync+ BRIGHT // Key4 Band- Freq Out- Slide < // Key5 Band+ Freq Out+ Slide > void HandlingStatus(void) { //---------------------------------------- if (KeyStatus==2) { // Mode+ if (Band<=9) {Mode++;} // 0=OSC, 1=OSC+miniOSC, 2=FFT, 3=Voltmeter if (Mode>2) { Mode=0; } if (Band>10) { Mode=0; } if (Mode==0) { // OSC Frame(0, 24, 320, 216, LGRID, 0); BufferSize=BufferSizeMax; } if (Mode==1) { // OSC+miniOSC Frame(0, 24, 320, 184, LGRID, 0); Frame(0, 208, 320, 32, LGRID, 0); BufferSize=BufferSizeMax; } if (Mode==2) { // FFT Frame(140, 0, 100, 24, LGRID, BLUE); // Frequence Frame(240, 0, 80, 24, LGRID, BLUE); // Uin LCDclr(0, 25, 320, 240-25,BLACK); Frame(31, 34, 258, 184, LGRID, 0); DrawString(StringFFT[Band], 23, 224, YELLOW, 0); Point(30, 219, YELLOW); Point(30+64, 219, YELLOW); Point(30+128, 219, YELLOW); Point(30+192, 219, YELLOW); Point(30+256, 219, YELLOW); DrawString(" 0", 0, 34, 0x0409, 0); DrawString("10", 0, 76, 0x0409, 0); DrawString("20", 0, 118, 0x0409, 0); DrawString("30", 0, 160, 0x0409, 0); DrawString("40", 0, 202, 0x0409, 0); DrawString("0 ", 290, 34, 0x0409, 0); DrawString("10", 290, 76, 0x0409, 0); DrawString("20", 290, 118, 0x0409, 0); DrawString("30", 290, 160, 0x0409, 0); DrawString("40", 290, 202, 0x0409, 0); BufferSize=512;} } //---------------------------------------- if (KeyStatus==3) { // Sync+ Sync++; if (Sync>4) { Sync=0; } DrawSim24x20(107, 2, YELLOW, Sync+2); // Draw Sync } //---------------------------------------- if (KeyStatus==4) { // Band+ if (Band<19) { Band++; if (Band==10) {Mode=0; Frame(0, 24, 320, 216, LGRID, 0);} ChangeBand(Band, Mode); } } //---------------------------------------- if (KeyStatus==5) { // Band- if (Band>0) { Band--; ChangeBand(Band, Mode); } } //---------------------------------------- if (KeyStatus==12) { // Freez ON/OFF if (Freez==0) { if (KeyAntiBug) { Freez=1; DrawSim24x20(108, 2, GBLUE, 8); } } else { Freez=0; DrawSim24x20(107, 2, YELLOW, Sync+2); } } //---------------------------------------- if (KeyStatus==13) { Bright++; if (Bright>2) { Bright=0; } SetBright(Bright); } //---------------------------------------- if (KeyStatus==14) { // Frequence_OUT + if (Frequence_OUT<27) {Frequence_OUT++;} TIM1->ARR = Frequence_OUT_Period[Frequence_OUT]-1; TIM1->PSC = Frequence_OUT_Prescaler[Frequence_OUT]-1; TIM1->CNT = 0; // DrawString(" ", 148, 3, WHITE, BLUE); DrawString(Frequence_OUT_String[Frequence_OUT], 140, 3, GREEN, BLUE); Draw_F_Out_Time_Counter=Draw_F_Out_Time; } //---------------------------------------- if (KeyStatus==15) { // Frequence_OUT - if (Frequence_OUT>0) {Frequence_OUT--;} TIM1->ARR = Frequence_OUT_Period[Frequence_OUT]-1; TIM1->PSC = Frequence_OUT_Prescaler[Frequence_OUT]-1; TIM1->CNT = 0; // DrawString(" ", 148, 3, WHITE, BLUE); DrawString(Frequence_OUT_String[Frequence_OUT], 140, 3, GREEN, BLUE); Draw_F_Out_Time_Counter=Draw_F_Out_Time; } //---------------------------------------- if (KeyStatus==50) { // Send BMP to USART 115200 226KB ~20sec // DrawSim24x20(107, 2, YELLOW, Sync+2); SendBMP(); SCB->AIRCR = 0x05FA0004; // SOFT RESET } //---------------------------------------- KeyStatus=0; } void ReadADC(register uint32_t addressbuffer, uint8_t Band) { register uint16_t rez; register uint32_t endb = addressbuffer + BufferSizeMax*2; if (Band==0) { __asm { m0: LDRH rez,[#0x4001244C] STRH rez,[addressbuffer], #2 NOP CMP addressbuffer, endb LDRH rez,[#0x4001244C] STRH rez,[addressbuffer], #2 BCC m0 } } if (Band==1) { __asm { m1: LDRH rez,[#0x4001244C] STRH rez,[addressbuffer], #2 NOP NOP NOP NOP CMP addressbuffer, endb BCC m1 } } if (Band==2) { __asm { m2: LDRH rez,[#0x4001244C] STRH rez,[addressbuffer], #2 NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP CMP addressbuffer, endb BCC m2 } } }