微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 嵌入式设计讨论 > ARM技术讨论 > 基于GD32F450的图标式多功能应用系统(续)

基于GD32F450的图标式多功能应用系统(续)

时间:10-02 整理:3721RD 点击:

设计中的一些关键函数及程序代码如下:

(1)温湿度检测程序

温湿度检测的程序代码为:

  1. i=0;
  2. POINT_COLOR=RED;
  3. BACK_COLOR=WHITE;       //BLACK
  4. DHT11_Init();
  5. while(SET == gpio_input_bit_get(GPIOA,GPIO_PIN_0)) // 确认
  6. {
  7.     DHT11_Read_Data(&temp,&humi);
  8. LCD_ShowCharh(100,100,'T',1);
  9. LCD_ShowCharh(100,90,'e',1);
  10. LCD_ShowCharh(100,80,'m',1);
  11. LCD_ShowCharh(100,70,'p',1);
  12. LCD_ShowCharh(100,60,':',1);
  13. LCD_ShowCharh(100,50,temp/10+'0',0);
  14. LCD_ShowCharh(100,40,temp%10+'0',0);
  15. LCD_ShowCharh(120,100,'H',1);
  16. LCD_ShowCharh(120,90,'u',1);
  17. LCD_ShowCharh(120,80,'m',1);
  18. LCD_ShowCharh(120,70,'i',1);
  19. LCD_ShowCharh(120,60,':',1);
  20. LCD_ShowCharh(120,50,humi/10+'0',0);
  21. LCD_ShowCharh(120,40,humi%10+'0',0);
  22. delay_1ms(200);
  23.   }

复制代码

(2)波形曲线绘制

曲线绘制的程序代码为:

   

  1. adc_config();
  2. adc_resolution_config(ADC1,ADC_RESOLUTION_12B);
  3. adc_oversample_mode_config(ADC1,ADC_OVERSAMPLING_ALL_CONVERT,ADC_OVERSAMPLING_SHIFT_NONE,ADC_OVERSAMPLING_SHIFT_NONE);
  4.     adc_oversample_mode_disable(ADC1);
  5. while(SET == gpio_input_bit_get(GPIOA,GPIO_PIN_0))
  6. {
  7. LCD_Clear(WHITE);
  8.     sp=95;
  9.     POINT_COLOR=RED;
  10.     LCD_DrawLine(10, 304, 230, 304);
  11.     LCD_DrawLine(125, 10, 125, 304);  
  12.     POINT_COLOR=BLUE;
  13.             for ( i = 0 ; i < 64; i++)
  14.     {
  15.   adc_enable(ADC1);
  16.               adc_software_trigger_enable(ADC1,ADC_REGULAR_CHANNEL);
  17.   while(RESET == adc_flag_get(ADC1,ADC_FLAG_EOC));
  18.   sj=ADC_RDATA(ADC1);
  19.   sj=sj/10;
  20.   LCD_DrawLine(320-sp, 300-4*(i-1), 320-sj, 300-4*(i));
  21.   sp=sj;
  22.   delay_1ms(20);
  23.             }
  24. }

复制代码


(3)图像显示

图标显示函数为:

  1. void show_tbh(unsigned int x,unsigned int y,unsigned int n) //200*200
  2. {  
  3. unsigned int i,j,k;
  4. unsigned int da;
  5. k=0;
  6. for(i=0;i<50;i++)
  7. {
  8. for(j=0;j<50;j++)
  9. {
  10. if(n==0) da=gImage_tb[k*2];
  11. if(n==1) da=gImage_pwm[k*2];
  12. if(n==2) da=gImage_rtc[k*2];
  13. if(n==3) da=gImage_adc[k*2];
  14. if(n==4) da=gImage_tft[k*2];
  15. if(n==5) da=gImage_sz[k*2];
  16. if(n==6) da=gImage_kz[k*2];
  17. if(n==7) da=gImage_dht[k*2];
  18.             da<<=8;
  19. if(n==0) da|=gImage_tb[k*2+1];
  20. if(n==1) da|=gImage_pwm[k*2+1];
  21. if(n==2) da|=gImage_rtc[k*2+1];
  22. if(n==3) da|=gImage_adc[k*2+1];
  23. if(n==4) da|=gImage_tft[k*2+1];
  24. if(n==5) da|=gImage_sz[k*2+1];
  25. if(n==6) da|=gImage_kz[k*2+1];
  26. if(n==7) da|=gImage_dht[k*2+1];
  27. POINT_COLOR=da;
  28. LCD_DrawPoint(x+i,y+j);
  29. k++;  
  30. }
  31. }
  32. }

复制代码

图像显示函数为:

  1. void show_pic(const unsigned char *p)
  2. {
  3. int i,j;
  4. unsigned char picH,picL;
  5. Address_set(0,0,LCD_W-1,LCD_H-1);
  6. for(i=0;i<240;i++)
  7. {
  8.   for(j=0;j<320;j++)
  9.   {
  10.   picH=*p++;
  11.   picL=*p++;
  12.   LCD_WR_DATA8(picH);
  13.   LCD_WR_DATA8(picL);
  14.   }
  15. }
  16. }

复制代码

(4)MP3播放程序

通过串口来控制MP3播放模块的指令是存放在数值中,其定义如下:

uint8_t aTxBuffer[] = " **** UART_TwoBoards_ComPolling **** ";

uint8_t cmd[]  = {0X7E, 0xFF, 0x06, 0X0D, 00, 00, 00, 0xFE, 0xEE, 0XEF}; //play

uint8_t cmd1[] = {0X7E, 0xFF, 0x06, 0X01, 00, 00, 00, 0xFE, 0xFA, 0XEF}; //next

uint8_t cmd2[] = {0X7E, 0xFF, 0x06, 0X02, 00, 00, 00, 0xFE, 0xF9, 0XEF}; //previous

uint8_t cmd3[] = {0X7E, 0xFF, 0x06, 0X03, 00, 00, 01, 0xFE, 0xF7, 0XEF}; //*play index

uint8_t cmd4[] = {0X7E, 0xFF, 0x06, 0X0E, 00, 00, 00, 0xFE, 0xED, 0XEF}; //pause

uint8_t cmd5[] = {0X7E, 0xFF, 0x06, 0X16, 00, 00, 00, 0xFE, 0xE5, 0XEF}; //stop

uint8_t cmd6[] = {0X7E, 0xFF, 0x06, 0X06, 00, 00, 10, 0xFE, 0xE5, 0XEF}; //*set  Volume

串行通讯的初始化函数为:

  1. void usb_to_uart_init(void)
  2. {
  3.    // enable GPIO clock
  4.    rcu_periph_clock_enable(RCU_GPIOD);
  5.    // enable USART clock
  6.    rcu_periph_clock_enable(RCU_USART1);
  7.    // connect port to USARTx_Tx
  8.    gpio_af_set(GPIOD, GPIO_AF_7, GPIO_PIN_5);
  9.    // connect port to USARTx_Rx
  10.    gpio_af_set(GPIOD, GPIO_AF_7, GPIO_PIN_6);
  11.    // configure USART Tx as alternate function push-pull
  12.    gpio_mode_set(GPIOD, GPIO_MODE_AF, GPIO_PUPD_PULLUP,GPIO_PIN_5);
  13.    gpio_output_options_set(GPIOD,GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ,GPIO_PIN_5);
  14.    // configure USART Rx as alternate function push-pull
  15.    gpio_mode_set(GPIOD, GPIO_MODE_AF, GPIO_PUPD_PULLUP,GPIO_PIN_6);
  16.    gpio_output_options_set(GPIOD, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ,GPIO_PIN_6);
  17.    // USART configure
  18.    usart_deinit(USART1);
  19.    usart_baudrate_set(USART1, 9600U);  
  20.    usart_receive_config(USART1, USART_RECEIVE_ENABLE);
  21.    usart_transmit_config(USART1, USART_TRANSMIT_ENABLE);
  22.    usart_word_length_set(USART1, USART_WL_8BIT);
  23.    usart_stop_bit_set(USART1, USART_STB_1BIT);
  24.    usart_parity_config(USART1, USART_PM_NONE);
  25.    usart_enable(USART1);
  26. }

复制代码


发送播放指令的函数为:

  1. void playn(uint16_t index) //play index
  2. {
  3. int i;
  4. uint8_t checksum = 0;
  5. cmd3[5] = (uint8_t)(index >> 8);
  6. cmd3[6] = (uint8_t)(index);
  7. for (i=2; i<8; i++)
  8. {
  9. checksum += cmd3[i];
  10. }
  11. cmd3[8] = (uint8_t)~checksum;
  12. }

复制代码


发送音量指令的函数为:

  1. void setVolume(uint8_t index) //setVolume index
  2. {
  3. uint8_t checksum = 0;
  4. int i;
  5. cmd6[6] = (uint8_t)(index);
  6. for (i=2; i<8; i++)
  7. {
  8. checksum += cmd6[i];
  9. }
  10. cmd6[8] = (uint8_t)~checksum;
  11. }

复制代码


资料很详细

多谢支持! ! !

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top