⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 s_toolssample.c

📁 dragon ball vz328 上的一个例子程序。 用于做手持仪表用。
💻 C
📖 第 1 页 / 共 4 页
字号:

U8 Cal_CRC(P_U8 ptr,U8 len)
{
    U8 i;
    U8 crc=0;
    while (len--!=0) {
        for (i=0x80;i!=0;i/=2) {
            if ((crc&0x80)!=0) {
                crc*=2;crc^=0x13;
            } else crc*=2;
            if ((*ptr&i)!=0)crc^=0x13;
        }
        ptr++;
    } 
    return(crc);
}


U8 DisplayTime(P_U16 time)
{
    TEXT YearMonthDay[7];//={'20','04','-','09','-','21'};
    TEXT HourMinuteSecond[6];
    TEXT Week[4]={'星','期'};
    U16 temp,temp1,temp2,i;
    U16 week_time;
    U16 read_time[7];
    //////////////////////////display YearMonthDay[];
    YearMonthDay[6]=0;
    for (i=0;i<7;i++) {
        read_time[i]=*time;
        time++;
    }

    //year  
    if (read_time[0]<2000) {
        YearMonthDay[0]='19';
    }
    if (read_time[0]>1999) {
        YearMonthDay[0]='20';
    }
    temp=0x30;
    temp1=read_time[0]%10;
    temp2=(read_time[0]%100)/10;
    temp1 +=temp;
    temp2 +=temp;
    YearMonthDay[1] =temp2;
    YearMonthDay[1] <<=8;
    YearMonthDay[1] |=temp1;

    YearMonthDay[2]='-';
    //month
    temp=0x30;
    temp1=read_time[1]%10;
    temp2=(read_time[1]%100)/10;
    temp1 +=temp;
    temp2 +=temp;
    YearMonthDay[3] =temp2;
    YearMonthDay[3] <<=8;
    YearMonthDay[3] |=temp1;

    YearMonthDay[4]='-';
    //day
    temp=0x30;
    temp1=read_time[2]%10;
    temp2=(read_time[2]%100)/10;
    temp1 +=temp;
    temp2 +=temp;
    YearMonthDay[5] =temp2;
    YearMonthDay[5] <<=8;
    YearMonthDay[5] |=temp1;
    Typing(GB_NORMAL_FONT, REPLACE_STYLE, BLACK, 10, 1, (P_U8)YearMonthDay);
    //////////////////////////display HourMinuteSecond[];
    //hour
    HourMinuteSecond[5]=0;
    temp=0x30;
    temp1=read_time[3]%10;
    temp2=(read_time[3]%100)/10;
    temp1 +=temp;
    temp2 +=temp;
    HourMinuteSecond[0] =temp2;
    HourMinuteSecond[0] <<=8;
    HourMinuteSecond[0] |=temp1;

    HourMinuteSecond[1] =':';
    //minute
    temp=0x30;
    temp1=read_time[4]%10;
    temp2=(read_time[4]%100)/10;
    temp1 +=temp;
    temp2 +=temp;
    HourMinuteSecond[2] =temp2;
    HourMinuteSecond[2] <<=8;
    HourMinuteSecond[2] |=temp1;

    HourMinuteSecond[3] =':';
    //second
    temp=0x30;
    temp1=read_time[5]%10;
    temp2=(read_time[5]%100)/10;
    temp1 +=temp;
    temp2 +=temp;
    HourMinuteSecond[4] =temp2;
    HourMinuteSecond[4] <<=8;
    HourMinuteSecond[4] |=temp1;
    Typing(GB_NORMAL_FONT, REPLACE_STYLE, BLACK, 10, 17, (P_U8)HourMinuteSecond);


    /*
    //////////////////////////display week[];
    Week[3]=0;
    GetWeek(&week_time);
    switch(week_time)
    {
      case(0x0001):
        Week[2]='一';
        break;
      case(0x0002):
        Week[2]='二';
        break;
      case(0x0003):
        Week[2]='三';
        break;
      case(0x0004):
        Week[2]='四';
        break;
      case(0x0005):
        Week[2]='五';
        break;
      case(0x0006):
        Week[2]='六';
        break;
      case(0x0007):
        Week[2]='日';
        break;
      default:
        return(0);
    
    }
    Typing(GB_NORMAL_FONT, REPLACE_STYLE, BLACK, 10, 33, (P_TEXT)Week);
    */
    return(1);
}

U8 DisplayTimeAn(P_U16 time)
{
    TEXT YearMonthDay[7];//={'20','04','-','09','-','21'};
    TEXT HourMinuteSecond[6];
    TEXT Week[4]={'星','期'};
    U16 temp,temp1,temp2,i;
    U16 week_time;
    U16 read_time[7];
    //////////////////////////display YearMonthDay[];
    YearMonthDay[6]=0;
    for (i=0;i<7;i++) {
        read_time[i]=*time;
        time++;
    }

    //year  
    if (read_time[0]<2000) {
        YearMonthDay[0]='19';
    }
    if (read_time[0]>1999) {
        YearMonthDay[0]='20';
    }
    temp=0x30;
    temp1=read_time[0]%10;
    temp2=(read_time[0]%100)/10;
    temp1 +=temp;
    temp2 +=temp;
    YearMonthDay[1] =temp2;
    YearMonthDay[1] <<=8;
    YearMonthDay[1] |=temp1;

    YearMonthDay[2]='-';
    //month
    temp=0x30;
    temp1=read_time[1]%10;
    temp2=(read_time[1]%100)/10;
    temp1 +=temp;
    temp2 +=temp;
    YearMonthDay[3] =temp2;
    YearMonthDay[3] <<=8;
    YearMonthDay[3] |=temp1;

    YearMonthDay[4]='-';
    //day
    temp=0x30;
    temp1=read_time[2]%10;
    temp2=(read_time[2]%100)/10;
    temp1 +=temp;
    temp2 +=temp;
    YearMonthDay[5] =temp2;
    YearMonthDay[5] <<=8;
    YearMonthDay[5] |=temp1;
    //Typing(GB_NORMAL_FONT, REPLACE_STYLE, BLACK, 50, 90, (P_U8)YearMonthDay);
    PutString270((P_TEXT)YearMonthDay,50, 90,16,16);
    //////////////////////////display HourMinuteSecond[];
    //hour
    HourMinuteSecond[5]=0;
    temp=0x30;
    temp1=read_time[3]%10;
    temp2=(read_time[3]%100)/10;
    temp1 +=temp;
    temp2 +=temp;
    HourMinuteSecond[0] =temp2;
    HourMinuteSecond[0] <<=8;
    HourMinuteSecond[0] |=temp1;

    HourMinuteSecond[1] =':';
    //minute
    temp=0x30;
    temp1=read_time[4]%10;
    temp2=(read_time[4]%100)/10;
    temp1 +=temp;
    temp2 +=temp;
    HourMinuteSecond[2] =temp2;
    HourMinuteSecond[2] <<=8;
    HourMinuteSecond[2] |=temp1;

    HourMinuteSecond[3] =':';
    //second
    temp=0x30;
    temp1=read_time[5]%10;
    temp2=(read_time[5]%100)/10;
    temp1 +=temp;
    temp2 +=temp;
    HourMinuteSecond[4] =temp2;
    HourMinuteSecond[4] <<=8;
    HourMinuteSecond[4] |=temp1;
    PutString270((P_TEXT)HourMinuteSecond,60, 110,16,16);
    //Typing(GB_NORMAL_FONT, REPLACE_STYLE, BLACK, 60, 110, (P_U8)HourMinuteSecond);
    /* 
   //////////////////////////display week[];
   Week[3]=0;
   GetWeek(&week_time);
   switch(week_time)
   {
     case(0x0001):
       Week[2]='一';
       break;
     case(0x0002):
       Week[2]='二';
       break;
     case(0x0003):
       Week[2]='三';
       break;
     case(0x0004):
       Week[2]='四';
       break;
     case(0x0005):
       Week[2]='五';
       break;
     case(0x0006):
       Week[2]='六';
       break;
     case(0x0007):
       Week[2]='日';
       break;
     default:
       return(0);
   
   }
   Typing(GB_NORMAL_FONT, REPLACE_STYLE, BLACK, 68, 130, (P_TEXT)Week);      */
    return(1);
}


U8 DisplayTimeOt(P_U16 time)
{
    TEXT YearMonthDay[7];//={'20','04','-','09','-','21'};
    TEXT HourMinuteSecond[6];
    TEXT Week[4]={'星','期'};
    U16 temp,temp1,temp2,i;
    U16 week_time;
    U16 read_time[7];
    //////////////////////////display YearMonthDay[];
    YearMonthDay[6]=0;
    for (i=0;i<7;i++) {
        read_time[i]=*time;
        time++;
    }

    //year  
    if (read_time[0]<2000) {
        YearMonthDay[0]='19';
    }
    if (read_time[0]>1999) {
        YearMonthDay[0]='20';
    }
    temp=0x30;
    temp1=read_time[0]%10;
    temp2=(read_time[0]%100)/10;
    temp1 +=temp;
    temp2 +=temp;
    YearMonthDay[1] =temp2;
    YearMonthDay[1] <<=8;
    YearMonthDay[1] |=temp1;

    YearMonthDay[2]='-';
    //month
    temp=0x30;
    temp1=read_time[1]%10;
    temp2=(read_time[1]%100)/10;
    temp1 +=temp;
    temp2 +=temp;
    YearMonthDay[3] =temp2;
    YearMonthDay[3] <<=8;
    YearMonthDay[3] |=temp1;

    YearMonthDay[4]='-';
    //day
    temp=0x30;
    temp1=read_time[2]%10;
    temp2=(read_time[2]%100)/10;
    temp1 +=temp;
    temp2 +=temp;
    YearMonthDay[5] =temp2;
    YearMonthDay[5] <<=8;
    YearMonthDay[5] |=temp1;
    PutString270((P_TEXT)YearMonthDay,22, 290,16,16);
    //Typing(GB_NORMAL_FONT, REPLACE_STYLE, BLACK, 22, 250, (P_U8)YearMonthDay);
    //////////////////////////display HourMinuteSecond[];
    //hour
    HourMinuteSecond[5]=0;
    temp=0x30;
    temp1=read_time[3]%10;
    temp2=(read_time[3]%100)/10;
    temp1 +=temp;
    temp2 +=temp;
    HourMinuteSecond[0] =temp2;
    HourMinuteSecond[0] <<=8;
    HourMinuteSecond[0] |=temp1;

    HourMinuteSecond[1] =':';
    //minute
    temp=0x30;
    temp1=read_time[4]%10;
    temp2=(read_time[4]%100)/10;
    temp1 +=temp;
    temp2 +=temp;
    HourMinuteSecond[2] =temp2;
    HourMinuteSecond[2] <<=8;
    HourMinuteSecond[2] |=temp1;

    HourMinuteSecond[3] =':';
    //second
    temp=0x30;
    temp1=read_time[5]%10;
    temp2=(read_time[5]%100)/10;
    temp1 +=temp;
    temp2 +=temp;
    HourMinuteSecond[4] =temp2;
    HourMinuteSecond[4] <<=8;
    HourMinuteSecond[4] |=temp1;
    if (temp1%2==0) {
        HourMinuteSecond[3]=' ';
        HourMinuteSecond[1] =' ';
    }
    PutString270((P_TEXT)HourMinuteSecond,135, 290,16,16);
    //Typing(GB_NORMAL_FONT, REPLACE_STYLE, BLACK, 135, 250, (P_U8)HourMinuteSecond);

    return(1);
}


void DECtoTEXT(P_U8 des,U16 ori,U8 num)//num小于5,将ori指向的数据按位转换为TEXT.
{
    U8 i;
    U16 temp;

    for (i=0;i<num;i++) {
        if (i==0) {
            temp=ori%10;
        } else if (i==1) {
            temp=ori%100;
            temp=temp/10;
        } else if (i==2) {
            temp=ori%1000;
            temp=temp/100;
        } else if (i==3) {
            temp=ori%10000;
            temp=temp/1000;
        }
        switch (temp) {
        case 0:
            *(des+num-1)='0';
            break;
        case 1:
            *(des+num-1)='1';
            break;
        case 2:
            *(des+num-1)='2';
            break;
        case 3:
            *(des+num-1)='3';
            break;
        case 4:
            *(des+num-1)='4';
            break;
        case 5:
            *(des+num-1)='5';
            break;
        case 6:
            *(des+num-1)='6';
            break;
        case 7:
            *(des+num-1)='7';
            break;
        case 8:
            *(des+num-1)='8';
            break;
        case 9:
            *(des+num-1)='9';
            break;
        default:
            break;
        }
        des--;

    }
}

void SystemInitApp(void)
{
    U16 read_time[7];
    TEXT   NowLoadingTxt[]={'系','统','正','在','初','始','化',',','请','稍','候','..','. ',0};

    PPSMInit(TRUE);   
    ClearScreen(WHITE);
    EL_ON();
    StartLowPowerCheck();
    Typing(GB_NORMAL_FONT, REPLACE_STYLE, BLACK, 5, 150, (P_U8)NowLoadingTxt);
    InitFlashDrv(); 
    SunrayBrighttest((U8)GetBrightless() == 0 ? 4 : (U8)GetBrightless());
    //FirstGetData(read_time);
    if (*(P_U16)0x1050014!=0x0001 || *(P_U16)0x1050000<500) {
        CalibratePen1( TRUE);
        ClearScreen(WHITE);
    }
    InitData();
    /**/
    //Uart_Init(1);  
    //if (UART_Configure(UART_NORMAL_MODE, UART_9600_BPS, NO_PARITY, 
    //   ONE_STOP_BIT, EIGHT_BIT_CHAR,1) !=PPSM_OK )rv = PPSM_ERROR;
    Uart_Init(2);  
    if (UART_Configure(UART_NORMAL_MODE, UART_9600_BPS, NO_PARITY, 
       ONE_STOP_BIT, EIGHT_BIT_CHAR,2) !=PPSM_OK )rv = PPSM_ERROR;
    /**/

}

void DisplayCut(void)
{
    U32  temp;
    TEXT LowPowerHintTxt[]={'电','量','不','足',',','正','在','关','机','..','. ',0};

    ClearScreen(WHITE); 
    Typing(GB_NORMAL_FONT, REPLACE_STYLE, BLACK, 30, 100, (P_U8)LowPowerHintTxt);
    for (temp=0;temp<0x3FFFFF;temp++);
    POWER_OFF();//关闭电源
    asm("    JSR START");  
}

void LowPowerAlarm(void)
{
    LowpowerCheckNum++;
    if ((LowpowerCheckNum%2)==0) {
        LEDHealthOn();
    } else {
        LEDHealthOff();
    }
    if ((LowpowerCheckNum%5)==0 ) {
        BUZZER_ON();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -