stm32_12864
单片机源程序如下:
- #include <stdio.h>
- #include "adc.h"
- #include "tim.h"
- #include "Systick.h"
- #include "lcd1602.h"
- #include "LCD12864.h"
- //
- /* Private function prototypes -----------------------------------------------*/
- #define LED_GPIO GPIOB
- #define LED3 GPIO_Pin_8
- #define LED4 GPIO_Pin_9
- #define KEY_GPIO GPIOB
- #define KEY1 GPIO_Pin_5
- #define KEY2 GPIO_Pin_6
- #define KEY3 GPIO_Pin_7
- //
- //#define Ture 0x00;
- //#define False 0xFF;
- //#define No_Key_Press 0x00;
- //#define Key_Press 0xFF;
- char LCD12864_STR[] = "OUT 12V Time= ";
- u8 LCD12864_DAT[] = {0x11,0x22};
-
- ///*
- u8 Disp_Buf[] = {0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,\
- 0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a,0x5b,0x5c,0x5d,0x5e,0x5f,0x60,\
- 0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,0x70,\
- 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f};
- void Delay(__IO uint32_t nCount);
- u16 ua = 0;
- u16 ub = 0;
- u16 uc = 0;
- u16 i = 678;
- u16 uab,ubb,ucb,ib;
- u16 T2_prescaler = 7200-1;
- u16 T2_time = 100-1;
- u8 time_sec;
- char Time2_Flg = 0x00;
- u32 Time_Cont ;
- u8 Key_Code=0x00;
- u8 Fun_Code=0x00;
- char Run_Code = 0x00;
- u8 Set_Val = 0x00; //电压或电流输出值
- char Key_Press = 0xFF;
- char No_Key_Press = 0x00;
- char Ture = 0x00;
- char False = 0xFF;
- char RUN = 0x00;
- char NO_RUN = 0xFF;
- char Key_Release = 0x00;
- //char LED3_Flg = 0x00;
- //char LED4_Flg = 0x00;
- char Key_Flg = 0x00;
-
- /*
- u8 u1buffer[4]={0}; //存放u1值 用于显示的缓冲数组
- u8 u2buffer[4]={0}; //存放u2
- */
- //char u1buffer[4]={0}; //存放u1值 用于显示的缓冲数组
- //char u2buffer[4]={0}; //存放u2
- //static void SYS_init(void);
- static void user_init(void);
- void RCC_Config(void);
- void NVIC_Config(void);
- void GPIO_Config(void);
- void USART1_IRQHandler(void);
- void UART5_IRQHandler(void);
- void LCD12864_init(void);
- void Disp_Dat(u16 u1,u16 u2,u32 t);
- static u16 Calculat_U(int k,int nux);
- void Time2_config(u16 prescaler,u16 time);
- void Time2_IRQHandler(void);
- //按键状态处理函数
- void Key_Code00( void);
- void Key_Code01( void);
- void Key_Code02( void);
- void Key_Code03( void);
- void Key_Code04( void);
- void Key_Code05( void);
- void Key_Code06( void);
- void Key_Code07( void);
- //功能编码处理函数
- void Fun_Code00( void);
- void Fun_Code01( void);
- void Fun_Code02( void);
- void Fun_Code03( void);
- void Fun_Code04( void);
- void Fun_Code05( void);
- void Fun_Code06( void);
- void Fun_Code07( void);
- //************************************************************************************************
- //
- //
- //
- //************************************************************************************************
- int main( )
- {
- //
- u8 j;
- u8 Jmp_Code;
- Run_Code = RUN;
- // u8 LED_FLG=0;
-
- RCC_Config();
- delay_us(10);
- GPIO_Config();
- delay_us(10);
- // NVIC_Config();
- //UART1_Config(115200);
- //UART5_Config(115200);
- for(j=0;j<6;j++)
- {
- GPIO_SetBits(LED_GPIO, LED3);// LED3亮
- GPIO_ResetBits(LED_GPIO, LED4);// LED4灭?
- delay_ms(100);
- GPIO_ResetBits(LED_GPIO, LED3); //LED3灭
- GPIO_SetBits(LED_GPIO, LED4); //LED4灭
- delay_ms(100);
- }
- GPIO_ResetBits(LED_GPIO, LED3); //LED3灭
- GPIO_ResetBits(LED_GPIO, LED4); //LED4灭
-
- //gpio_config();
- delay_us(10);
- ADC_Config();
- DMA_Config();
- Tim2_Config(T2_prescaler,T2_time );
- //Tim2_Config(TWENTYMS);
- delay_us(10);
-
- LCD12864_Init();
- // LCD12864_ShowString(2,0,"ZIGBEE R 1C");
- // LCD12864_ShowString(3,0,"LCD12864");
- // user_init();
-
- while(1)
- {
- u16 nad;
- delay_ms(100);
- nad = read_adc(0); //得到对应通道的adc值
- ua = Calculat_U(5,nad);//求出对应的实际电压值
- ua=(ua+uab)/2;
- uab=ua;
- nad = read_adc(1);//u2的ad值
- ub = Calculat_U(1,nad);//u2的实际值
- ub=(ub+ubb)/2;
- ubb=ub;
- uc=(uc+2)&0x0FFFF;
- //Time_Cont = Time_Cont++;
- Disp_Dat(ua,ub,Time_Cont);
- LCD12864_Disp( );//显示u1和u2
- //如果有按键按下,依据按键组合编码转移到不同处理分支进行处理
- // if (Run_Code == RUN)
- // {
- // Disp_Buf[0x0C] = ' ';
- // Disp_Buf[0x0D] = 'R';
- // Disp_Buf[0x0E] = 'U';
- // Disp_Buf[0x0F] = 'N';
- //按照设定的功能编码转移到不同处理分支。
- switch(Fun_Code)
- {
- case 0x00:
- Fun_Code00();
- break;
- case 0x01:
- Fun_Code01();
- break;
- case 0x02:
- Fun_Code02( );
- break;
- case 0x03:
- Fun_Code03( );
- break;
- case 0x04:
- Fun_Code04( );
- break;
- case 0x05:
- Fun_Code05( );
- break;
- case 0x06:
- Fun_Code06( );
- break;
- case 0x07:
- Fun_Code07( );
- break;
- }
- /* }
- else
- {
- Disp_Buf[0x0C] = ' ';
- Disp_Buf[0x0D] = 'S';
- Disp_Buf[0x0E] = 'E';
- Disp_Buf[0x0F] = 'T';
- }
- */
- //*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- if (Key_Flg == Key_Press)
- {
- Key_Flg = No_Key_Press; //进入按键处理程序,清除按键标志。
- Jmp_Code = Key_Code;
- switch (Jmp_Code)
- {
- case 0x00:
- Key_Code00();
- break;
- case 0x01:
- Key_Code01();
- break;
- case 0x02:
- Key_Code02( );
- break;
- case 0x03:
- Key_Code03( );
- break;
- case 0x04:
- Key_Code04( );
- break;
- case 0x05:
- Key_Code05( );
- break;
- case 0x06:
- Key_Code06( );
- break;
- case 0x07:
- Key_Code07( );
- Key_Release = False;
- break;
- }
- }
- //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
- //信号灯LED3闪烁。表明主函数运行
- if (GPIO_ReadInputDataBit(LED_GPIO,LED3) == Bit_SET)
- {
- GPIO_ResetBits(LED_GPIO, LED3);// LED3亮
- // LED3_Flg = 0x55;
- }
- else
- {
- GPIO_SetBits(LED_GPIO, LED3); //LED3灭
- // LED3_Flg = 0x00;
- }
- // Disp_Buf[0x0A]=' ';
- // Disp_Buf[0x0B]='F';
- // Disp_Buf[0x0C]='_';
- Disp_Buf[0x0D]=' ';
- Disp_Buf[0x0E]=' ';
- Disp_Buf[0x0F]=' ';
- // Disp_Buf[0x0E]='F';
- // Disp_Buf[0x0F]=Fun_Code+0x30;
- delay_ms(50);
- }
- }
- //************************************************************************************************
- //函数功能:开启显示
- //************************************************************************************************
- static void user_init(){
- lcd_write_string(0,0,(u8*)"U1=");
- lcd_write_string(7,0,(u8*)"mV");
- lcd_write_string(0,1,(u8*)"U2=");
- lcd_write_string(4,1,(u8*)".");
- lcd_write_string(8,1,(u8*)"V");
-
- }
- //************************************************************************************************
- //函数功能:计算对应通道的电压值
- //入口参数:k 放大倍数 nux 对应ADC通道的AD值
- //返回值:对应通道的实际电压值
- //************************************************************************************************
- static u16 Calculat_U(int k,int nux)
- {
- u32 temp;
- u16 u;
- temp = ((825*nux)*1/k)+1;
- u = temp >>10;
- return u;
-
- }
- //************************************************************************************************
- //
- //
- //************************************************************************************************
- void Disp_Dat(u16 u1,u16 u2,u32 t)
- {
- u16 ux,uy;
- u32 tx;
- ux = u1;
- uy = u2;
- tx = t;
- Disp_Buf[0x20] = 'U';
- Disp_Buf[0x21] = 'a';
- Disp_Buf[0x22] = '=';
- Disp_Buf[0x23] = (ux/1000)+0x30;
- Disp_Buf[0x24] = (ux%1000/100)+0x30;
- Disp_Buf[0x25] = (ux%100/10)+0x30;
- Disp_Buf[0x26] = (ux%10)+0x30;
- Disp_Buf[0x27] = ' ';
- Disp_Buf[0x28] = 'm';
- Disp_Buf[0x29] = 'V';
- Disp_Buf[0x2A] = ' ';
- Disp_Buf[0x2B] = ' ';
- Disp_Buf[0x2C] = ' ';
- Disp_Buf[0x2D] = ' ';
- Disp_Buf[0x2E] = ' ';
- Disp_Buf[0x2F] = ' ';
- /*
- Disp_Buf[0x2B]='K';
- Disp_Buf[0x2C]='=';
- if (Key_Release == Ture)
- {
- Disp_Buf[0x2D]='Y';
- Disp_Buf[0x2E]='S';
- Disp_Buf[0x2F]='F';
- }
- else
- {
- Disp_Buf[0x2D]='W';
- Disp_Buf[0x2E]='S';
- Disp_Buf[0x2F]='F';
- }
- */
-
- Disp_Buf[0x10] = 'U';
- Disp_Buf[0x11] = 'b';
- Disp_Buf[0x12] = '=';
- Disp_Buf[0x13] = (uy/1000)+0x30;
- Disp_Buf[0x14] = '.';
- Disp_Buf[0x15] = (uy%1000/100)+0x30;
- Disp_Buf[0x16] = (uy%100/10)+0x30;
- Disp_Buf[0x17] = (uy%10)+0x30;
- Disp_Buf[0x18] = ' ';
- Disp_Buf[0x19] = 'V';
- Disp_Buf[0x1A] = ' ';
- Disp_Buf[0x1B] = ' ';
- Disp_Buf[0x1C] = ' ';
- Disp_Buf[0x1D] = ' ';
- Disp_Buf[0x1E] = ' ';
- Disp_Buf[0x1F] = ' ';
- /*
- Disp_Buf[0x1B]='K';
- Disp_Buf[0x1C]='=';
- if (Key_Flg == Key_Press)
- {
- Disp_Buf[0x1D]='P';
- Disp_Buf[0x1E]='R';
- Disp_Buf[0x1F]='S';
- }
- else
- {
- Disp_Buf[0x1D]='N';
- Disp_Buf[0x1E]='O';
- Disp_Buf[0x1F]='P';
- }
- */
-
- // Disp_Buf[0x30] = ':';
- //tx = tx /50;
- Disp_Buf[0x30] = 'T';
- Disp_Buf[0x31] = '=';
- Disp_Buf[0x32] = (tx/360000)+0x30; //时百位
- tx=tx%360000;
- Disp_Buf[0x33] = (tx/36000)+0x30; //时十位
- tx=tx%36000;
- Disp_Buf[0x34] = (tx/3600)+0x30; //时个位
- tx=tx%3600;
- Disp_Buf[0x35] = '-';
- Disp_Buf[0x36] = (tx/600)+0x30; //分十位
- tx=tx%600;
- Disp_Buf[0x37] = (tx/60)+0x30; //分个位
- tx=tx%60;
- Disp_Buf[0x38] = '-';
- Disp_Buf[0x39] = (tx/10)+0x30; //秒十位
- tx=tx%10;
- Disp_Buf[0x3A] = tx+0x30; //秒个位
- Disp_Buf[0x3B] = ' ';
- Disp_Buf[0x3C] = ' ';
- // Disp_Buf[0x3D] = ' ';
- // Disp_Buf[0x3E] = ' ';
- // Disp_Buf[0x3F] = ' ';
- Disp_Buf[0x3D]='F';
- Disp_Buf[0x3E]='=';
- Disp_Buf[0x3F]=Fun_Code+0x30;
- // Disp_Buf[0x3D]='K';
- // Disp_Buf[0x3E]='=';
- // Disp_Buf[0x3F]=Key_Code+0x30;
- }
- //*/
- //************************************************************************************************
- //
- //
- //************************************************************************************************
- void RCC_Config(void)
- {
- u8 HSE_StartUp;
- /* Setup the microcontroller system. Initialize the Embedded Flash Interface,
- initialize the PLL and update the SystemFrequency variable. */
- // SystemInit();
- RCC_DeInit();
- // RCC_HSICmd(ENABLE);
- // while(RCC_GetFlagStatus(RCC_FLAG_HSIRDY) == RESET){} //等待
- HSE_StartUp = ERROR;
- RCC_HSEConfig(RCC_HSE_ON);
- while (HSE_StartUp == ERROR)
- {
- HSE_StartUp=RCC_WaitForHSEStartUp();
- };
- RCC_HSICmd(DISABLE);
- if(1)
- {
- FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
- FLASH_SetLatency(FLASH_Latency_2);
- RCC_HCLKConfig(RCC_SYSCLK_Div1);
- RCC_PCLK2Config(RCC_HCLK_Div1);
- RCC_PCLK1Config(RCC_HCLK_Div2);
- RCC_ADCCLKConfig(RCC_PCLK2_Div2);
- RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9); //PLL输入时钟=HSE,*9输出
- RCC_PLLCmd(ENABLE);
- while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET){}
- RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
- while(RCC_GetSYSCLKSource() != 0x08){}
- }
-
- RCC_APB1PeriphClockCmd( RCC_APB1Periph_UART5,ENABLE);
- RCC_APB2PeriphClockCmd( RCC_APB2Periph_USART1|RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |
- RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD |RCC_APB2Periph_GPIOE,
- ENABLE);
- }
- //************************************************************************************************
- //
- //
- //************************************************************************************************
- void GPIO_Config(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- RCC_APB1PeriphClockCmd( RCC_APB1Periph_UART4|RCC_APB1Periph_UART5,ENABLE);
- RCC_APB2PeriphClockCmd( RCC_APB2Periph_USART1|RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |
- RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD |
- RCC_APB2Periph_GPIOE|RCC_APB2Periph_AFIO, ENABLE);
- GPIO_InitStructure.GPIO_Pin = LED3|LED4; //led3~led4
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
- GPIO_Init(LED_GPIO, &GPIO_InitStructure);
-
- GPIO_InitStructure.GPIO_Pin = KEY1|KEY2|KEY3; //KEY1,KEY2,KEY3
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(KEY_GPIO, &GPIO_InitStructure);
-
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7; //CTRL口,PA5,PA6,PA7
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
-
- }
- //************************************************************************************************
- //
- //************************************************************************************************
- void NVIC_Config(void)
- {
- // NVIC_InitTypeDef NVIC_InitStructure;
- // /* Configure the NVIC Preemption Priority Bits */
- // NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
- //
- // /* Enable the UART5 Interrupt */
- // NVIC_InitStructure.NVIC_IRQChannel = UART5_IRQn;
- // NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
- // NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- // NVIC_Init(&NVIC_InitStructure);
- }
- //************************************************************************************************
- //
- //
- //************************************************************************************************
- void TIM2_IRQHandler(void)
- {
- u8 Key_In;
- u8 Key_State = 0xFF;
- TIM_ClearITPendingBit(TIM2, TIM_IT_Update );
- if (time_sec < 100)
- {
- time_sec++;
- }
- else
- {
- time_sec =0;
- Time_Cont++;
- if (GPIO_ReadInputDataBit(LED_GPIO,LED4)== Bit_SET)
- {
- GPIO_ResetBits(LED_GPIO, LED4);// LED3亮
- }
- else
- {
- GPIO_SetBits(LED_GPIO, LED4); //LED3灭
- }
- }
- Key_In = GPIO_ReadInputDataBit(KEY_GPIO,KEY3);
- if (Key_In == Bit_RESET)
- {
- Key_State =Key_State & 0xFB; //D2=0,1111,1011,0xFB
- Disp_Buf[0x3F] = '0';
- }
- Key_In = GPIO_ReadInputDataBit(KEY_GPIO,KEY2);
- if (Key_In == Bit_RESET)
- {
- Key_State =Key_State & 0xFD; //D1=0, 1111,1101,0xFD
- Disp_Buf[0x1F] = '0';
- }
- Key_In = GPIO_ReadInputDataBit(KEY_GPIO,KEY1);
- if (Key_In == Bit_RESET)
- {
- Key_State =Key_State & 0xFE; //D0=0,1111,1110, 0xFE
- Disp_Buf[0x2F] = '0';
- }
- Key_State=Key_State & 0x07;
-
- if (Key_State == Key_Code )
- {
- if (Key_State == 0x07)
- {
- Key_Release = Ture; //无按键按下(按键释放)
- //维持原来的Key_Flg,等待主函数处理
-
- }
- else
- {
- if(Key_Release == Ture) //原来按键是释放的
- {
- Key_Code = Key_State;
- Key_Flg = Key_Press;
- Key_Release = False;
- }
- }
- }
- else
- {
- Key_Code = Key_State; //相邻两次扫描的键状态不一致,是抖动状态
- // 暂存当前键状态,等待下一次定时中断
- }
- // Disp_Buf[0x3C]='K';
- // Disp_Buf[0x3E]='=';
- // Disp_Buf[0x3F]=Key_Code+0x30;
-
- // */
- }
- //************************************************************************************************
- //
- //
- //************************************************************************************************
- void USART1_IRQHandler(void)
- {
- }
- //************************************************************************************************
- //串口5中断处理
- //************************************************************************************************
- void UART5_IRQHandler(void)
- {
- ;//
- }
-
-
- //*********************************************************************************************
- // 按键处理程序
- //*********************************************************************************************
- void Key_Code00(void) //000:三个按键全按下,第一行最右端显示E-K0
- {
- Disp_Buf[0x0C] = 'E';
- Disp_Buf[0x0D] = '-';
- Disp_Buf[0x0E] = 'K';
- Disp_Buf[0x0F] = '0';
- }
-
- //*********************************************************************************************
- // 按键处理程序
- //*********************************************************************************************
- void Key_Code01(void) //001:K1,K2按下,第一行最右端显示E-K1
- {
- Disp_Buf[0x0C] = 'E';
- Disp_Buf[0x0D] = '-';
- Disp_Buf[0x0E] = 'K';
- Disp_Buf[0x0F] = '1';
- }
- //*********************************************************************************************
- // 按键处理程序
- //*********************************************************************************************
- void Key_Code02(void) //010:K1,K3按下,在第一行最右端显示E-K2
- {
- Disp_Buf[0x0C] = 'E';
- Disp_Buf[0x0D] = '-';
- Disp_Buf[0x0E] = 'K';
- Disp_Buf[0x0F] = '2';
- }
- //*********************************************************************************************
- // 按键处理程序,模式按键,每按一次,模式在 电压→电流→电压脉冲→电流脉冲→电压之间转换
- // Fun_Code值在 0→1→2→3→4→5→6→7→0之间转换。
- //*********************************************************************************************
- void Key_Code03(void) //011:K1按下
- {
- Fun_Code = (Fun_Code +1)&0x07;
- Disp_Buf[0x0C] = 'F';
- Disp_Buf[0x0D] = 'C';
- Disp_Buf[0x0E] = '=';
- Disp_Buf[0x0F] = Fun_Code+0x30;
- }
- //*********************************************************************************************
- // 按键处理程序
- //*********************************************************************************************
- void Key_Code04(void) //100:K2,K3按下,在第一行最右端显示E-K4
- {
- Disp_Buf[0x0C] = 'E';
- Disp_Buf[0x0D] = '-';
- Disp_Buf[0x0E] = 'K';
- Disp_Buf[0x0F] = '4';
- }
- //*********************************************************************************************
- // 按键处理程序,设定值减小按键,每按一次,设定值Set_Val-1直到0
- //*********************************************************************************************
- void Key_Code05(void) //101:K2按下
- {
- if(Set_Val != 0x00)
- {
- Set_Val = (Set_Val -1);
- }
- Disp_Buf[0x0A] = 'S';
- Disp_Buf[0x0B] = 'E';
- Disp_Buf[0x0C] = 'T';
- Disp_Buf[0x0D] = '=';
- Disp_Buf[0x0E] = ' ';
- Disp_Buf[0x0F] = Set_Val+0x30;
- }
- //*********************************************************************************************
- // 按键处理程序,设定增大按键,每按一次,设定值Set_Val+1直到7(档)
- //*********************************************************************************************
- void Key_Code06(void) //110:K3按下
- {
- if(Set_Val < 0x07)
- {
- Set_Val = (Set_Val +1)&0x07;
- }
- Disp_Buf[0x0A] = 'S';
- Disp_Buf[0x0B] = 'E';
- Disp_Buf[0x0C] = 'T';
- Disp_Buf[0x0D] = '=';
- Disp_Buf[0x0E] = ' ';
- Disp_Buf[0x0F] = Set_Val+0x30;
- }
- //*********************************************************************************************
- // 按键处理程序,无按键按下,设置Key_on标识
- //*********************************************************************************************
- void Key_Code07(void) //111:无键按下
- {
- Key_Release = Ture;
- Disp_Buf[0x0E] = 'K';
- Disp_Buf[0x0F] = 'O';
- }
- //--------------------------------------------------------------------------------------------
- //********************************************************************************************
- //--------------------------------------------------------------------------------------------
- //功能函数0: 直流电压输出,在第一行左边显示 DC,U=xx.yV
- // 依据设定值Set_Val控制直流输出电压(PA7,PA6,PA5)三位控制DC-DC输出电压,
- //
- //********************************************************************************************
- //............................................................................................
- void Fun_Code00(void) //000:
- {
- u8 Voltage;
- Disp_Buf[0x00] = 'D';
- Disp_Buf[0x01] = 'C';
- Disp_Buf[0x02] = ':';
- Disp_Buf[0x03] = 'U';
- Disp_Buf[0x04] = 's';
- Disp_Buf[0x05] = '=';
- switch (Set_Val)
- {
- case 0x00:
- Voltage = 6;
- GPIO_ResetBits(GPIOA,GPIO_Pin_5);
- GPIO_ResetBits(GPIOA,GPIO_Pin_6);
- GPIO_ResetBits(GPIOA,GPIO_Pin_7);
- // DA_OUT(60}; //DA输出60。
- break;
- case 0x01:
- Voltage = 9;
- GPIO_ResetBits(GPIOA,GPIO_Pin_5);
- GPIO_ResetBits(GPIOA,GPIO_Pin_6);
- GPIO_SetBits(GPIOA,GPIO_Pin_7);
- // DA_OUT(90}; //DA输出60。
- break;
- case 0x02:
- Voltage = 12;
- GPIO_ResetBits(GPIOA,GPIO_Pin_5);
- GPIO_SetBits(GPIOA,GPIO_Pin_6);
- GPIO_ResetBits(GPIOA,GPIO_Pin_7);
- // DA_OUT(120}; //DA输出60。
- break;
- case 0x03:
- Voltage = 15;
- GPIO_ResetBits(GPIOA,GPIO_Pin_5);
- GPIO_SetBits(GPIOA,GPIO_Pin_6);
- GPIO_SetBits(GPIOA,GPIO_Pin_7);
- // DA_OUT(15}; //DA输出60。
- break;
- case 0x04:
- Voltage = 18;
- GPIO_SetBits(GPIOA,GPIO_Pin_5);
- GPIO_ResetBits(GPIOA,GPIO_Pin_6);
- GPIO_ResetBits(GPIOA,GPIO_Pin_7);
- // DA_OUT(180}; //DA输出60。
- break;
- case 0x05:
- Voltage = 20;
- GPIO_SetBits(GPIOA,GPIO_Pin_5);
- GPIO_ResetBits(GPIOA,GPIO_Pin_6);
- GPIO_SetBits(GPIOA,GPIO_Pin_7);
- // DA_OUT(200}; //DA输出60。
- break;
- case 0x06:
- Voltage = 22;
- GPIO_SetBits(GPIOA,GPIO_Pin_5);
- GPIO_SetBits(GPIOA,GPIO_Pin_6);
- GPIO_ResetBits(GPIOA,GPIO_Pin_7);
- // DA_OUT(220}; //DA输出60。
- break;
- case 0x07:
- Voltage = 25;
- GPIO_SetBits(GPIOA,GPIO_Pin_5);
- GPIO_SetBits(GPIOA,GPIO_Pin_6);
- GPIO_SetBits(GPIOA,GPIO_Pin_7);
- // DA_OUT(250}; //DA输出60。
- break;
- }
- Disp_Buf[0x06] = Set_Val+0x30;
- Disp_Buf[0x07] = ' ';
- Disp_Buf[0x08] = 'L';
- Disp_Buf[0x09] = 'e';
- Disp_Buf[0x0A] = 'v';
- Disp_Buf[0x0B] = 'e';
- Disp_Buf[0x0C] = 'l';
- Disp_Buf[0x0D] = ' ';
- Disp_Buf[0x0E] = ' ';
- Disp_Buf[0x0F] = ' ';
-
- /*
- Disp_Buf[0x06] = Voltage/10+0x30;
- Disp_Buf[0x07] = Voltage%10+0x30;
- Disp_Buf[0x08] = '.';
- Disp_Buf[0x09] = '0';
- */
- }
- //--------------------------------------------------------------------------------------------
- //********************************************************************************************
- //--------------------------------------------------------------------------------------------
- //功能函数0: 直流电压输出,在第一行左边显示 DC,U=xx.yV
- // 依据设定值Set_Val控制直流输出电压(PA7,PA6,PA5)三位控制DC-DC输出电压,
- //
- //********************************************************************************************
- //............................................................................................
- void Fun_Code01(void) //000:
- {
- u8 Voltage;
- Disp_Buf[0x00] = 'D';
- Disp_Buf[0x01] = 'C';
- Disp_Buf[0x02] = ':';
- Disp_Buf[0x03] = 'I';
- Disp_Buf[0x04] = 's';
- Disp_Buf[0x05] = '=';
- switch (Set_Val)
- {
- case 0x00:
- Voltage = 6;
- GPIO_ResetBits(GPIOA,GPIO_Pin_5);
- GPIO_ResetBits(GPIOA,GPIO_Pin_6);
- GPIO_ResetBits(GPIOA,GPIO_Pin_7);
- // DA_OUT(60}; //DA输出60。
- break;
- case 0x01:
- Voltage = 9;
- GPIO_ResetBits(GPIOA,GPIO_Pin_5);
- GPIO_ResetBits(GPIOA,GPIO_Pin_6);
- GPIO_SetBits(GPIOA,GPIO_Pin_7);
- // DA_OUT(90}; //DA输出90。
- break;
- case 0x02:
- Voltage = 12;
- GPIO_ResetBits(GPIOA,GPIO_Pin_5);
- GPIO_SetBits(GPIOA,GPIO_Pin_6);
- GPIO_ResetBits(GPIOA,GPIO_Pin_7);
- // DA_OUT(120}; //DA输出120。
- break;
- case 0x03:
- Voltage = 15;
- GPIO_ResetBits(GPIOA,GPIO_Pin_5);
- GPIO_SetBits(GPIOA,GPIO_Pin_6);
- GPIO_SetBits(GPIOA,GPIO_Pin_7);
- // DA_OUT(150}; //DA输出150。
- break;
- case 0x04:
- Voltage = 18;
- GPIO_SetBits(GPIOA,GPIO_Pin_5);
- GPIO_ResetBits(GPIOA,GPIO_Pin_6);
- GPIO_ResetBits(GPIOA,GPIO_Pin_7);
- // DA_OUT(180}; //DA输出180。
- break;
- case 0x05:
- Voltage = 20;
- GPIO_SetBits(GPIOA,GPIO_Pin_5);
- GPIO_ResetBits(GPIOA,GPIO_Pin_6);
- GPIO_SetBits(GPIOA,GPIO_Pin_7);
- // DA_OUT(200}; //DA输出200。
- break;
- case 0x06:
- Voltage = 22;
- GPIO_SetBits(GPIOA,GPIO_Pin_5);
- GPIO_SetBits(GPIOA,GPIO_Pin_6);
- GPIO_ResetBits(GPIOA,GPIO_Pin_7);
- // DA_OUT(220}; //DA输出220。
- break;
- case 0x07:
- Voltage = 25;
- GPIO_SetBits(GPIOA,GPIO_Pin_5);
- GPIO_SetBits(GPIOA,GPIO_Pin_6);
- GPIO_SetBits(GPIOA,GPIO_Pin_7);
- // DA_OUT(250}; //DA输出250。
- break;
- }
- Disp_Buf[0x06] = Set_Val+0x30;
- Disp_Buf[0x07] = ' ';
- Disp_Buf[0x08] = 'L';
- Disp_Buf[0x09] = 'e';
- Disp_Buf[0x0A] = 'v';
- Disp_Buf[0x0B] = 'e';
- Disp_Buf[0x0C] = 'l';
- Disp_Buf[0x0D] = ' ';
- Disp_Buf[0x0E] = ' ';
- Disp_Buf[0x0F] = ' ';
- /*
- Disp_Buf[0x06] = Voltage/10+0x30;
- Disp_Buf[0x07] = Voltage%10+0x30;
- Disp_Buf[0x08] = '.';
- Disp_Buf[0x09] = '0';
- */
- }
- //--------------------------------------------------------------------------------------------
- //********************************************************************************************
- //--------------------------------------------------------------------------------------------
- //功能函数0: 直流电压输出,在第一行左边显示 DC,U=xx.yV
- // 依据设定值Set_Val控制直流输出电压(PA7,PA6,PA5)三位控制DC-DC输出电压,
- //
- //********************************************************************************************
- //............................................................................................
- void Fun_Code02(void) //010:
- {
- u8 Voltage;
- Disp_Buf[0x00] = 'P';
- Disp_Buf[0x01] = 'V';
- Disp_Buf[0x02] = ':';
- Disp_Buf[0x03] = 'U';
- Disp_Buf[0x04] = 's';
- Disp_Buf[0x05] = '=';
- switch (Set_Val)
- {
- case 0x00:
- Voltage = 6;
- GPIO_ResetBits(GPIOA,GPIO_Pin_5);
- GPIO_ResetBits(GPIOA,GPIO_Pin_6);
- GPIO_ResetBits(GPIOA,GPIO_Pin_7);
- // DA_OUT(60}; //DA输出60。
- break;
- case 0x01:
- Voltage = 9;
- GPIO_ResetBits(GPIOA,GPIO_Pin_5);
- GPIO_ResetBits(GPIOA,GPIO_Pin_6);
- GPIO_SetBits(GPIOA,GPIO_Pin_7);
- // DA_OUT(90}; //DA输出90。
- break;
- case 0x02:
- Voltage = 12;
- GPIO_ResetBits(GPIOA,GPIO_Pin_5);
- GPIO_SetBits(GPIOA,GPIO_Pin_6);
- GPIO_ResetBits(GPIOA,GPIO_Pin_7);
- // DA_OUT(120}; //DA输出120。
- break;
- case 0x03:
- Voltage = 15;
- GPIO_ResetBits(GPIOA,GPIO_Pin_5);
- GPIO_SetBits(GPIOA,GPIO_Pin_6);
- GPIO_SetBits(GPIOA,GPIO_Pin_7);
- // DA_OUT(150}; //DA输出150。
- break;
- case 0x04:
- Voltage = 18;
- GPIO_SetBits(GPIOA,GPIO_Pin_5);
- GPIO_ResetBits(GPIOA,GPIO_Pin_6);
- GPIO_ResetBits(GPIOA,GPIO_Pin_7);
- // DA_OUT(180}; //DA输出180。
- break;
- case 0x05:
- Voltage = 20;
- GPIO_SetBits(GPIOA,GPIO_Pin_5);
- GPIO_ResetBits(GPIOA,GPIO_Pin_6);
- GPIO_SetBits(GPIOA,GPIO_Pin_7);
- // DA_OUT(200}; //DA输出200。
- break;
- case 0x06:
- Voltage = 22;
- GPIO_SetBits(GPIOA,GPIO_Pin_5);
- GPIO_SetBits(GPIOA,GPIO_Pin_6);
- GPIO_ResetBits(GPIOA,GPIO_Pin_7);
- // DA_OUT(220}; //DA输出220。
- break;
- case 0x07:
- Voltage = 25;
- GPIO_SetBits(GPIOA,GPIO_Pin_5);
- GPIO_SetBits(GPIOA,GPIO_Pin_6);
- GPIO_SetBits(GPIOA,GPIO_Pin_7);
- // DA_OUT(250}; //DA输出250。
- break;
- }
- Disp_Buf[0x06] = Set_Val+0x30;
- Disp_Buf[0x07] = ' ';
- Disp_Buf[0x08] = 'L';
- Disp_Buf[0x09] = 'e';
- Disp_Buf[0x0A] = 'v';
- Disp_Buf[0x0B] = 'e';
- Disp_Buf[0x0C] = 'l';
- Disp_Buf[0x0D] = ' ';
- Disp_Buf[0x0E] = ' ';
- Disp_Buf[0x0F] = ' ';
- /*
- Disp_Buf[0x06] = Voltage/10+0x30;
- Disp_Buf[0x07] = Voltage%10+0x30;
- Disp_Buf[0x08] = '.';
- Disp_Buf[0x09] = '0';
- */
- }
- //--------------------------------------------------------------------------------------------
- //********************************************************************************************
- //--------------------------------------------------------------------------------------------
- //功能函数0: 直流电压输出,在第一行左边显示 DC,U=xx.yV
- // 依据设定值Set_Val控制直流输出电压(PA7,PA6,PA5)三位控制DC-DC输出电压,
- //
- //********************************************************************************************
- //............................................................................................
- void Fun_Code03(void) //011:
- {
- u8 Voltage;
- Disp_Buf[0x00] = 'P';
- Disp_Buf[0x01] = 'C';
- Disp_Buf[0x02] = ':';
- Disp_Buf[0x03] = 'I';
- Disp_Buf[0x04] = 's';
- Disp_Buf[0x05] = '=';
- switch (Set_Val)
- {
- case 0x00:
- Voltage = 6;
- GPIO_ResetBits(GPIOA,GPIO_Pin_5);
- GPIO_ResetBits(GPIOA,GPIO_Pin_6);
- GPIO_ResetBits(GPIOA,GPIO_Pin_7);
- // DA_OUT(60}; //DA输出60。
- break;
- case 0x01:
- Voltage = 9;
- GPIO_ResetBits(GPIOA,GPIO_Pin_5);
- GPIO_ResetBits(GPIOA,GPIO_Pin_6);
- GPIO_SetBits(GPIOA,GPIO_Pin_7);
- // DA_OUT(90}; //DA输出90。
- break;
- case 0x02:
- Voltage = 12;
- GPIO_ResetBits(GPIOA,GPIO_Pin_5);
- GPIO_SetBits(GPIOA,GPIO_Pin_6);
- GPIO_ResetBits(GPIOA,GPIO_Pin_7);
- // DA_OUT(120}; //DA输出120。
- break;
- case 0x03:
- Voltage = 15;
- GPIO_ResetBits(GPIOA,GPIO_Pin_5);
- GPIO_SetBits(GPIOA,GPIO_Pin_6);
- GPIO_SetBits(GPIOA,GPIO_Pin_7);
- // DA_OUT(150}; //DA输出150。
- break;
- case 0x04:
- Voltage = 18;
- GPIO_SetBits(GPIOA,GPIO_Pin_5);
- GPIO_ResetBits(GPIOA,GPIO_Pin_6);
- GPIO_ResetBits(GPIOA,GPIO_Pin_7);
- // DA_OUT(180}; //DA输出180。
- break;
- case 0x05:
- Voltage = 20;
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
STM32_12864(ok).rar
(390.64 KB, 下载次数: 207)
|