[MM32软件] EV Board (MM32L0136C7P)测评】+SLCD外设的深度研究

[复制链接]
 楼主| gaoyang9992006 发表于 2022-12-6 19:18 | 显示全部楼层 |阅读模式
<
其他片上外设我都用过了,就这个SLCD我没用过,如果让我设计电路,我一定让MCU与管脚的搭配有规律可寻,而本次活动的开发板规律不明显,那么如何对任意连接方式实现方便的驱动呢?思路参考我上一个贴子:

https://bbs.21ic.com/icview-3269640-1-1.html

上贴中我用Excel实现了该应用的快速求对应图形的8个显示寄存器值。本次项目我将通过C语言来实现快速求对应图形的显示寄存器值。
思路不再多说,参考上贴,本次仅公告C语言的循环实现等效的操作。该贴也可作为**后遗忘之时回头再参考的内容。希望大家也养成这个好习惯,将感悟和收获发帖分享,交流。
  1. #include<stdio.h>
  2. int main(void)
  3. {
  4.     int SEG[29]={3,7,6,5,4,58,26,27,30,-1,-1,35,40,0,1,8,9,10,11,15,16,17,-1,20,19,22,21,28,29};
  5.         int COM[4] ={35,40,0,1};
  6.         int Pxy[4][29];
  7.         int x=0,y=0,i=0;
  8.         unsigned int DR[8];
  9.         /*SEG段码对应线设置,该板子为4个COM加2个SEG表示一组显示内容*/
  10.         int segch1=4,segch2=5;

  11.         for(i=0;i<8;i++) DR[i]=0;

  12.         for(x=0;x<4;x++)
  13.                 for(y=0;y<29;y++)
  14.                         Pxy[x][y]=0;

  15. /*下面为显示矩阵,填写1的表示被选中*/
  16.     Pxy[0][segch1]=1; Pxy[0][segch2]=1;
  17.     Pxy[1][segch1]=1; Pxy[1][segch2]=1;
  18.     Pxy[2][segch1]=1; Pxy[2][segch2]=1;
  19.     Pxy[3][segch1]=1; Pxy[3][segch2]=1;


  20. for(x=0;x<4;x++)
  21. {
  22.         for(y=segch1;y<segch2+1;y++)
  23.         {
  24.             if(Pxy[x][y]==1)
  25.                 {
  26.                     {
  27.                         if(COM[x]>=32)     DR[(2*x)+1] |= (1<<(COM[x]-32));
  28.                         else if(COM[x]>=0) DR[2*x]  |=  (1<<COM[x]);
  29.                         else printf("COM[x] is error!");
  30.                     }

  31.                     {
  32.                         if(SEG[y]>=32)     DR[2*x+1] |= (1<<(SEG[y]-32));
  33.                         else if(SEG[y]>=0) DR[2*x]  |=  (1<<SEG[y]);
  34.                         else printf("SEG[y] is error!");

  35.                     }
  36.                 }


  37.             }

  38. }
  39. /*输出对应的显示寄存器值*/
  40. for(i=0;i<8;i++)
  41.             printf("DR[%d]=%d\n",i,DR[i]);

  42. return 0;
  43. }
30097638f229466a81.png
这与我Excel工具计算的结果是一致的。
36063638f22b0114ea.png
接下来利用单片机来显示一个计数的方法,由于我们可以全部点亮所有的段,因此可以实现静态点亮LCD数码管,这比循环点亮的LED段码管好用多了。
  1. /*
  2. * Copyright 2022 MindMotion Microelectronics Co., Ltd.
  3. * All rights reserved.
  4. *
  5. * SPDX-License-Identifier: BSD-3-Clause
  6. */

  7. #include "board_init.h"
  8. #include "lcd.h"
  9. /*
  10. * Macros.
  11. */
  12. #define APP_SLCD_SEG_BITS_BUFF_LEN 2u

  13. /*
  14. * Variables.
  15. */
  16. volatile uint32_t app_slcd_seg_bits[APP_SLCD_SEG_BITS_BUFF_LEN];
  17. const uint32_t app_slcd_com_pin_buff[BOARD_SLCD_COM_NUM] = {BOARD_SLCD_COM_PIN_BUFF};
  18. const uint32_t app_slcd_seg_pin_buff[BOARD_SLCD_SEG_NUM] = {BOARD_SLCD_SEG_PIN_BUFF};

  19. /*
  20. * Declerations.
  21. */
  22. void app_delay(uint32_t delay);
  23. void app_slcd_init(void);


  24. /*
  25. * Functions.
  26. */
  27. int main(void)
  28. {
  29.         int i=0,j=0,x1,x2,x3,x4;
  30.         int ch[4]={0};
  31.         BOARD_Init();

  32.     app_slcd_init();
  33.   
  34.         uint32_t BOARD_SLCD_COM[BOARD_SLCD_COM_NUM]={BOARD_SLCD_COM_PIN_BUFF};
  35.         uint32_t BOARD_SLCD_SEG[BOARD_SLCD_SEG_NUM]={BOARD_SLCD_SEG_PIN_BUFF};       

  36.         x1=0;
  37.         x2=1;
  38.         x3=2;
  39.         x4=3;

  40.     while (1)
  41.     {
  42.                         for(i=0;i<1999;i++)
  43.                         {
  44.                                 ch[0]=i/1000;
  45.                                 ch[1]=(i%1000)/100;
  46.                                 ch[2]=(i%100)/10;
  47.                                 ch[3]=i%10;
  48.                                
  49.                                 // COM0
  50.                                 BOARD_SLCD_PORT->DR0 =TAB[x1][ch[0]][0]|TAB[x2][ch[1]][0]|TAB[x3][ch[2]][0]|TAB[x4][ch[3]][0];
  51.                                 BOARD_SLCD_PORT->DR1 =TAB[x1][ch[0]][1]|TAB[x2][ch[1]][1]|TAB[x3][ch[2]][1]|TAB[x4][ch[3]][1];
  52.                                 // COM1                       
  53.                                 BOARD_SLCD_PORT->DR2 =TAB[x1][ch[0]][2]|TAB[x2][ch[1]][2]|TAB[x3][ch[2]][2]|TAB[x4][ch[3]][2];
  54.                                 BOARD_SLCD_PORT->DR3 =TAB[x1][ch[0]][3]|TAB[x2][ch[1]][3]|TAB[x3][ch[2]][3]|TAB[x4][ch[3]][3];               
  55.                                 // COM2                       
  56.                                 BOARD_SLCD_PORT->DR4 =TAB[x1][ch[0]][4]|TAB[x2][ch[1]][4]|TAB[x3][ch[2]][4]|TAB[x4][ch[3]][4];
  57.                                 BOARD_SLCD_PORT->DR5 =TAB[x1][ch[0]][5]|TAB[x2][ch[1]][5]|TAB[x3][ch[2]][5]|TAB[x4][ch[3]][5];
  58.                                 // COM3                       
  59.                                 BOARD_SLCD_PORT->DR6 =TAB[x1][ch[0]][6]|TAB[x2][ch[1]][6]|TAB[x3][ch[2]][6]|TAB[x4][ch[3]][6];               
  60.                                 BOARD_SLCD_PORT->DR7 =TAB[x1][ch[0]][7]|TAB[x2][ch[1]][7]|TAB[x3][ch[2]][7]|TAB[x4][ch[3]][7];       
  61.                                 app_delay(20u);
  62.                                
  63.                         }

  64.     }
  65. }

  66. void app_slcd_init(void)
  67. {
  68.     /* Setup the SLCD engine. */
  69.     SLCD_Init_Type slcd_init;
  70.     slcd_init.ClockDiv0 = BOARD_SLCD_DIV0;
  71.     slcd_init.ClockDiv1 = BOARD_SLCD_DIV1;
  72.     slcd_init.ChargePumpClockDiv = BOARD_SLCD_CHARGEPUMPDIV;
  73.     slcd_init.DutyCycle = BOARD_SLCD_DUTYCYCLE;
  74.     slcd_init.BiasMode = BOARD_SLCD_BIASMODE;
  75.     slcd_init.PowerSource = SLCD_PowerSource_Internal;
  76.     slcd_init.ChargePumpMode = SLCD_ChargePumpMode_Boost;
  77.     slcd_init.Brightness = BOARD_SLCD_BRIGHTNESS;
  78.     slcd_init.EnableLowPowerMode = false;
  79.     SLCD_Init(BOARD_SLCD_PORT, &slcd_init);

  80.     /* Set common pin. */
  81.     for (uint32_t com_x = 0; com_x < BOARD_SLCD_COM_NUM; com_x++)
  82.     {
  83.         SLCD_SetCOMxPinMux(BOARD_SLCD_PORT, com_x, app_slcd_com_pin_buff[com_x]);
  84.     }

  85.     /* Set segment pin. */
  86.     for (uint32_t seg_y = 0; seg_y < BOARD_SLCD_SEG_NUM; seg_y++)
  87.     {
  88.         SLCD_SetSegBitPinMux(BOARD_SLCD_PORT, app_slcd_seg_pin_buff[seg_y]);
  89.     }

  90.     /* Enable SLCD. */
  91.     SLCD_Enable(BOARD_SLCD_PORT, true);
  92. }


  93. void app_delay(uint32_t delay)
  94. {
  95.     for (uint32_t i = 0u; i < delay; i++)
  96.     {
  97.         for (uint32_t j = 0u; j < BOARD_DELAY_COUNT; j++)
  98.         {
  99.             __NOP();
  100.         }
  101.     }
  102. }

  103. /* EOF. */
需要多少个就按位或多少个即可。非常好用。
32081638f24db6889d.png

显示对比度修改

#define BOARD_SLCD_BRIGHTNESS    10u
官方提供的扫线测试程序默认为5u,我这里修改成10u显示效果非常好。
weifeng90 发表于 2022-12-6 19:21 来自手机 | 显示全部楼层
SLCD就是段码LCD
 楼主| gaoyang9992006 发表于 2022-12-6 19:25 | 显示全部楼层

是的,不过这个跟LED那种还不同,那个LED的通常是一个8段数码管共阴极共阳极连接,这个是阵列式连接。
xu@xupt 发表于 2022-12-10 13:23 | 显示全部楼层
感谢分享
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:如果你觉得我的分享或者答复还可以,请给我点赞,谢谢。

2046

主题

16351

帖子

222

粉丝
快速回复 在线客服 返回列表 返回顶部
个人签名:如果你觉得我的分享或者答复还可以,请给我点赞,谢谢。

2046

主题

16351

帖子

222

粉丝
快速回复 在线客服 返回列表 返回顶部