前言:简易示波器、1MHz以内的频率检测、数据形式的触发、电压值的标定
一、整体介绍
在本次设计中,采用的是TI公司的TivaTM4123GXL系列单片机。本次给大家带来的是简易示波器的一些设计方法和自己的一些见解,希望对大家的学习有所帮助。另外如有错误,还请多多指正。
二、代码的分段解读
1、头函数
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include "inc/tm4c123gh6pm.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_flash.h"
#include "inc/hw_ints.h"
#include "driverlib/sysctl.h"
#include "driverlib/interrupt.h"
#include "driverlib/gpio.h"
#include "driverlib/uart.h"
#include "driverlib/timer.h"
#include "utils/uartstdio.h"
#include "driverlib/systick.h"
#include "driverlib/pin_map.h"
#include "driverlib/adc.h"
#include "inc/hw_adc.h"
#include "assert.h"
#include "driverlib/pwm.h"
#include "driverlib/flash.h"
#include "driverlib/fpu.h"
有缺文件的可以去Ti官网找
2、宏定义及变量定义
#define delay_ms(n); SysCtlDelay(n*(SysCtlClockGet()/3000));
uint32_t LCD_X[2];
uint32_t LCD_Y[2];
uint32_t MCUModel;
uint32_t MCUModel1;
uint32_t UartPlayorStop;
uint32_t ADC0WriteorRead=1;
uint32_t f0Check=0;
int32_t ADC0SignGet[1]={0};
uint8_t UartDateRead;
uint8_t UartLCDDateReads[20];
uint32_t UartLCDDateReadNum=0;
uint32_t TriggerCheckPin=1;
uint32_t TriggerCheck=0;
uint32_t TriggerNum=1;
uint32_t Date[640]={0};
uint32_t DateNum=0;
uint32_t Vtemp=0;
uint32_t StopCheck=0;
float TimeGear[4]={1,2,3,4};
uint32_t TimeGearNum=0;
uint32_t TimeGearNum1;
float RangeGear[4]={0.25,0.5,1,2};
uint32_t RangeGearNum=2;
uint32_t RangeGearNum1;
uint32_t VpporVrmsCheck=0;
uint32_t Vmax=0;
uint32_t VmaxSum=0;
uint32_t Vmin=3300;
uint32_t VminSum=0;
uint32_t VCheckStand=200;
uint32_t VCheckStandNum=0;
uint32_t Vrect=0;
uint32_t VppCheckNum=0;
unsigned char delay = 200;
unsigned int Frequencecount = 0;
unsigned char state = 0;
unsigned int fre = 0;
unsigned int temp = 0;
unsigned int Frequence = 0;
unsigned int FCheck=0;
uint32_t VCheckNum=0;
uint32_t VCheckSum=20;
uint32_t VCheckAddSum=0;
float VCheckStand075=1;
float VCheckStand150=1;
float VCheckStand225=1;
float VCheckStand300=1;
uint32_t VCheckS075=0;
uint32_t VCheckS150=0;
uint32_t VCheckS225=0;
uint32_t VCheckS300=0;
变量定义就不说太多了
3、外设初始化
void SysCtlPeripheralEnableInt(void)
{
MCUModel=6;
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
IntPrioritySet(INT_UART1, 0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
GPIOPinConfigure(GPIO_PB0_U1RX);
GPIOPinConfigure(GPIO_PB1_U1TX);
GPIOPinTypeUART(GPIO_PORTB_BASE,GPIO_PIN_0|GPIO_PIN_1);
UARTClockSourceSet(UART1_BASE, UART_CLOCK_PIOSC);
UARTStdioConfig(1,115200, 16000000);
IntEnable(INT_UART1);
UARTIntEnable(UART1_BASE, UART_INT_RX | UART_INT_RT);
UARTIntRegister(UART1_BASE,UARTIntHandler);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
GPIODirModeSet(GPIO_PORTE_BASE, GPIO_PIN_4, GPIO_DIR_MODE_IN);
GPIOPadConfigSet(GPIO_PORTE_BASE, GPIO_PIN_4, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
LCD_Open_int();
delay_ms(1000);
MCUModel=5;
LCD_Check_int();
IntPrioritySet(INT_ADC0SS3, 2);
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_5);
ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_ALWAYS, 0);
ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH8 | ADC_CTL_IE | ADC_CTL_END);
ADCIntRegister(ADC0_BASE ,3, ADC0Sequence0Handler);
IntEnable(INT_ADC0SS3);
ADCSequenceEnable(ADC0_BASE, 3);
SysCtlPWMClockSet(SYSCTL_PWMDIV_1);
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
GPIOPinTypePWM(GPIO_PORTF_BASE,GPIO_PIN_2);
GPIOPinConfigure(GPIO_PF2_M1PWM6);
PWMGenConfigure(PWM1_BASE,PWM_GEN_3,PWM_GEN_MODE_UP_DOWN|PWM_GEN_MODE_NO_SYNC);
PWMGenPeriodSet(PWM1_BASE,PWM_GEN_3,10000);
PWMPulseWidthSet(PWM1_BASE,PWM_OUT_6,PWMGenPeriodGet(PWM1_BASE, PWM_GEN_3)*0.5);
PWMOutputState(PWM1_BASE,PWM_OUT_6_BIT,true);
PWMGenEnable(PWM1_BASE,PWM_GEN_3);
IntPrioritySet(INT_TIMER3A, 1);
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER3);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_2);
GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_2);
GPIOPinConfigure(GPIO_PB2_T3CCP0);
TimerConfigure(TIMER3_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_CAP_TIME_UP);
TimerControlEvent(TIMER3_BASE, TIMER_A, TIMER_EVENT_NEG_EDGE);
TimerIntRegister(TIMER3_BASE, TIMER_A, FrequentHandler);
IntMasterEnable();
TimerIntEnable(TIMER3_BASE, TIMER_CAPA_EVENT);
IntEnable(INT_TIMER3A);
}
这里的PWM生成是为了随手进行示波器的测试(就不用测试都需要示波器)
4、波形触发设计
if(MCUModel==4)
{
if(TriggerCheck!=1)
{
if( (Date[TriggerNum-1]<Date[TriggerNum])&&Date[TriggerNum]>=1861)
{
TriggerCheckPin=1;
TriggerCheck=1;
LCD_X[1]=53;
Vtemp=Date[TriggerNum]*(155/4095.0)*RangeGear[RangeGearNum];
LCD_Y[1]=227+75*(RangeGear[RangeGearNum]-1)-Vtemp;
MCUModel=3;
if(VpporVrmsCheck==0)
{
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("DS16(250,256,'Vrect:',4,0);\r\n");
}
else
{
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("DS16(250,256,'000000',8,0);\r\n");
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("DS16(250,256,'Vrms:',4,0);\r\n");
}
}
else
{
if(TriggerNum>600)
{
TriggerNum=1;
MCUModel=1;
if(TriggerCheckPin==1)
{
TriggerCheckPin=0;
ClearP(51,71,349,229);
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("DS16(90,140,'未找到触发点,正在等待触发···',4,0);\r\n");
ClearP(175, 257,245,280);
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("DS16(175,257,'----Hz',4,0);\r\n");
ClearP(98,257,145,280);
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("DS16(95,257,'----mV',4,0);\r\n");
ClearP(300,257,345,280);
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("DS16(300,257,'----mV',4,0);\r\n");
}
delay_ms(10);
ADCIntEnable(ADC0_BASE,3);
}
else TriggerNum++;
}
}
}
第五行判断里的<号为上升沿的意思,改为>号,即为下降沿。后面的数据1861为1500mV根据3300/4095转换出来的数据,更改数据即为改变触发电平。(我这里的代码翻译过来就是在1.5且处于上升沿时触发波形显示)
5、电压标定设计
if(MCUModel==5)
{
if(ADC0WriteorRead==0&&VCheckS075==1)
{
ADC0WriteorRead=1;
if(700<(ADC0SignGet[0]*3300/4095.0)&&(ADC0SignGet[0]*3300/4095.0)<800)
{
VCheckNum++;
VCheckAddSum=ADC0SignGet[0]+VCheckAddSum;
if(VCheckNum==VCheckSum)
{
VCheckStand075=18613.63636/(1.0*VCheckAddSum);
VCheckS075=0;
VCheckNum=0;
VCheckAddSum=0;
ADCIntDisable(ADC0_BASE, 3);
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("DS12(300,260,'标定完成',4,0);\r\n");
}
}
}
if(ADC0WriteorRead==0&&VCheckS150==1)
{
ADC0WriteorRead=1;
if(1450<(ADC0SignGet[0]*3300/4095.0)&&(ADC0SignGet[0]*3300/4095.0)<1550)
{
VCheckNum++;
VCheckAddSum=ADC0SignGet[0]+VCheckAddSum;
if(VCheckNum==VCheckSum)
{
VCheckStand150=37227.27273/(1.0*VCheckAddSum);
VCheckS150=0;
VCheckNum=0;
VCheckAddSum=0;
ADCIntDisable(ADC0_BASE, 3);
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("DS12(300,260,'标定完成',4,0);\r\n");
}
}
}
if(ADC0WriteorRead==0&&VCheckS225==1)
{
ADC0WriteorRead=1;
if(2200<(ADC0SignGet[0]*3300/4095.0)&&(ADC0SignGet[0]*3300/4095.0)<2300)
{
VCheckNum++;
VCheckAddSum=ADC0SignGet[0]+VCheckAddSum;
if(VCheckNum==VCheckSum)
{
VCheckStand225=55840.90909/(1.0*VCheckAddSum);
VCheckS225=0;
VCheckNum=0;
VCheckAddSum=0;
ADCIntDisable(ADC0_BASE, 3);
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("DS12(300,260,'标定完成',4,0);\r\n");
}
}
}
if(ADC0WriteorRead==0&&VCheckS300==1)
{
ADC0WriteorRead=1;
if(2950<(ADC0SignGet[0]*3300/4095.0)&&(ADC0SignGet[0]*3300/4095.0)<3050)
{
VCheckNum++;
VCheckAddSum=ADC0SignGet[0]+VCheckAddSum;
if(VCheckNum==VCheckSum)
{
VCheckStand300=74454.54545/(1.0*VCheckAddSum);
VCheckS300=0;
VCheckNum=0;
VCheckAddSum=0;
ADCIntDisable(ADC0_BASE, 3);
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("DS12(300,260,'标定完成',4,0);\r\n");
}
}
}
}
这里设计了四个电压标定值 750mV 1500mV 2500mV 3000mV,VCheckStand075、VCheckStand150、VCheckStand225、VCheckStand300这四个数即为计算出的修正系数,使用时直接乘就行。
6、频率测定(最高到达1MHz)
外设定义详见第三部分的外设初始化
void FrequentHandler()
{
if(Frequencecount<=delay)
Frequencecount++;
else
{
if(state == 0)
{
fre = TimerValueGet(TIMER3_BASE, TIMER_A);
state = 1;
}
else
{
temp = SysCtlClockGet() / ((unsigned int)TimerValueGet(TIMER3_BASE, TIMER_A) - fre);
state = 0;
if( temp > 0.5 )
{
MCUModel=2;
Frequence =temp;
ClearP(175, 257,245,280);
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("DS16(175,257,'%dHz',4,0);\r\n",Frequence);
}
Frequencecount = 0;
}
}
TimerIntClear(TIMER3_BASE,TIMER_CAPA_EVENT);
if(MCUModel==2)
{
TimerDisable(TIMER3_BASE, TIMER_A);
}
}
简单来说就是定时器测频率,另外因为去噪声的缘故,频率下限较高
7、采集数据处理
void ADC0Sequence0Handler(void)
{
ADC0WriteorRead=1;
ADCSequenceDataGet(ADC0_BASE, 3, ADC0SignGet);
ADC0WriteorRead=0;
if(MCUModel==1)
{
Date[DateNum]=ADC0SignGet[0];
DateNum++;
if(DateNum>=640)
{
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("PL(%d,71,%d,229,8);\r\n",52,52);
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("PL(%d,71,%d,229,8);\r\n",53,53);
MCUModel=4;
DateNum=0;
ADCIntDisable(ADC0_BASE, 3);
}
}
if(MCUModel==5)
{
if(VCheckS075==1&&700<(ADC0SignGet[0]*3300/4095.0)&&(ADC0SignGet[0]*3300/4095.0)<800)
{
VCheckNum++;
VCheckAddSum=ADC0SignGet[0]+VCheckAddSum;
if(VCheckNum==VCheckSum)
{
VCheckStand075=18613.63636/(1.0*VCheckAddSum);
VCheckS075=0;
VCheckNum=0;
VCheckAddSum=0;
ADCIntDisable(ADC0_BASE, 3);
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("DS12(300,260,'标定完成',4,0);\r\n");
}
}
if(VCheckS150==1&&1450<(ADC0SignGet[0]*3300/4095.0)&&(ADC0SignGet[0]*3300/4095.0)<1550)
{
VCheckNum++;
VCheckAddSum=ADC0SignGet[0]+VCheckAddSum;
if(VCheckNum==VCheckSum)
{
VCheckStand150=37227.27273/(1.0*VCheckAddSum);
VCheckS150=0;
VCheckNum=0;
VCheckAddSum=0;
ADCIntDisable(ADC0_BASE, 3);
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("DS12(300,260,'标定完成',4,0);\r\n");
}
}
if(VCheckS225==1&&2200<(ADC0SignGet[0]*3300/4095.0)&&(ADC0SignGet[0]*3300/4095.0)<2300)
{
VCheckNum++;
VCheckAddSum=ADC0SignGet[0]+VCheckAddSum;
if(VCheckNum==VCheckSum)
{
VCheckStand225=55840.90909/(1.0*VCheckAddSum);
VCheckS225=0;
VCheckNum=0;
VCheckAddSum=0;
ADCIntDisable(ADC0_BASE, 3);
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("DS12(300,260,'标定完成',4,0);\r\n");
}
}
if(VCheckS300==1&&2950<(ADC0SignGet[0]*3300/4095.0)&&(ADC0SignGet[0]*3300/4095.0)<3050)
{
VCheckNum++;
VCheckAddSum=ADC0SignGet[0]+VCheckAddSum;
if(VCheckNum==VCheckSum)
{
VCheckStand300=74454.54545/(1.0*VCheckAddSum);
VCheckS300=0;
VCheckNum=0;
VCheckAddSum=0;
ADCIntDisable(ADC0_BASE, 3);
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("DS12(300,260,'标定完成',4,0);\r\n");
}
}
}
ADCIntClear(ADC0_BASE, 3);
}
这里涉及到了数据处理,以及多个外设之间的数据传递与协调
8、界面设计(UART串口屏)
8.1、开机界面图形设计
void LCD_Open_int()
{
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("CLS(0);\r\n");
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("PIC(81,112,2);\r\n");
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("DS48(168,128,'Oscilloscope',5,0);\r\n");
}
这里我调用了我的logo,另外有关图片导入的问题,详见GPU使用方法,这里不再详述
8.2、初始界面设计
void LCD_Check_int()
{
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("CLS(0);\r\n");
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("BOXF(0,0,480,320,8);\r\n");
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("SBC(8);\r\n");
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("DS24(180,25,'示波器校准',15,0);\r\n");
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("BOX(40,60,440,300,13);\r\n");
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("BOX(50,70,350,230,5);\r\n");
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("BOX(50,240,350,290,4);\r\n");
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("BTN(1,355,70,430,100,2);\r\n");
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("BTN(2,355,105,430,135,2);\r\n");
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("BTN(3,355,155,430,185,2);\r\n");
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("BTN(4,355,190,430,220,2);\r\n");
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("BTN(5,355,225,430,255,2);\r\n");
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("BTN(6,355,260,430,290,2);\r\n");
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("DS16(360,75,'执行校验',15,0);\r\n");
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("DS16(360,110,'结束校验',15,0);\r\n");
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("DS16(360,160,'0.75V标定',15,0);\r\n");
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("DS16(360,195,'1.50V标定',15,0);\r\n");
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("DS16(360,230,'2.25V标定',15,0);\r\n");
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("DS16(360,265,'3.00V标定',15,0);\r\n");
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("DS12(60,260,'当前电压标定幅值:',4,0);\r\n");
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("DS12(220,260,'当前标定状态:',4,0);\r\n");
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("DS12(165,260,'-----',4,0);\r\n");
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("DS12(300,260,'-----',4,0);\r\n");
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("BS12(60,75,345,5,' 欢迎使用本示波器,本示波器采用TI出品的EK-TM4C123GXL作为主控。',5);\r\n");
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("BS12(60,110,345,5,' 波形最高频率可显示到20kHz,频率、峰峰值、以及平均值的测算最高可以满足1MHz。',5);\r\n");
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("BS12(60,145,345,5,' 内置数字触发,为1.5V上升沿触发,同时具备时轴展宽、缩减,幅轴展宽、缩减的功能。',5);\r\n");
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("BS12(60,180,345,5,' 示波器频率测量误差为1%%(10Hz~1MHz),峰峰值测量误差为2%%(1Hz~1MHz)',5);\r\n");
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("BS12(60,210,345,5,' -----开发者G 2021年6月4号',5);\r\n");
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("DS12(40,305,'具体详情请访问网址:https://blog.csdn.net/qq_15038387/article/details/119142364?spm=1001.2014.3001.5501',7,0);\r\n");
}
这里为示波器标定与介绍界面
8.3、示波界面设计
void LCD_int()
{
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("CLS(0);\r\n");
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("BOXF(0,0,480,320,8);\r\n");
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("SBC(8);\r\n");
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("DS24(180,25,'简易示波器',15,0);\r\n");
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("BOX(40,60,440,300,13);\r\n");
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("BOX(50,70,350,230,5);\r\n");
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("BOX(50,240,350,290,4);\r\n");
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("BTN(1,355,70,430,100,2);\r\n");
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("BTN(2,355,105,430,135,2);\r\n");
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("BTN(3,355,155,430,185,2);\r\n");
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("BTN(4,355,190,430,220,2);\r\n");
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("BTN(5,355,225,430,255,2);\r\n");
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("BTN(6,355,260,430,290,2);\r\n");
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("DS16(360,75,'暂停/运行',15,0);\r\n");
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("DS16(360,110,'电压标定',15,0);\r\n");
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("DS16(360,160,'时轴放大',15,0);\r\n");
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("DS16(360,195,'时轴缩减',15,0);\r\n");
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("DS16(360,230,'幅轴放大',15,0);\r\n");
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("DS16(360,265,'幅轴缩减',15,0);\r\n");
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("DS16(55,256,'Yp-p:',4,0);\r\n");
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("DS16(150,256,'f0:',4,0);\r\n");
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("DS16(250,256,'Vrect:',4,0);\r\n");
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("DS12(40,305,'我已经写在博客里:https://blog.csdn.net/qq_15038387',7,0);\r\n");
}
以上为示波界面设计
8.4、交互按键设计
void LCDstringcheck(void)
{
if(UartLCDDateReads[4]=='1')
{
if(MCUModel==2||MCUModel==0)
{
if(StopCheck==0)
{
MCUModel1=MCUModel;
MCUModel=0;
StopCheck=1;
}
else
{
MCUModel=MCUModel1;
StopCheck=0;
}
}
if(MCUModel==5)
{
if((VCheckS075+VCheckS150+VCheckS225+VCheckS300)>=1)
{
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("DS12(300,260,'正在标定',4,0);\r\n");
ADCIntEnable(ADC0_BASE, 3);
}
}
UartLCDDateReads[4]="X";
}
if(UartLCDDateReads[4]=='2')
{
if(MCUModel==5)
{
LCD_int();
MCUModel=1;
TriggerCheckPin=1;
TriggerCheck=0;
ADCIntEnable(ADC0_BASE, 3);
}
else
{
MCUModel=5;
ADCIntDisable(ADC0_BASE, 3);
LCD_Check_int();
}
UartLCDDateReads[4]="X";
}
if(UartLCDDateReads[4]=='3')
{
if(MCUModel==2)
{
if(TimeGearNum<3)
{
TimeGearNum++;
}
}
if(MCUModel==5)
{
VCheckS075=1;
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("DS12(165,260,'0.75V',4,0);\r\n");
}
UartLCDDateReads[4]="X";
}
if(UartLCDDateReads[4]=='4')
{
if(MCUModel==2)
{
if(TimeGearNum>0)
{
TimeGearNum--;
}
}
if(MCUModel==5)
{
VCheckS150=1;
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("DS12(165,260,'1.50V',4,0);\r\n");
}
UartLCDDateReads[4]="X";
}
if(UartLCDDateReads[4]=='5')
{
if(MCUModel==2)
{
if(RangeGearNum<3)
{
RangeGearNum++;
}
}
if(MCUModel==5)
{
VCheckS225=1;
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("DS12(165,260,'2.25V',4,0);\r\n");
}
UartLCDDateReads[4]="X";
}
if(UartLCDDateReads[4]=='6')
{
if(MCUModel==2)
{
if(RangeGearNum>0)
{
RangeGearNum--;
}
}
if(MCUModel==5)
{
VCheckS300=1;
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_4)!=0x0);
UARTprintf("DS12(165,260,'3.00V',4,0);\r\n");
}
UartLCDDateReads[4]="X";
}
}
以上是对LCD屏幕热键返回值的处理
9、主程序分享
点这里下载
三、常见问题
1、之前写过类似的测定频率的函数,但是就是不好使。
FPUEnable();
FPULazyStackingEnable();
注意将以上的浮点数和浮点运算使能。 (我个人感觉这里就是玄学,我本人也写过,但没开这个两个使能就是数据乱飞,开了就好使了)
2、接上后屏幕没反应
我使用的是480*320的屏幕,上面自带busy口,用以检测屏幕的串口数据处理是否完成。如果手边没有和我一样的。那就发送语句后加延时。 ————做一只萌萌的耗子萌翻世界
|