zoukankan      html  css  js  c++  java
  • FUTABA 13-ST-84GINK + DS3231 时钟

    收拾东西的时候又看到之前收拾的vfd相关的盒子,偶然又加的群,又买了两种屏试水。

    大的买屏还送vfd变压器,这玩意卖的少,一个5块,不买血亏!不知道什么时候开始早已没有DIY是省钱这种观念了。草。。。


    一.灯丝驱动

    我拿到变压器,按照之前的电路,简单用洞洞板焊接了一个,由于做的时候没有拍照,也不想拆开盒子了。原理图见之前的帖子。

    调试的时候出了两个问题:

    1.没加电解电容,电路储能不够,不能起震。后加一470uF电容。

    2.由于我没有120mH那么大的电感,我用的100uH的,C13按照470pF似乎没有起震。手里没有示波器看不到状况。总之,换成0.1uF后工作了,这个电路我也分析不出来频率理论式是多少了,但是这个电容和电感肯定是决定震荡频率的。其他值都是这个电路的。

    老王提供的原理图,尚未验证这组值,但是群友似乎采用了。准备做小那块板再验证一下。

    不过我最后控制的时候效仿该电路加了一个pmos控制灯丝电路通断。5V进入电路,MCU和改FUTABA VFD驱动共用该电源,再经pmos控制输入灯丝电路。

    FUTABA手册里说,VH即栅极阳极电压(这里的VEE)应该先于或者与驱动同时断电,这样设计没问题。

    和我之前手工绕的变压器不同的是,这个电路输出灯丝交流电压大概只有1.3Vac。难道是之前匝数太多啦?反正上一版由于三极管,变压器和PT6311发热比较严重,

    5V供电时电流达到了0.8A。基本同样的电路这个板只有0.2A。可能是自己绕制的变压器和这个差比较远吧。这个功耗大导致上一板开板计划搁浅。烂尾了。下次使用这个变压器再做吧。

    二.MCU驱动程序

    这次没用stm8,因为封装(tssop20)的原因,不方便在洞洞板上焊接了。再有就是群友提供的驱动亦是stc8的,我直接使用stc12稍稍改了引脚就驱动了这个屏。

    三.时钟总体设计

     方案:FUTABA VFD + DS3231 + stc15w404as + 3D打印外壳

    1.mcu,15的mcu直接把以前作废的航模接受机锯下核心板,供电测试可以烧录程序。再改引脚这个u也成功驱动了。下面也没有时钟的内部图了,一是因为洞洞板焊接,二是主要的,我洞洞板也是从以前废板上裁下来的,手头连洞洞板也没了。由于是方案验证,也不想制板甚至开板了。作给下版再考虑吧。

    2.DS3231,这玩意浪费时间不短!用的这块就是上次的vfd时钟上拆下来的。之前给它接的电池都挂了,0v电压。给那块板供电板子不工作,拔了电池才工作。其实这块芯片备用电池这里内部可能出了问题。导致我后来花很长世间调试掉电走时。

    3.总体思路,开定时器刷屏,读温度时间,通过串口交互完成授时等操作。

    四.坑

    1.FUTABA驱动,原作者可能是基于其他FUTABA的板改的,有些地方我没搞懂就又去找手册自己琢磨了好久,还是想利用那些图标。最后也没用上,但是大致又搞了一遍这个驱动显示原理。

    感觉和lcd1602这种屏很像。自带部分ascii字库,花圈的是CGRAM,用户自定义码。其它是CGROM,固化在驱动内的。

     

    Basically flowchart of commands:

     1.有很多种ram,拣几个用到的说。CGRAM(character generator RAM)上面说了是自定义字符,一共有8个,可以反复更新,再引用时可以通过先写到CGRAM立即更新到DCRAM显示,或者通过相关方法以编号的形式引用。

    DCRAM(data control RAM),每个显示符最终写入交由硬件执行显示的RAM,写给它硬件就去查表显示了。ADRAM(additional data RAM),额外的字符RAM,用于显示下图标记的icon。这个是写入立即生效,不用写入DCRAM。

    2.FUTABA 驱动

      1 #include "futaba_vfd.h"
      2 /*
      3 //typical:
      4     @1. VFD_Write_CGRAM(0x00,VFD_CGRAM[0]);//VFD_CGRAM[0]:assign character
      5             VFD_Write_DCRAM(0x01,0x00);                    //0x01:assign position 0x00:(dat?dat:VFD_CGRAM[0])
      6             in this way,first write to cgram and then write to dcram to display soon
      7             
      8     VFD_Write_DCRAM(0x01,'1');                    //0x01:pos '1':the char to display
      9             it's convenient,but it doesn't work appropriately when only write 1 char.so repeat it!
     10 */
     11 
     12 sbit VFD_SCK = P1^6;    //VFD SPI SCLK
     13 sbit VFD_DAT = P1^5;    //VFD SPI MOSI
     14 sbit VFD_CS  = P1^7;    //VFD chip select
     15 sbit VFD_RST = P5^4;    //VFD reset
     16 
     17 
     18 
     19 //G1,G2,G3,G4,G5,G6,G7,G8,G9,G10,G11,G12,G13,G14
     20 unsigned char xdata VFD_DCRAM[13] = {0x07,'1','3','-','S','T','-','8','4','G','I','N','K' };    //DCRAM
     21 unsigned char xdata VFD_CGRAM[8][5] = {                //CGRAM
     22     0x08,0x1c,0x3e,0x00,0x3e,    //left arrow
     23     0x3e,0x00,0x3e,0x1c,0x08,    //right arrow
     24     0x28,0x2c,0x2e,0x2c,0x28,    //up arrow
     25     0x0a,0x1a,0x2a,0x1a,0x0a,    //down arrow
     26     0xff,0x00,0x00,0x00,0x00,
     27     0x00,0x00,0x00,0x00,0x00,
     28     0x00,0x00,0x00,0x00,0x00,
     29     0x00,0x00,0x00,0x00,0x00
     30 };
     31 //NC,TIME_D1,SHIFT_D1,CLOCK_D1,HD_D1,USB_D1,LOCK_D1,DOLBY_D1,MUTE_D1,TU1_D1,TU2_D1,MP3_D1,LOOP_D1,    repeat addr:1_D0,:2_D0,:3_d0
     32 unsigned char xdata VFD_ADRAM[13] = {0};//{0x00,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02};            //ADRAM
     33 
     34 unsigned int  xdata VFD_BRT_DATA;        // display duty
     35 
     36     
     37 //---------------------------------------------------------------------------------------//
     38 void Delay_10uS()        //@12.000MHz
     39 {
     40     unsigned char i;
     41 
     42     i = 27;
     43     while (--i);
     44 }
     45 void Delay_5mS()        //@12.000MHz
     46 {
     47     unsigned char i, j;
     48 
     49     _nop_();
     50     _nop_();
     51     i = 59;
     52     j = 89;
     53     do
     54     {
     55         while (--j);
     56     } while (--i);
     57 }
     58 void Delay_1S()        //@12.000MHz
     59 {
     60     unsigned char i, j, k;
     61 
     62     _nop_();
     63     _nop_();
     64     i = 46;
     65     j = 153;
     66     k = 245;
     67     do
     68     {
     69         do
     70         {
     71             while (--k);
     72         } while (--j);
     73     } while (--i);
     74 }
     75 //---------------------------------------------------------------------------------------//
     76 //Wtite data to VFD's CIG
     77 void VFD_Write_Data(unsigned char DAT)
     78 {
     79     unsigned char i;
     80     for(i=0;i<8;i++)
     81     {
     82         VFD_SCK = 0;
     83         VFD_DAT = DAT&0x01;
     84         Delay_10uS();
     85         VFD_SCK = 1;
     86         Delay_10uS();
     87         DAT >>= 1;
     88     }
     89 }
     90 
     91 //Initialize the CIG
     92 void VFD_Init(void)
     93 {
     94     unsigned char i , j;
     95     
     96     VFD_RST = 0;    //reset the CIG
     97     Delay_5mS();    
     98     VFD_RST = 1;
     99     Delay_5mS();
    100     
    101     VFD_CS=0;
    102     VFD_Write_Data(0xe0);     //Set the display timing
    103     VFD_Write_Data(0x0d);    //
    104     VFD_CS=1;
    105 
    106     VFD_CS=0;
    107     VFD_Write_Data(0xe4);     //Set the dimming data
    108     VFD_Write_Data(150);
    109     VFD_CS=1;
    110 
    111     VFD_CS=0;
    112     VFD_Write_Data(0x40);     //write CGRAM
    113     for (i=0;i<8;i++)                
    114     {
    115         for(j=0;j<5;j++)
    116         {
    117             VFD_Write_Data(VFD_CGRAM[i][j]); //CGRAM
    118         }//????display at once ??
    119     }
    120     VFD_CS=1;
    121 
    122     VFD_CS=0;
    123     VFD_Write_Data(0x20);     //write DCRAM
    124     for(i=0;i<13;i++)                
    125     {
    126         VFD_Write_Data(VFD_DCRAM[i]); //DCRAM
    127     }
    128     VFD_CS=1;
    129 
    130     VFD_CS=0;
    131     VFD_Write_Data(0X60);    //write ADRAM
    132     for(i=0;i<13;i++)                
    133     {
    134         VFD_Write_Data(VFD_ADRAM[i]); //ADRAM
    135     }
    136     VFD_CS=1;
    137 
    138     VFD_CS=0; 
    139     VFD_Write_Data(0xe8);     //all display on
    140     VFD_CS=1;
    141 }
    142 void VFD_Clr(void)
    143 {
    144 //    VFD_CS=0; 
    145 //    VFD_Write_Data(0x60 | AD_COLON1);     //ADRAM
    146 //    VFD_Write_Data(0x03); //ADRAM
    147 //    VFD_Write_Data(0x03);
    148 //    VFD_Write_Data(0x60 | AD_COLON2);     //ADRAM
    149 //        VFD_Write_Data(0x03); //ADRAM
    150 //    VFD_Write_Data(0x03);
    151 //    VFD_Write_Data(0x60 | AD_COLON3);     //ADRAM
    152 //            VFD_Write_Data(0x03); //ADRAM
    153 //    VFD_Write_Data(0x03); //ADRAM
    154 //    VFD_CS=1;
    155     VFD_CS=0;
    156     VFD_Write_Data(0x20|0x0); //DCRAM
    157     VFD_Write_Data(4);
    158 //    VFD_Write_CGRAM(0x00,VFD_CGRAM[4]);
    159     VFD_CS=1;        
    160 }
    161 //set VFD display on or off , 0-off , 1-on
    162 void VFD_Disp_On_Off(bit on_off_flag)
    163 {
    164     VFD_CS=0;
    165     VFD_Write_Data(0xe8 | (((unsigned char)(~on_off_flag))<<1));
    166     VFD_CS=1;
    167 }
    168 
    169 //Set the display dimming data
    170 void VFD_Brt_Set(unsigned char BRT_DAT)
    171 {
    172     VFD_CS=0;
    173     VFD_Write_Data(0xe4);  //display dimming set command
    174     VFD_Write_Data(BRT_DAT);
    175     VFD_CS=1;    
    176 }
    177 
    178 //Load DCRAM buffer to VFD's DCRAM
    179 void VFD_DCRAM_Load(void)
    180 {
    181     unsigned char i;
    182     VFD_CS=0;
    183     VFD_Write_Data(0x20);     //write DCRAM
    184     for(i=0;i<13;i++)                
    185     {
    186         VFD_Write_Data(VFD_DCRAM[i]); //DCRAM
    187     }
    188     VFD_CS=1;    
    189 }
    190 //Write data to fixed DCRAM address
    191 void VFD_Write_DCRAM(unsigned char addr , unsigned char dat)
    192 {
    193     VFD_CS=0;
    194     VFD_Write_Data(0x20 | addr);     //write DCRAM
    195     VFD_Write_Data(dat); //DCRAM
    196     VFD_CS=1;    
    197 }
    198 //Load CGRAM buffer to VFD's CGRAM
    199 void VFD_CGRAM_Load(void)
    200 {
    201     unsigned char i , j;
    202     VFD_CS=0;
    203     VFD_Write_Data(0x40);     //write CGRAM
    204     for (i=0;i<8;i++)                
    205     {
    206         for(j=0;j<5;j++)
    207         {
    208             VFD_Write_Data(VFD_CGRAM[i][j]); //CGRAM
    209         }
    210     }
    211     VFD_CS=1;    
    212 }
    213 //Write data to fixed CGRAM address
    214 void VFD_Write_CGRAM(unsigned char addr , unsigned char *dat)
    215 {
    216     unsigned char i;
    217     VFD_CS=0;
    218     VFD_Write_Data(0x40 | addr);     //write CGRAM
    219     for(i=0;i<5;i++)
    220     {
    221         VFD_Write_Data(*dat++); //CGRAM
    222     }
    223     VFD_CS=1;    
    224 }
    225 //Load ADRAM buffer to VFD's ADRAM
    226 void VFD_ADRAM_Load(void)
    227 {
    228     unsigned char i;
    229     VFD_CS=0; 
    230     VFD_Write_Data(0x60);     //ADRAM
    231     for (i=0;i<13;i++)                
    232     {
    233         VFD_Write_Data(VFD_ADRAM[i]); //ADRAM
    234     }
    235     VFD_CS=1;
    236 }
    237 //Write data to fixed ADRAM address
    238 void VFD_Write_ADRAM(unsigned char ad_dat , bit on_off_flag)
    239 {
    240     unsigned char ad_dat_temp;
    241     VFD_CS=0; 
    242     VFD_Write_Data(0x60 | ad_dat);     //ADRAM
    243     if((ad_dat == AD_COLON1) || (ad_dat == AD_COLON2) || (ad_dat == AD_COLON3)) ad_dat_temp = 0x01;
    244     else ad_dat_temp = 0x02;
    245     on_off_flag ? VFD_Write_Data(ad_dat_temp) : VFD_Write_Data(0x00); //ADRAM
    246     VFD_CS=1;
    247 }
    View Code

     (1)显示某个字符,若字符为字库内的,可直接使用内码。

    如,

    VFD_Write_DCRAM(0x01,'1'); //0x01:pos '1':the char to display

    交由其自行转换为码字地址。

    或者直接给DCRAM写入字符地址,

    VFD_Write_DCRAM(0x01,0);//0x01:pos 0:the char's address

    即显示这个字符。

    (2)CGRAM显示

    其实上面那行代码显示的就是CGRAM,CGRAM和CGROM共用一页地址,只是低8个给RAM了。所以按地址方式赋值是可以显示用户字符和字库字符的。

    还有一种方式,

    VFD_Write_CGRAM(0x00,VFD_CGRAM[0]);//VFD_CGRAM[0]:assign character
    VFD_Write_DCRAM(0x01,0x00);    //0x01:assign position 0x00:(dat?dat:VFD_CGRAM[0])

    采用写入CGRAM并立即更新到DCRAM的方式,当DCRAM的字符参数为0时,写入的就是最近写入的CGRAM。经验证这两行代码的确可行,但是在手册上没有明确找到这个流程。

    行业既定规则?也有可能是我没看到。

    3.DS3231掉电走时

    前面也说到了,这里调试了很久都不能掉电走时。

    学到新的就是这个芯片其实RST脚根本不需要上电复位,这个脚设计来是接按键的。许多设计直接将这个脚悬空。

    VBAT这个脚我尝试过接锂电池,甚至直接接了5v一样不走时。

    调试到最后我差点就把这个芯片换成之前买的DS12C887,这个自带电池总归可以掉电走时了吧?

    但是就在快下手时突然有了新思路,我直接用电池给这个芯片供电不就行了?反正3231工作时电流是微安级的。

    找来以前从pos机拆下的小锂电,接一个充电模块,该模块电源输入加一路前面提到的pmos控制,尚未测试电池可以管多久。反正我现在是每天给它充电5min。

    这部分还自己写了程序,后来想其实可以用3231的闹钟功能。这种思路似乎可以用于不支持备用电池供电的芯片?但是大多芯片其实都有这个vbat脚的。

    4.main.c

      1 #include <STC15.h>
      2 #include <string.h>
      3 #include "futaba_vfd.h"
      4 #include "ds3231.h"
      5 //#include "myiicForDs3231.h"            //for init rst
      6 
      7 sbit vpwr=P1^0;
      8 sbit batcharge=P1^2;
      9 //uart
     10 unsigned char xdata RxBuffer[64]={0};
     11 unsigned char UART_RX_NUM=0;
     12 //display
     13 bit reflash_flag=0;
     14 bit dateOrTemp;
     15 unsigned char normalTime[6];//mth day wk hr min sec
     16 //charging
     17 u8 lastChargeHour,lastChargeDay,chargingMinute;
     18 bit chargingFlag;
     19 //---------------------------------------------------------------------------------------//
     20 void Uart_Init(void);        //115200bps@12.000MHz
     21 void Uart_Init(void);        //115200bps@12.000MHz
     22 void Uart_Send_String(unsigned char *str);
     23 void Tim0_Init(void);//2ms
     24 
     25 
     26 void DataDel(u8 *str,u8 len);
     27 void CMD_Compare(void);
     28 //---------------------------------------------------------------------------------------//
     29 
     30 //---------------------------------------------------------------------------------------//
     31 void main(void)
     32 {
     33     u8 i,lastMin;
     34     u8 cnt_min;
     35 
     36     Uart_Init();
     37     Tim0_Init();
     38     VFD_Init();
     39     //DS3231IIC_Init();//do not need rst !!!
     40     //ModifyTime(4,12,5,11,21,0);// 4-12 w5 tm11-21-00
     41     Uart_Send_String("VFD Init done");
     42     get_show(normalTime);
     43     for (i=0;i<6;i++){
     44         if (i==2){
     45             VFD_DCRAM[5]=normalTime[2]+'0';//week
     46             VFD_DCRAM[6]='-';
     47         }
     48         else{
     49             VFD_DCRAM[2*i+1]=normalTime[i]/10+'0';
     50             VFD_DCRAM[2*i+2]=normalTime[i]%10+'0';
     51         }
     52     }
     53     lastChargeHour=normalTime[3];//record first boot hour as last charge hour
     54     lastChargeDay=(normalTime[1]+1);//record first boot day-1 as last charge day
     55     lastMin=normalTime[4];                //record last min
     56     
     57     VFD_Write_ADRAM(AD_COLON2,1);
     58     VFD_Write_ADRAM(AD_COLON3,1);
     59     VFD_DCRAM_Load();
     60     vpwr=0;//switch on pmos
     61     batcharge=1;//turn off charging bat
     62     while(1)
     63     {
     64         if (reflash_flag){//display interval 
     65             reflash_flag=0;
     66             
     67             get_time(&normalTime[3]);//hr min sec                    
     68             if (lastMin!=normalTime[4]){//pass 1 min??
     69                 lastMin=normalTime[4];        //update "last"min
     70                 
     71                 get_date(normalTime);//read mth day wk
     72                 dateOrTemp=!dateOrTemp;//bit switch 
     73                 if (dateOrTemp){        //1 for date
     74                     
     75                     for (i=0;i<2;i++){
     76                         VFD_DCRAM[2*i+1]=normalTime[i]/10+'0';
     77                         VFD_DCRAM[2*i+2]=normalTime[i]%10+'0';
     78                     }            
     79                     VFD_DCRAM[5]=normalTime[2]+'0';//week
     80                     VFD_DCRAM[6]='-';                    
     81                 }
     82                 else{                                //0 for temp
     83                     //strncpy(&VFD_DCRAM[1],(const char*)"Temp",4);
     84                     get_show_Temperature(normalTime);
     85                     VFD_DCRAM[1]='T';
     86                     VFD_DCRAM[2]=normalTime[0]/10 + '0';
     87                     VFD_DCRAM[3]=normalTime[0]%10 + '0';
     88                     VFD_DCRAM[4]=0x19;//dot
     89                     VFD_DCRAM[5]='C';
     90                     
     91                 }
     92                 if ((lastChargeHour==normalTime[3])&&(lastChargeDay!=normalTime[1])){//update charging reg
     93                     lastChargeDay=normalTime[1];//update the day of last charging 
     94                     chargingFlag=1;
     95                 }                
     96                 if (chargingFlag){//charging???
     97                     batcharge=0;//turn on charging
     98                     if (++chargingMinute>=2){
     99                         chargingMinute=0;
    100                         chargingFlag=0;
    101                         batcharge=1;//turn off charging
    102                     }
    103                 }
    104             }
    105             //update hr min sec
    106             for (i=3;i<6;i++){
    107                 VFD_DCRAM[2*i+1]=normalTime[i]/10+'0';
    108                 VFD_DCRAM[2*i+2]=normalTime[i]%10+'0';
    109             }
    110             if ((normalTime[3]>=23)||(normalTime[3]<=5)){//auto dimming
    111                 VFD_Brt_Set(8);
    112             }else VFD_Brt_Set(12);
    113             
    114             VFD_DCRAM_Load();
    115         }
    116         //other
    117         if(UART_RX_NUM&0x80)//uart catch
    118         {
    119             CMD_Compare();
    120         }
    121     }
    122 }
    123 void Tim0_Isr()interrupt 1
    124 {
    125     static u8 cnt_500ms;
    126     if (++cnt_500ms>=250){
    127         cnt_500ms=0;
    128         reflash_flag=1;
    129         //Uart_Send_String(".5s");
    130     }
    131 }
    132 void Uart0_Isr()interrupt 4
    133 {
    134     unsigned char res=0;
    135     if (RI)
    136     {
    137         RI=0;
    138         res=SBUF;
    139         if ((UART_RX_NUM&0x80)==0)//?????
    140         {                        
    141             if (UART_RX_NUM&0x40)//?????????
    142             {
    143                 if (res!=0x0a)UART_RX_NUM=0;//?? rst
    144                 else UART_RX_NUM|=0x80;    //????
    145             }
    146             else
    147             {
    148                 if (res==0x0d)UART_RX_NUM|=0x40;//?????
    149                 else
    150                 {
    151                     RxBuffer[UART_RX_NUM&0x3f]=res;//????
    152                     UART_RX_NUM++;
    153                     if (UART_RX_NUM>63)UART_RX_NUM=0;
    154                 }
    155             }
    156         }    
    157     }
    158 }
    159 //---------------------------------------------------------------------------------------//
    160 void DataDel(u8 *str,u8 len)
    161 {
    162     u8 i;
    163     for (i=0;i<len-8;i++)
    164         str[i]=str[i+8];
    165 }
    166 void CMD_Compare(void)    //
    167 {
    168   u8 tmp[9]={0};
    169   u8 i,len;
    170   
    171   len=UART_RX_NUM&0x3f;//get the length
    172   Uart_Send_String("
    What you have in put is:
    ");
    173   Uart_Send_String(RxBuffer);
    174   Uart_Send_String("
    ");
    175   //get cmd
    176 //  for (i=0;i<8;i++)    
    177 //    tmp[i]=RxBuffer[i];
    178   strncpy(tmp,(const char*)RxBuffer,8);
    179 
    180 
    181   //cmd explaine
    182   if (strcmp("cmd_time",(const char*)tmp)==0)
    183   {
    184         Uart_Send_String("now modify time!
    ");
    185         DataDel(RxBuffer,len);//del cmd to get data
    186         //combine the data && transport from ascii to value
    187         //ModifyTime(4,12,5,11,21,0);// 4-12 w5 tm11-21-00
    188         ModifyTime((RxBuffer[0]-'0')*10 + RxBuffer[1]-'0',    //month
    189                                 (RxBuffer[2]-'0')*10 + RxBuffer[3]-'0',//day
    190                                 (RxBuffer[4]-'0'),                                            //week
    191                                 (RxBuffer[5]-'0')*10 + RxBuffer[6]-'0',//hr
    192                                 (RxBuffer[7]-'0')*10 + RxBuffer[8]-'0',//min
    193                                 (RxBuffer[9]-'0')*10 + RxBuffer[10]-'0');//sec
    194   }
    195     else if (strcmp("cmd_dimm",(const char*)tmp)==0)
    196   {
    197         Uart_Send_String("now modify brightness!
    ");
    198         DataDel(RxBuffer,len);//del cmd to get data    
    199         i=(RxBuffer[0]-'0')*100+(RxBuffer[1]-'0')*10+(RxBuffer[2]-'0');
    200         VFD_Brt_Set(i);
    201         Uart_Send_String("dimming (0-240):");Uart_Send_String(RxBuffer);
    202   }
    203     else if (strcmp("cmd_svfd",(const char*)tmp)==0)
    204   {
    205         Uart_Send_String("switch on or off vfd!
    ");
    206         DataDel(RxBuffer,len);//del cmd to get data            
    207         VFD_Disp_On_Off(RxBuffer[0]-'0');
    208   }
    209     else if(strcmp("cmd_spwr",(const char*)tmp)==0)
    210   {
    211         Uart_Send_String("switch on or off lamp pwr!
    ");
    212         DataDel(RxBuffer,len);//del cmd to get data            
    213         vpwr=RxBuffer[0]-'0';
    214   }
    215     else if(strcmp("cmd_sbat",(const char*)tmp)==0)
    216   {
    217         Uart_Send_String("start charging bat!
    ");        
    218         lastChargeHour=normalTime[3];//update charge hour
    219         lastChargeDay=normalTime[1];//update the day of last charging 
    220   }
    221     VFD_DCRAM_Load();
    222     //clr
    223     for (i=0;i<len;i++)
    224         RxBuffer[i]=0;
    225     UART_RX_NUM=0;//clr
    226 }
    227 
    228 
    229 
    230 void Tim0_Init(void){
    231     AUXR &= 0x7F;        //?????12T??
    232     TMOD &= 0xF0;        //???????
    233     TL0 = 0x30;        //??????
    234     TH0 = 0xF8;        //??????
    235     TR0 = 1;        //???0????    
    236     ET0=1;
    237     EA=1;
    238 }
    239 
    240 void Uart_Init(void)        //115200bps@12.000MHz
    241 {
    242     SCON = 0x50;        //8???,?????
    243     AUXR |= 0x01;        //??1?????2???????
    244     AUXR |= 0x04;        //???2???Fosc,?1T
    245     T2L = 0xE6;        //??????
    246     T2H = 0xFF;        //??????
    247     AUXR |= 0x10;        //?????2
    248     ES=1;
    249 }
    250 
    251 void Uart_Send_Data(unsigned char dat)
    252 {
    253     SBUF = dat;
    254     //while(!Uart_Snd_Flag);
    255     //Uart_Snd_Flag = 0;
    256     while(!TI);
    257     TI=0;
    258 }
    259 
    260 void Uart_Send_String(unsigned char *str)
    261 {
    262     while(*str)
    263     {
    264         Uart_Send_Data(*str++);
    265     }
    266 }
    267 //---------------------------------------------------------------------------------------//
    View Code

     主函数就是简单时钟读取和显示,电池充电控制逻辑。串口部分直接沿用以前代码,稍加修改就可以用了。

    更多功能留给后续修改实现。电池待机时间有待测试,充电应该改为闹钟控制。

    放图

    未完待续。。。。

     

  • 相关阅读:
    Object-C,NSArraySortTest,数组排序3种方式
    Object-C,NSArraySortTest,数组排序3种方式
    Object-C,数组NSArray
    Object-C,数组NSArray
    Zookeeper入门-Linux环境下异常ConnectionLossException解决
    Zookeeper入门-Linux环境下异常ConnectionLossException解决
    POJ 2533 Longest Ordered Subsequence
    HDU 1087 Super Jumping! Jumping! Jumping!
    ZJU 2676 Network Wars
    ZJU 2671 Cryptography
  • 原文地址:https://www.cnblogs.com/katachi/p/10713969.html
Copyright © 2011-2022 走看看