jyz0025341:
源代码//*****************************************************************************//////*****************************************************************************#include"inc/hw_ints.h"#include"inc/hw_memmap.h"#include"inc/hw_types.h"#include"inc/hw_adc.h"#include"driverlib/debug.h"#include"driverlib/gpio.h"#include"driverlib/interrupt.h"#include"driverlib/sysctl.h"#include"driverlib/uart.h"#include"driverlib/timer.h"#include"driverlib/pwm.h"#include"driverlib/adc.h"//#include"driverlib/watchdog.h"/*******************************************************************************LCD:OKIM5265GNDDATA:PD7GNDCLK:PD6VCCLAH:PD5*******************************************************************************/#defineSET_LCD_DATA GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_7,GPIO_PIN_7);#defineCLR_LCD_DATA GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_7,0);#defineSET_LCD_CLK GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_6,GPIO_PIN_6);#defineCLR_LCD_CLK GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_6,0);#defineSET_LCD_LAH GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_5,GPIO_PIN_5);#defineCLR_LCD_LAH GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_5,0);//*****************************************************************************//*****************************************************************************unsignedlongg_ulFlags=0;unsignedlongulADC0_Value[2];unsignedlongulData; /* 采样数据缓冲器 */staticunsignedchar flag_Charge; /* 采样次数 */ unsignedchar flag_ADC_finish=0; /* 采样完成标志 */unsignedint Charge_Val[3] ={0,0,0}; /* 存放采样数据 */unsignedlongulPeriod;//PWM周期//LCD相关unsignedcharDisplay_Buff[20];//constunsignedcharseg_code[10]={};typedefunion{ unsignedchardt; struct { unsignedchar bit0:1, bit1:1, bit2:1, bit3:1, bit4:1, bit5:1, bit6:1, bit7:1; };}T_;T_ T,c1,c2,c3,c4; //米形数码#definecc1.bit0#definedc1.bit2#defineec1.bit4#defineac2.bit5#definefc2.bit4#definegc2.bit3#definebc2.bit0//田形数码#defineaa c3.bit2#definebb c3.bit3#defineff c3.bit1#definedd c3.bit0#definecc c4.bit4#defineee c4.bit1#definegg c4.bit3 typedefunion{ unsignedcharucdata[2]; unsignedintuidata ;}uc2ul;unsignedintPWMA,PWMB;unsignedcharD[6];//*****************************************************************************//函数名称:voidrecode(unsignedchar*data,unsignedcharyd)//输入参数:unsignedchar*data,unsignedcharyd//输出参数:void//功能:数字0~9对应显示段码列表//*****************************************************************************voidrecode(unsignedchar*data,unsignedcharyd){ switch(yd) { case0:a=1;b=1;c=1;d=1;e=1;f=1;g=0;break; case1:a=0;b=1;c=1;d=0;e=0;f=0;g=0;break; case2:a=1;b=1;c=0;d=1;e=1;f=0;g=1;break; case3:a=1;b=1;c=1;d=1;e=0;f=0;g=1;break; case4:a=0;b=1;c=1;d=0;e=0;f=1;g=1;break; case5:a=1;b=0;c=1;d=1;e=0;f=1;g=1;break; case6:a=1;b=0;c=1;d=1;e=1;f=1;g=1;break; case7:a=1;b=1;c=1;d=0;e=0;f=0;g=0;break; case8:a=1;b=1;c=1;d=1;e=1;f=1;g=1;break; case9:a=1;b=1;c=1;d=1;e=0;f=1;g=1;break; } *data=c1.dt; *(data+10)=c2.dt;}//*****************************************************************************//函数名称:voidrecode1(unsignedchar*data,unsignedcharyd)//输入参数:unsignedchar*data,unsignedcharyd//输出参数:void//功能:数字0~9对应显示段码列表//*****************************************************************************voidrecode1(unsignedchar*data,unsignedcharyd){ switch(yd) { case0:aa=1;bb=1;cc=1;dd=1;ee=1;ff=1;gg=0;break; case1:aa=0;bb=1;cc=1;dd=0;ee=0;ff=0;gg=0;break; case2:aa=1;bb=1;cc=0;dd=1;ee=1;ff=0;gg=1;break; case3:aa=1;bb=1;cc=1;dd=1;ee=0;ff=0;gg=1;break; case4:aa=0;bb=1;cc=1;dd=0;ee=0;ff=1;gg=1;break; case5:aa=1;bb=0;cc=1;dd=1;ee=0;ff=1;gg=1;break; case6:aa=1;bb=0;cc=1;dd=1;ee=1;ff=1;gg=1;break; case7:aa=1;bb=1;cc=1;dd=0;ee=0;ff=0;gg=0;break; case8:aa=1;bb=1;cc=1;dd=1;ee=1;ff=1;gg=1;break; case9:aa=1;bb=1;cc=1;dd=1;ee=0;ff=1;gg=1;break; } *data=c3.dt; *(data+10)=c4.dt;}//*****************************************************************************//函数名称:voidnumbertochar(unsignedintvalue,unsignedcharsel)//输入参数:unsignedintvalue,unsignedcharsel//输出参数:void//*****************************************************************************voidnumbertochar(unsignedintvalue,unsignedcharsel){ unsignedchari; unsignedintq[4]; q[3]=value/1000;value=value%1000; q[2]=value/100;value=value%100; q[1]=value/10;value=value%10; q[0]=value; for(i=0;iTX为UART功能脚 GPIOPinTypeUART(GPIO_PORTA_BASE,GPIO_PIN_0|GPIO_PIN_1); //配置UART为38,400,8-N-1 UARTConfigSetExpClk(UART0_BASE,SysCtlClockGet(),38400, (UART_CONFIG_WLEN_8|UART_CONFIG_STOP_ONE| UART_CONFIG_PAR_NONE)); //使能UART0中断 IntEnable(INT_UART0); UARTIntEnable(UART0_BASE,UART_INT_RX|UART_INT_RT);#ifdefT0 //************************初始化T0****************************************** SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); //Configurethetwo32-bitperiodictimers. TimerConfigure(TIMER0_BASE,TIMER_CFG_32_BIT_PER); TimerLoadSet(TIMER0_BASE,TIMER_A,SysCtlClockGet()); //使能定时器中断 IntEnable(INT_TIMER0A); //定时器超时中断 TimerIntEnable(TIMER0_BASE,TIMER_TIMA_TIMEOUT); //使能定时器 TimerEnable(TIMER0_BASE,TIMER_A);#endif //************************初始化ADC***************************************** Init_ADC(); UARTSend((unsignedchar*)"1234567890",12); while(1) { ADCProcessorTrigger(ADC0_BASE,0); if(flag_ADC_finish==1) { flag_ADC_finish=0; UARTCharPutNonBlocking(UART0_BASE,0x01); UARTCharPutNonBlocking(UART0_BASE,0x02); data.uidata=Charge_Val[0]; UARTSend(&data.ucdata[0],2); data.uidata=Charge_Val[1]; UARTSend(&data.ucdata[0],2); data.uidata=Charge_Val[2]; UARTSend(&data.ucdata[0],2); } //段码LCD显示功能 Charge_Val[1]=(Charge_Val[1]*2.4544921875);//电压系数根据实际修改 numbertochar(Charge_Val[1],1); Charge_Val[0]=(Charge_Val[0]*0.01);//电压系数根据实际修改 numbertochar(Charge_Val[0],0); Display_LCD(); SysCtlDelay(SysCtlClockGet()/2); }}