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

📄 bspdotprnt.c

📁 基于ARM与μCOS-II的嵌入式操作系统实现针式和热敏微型打印程序.
💻 C
📖 第 1 页 / 共 5 页
字号:
			ucDealData[ucByteCount -1 - k] |= ((ucaData[k] & 0x01)<<7)|((ucaData[k] & 0x02)<<5)|((ucaData[k] & 0x04)<<3)|((ucaData[k] & 0x08)<<1);
			ucDealData[ucByteCount -1 - k] |= ((ucaData[k] & 0x10)>>1)|((ucaData[k] & 0x20)>>3)|((ucaData[k] & 0x40)>>5)|((ucaData[k] & 0x80)>>7);
		}
		for ( j = 1; j < ucByteCount; j ++ )
		{
			ucDealData[j] = (( ucDealData[j])|(ucDealData[j - 1])) - (ucDealData[j - 1]);
		}					
		for (j = 0; j < ucByteCount; j ++)
		{
			if (!s_ucPrntDoubleHigh)
			{
				g_ucprntPattern1 [PRNT_WIDTH - s_usprntPatternCount] = ucDealData[j];
				s_usprntPatternCount ++;
				if (s_ucPrntDoubleWidth) /* 倍宽打印*/
				{
					g_ucprntPattern1 [PRNT_WIDTH - s_usprntPatternCount] = 0;
					s_usprntPatternCount ++;
				}
			}
			else /* 倍高打印 */
			{
				s_ucRequestDoubleHigh = 1;
				g_ucprntPattern1[PRNT_WIDTH - s_usprntPatternCount] = bspDotByteToWord(ucDealData[j]&0x0f);
				g_ucprntPattern3[PRNT_WIDTH - s_usprntPatternCount] = bspDotByteToWord(ucDealData[j]>>4);
				s_usprntPatternCount ++;
				if (s_ucPrntDoubleWidth) /* 倍宽打印*/
				{
					g_ucprntPattern1 [PRNT_WIDTH - s_usprntPatternCount] = 0;
					g_ucprntPattern3 [PRNT_WIDTH - s_usprntPatternCount] = 0;
					s_usprntPatternCount ++;
				}
			}
		}
		if (s_ucPrntDoubleWidth)     /* 倍宽打印 */
		{
			usTempWidth = s_usprntPatternCount;
			s_usprntPatternCount -= 2;
			for (j = 0; j < (ucByteCount - 1); j++)
			{
				g_ucprntPattern1[PRNT_WIDTH - s_usprntPatternCount] = g_ucprntPattern1[PRNT_WIDTH - s_usprntPatternCount]
				 |g_ucprntPattern1[PRNT_WIDTH - (s_usprntPatternCount - 2)];	
				g_ucprntPattern3[PRNT_WIDTH - s_usprntPatternCount] = g_ucprntPattern3[PRNT_WIDTH - s_usprntPatternCount]
				 |g_ucprntPattern3[PRNT_WIDTH - (s_usprntPatternCount - 2)];
				s_usprntPatternCount -= 2;
			}
			s_usprntPatternCount = usTempWidth;
		}
	}
	return SUCCESS;
}

/*
*****************************************************
*
* 函数名:bspDotChineseDealPattern
*
* 功  能:穿孔打印机汉字字模处理函数
*
* 输  入:s_ucPrntDoubleHigh
*		  s_ucprntCharSpace
*		  s_ucPrntDoubleWidth
*
* 输  出:g_ucprntPattern1
*     	  g_ucprntPattern2
*         g_ucprntPattern3
*		  s_usprntPatternCount
*
* 返  回:SUCCESS
*
******************************************************
*/
UINT1 bspDotChineseDealPattern
(
	UINT4  _offset			/* 开始取字模的地址 */
)
{
	UINT1 j, k, l,m,n; 
	UINT1 ucDealData[32] = {0};
	UINT1 ucDealData1[32] = {0};
	
	mem_set(ucDealData,0,sizeof(ucDealData));
	mem_set(ucDealData1,0,sizeof(ucDealData1));
	mem_cpy(ucDealData, (UINT1 *)_offset, 32);
	if (s_ucPrntDoubleHigh) /* 倍高 */
	{
		s_ucRequestDoubleHigh = 1;
		for (l = 0; l < 8; l ++)
		{
			for (j = 0; j < 8; j ++)
			{
				for (n = 0; n < 4; n ++)
				{
					bspDotprntBitWrite(ucDealData1 + 8*n + l, 7 - j, bspDotprntBitRead(ucDealData[2 * j + 16*(n/2) + n%2],(7 - l)));
				}
			}
		}
		if (!s_ucPrntDoubleWidth)/* 不是倍宽 */
		{
			/* 不能连续出针,进行半点处理 */
			for (m = 1; m < 16; m ++)
			{
				ucDealData1[m] &= ~(ucDealData1[m] & ucDealData1[m - 1]);
				ucDealData1[16 + m] &= ~(ucDealData1[16 + m] & ucDealData1[16 + m - 1]);
			}
		}
		for (m = 0; m < 16; m++ )
		{
			g_ucprntPattern3[s_usprntPatternCount] = ucDealData1[m];
			g_ucprntPattern1[s_usprntPatternCount] = ucDealData1[16 + m];
			s_usprntPatternCount ++;
			if (s_ucPrntDoubleWidth)
			{
				s_usprntPatternCount ++;
			}
		}
	}
	else  /* 非倍高 */
	{
		/* 根据字模重新取位构成汉字打印字模,其中i 表示字节 j表示对应的位 */
		for (l = 0; l < 8; l ++)
		{
			for (j = 0; j < 8; j ++)
			{
				/* 汉字字模处理,处理后的字模前16字节为正向出针字模,后16字节为反向出针字模 */
				for (n = 0; n < 4; n ++)
				{
					bspDotprntBitWrite(ucDealData1 + 8*n + l, 7 - j, bspDotprntBitRead(ucDealData[4 * j + n],(7 - l)));
				}
			}
		}
		if (s_ucPrntDoubleWidth)
		{
			for (k = 0; k < 16; k ++)
			{
				g_ucprntPattern1[s_usprntPatternCount] = ucDealData1[k];
	 			g_ucprntPattern2[s_usprntPatternCount] = ucDealData1[k + 16];
	 			s_usprntPatternCount ++;
	 			s_usprntPatternCount ++;
			}
		}
		else
		{
			/* 不能连续出针,进行半点处理 */
			for (m = 1; m < 16; m ++)
			{
				ucDealData1[m] &= ~(ucDealData1[m] & ucDealData1[m - 1]);
				ucDealData1[16 + m] &= ~(ucDealData1[16 + m] & ucDealData1[16 + m - 1]);
			}
			for (k = 0; k < 16; k ++)
			{
				g_ucprntPattern1[s_usprntPatternCount] = ucDealData1[k];
				g_ucprntPattern2[s_usprntPatternCount] = ucDealData1[k + 16];
				s_usprntPatternCount ++;
			}
		}
	}
	return SUCCESS;
}

/*
******************************************************
*
* 函数名:bspDotByteToWord
*
* 功  能:对单字节字模数据拉长处理(0 1 1 0 -> 00 11 11 00)
*
* 输  入:无
*
* 输  出:无
*
* 返  回:N/A
*
******************************************************
*/
UINT1  bspDotByteToWord(UINT1 _ucByte)
{
	switch (_ucByte)
	{
		case 0:
			return 0x00;
		case 1:
			return 0x03;
		case 2:
			return 0x0c;
		case 3:
			return 0x0f;
		case 4:
			return 0x30;
		case 5:
			return 0x33;
		case 6:
			return 0x3c;
		case 7:
			return 0x3f;
		case 8:
			return 0xc0;
		case 9:
			return 0xc3;
		case 10:
			return 0xcc;
		case 11:
			return 0xcf;
		case 12:
			return 0xf0;
		case 13:
			return 0xf3;
		case 14:
			return 0xfc;
		case 15:
			return 0xff;	
		default: 
			return 0;
	}
}

/*
******************************************************
*
* 函数名:bspDotprntBitRead
*
* 功  能:读取字节某一位
*
* 输  入:无
*
* 输  出:无
*
* 返  回:N/A
*
******************************************************
*/
UINT1 bspDotprntBitRead
(
	UINT1 _ucData,		/* 读取字节数据 */
	UINT1 _ucBit		/* 处理字节某一位 */
)
{
	return ((_ucData >> _ucBit) & 0x01);
}

/*
***************************************************
*
* 函数名:bspDotprntBitWrite
*
* 功  能:写字节数据的某一位
*
* 输  入:无
*
* 输  出:无
*
* 返  回:N/A
*
****************************************************
*/
void bspDotprntBitWrite
(
	UINT1 *_ucData,	   /* [out]写字节数据 */
	UINT1  _ucBit, 	   /*第几位*/
	UINT1  _ucBitValue /*位值*/
)
{
	if (_ucBitValue == 0)
	{
		*_ucData &= (~(0x01 << _ucBit));
	}
	else if (_ucBitValue == 1)
	{
		*_ucData |= (0x01 << _ucBit);
	}
	return;
}

/*
***************************************************
*
* 函数名:bspDotPrntBitMap
*
* 功  能:穿孔打印填充位图打印数据
*
* 输  入:无
*
* 输  出:无
*
* 返  回:N/A
*
****************************************************
*/
INT1 bspDotPrntBitMap
(
	UINT1* _pBuffer, 		/* [in]存放位图数据缓存首地址 */	
	UINT2  _usLength		/* 打印位图数据长度 */
)
{
	UINT2 i;
	if (_usLength == 0)
	{
		return FAULT;
	}
	for (i = 0; i < _usLength; i ++)
	{
		s_usprntPatternCount ++;
		g_ucprntPattern1[s_usprntPatternCount] = _pBuffer[i];
		s_usprntPatternCount ++;
		if (s_usprntPatternCount >= (PRNT_WIDTH - 2*g_ucPrntWidthAdjust))
		{
			break;
		}
	}

	return SUCCESS;
}

/*
**************************************************
*
* 函数名:bspDotPrntCheckHP
*
* 功  能:穿孔打印机检测HP开关触发信号
*
* 输  入:无
*
* 输  出:无
*
* 返  回:0-----未检测到HP位置
*         1-----检测到HP位置
*
**************************************************
*/
INT1 bspDotPrntCheckHP(void)
{
	if (HOME_SENSOR)
	{
		return 0;/* 未找到HP */
	}
	else
	{
		return 1;/*找到HP HOME_SENSOR */
	}
}

/*
**************************************************
*
* 函数名:bspDotPrntCheckHP
*
* 功  能:穿孔打印机检测纸状态触发信号
*
* 输  入:无
*
* 输  出:g_ucprinterState
*
* 返  回:0------检测到有纸
*         1------检测到无纸
****************************************************
*/
INT1 bspDotPrntCheckPE(void)
{
	if (PE_SENSOR)
	{
		g_ucprntState = g_ucprntState&0xfe;
		return 0; /*有纸 */
	}
	else
	{
		g_ucprntState = g_ucprntState|NOPAPER;
		return 1;/* 无纸 */
	}
}

/*
**************************************************
*
* 函数名:bspDotPrntCRStop
*
* 功  能:穿孔打印机CR电机停机
*
* 输  入:无
*
* 输  出:无
*
* 返  回:N/A
*
**************************************************
*/
void bspDotPrntCRStop(void)
{
	/* 设置电流为33%,关闭基准电流 */
	bspDotPrntSetCurrentLevel(ZERO_CURRENT);
	return;
}

/*
**************************************************
*
* 函数名:bspDotPrntPFStop
*
* 功  能:穿孔打印机进纸电机停机
*
* 输  入:无
*
* 输  出:无
*
* 返  回:N/A
*
**************************************************
*/
void bspDotPrntPFStop(void)
{
	/* 关进纸电机5v电源 */
	LF_STEP_SIGNAL_OFF();
	return;
}

/*
**************************************************
*
* 函数名:bspDotPrntSetCurrentLevel
*
* 功  能:穿孔打印机CR电机和进纸电机电流等级选择
*
* 输  入:无
*
* 输  出:无
*
* 返  回:N/A
*
****************************************************
*/
void bspDotPrntSetCurrentLevel
(
	UINT1 _ucCurrentLevel	   /* 驱动电流等级 */
)
{
	switch (_ucCurrentLevel)
	{
		case ZERO_CURRENT:	/*电流为0% */
			CRI11_I121();
			CRI01_I011();
			break;

		case LOW_CURRENT:	/*电流为33% */
			CRI11_I120();
			CRI01_I011();
			break;

		case MIDDLE_CURRENT:/*电流为66% */
			CRI11_I121();
			CRI01_I010();
			break;

		case HIGH_CURRENT:	/*电流为100% */
			CRI11_I120();
			CRI01_I010();
			break;

		default:
			return;
			break;
	}
}

/*
**************************************************
*
* 函数名:bspDotPrntPowerOn
*
* 功  能:穿孔打印机上电
*
* 输  入:无
*
* 输  出:无
*
* 返  回:N/A
*
**************************************************
*/
void bspDotPrntPowerOn(void)
{
	/* 开机芯24v电源 */
	PRTPWR_CON_ON();
	return;
}

/*
**************************************************
*
* 函数名:bspDotPrntPowerOff
*
* 功  能:穿孔打印机下电
*
* 输  入:无
*
* 输  出:无
*
* 返  回:N/A
*
**************************************************
*/
void bspDotPrntPowerOff(void)
{
	/* 关进纸电机5v电源 */
	LF_STEP_SIGNAL_OFF();
	/* 关机芯24v电源 */
	PRTPWR_CON_OFF();
	return;
}

/*
**************************************************
*
* 函数名:bspPrntPutDataToBuff
*
* 功  能:传送打印数据到缓冲区
*
* 输  入:无
*
* 输  出:s_ucprntBuffDataIn
*         s_ucprntDataBuffer
*
* 返  回:SUCCESS-----处理成功
*         FAULT-------数据越界(数据长度不超过80个)
*
****************************************************
*/
INT1 bspDotprntPutDataToBuff
(
    UINT1  * _pAdrress,    /* [in]数据起始地址 */
    UINT1    _Lenth        /* 数据长度 */
)
{
	if ( _Lenth > 80)
	{
		return FAULT;
	}
	if ((s_ucprntBuffDataIn + _Lenth) > sizeof(s_ucprntDataBuffer))
	{
		s_ucDataBufferFull = 1;
		bspDotprntAndNewline(1, 24); 
	}
	mem_cpy(s_ucprntDataBuffer + s_ucprntBuffDataIn, _pAdrress, _Lenth);
	s_ucprntBuffDataIn += _Lenth;

	return SUCCESS;
}

⌨️ 快捷键说明

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