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

📄 s_toolssample.c

📁 dragon ball vz328 上的一个例子程序。 用于做手持仪表用。
💻 C
📖 第 1 页 / 共 4 页
字号:
/******************************************************************************
02.11.14 by Nie Copyright Shanghai Sunray Technology  Co.,Ltd http://www.51sunray.com 
*****************************************************************************/ 

/******************************************************************************


Functions:   1. Typing       -- Type Messages on the screen
             2. TextButton   -- Enable a text icon with the given areaId and text
             3. Button3D     -- Draw a 3D region
             4. DisplayTitle -- Display the title and title bar on the screen
             5. MakeCtrlIcon -- Create and enable an active icon
             6. Layout       -- Clear the screen and display the title
             7. DisplayNum   -- Display the number string
             8. DisplayLoc   -- Display the x,y location
             9. ErrCheck     -- Error Checking function
             10:Strlen 		 -- Return length of a null terminated string
             11:Strcpy		 -- Copy string from src to dest
             12:Strcmp		 -- Compare string1 with string2
             13:StrASCIIToTEXT--Copy an ASCII string at src into a TEXT (16-bit) 
                                string at dest            
**********************************************************************/
#include <stdlib.h>    /* Standard C library and I/O header file            */
#include <stdio.h>          
#include "ppsm.h"      /* PPSM pre-defined system constants and header file */
#include "errors.h"    /* PPSM error codes header file                      */
#include "m68328.h"    /* Header file for m68328                            */
#include "proto.h"     /* PPSM tools function prototypes                    */    
#include "Bmapfont.h" 
#include "tools.h"
#include "Sunray.h"

#define GB_FONT_STYLE       1
#define ASSIC_FONT_STYLE    0   
/* Global variable for error checking */  

STATUS rv = PPSM_OK;
U16  LowpowerCheckNum;
U8   CheckVoltageNum;

unsigned char UTL_Word2Deci( unsigned short  word, unsigned char *buff)
{      
    unsigned char temp, i;

    i = 0; 
    temp = word / 10000;
    word = word % 10000;
    if ( temp ) *(buff+i++) = temp + '0';

    temp = word / 1000;           
    word = word % 1000;
    if ( i || temp ) *(buff+i++) = temp + '0';

    temp = word / 100;           
    word = word % 100;
    if ( i || temp ) *(buff+i++) = temp + '0';

    temp = word / 10;           
    if ( i || temp ) *(buff+i++) = temp + '0';
    temp = word % 10;           
    *(buff+i++) = temp + '0';
    *(buff+i) = '\0';    
    return i;
} 

void UTL_U8toU16(U8 *buffU8 ,U16 *buffU16 )
{
    unsigned char i;
    for (i=0; *(P_U8)buffU8 !=0;i++) {
        *(buffU16)=*(buffU8); 
        buffU8++;
        *(buffU16)=*(buffU16)<<8;
        *(buffU16)=*(buffU16)|*(buffU8);
        buffU16++;
        buffU8++;
    }
}

unsigned char UTL_Word2BCD( unsigned short  word, unsigned char *buff )
{      
    unsigned char temp, i;             
    i = 0; 
    word -=(word/9999)*9999;            
    temp = word / 1000;           
    word = word % 1000;
    if ( i || temp ) {
        *(buff+i) = temp ;
        *(buff+i) <<=4;     
    }
    temp = word / 100;           
    word = word % 100;
    if ( i || temp ) {
        *(buff+i) |= temp ;
        i++;
    }
    temp = word / 10;           
    if ( i || temp ) {
        *(buff+i) = temp ;
        *(buff+i) <<=4; 
    }
    temp = word % 10;           
    *(buff+i) |= temp ;
    i++; 
    return i;
}   

unsigned char UTL_BCD2Float( unsigned short word, unsigned char *buff, unsigned char deci )
{  
    unsigned char len, i, p;

    len = UTL_Word2BCD( word, buff );      
    if ( deci ) {
        if ( len==deci ) {
            for ( i=0; i<=deci; i++ ) {
                p = len - i;
                *(buff+p+2) = *(buff+p);
            }
            *buff = '0';
            *(buff+1) = '.';
            return( len + 2 );
        } else if ( len < deci ) {
            for ( i=0; i<=len; i++ ) {
                p = len - i;
                *(buff+p+deci) = *(buff+p);
            }
            for ( i=(deci - len); i>=1; i-- ) {
                *(buff+i+1) = '0';
            }
            *buff = '0';
            *(buff+1) = '.';
            return( deci+2 );
        } else {
            for ( i=0; i<=deci; i++ ) {
                p = len - i;
                *(buff+p+1) = *(buff+p);
            }
            *(buff+len-deci) = '.';
            return( len + 1 );
        }
    }
    return len;
} 


unsigned char UTL_Word2Float( unsigned short word, unsigned char *buff, unsigned char deci )
{  
    unsigned char len, i, p;

    len = UTL_Word2Deci( word, buff );      
    if ( deci ) {
        if ( len==deci ) {
            for ( i=0; i<=deci; i++ ) {
                p = len - i;
                *(buff+p+2) = *(buff+p);
            }
            *buff = '0';
            *(buff+1) = '.';
            return( len + 2 );
        } else if ( len < deci ) {
            for ( i=0; i<=len; i++ ) {
                p = len - i;
                *(buff+p+deci) = *(buff+p);
            }
            for ( i=(deci - len); i>=1; i-- ) {
                *(buff+i+1) = '0';
            }
            *buff = '0';
            *(buff+1) = '.';
            return( deci+2 );
        } else {
            for ( i=0; i<=deci; i++ ) {
                p = len - i;
                *(buff+p+1) = *(buff+p);
            }
            *(buff+len-deci) = '.';
            return( len + 1 );
        }
    }
    return len;
} 
//extern U32 gErrorId;

/*
 * Function1:   Type Messages on the screen
 * U8   font:   The font of the message to be displayed
 * U8   style:  The style of the message to be displayed
 * U8   greylev The greylev of the message to be displayed
 * U16  xSrc    The top-left corner of the message to be displayed
 * U16  ySrc                                                       
 * TEXT str[]   The text string to be displayed
 */    
const U8 Keychar_letter[]={'1','2','3','4','5','6','7','8','9',
    '0','.',0};
U32 NumberKeyIconId[20];

const TEXT keyPadchar_letter[][4]={
    {'1 ',0}, {'2 ',0}, {'3 ',0}, {'4 ',0}, 
    {'5 ',0}, {'6 ',0}, {'7 ',0}, {'8 ',0},  
    {'9 ',0}, {'0 ',0}, {'. ',0}, {'<-',0} 
}; 

void KeyPadFunction_letter(U16 yPos){
    U8 i;
    ClearRec(WHITE,yPos,2,100,236,REPLACE_STYLE);
    for (i=0;i<12;i++) {
        if (i!=11) {
            if (TextButton(&NumberKeyIconId[i], GB_NORMAL_FONT,(P_TEXT)keyPadchar_letter[i], 40+(i%3)*52, 32*(i/3)+yPos, 50, 30, 1)
                != PPSM_OK) rv=PPSM_ERROR;
        } else {
            if (TextButton(&NumberKeyIconId[i], GB_NORMAL_FONT,(P_TEXT)keyPadchar_letter[i], 40+(i%3)*52, 32*(i/3)+yPos, 50, 30, 1)
                != PPSM_OK) rv=PPSM_ERROR;
        }            
    }      
}


U8 GetKeyChar_Letter(U32 id){
    U8 keyvalue,i; 
    keyvalue=0;
    for (i=0;i<12;i++) {
        if ( id==NumberKeyIconId[i] ) {
            if (i <11) {
                keyvalue = Keychar_letter[i];
            } else {
                keyvalue=i;
            }
            break;
        }
    }
    return keyvalue;
}


U16 U8len(P_U8 str)
{
    U16 len=0;

    while (str[len])
        len++;
    return len;
}

U8 U8cmp(P_U8 str , P_U8 dest){
    U8 testflag,i;

    testflag=1;
    if (U8len((P_U8)str) ==U8len((P_U8)dest) ) {
        i=0;
        while (i<U8len((P_U8)str)) {
            if (*(P_U8)str != *(P_U8)dest ) {
                testflag=0;
                break;
            }
            i++;
        }
        if (testflag==0) {
            return 0;
        }
        if (testflag==1) {
            return 1;                  
        }
    } else
        return 0;   
}

void U8HexToBCD(P_U8 strDes, P_U8 strSrc)
{
    U8 SrcLength;
    U8 TempData[20], i;

    SrcLength=U8len(strSrc);
    if (SrcLength<20) {
        for (i=0;i<SrcLength;i++) {
            TempData[i]=strSrc[i]/10;
            TempData[i]<<=4;
            TempData[i]|=(strSrc[i]%10);
        }
    } else {
        for (i=0;i<20;i++) {
            TempData[i]=strSrc[i]/10;
            TempData[i]<<=4;
            TempData[i]|=(strSrc[i]%10);
        }
    }
    for (i=0;i<SrcLength;i++) {
        *(P_U8)strDes++=TempData[i];
    }
}

void U8toBCD(P_U8 dest, P_U8 add)
{
    U8 i,j;
    U32 addr;
    U8 temp;
    U8 tempbuff[20];
    U8 datbuff[10]; 

    for (i=0;i<20;i++) {
        tempbuff[i]=0;
        datbuff[i/2]=0;
    }
    i=0; 
    while (*(P_U8)add !=0  && i<20) {
        tempbuff[i]=*(P_U8)add;
        i++;
        add++;
    }
    i=U8len((P_U8)tempbuff);
    for (j=0;j<i;j++) {
        if (j%2==0) {
            temp=tempbuff[j]-0x30;
            temp <<=4;
            datbuff[j/2] =temp;  
        } else {
            temp=tempbuff[j]-0x30;
            temp &=0x0F;
            datbuff[j/2] |=temp;
        }

    }
    for (j=0;j<5;j++) {
        *(P_U8)dest++=datbuff[j];
    }
}


void TEXTtoBCD(P_U8 dest, P_U8 add)
{
    U8 i,j;
    U32 addr;
    U8 temp;
    U8 tempbuff[20];
    U8 datbuff[10]; 

    for (i=0;i<20;i++) {
        tempbuff[i]=0;
        datbuff[i/2]=0;
    }
    for (i=0;i<5;i++) {
        datbuff[i]=0xAA;
    }
    i=0; 
    while (*(P_U8)add !=0  && i<20) {
        tempbuff[i]=*(P_U8)add;
        i++;
        add++;
    }
    i=U8len((P_U8)tempbuff);
    for (j=0;j<i;j++) {
        if (j%2==0) {
            temp=tempbuff[i-j-1]-0x30;
            temp &=0x0F;
            datbuff[j/2] =temp;  
        } else {
            temp=tempbuff[i-j-1]-0x30;
            temp <<=4;
            datbuff[j/2] |=temp;
        }

    }
    for (j=0;j<6;j++) {
        *(P_U8)dest++=datbuff[5-j];
    }
}


U16 AsciitoNum( P_U8 str)
{   U8 i,j;
    U16 num;
    U8 result;
    U8 data1;

    num=0;
    for (i=0;i<=sizeof(str);i++,str++) {
        data1=*(P_U8)str;
        if (i==0) {
            if ((data1<'0')||(data1>'9')) {
                break;
            } else {
                num=(data1-'0'); 
            }
        } else {
            if ((data1<'0')||(data1>'9')) {
                break;
            } else {
                num=num*10+(data1-'0'); 
            }    
        }    
    }     
    return num;
}    

U16 Strlen(P_TEXT str)
{
    U16 len=0;

    while (*(P_TEXT)str) {
        str++;
        len++;
    }    
    return len;
} 


static char getbytebit(unsigned char data, int i)
{
    if (i > 8 || i < 0)
        return -1;
    return((data>>i)&1);
}
///////////////////////////////////////////////////////////////////////////
//函数说明:此函数用于将字库(汉字及ASSIC)中象素1比bit位表示,生成2bit位表示。
//          将一个bit位,扩成2个bit位。
//函数参数:
//          unsigned char *ptrFont   1bit位表示的buffer,从字库中获得。
//          unsigned char style      转换类型 0  ASSIC字符,   1   汉字字符.
//			unsigned char *addrFont  转化2bit位的buffer,大小为64unsigned char(汉字)/32unsigned char(ASSIC).
//应用举例:
//          ASSIC 字符: 'A'
//          unsigned char *ptrFont = ASSIC_ADDR(assic字库的位置) + 'A' << 4;
//          unsigned char style = 0;
//          unsigned char addrFont[32];
//          Convert1bitTo2bit(ptrFont, style, addrFont);
//
//          汉字字符: 0xD2BB
//          unsigned char *ptrFont = GB_ADDR(GB字库的位置) + (0xD2-0xA0)*94+(0xBB-0xA0);
//          unsigned char style = 1;
//          unsigned char addrFont[64];
//          Convert1bitTo2bit(ptrFont, style, addrFont);

void Convert1bitTo2bit(unsigned char *ptrFont, unsigned char style, unsigned char *addrFont)
{
    int ncount = 0;
    int i = 0;
    unsigned char ttp = 0;
    unsigned char tmp;

    if (style == GB_FONT_STYLE)
        ncount = 32;
    else if (style == ASSIC_FONT_STYLE)
        ncount = 16;
    while (i++ < ncount) {
        tmp = *ptrFont++;
        if (getbytebit(tmp, 7))
            ttp += (3<<6);
        else
            ttp += (0<<6);
        if (getbytebit(tmp, 6))
            ttp += (3<<4);
        else
            ttp += (0<<4);
        if (getbytebit(tmp, 5))
            ttp += (3<<2);
        else
            ttp += (0<<2);
        if (getbytebit(tmp, 4))
            ttp += 3;
        else
            ttp += 0;

        *addrFont++ = ttp;
        ttp = 0;

        if (getbytebit(tmp, 3))
            ttp += (3<<6);
        else
            ttp += (0<<6);
        if (getbytebit(tmp, 2))
            ttp += (3<<4);
        else
            ttp += (0<<4);
        if (getbytebit(tmp, 1))
            ttp += (3<<2);
        else

⌨️ 快捷键说明

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