基于GD32的段码显示器设计

描述

说明一下:选用了IIC驱动方式,硬件连接SCL、SDAIN和SDAOUT引脚,

也就是说有应答检测是从SDAOUT引脚返回给MCU的。

硬件平台:微控制器选择GD32F103

PCA8538评估板

红外遥控器

并使用红外遥控器进行控制

锐鑫同创提供的示例十分丰富,注释清晰,移植太方便了。

IIC,RTC,DS18B20等驱动完全都不用改,项目完成很顺利。

核心代码部分分析:

主循环里 if(now!=timer.sec){}中每秒进行温度和时间更新。

if(Remote_Rdy){}检测遥控器发出的指令并执行。

PCA8538_TIME();参数较多,大家可以详细看一下,实现温度和时间同时显示,有点复杂

(相对于寄存器“冲突”情况)

while(1)

{

      if(POWER_flag == 1)

      {

            if(now!=timer.sec)

            {

                  now=timer.sec;

                  temp = DS18B20_Get_Temp();

                  printf("t1:%dn",temp);

                   temp_high = (temp/100);

                   temp_low = (temp/10-(temp/100*10));

                   PCA8538_TIME(temp_high,temp_low,timer.hour/10,timer.hour%10,timer.min/10,timer.min%10);

                   LED0 = !LED0;

            }

      }

      if(Remote_Rdy)

      {

            key=Remote_Process();

            switch(key)

            {

                  case BUTTON_POWER:

                        PCA8538_POWER();

                        POWER_flag=1;

                        ice_num=0;

                        break;

                  case BUTTON_1:

                        if(flag == 0)

                        {

                        PCA8538_AUTO(1);

                        flag = 1;

                         }

                          else

                         {

                          PCA8538_AUTO(0);

                          flag = 0;

                          }

                          break;

                  case BUTTON_2:

                          ice_num++;

                          if(ice_num>=4)

                          {

                                 ice_num=1;

                           }

                           PCA8538_NUM(ice_num);

                           break;

                  case BUTTON_3:

                           if(flag_light == 0)

                           {

                            PCA8538_LIGHT(1);

                             flag_light = 1;

                             }

                             else

                              {

                               PCA8538_LIGHT(0);

                               flag_light = 0;

                               }

                               break;

                  case BUTTON_4:

                               PCA8538_CLEAR();

                               POWER_flag=0;

                               break;

                   default:

                                break;

                  }

            }

      }


打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分