你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

查看: 1941|回复: 1

【MCU实战经验】STM32F429I-DISO探索第一篇 --GPIO LCD显示状态

[复制链接]

6

主题

3

回帖

0

蝴蝶豆

初级会员

最后登录
2018-6-28
发表于 2014-4-4 13:45:03 | 显示全部楼层 |阅读模式
上一篇写了GPIO简单的流水灯测试,看着有点单调,习惯了串口调试,板子上没有串口 那就另想办法吧,看着LCD突然有了个想法,为什么不把调试信息输出到LCD上,以前在做2416 WINCE开发的时候就经常这样干非常直观,那说干就干。
STM32F429I-DISO SDK里已经把开发包做好,那就直接拿过来用吧。
[html] view plaincopy

       
  • #define MESSAGE1   "STM32F429I-Discoverry"   //提示信息     
  • #define MESSAGE1_1 "    GPIO TEST        "        
  • #define MESSAGE2   " LED3     LED4  "     
  • #define MESSAGE2_1 "      ^-^       "     
  • #define MESSAGE5   "   LED3 = %d"      //LED3状态  1亮 0灭     
  • #define MESSAGE6   "   LED4 = %d"      //LED4状态     
  • #define LINENUM            0x15        //行数     
  • #define FONTSIZE         Font12x12     //字体大小  


定义完了,那就该具体实现了,惯例先初始化 LCD初始化实现:
[html] view plaincopy

       
  • static void Display_Init(void)     
  • {     
  •   /* Initialize the LCD */     
  •   LCD_Init();     
  •   LCD_LayerInit();     
  •   /* Eable the LTDC */     
  •   LTDC_Cmd(ENABLE);     
  •        
  •   /* Set LCD Background Layer  */     
  •   LCD_SetLayer(LCD_BACKGROUND_LAYER);     
  •        
  •   /* Clear the Background Layer */      
  •   LCD_Clear(LCD_COLOR_WHITE);     
  •        
  •   /* Configure the transparency for background */     
  •   LCD_SetTransparency(0);     
  •        
  •   /* Set LCD Foreground Layer  */     
  •   LCD_SetLayer(LCD_FOREGROUND_LAYER);     
  •      
  •   /* Configure the transparency for foreground */     
  •   LCD_SetTransparency(200);     
  •        
  •   /* Clear the Foreground Layer */      
  •   LCD_Clear(LCD_COLOR_WHITE);     
  •        
  •   /* Set the LCD Back Color and Text Color*/     
  •   LCD_SetBackColor(LCD_COLOR_BLUE);     
  •   LCD_SetTextColor(LCD_COLOR_WHITE);     
  •        
  •     /* Set the LCD Text size */     
  •   LCD_SetFont(&FONTSIZE);     
  •        
  •   /* Set the LCD Back Color and Text Color*/     
  •   LCD_SetBackColor(LCD_COLOR_BLUE);     
  •   LCD_SetTextColor(LCD_COLOR_WHITE);     
  •        
  •   LCD_DisplayStringLine(LINE(LINENUM), (uint8_t*)MESSAGE1);     
  •   LCD_DisplayStringLine(LINE(LINENUM + 1), (uint8_t*)MESSAGE1_1);     
  •   LCD_DisplayStringLine(LINE(0x17), (uint8_t*)"                               ");     
  •        
  •   /* Set the LCD Text size */     
  •   LCD_SetFont(&Font16x24);     
  •        
  •   LCD_DisplayStringLine(LCD_LINE_0, (uint8_t*)MESSAGE2);     
  •   LCD_DisplayStringLine(LCD_LINE_1, (uint8_t*)MESSAGE2_1);     
  •        
  •   /* Set the LCD Back Color and Text Color*/     
  •   LCD_SetBackColor(LCD_COLOR_WHITE);     
  •   LCD_SetTextColor(LCD_COLOR_BLUE);      
  • }  


初始化完成了,那就改实现显示函数了
[html] view plaincopy

       
  • static void Display(void)     
  • {     
  •   uint8_t  led3 = 0, led4 = 0;     
  •   uint8_t aTextBuffer[50];     
  •        
  •   led3 = GPIO_ReadOutputDataBit(LED3_GPIO_PORT,LED3_PIN);     //读取LED3对应引脚值     
  •      
  •   sprintf((char*)aTextBuffer, MESSAGE5, led3);     
  •   LCD_DisplayStringLine(LCD_LINE_4, (uint8_t*)aTextBuffer);    //把LED3状态更新到屏幕上     
  •          
  •   led4 = GPIO_ReadOutputDataBit(LED3_GPIO_PORT,LED4_PIN);      //读取LED4对应引脚值         
  •   sprintf((char*)aTextBuffer, MESSAGE6, led4);       
  •    LCD_DisplayStringLine(LCD_LINE_6, (uint8_t*)aTextBuffer);    //把LED4状态更新到屏幕上     
  • }  


这就是显示函数,读取LED对应的值,组成字符串,最后更新到LCD,LCD显示。
接下来就改主函数了:
[html] view plaincopy

       
  • int main(void)     
  • {     
  •   int i;     
  •          
  •     Display_Init();     
  •   LEDInit();     
  •     SysTickInit();     
  •   while (1)     
  •   {     
  •         Delay(500);     
  •         GPIO_SetBits(LED4_GPIO_PORT,LED4_PIN);     
  •         GPIO_ResetBits(LED3_GPIO_PORT,LED3_PIN);     
  •         Display();     
  •         Delay(500);     
  •         GPIO_SetBits(LED3_GPIO_PORT,LED3_PIN);     
  •         GPIO_ResetBits(LED4_GPIO_PORT,LED4_PIN);     
  •         Display();     
  •   }     
  • }  


惯例,主要函数部分实现完了,那就看最终的显示结果吧.
 
回复

使用道具 举报

2

主题

17

回帖

0

蝴蝶豆

初级会员

最后登录
2019-5-10
发表于 2014-4-6 01:21:21 | 显示全部楼层

RE:STM32F429I-DISO探索第一篇 --GPIO LCD显示状态

用stlink调试就知道了。从前我也是用串口的。遇到这板子没串口,就改用stlink了。
回复 支持 反对

使用道具 举报

关于意法半导体
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
招聘信息
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
关注我们
st-img 微信公众号
st-img 手机版