標題: stm32串口發(fā)送數(shù)據(jù),LCD同步顯示成功,包括了malloc [打印本頁]

作者: Hmily    時間: 2015-8-9 14:31
標題: stm32串口發(fā)送數(shù)據(jù),LCD同步顯示成功,包括了malloc
看資料,LCD的驅(qū)動是HX8347,有兩個不同方法實現(xiàn)

單片機源程序如下:
  1. ////////////////////////////////////////////////////////////////
  2. //   8月6號,功能:發(fā)送數(shù)據(jù)在顯示屏上顯示  LCD 控制器 HX8347 ///
  3. ////////////////////////////////////////////////////////////////
  4. #include "stm32f10x.h"
  5. #include "delay.h"
  6. #include "lcd_botton.h"
  7. #include "lcd.h"
  8. #include "led.h"
  9. #include "sys.h"
  10. #include "usart.h"          
  11. #include "stdio.h"
  12. #include "malloc.h"

  13. //#define FILE_MAX_SIZE 512


  14. int main(void)
  15. {
  16.         u8 rxlen;
  17.         u16 i;
  18.         u8 *write_buf=0;
  19.        
  20.         delay_config();       
  21.         led_GPIO_config();         // LED 端口初始化
  22.   LCD_Init();
  23.         uart_init(9600);
  24.         while (1)
  25.         {
  26.                 printf("\r\n您發(fā)送的消息為:\r\n\r\n");
  27.                 LCD_Str_6x12_O(150, 80,"start ", BLACK);
  28.          if(USART_RX_STA&0X8000)//串口收到數(shù)據(jù)了
  29.          {
  30.                  rxlen=USART_RX_STA&0X7FFF;        //得到數(shù)據(jù)長度
  31.                  write_buf=mymalloc(SRAMIN,512); //申請FILE_MAX_SIZE字節(jié)的空間
  32.                  for(i=0;i<rxlen;i++)
  33.                 {
  34.                         write_buf[i]=USART_RX_BUF[i];
  35.                 }
  36.                
  37.                
  38.                 for(i=rxlen;i<512;i++)
  39.                 {
  40.                         write_buf[i]=' ';
  41.                 }
  42.        
  43.                  LCD_Str_6x12_O(150, 120, write_buf, BLACK);
  44.                        
  45.                  delay_ms(1000);       
  46.                 myfree(SRAMIN,write_buf);        //釋放內(nèi)存               
  47.                 USART_RX_STA=0; //啟動下一次接收
  48.         }
  49. }         
  50. }

復制代碼

Keil代碼下載:
Keil代碼.7z (210.83 KB, 下載次數(shù): 53)

作者: 蒲公英lhl    時間: 2015-9-20 16:14
樓主好厲害啊




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1