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

📄 funccommon.c

📁 本人编写的无线电话程序,给予PIC18C801设计,包括了uCOS的移植以及菜单,自己设计的拼音注入法,完整地一级汉字库,希望对大家有所帮助
💻 C
字号:
/**********************************************************
 This contains some common functions to be used by others.
 The functions here is included in the "funccommon.h"
 **********************************************************/

#include "includes.h"
#include "network.h"
#include "funcfontlib.h"

INT16U swaps(INT16U v)
{
    WORD_VAL t;
    BYTE b;

    t.Val   = v;
    b       = t.v[1];
    t.v[1]  = t.v[0];
    t.v[0]  = b;

    return t.Val;
}


INT32U swapl(INT32U v)
{
    INT8U b;
    INT32U myV;
    DWORD_VAL *myP;

    myV     = v;
    myP     = (DWORD_VAL*)&myV;

    b       = myP->v[3];
    myP->v[3] = myP->v[0];
    myP->v[0] = b;

    b       = myP->v[2];
    myP->v[2] = myP->v[1];
    myP->v[1] = b;

    return myV;

}
/*********************************************************
 This 6 functions are to convert certain code to another
 There are some common restrictions:
 1, the compressed codes have to be digit
 2, the parameter "ps" point to the source buffer
 3, the parameter "pd" point to the destination buffer
 4, the "len" is the length of the source, with unit of 
    the source
 5, the return value is the length of result. if 0, no 
    code converted
 *********************************************************/

//compressed digital codes to unicode converssion
INT8U app_c2u(INT8U rom * ps, INT8U len, INT16U rom * pd){
	INT8U i, t;
	for(i=0; i<len; i++){
		t = *ps;
		t = (t >> 4) | 0x30;
		if(t > 0x39){
			return(i*2);
		}
		*pd++ = (INT16U)t;

		t = *ps;
		t = (t & 0x0f) | 0x30;
		if(t > 0x39){
			return(i*2+1);
		}
		*pd++ = (INT16U)t;
		ps++;
	}
	return(len*2);
}
//unicode to compressed digital codes converssion
INT8U app_u2c(INT16U rom * ps, INT8U len, INT8U rom * pd){
    WORD_VAL t;
    INT8U i, b;

	b = 0xff;
	for(i=0; i<len; i++){
		t.Val = *ps++;
		if(i & 0b00000001){	//if 1,3,5,7,9,...
			b &= t.v[0] | 0xf0;
			*pd = b;
			if(t.v[0] > 0x39 || t.v[0] < 0x30){
				*pd = b | 0x0f;
				return(i/2+1);
			}
			b = 0xff;
			pd++;
			*pd = 0xff;
		}
		else{ //or 0,2,4,6,8,...
			b &= (t.v[0] << 4) | 0x0f;
			*pd = b;
			if(t.v[0] > 0x39 || t.v[0] < 0x30){
				*pd = 0xff;
				return(i/2);
			}
		}
	}
	return((len+1)/2);
}
//ascii to unicode converssion
INT8U app_a2u(INT8U rom * ps, INT8U len, INT16U rom * pd){
	INT8U i;
	for(i=0; i<len; i++){
		*pd = (INT16U) (*ps);
		ps++;
		pd++;
	}
	return(len);
}
//unicode to ascii converssion
INT8U app_u2a(INT16U rom * ps, INT8U len, INT8U rom * pd){
    WORD_VAL t;
    INT8U i;
	for(i=0; i<len; i++){
		*pd = ((WORD_VAL rom *)ps)->v[0];
		pd++;
		ps++;
	}
	return(len);
}
//compressed digital code to ascii converssion
INT8U app_c2a(INT8U rom * ps, INT8U len, INT8U rom * pd){
	INT8U i, t;
	for(i=0; i<len; i++){
		t = *ps;
		t = (t >> 4) | 0x30;
		if(t > 0x39){
			return(i*2);
		}
		*pd++ = t;

		t = *ps;
		t = (t & 0x0f) | 0x30;
		if(t > 0x39){
			return(i*2+1);
		}
		*pd++ = t;
		ps++;
	}
	return(len*2);
}
//ascii to compressed code converssion
INT8U app_a2c(INT8U rom * ps, INT8U len, INT8U rom * pd){
    INT8U i, b, t;

	b = 0xff;
	for(i=0; i<len; i++){
		t = *ps++;
		if(i & 0b00000001){	//if 1,3,5,7,9,...
			b &= t | 0xf0;
			*pd = b;
			if(t > 0x39 || t < 0x30){
				*pd = b | 0x0f;
				return(i/2+1);
			}
			b = 0xff;
			pd++;
			*pd = 0xff;
		}
		else{ //or 0,2,4,6,8,...
			b &= (t << 4)|0x0f;
			*pd = b;
			if(t > 0x39 || t < 0x30){
				*pd = 0xff;
				return(i/2);
			}
		}
	}
	return((len+1)/2);
}
/*********************************************************/
INT8U app_getwordwide(INT16U wd)
{
    WORD_VAL t;

    t.Val   = wd;
    if(t.v[1] == 0x00) {
    	if(t.v[0]==0x00)
    		return(0);
    	else
    	    return (8);
    }
    else if(t.v[1] == 0xd4)
    	return (6);
	else
		return (16);
}


//extern OS_EVENT  *rom DisplaySem;
extern INT8U Disp_Word(unsigned char PosX,unsigned char PosY,unsigned int unicode,unsigned char Type);

rom INT16U *app_printf(rom INT16U *pchar,INT8U len,INT8U x,INT8U y)
{
	INT8U i,err;
	INT8U delta;
	INT8U disp_type;

	if(x<=7){
		if(len==0)	len=32;
		for(i=0;i<len;i++){
			delta=app_getwordwide(*pchar);
			if(delta==0)
				return(pchar);
			else{
				if(delta==6)
					disp_type=PIX6;
				else if(delta==8)
					disp_type=PIX8;
				else
					disp_type=PIX16;
				
				if(y+delta>128)
					return(pchar);
//				OSSemPend(DisplaySem,0,&err);
//				if (err == OS_NO_ERR)
					(void)Disp_Word(x,y,*pchar,disp_type);
//				OSSemPost(DisplaySem);
				y+=delta;
				pchar++;
			}
		}
	}
	//else ---> print to serial port
	else
		return(pchar);
}

//the function to clear messages--to release message memblock and attached memblock if there is one
void Func_Clear_Msg(INT8U rom * pMsg){
	if((INT24U)pMsg < PTR_MAX){
		if(((MSG_HEAD *)pMsg)->Attached == TRUE){
			OSMemPut(((MSG_HEAD *)pMsg)->pmemATT, ((MSG_HEAD *)pMsg)->pMem);
		}
		OSMemPut(((MSG_HEAD *)pMsg)->pmemME, pMsg);
	}
}

⌨️ 快捷键说明

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