您当前的位置:首 页 > 应用方案

基于GD32微控制器的段码显示器

时间:2013-09-03  来源:21ic  浏览次数:2527  字体:"大" "小"

说明一下:选用了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;

                  }

            }

      }