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

📄 bsptsprnt.c

📁 基于ARM与μCOS-II的嵌入式操作系统实现针式和热敏微型打印程序.
💻 C
📖 第 1 页 / 共 5 页
字号:

#include "intfBsp.h"
#include "intfPrnt.h"

#include "bspTSPrnt.h"
#include "bspDotPrnt.h"


/*------------------ ----全局变量定义-- ----------------------*/
UINT1	g_ucprntPrintLineBuffer[DOTLINE_LIMIT][TS_ONE_LINE_BYTE];/* 内存中二维数组是按行存放的,DOTLINE_LIMIT为行数,48为列数 */
UINT1   g_ucBatVolLower = 0;					/* 锂电池电压低标志 */
UINT1	g_ucTsOccupySpiMark = 0;				/* 热敏占用SPI(0:占用结束 1:占用期间) */
/*------------------ ----静态全局变量定义-- ----------------------*/
static UINT1 s_ucprntTimerStepCnt = 0;			/* 定时器走步时间统计最小单位倍数 */
static UINT1 s_ucprntTimerHeatCnt = 0;			/* 定时器加热时间最小单位倍数 */
static UINT1 s_ucprntTimerNeedStepCnt = 0;		/* 需要时间定时为最小单位的倍数 */
static UINT1 s_ucprntHeatEnable  = 0;			/* 热敏加热使能标志 */
static UINT2 s_usprntPFStepCnt = 0;				/* 打印进纸步数统计 */
static UINT1 s_ucprntPrintEnable = 0;			/* 热敏打印机打印使能标志 */
static UINT1 s_ucprntStepTime = 0;				/* 打印走步时间设置 */
static UINT2 s_usprntDotLineDealed = 0;			/* 已处理的点行数 */
static UINT2 s_usprntHoriPosition = 0;			/* 热敏打印水平起始位置 */
static UINT2 s_usprntDotLine = 0; 				/* 垂直位置 以点行计 */
static UINT1 s_ucprntBitInByte = 0x80; 			/* 字节中处于的位数 */
static UINT1 s_ucprntHoriByte = 0; 				/* 水平位置,以字节计数 */
static UINT1 s_ucprntPFRunSign = 0;				/* 进纸运行标志 */
static UINT2 s_usTSprntLinePrinted = 0;			/* 热敏打印已成功打印点行数 */
static UINT1 s_ucOverFlowPrinted = 0;			/* 热敏打印过程中处理数据指针与已打印数据指针对齐标志 */
static UINT1 s_ucTSSendOneLine = 0;				/* 热敏打印需要占用SPI发送一点行数据(0数据发送完毕、1数据待发送) */
static UINT1 s_ucTSSwitchSpiMark = 0;			/* 切换SPI占用标志 */
static UINT1 s_ucRsponseKey = 0; 				/* 是否允许响应进、退纸键(0 允许  1不允许)*/
static UINT1 s_ucTSDoubleWidth = 0;			    /* 倍宽打印标志(0 正常打印 1倍宽打印) */
static UINT1 s_ucTSDoubleHigh = 0;				/* 倍高打印标志(0 正常打印 1倍高打印) */
static UINT1 s_ucTSRequestDoubleHigh = 0;		/* 单行字模是否请求倍高打印标志(0 否、1 是) */
static UINT1 s_ucTSprntDataBuffer[LINEASCIINUM];/* 存储阿拉伯语单词区位码缓冲区 */
static UINT1 s_ucTSprntDataBuffDataIn = 0;		/* 存储阿拉伯语单词区位码索引 */
/*------------------ ----修改BUG增加静态全局变量定义-- ----------------------*/
static UINT1 s_ucNumInWord = 0;					/*阿拉伯语中当前英语单词或数字记录*/
static UINT1 s_ucRevBuffer[LINEASCIINUM];		/*存储阿拉伯语中英文或数字用于反转 */
static UINT1 s_ucWordPlus[LINEASCIINUM];		/*未打完的剩余单词 */
static UINT1 s_ucMaxASClen = LINEASCIINUM;		/*根据倍宽决定的每行最多ASCII长度 */

static UINT1 s_ucFirstArrayHeatEnd = 2;         /* 第一组加热完毕0;第二组加热完毕1 */
static UINT1 s_ucAdapterPowder = 0;             /* 1 适配器供电 0 锂电池供电 */
static UINT1 s_ucDoubleHeat = 0;				/* 当行是否双次加热标志 0 单次 1双次 */
static UINT1 s_ucNextDoubleHeat = 0;     		/* 下一行是否分段加热标志 0 不是 1是 */
static UINT1 s_ucPrntBlankLine = 0;				/* 1第一行打印空行,0后续打印正常行数 */
static UINT1 s_ucPrntAdjEffect = 0;				/* 是否需要修正锂电池供电点行数据打印效果(1-Y 0-N) */
static UINT1 s_ucPrntHeatAdjVal = 0;			/* 热敏打印加热时间修正值 */	
/* 热敏进纸电机加减速值 */
const  static UINT2 s_usPFSpeedUp[UP_DOWN_STEP] = {12,11,10,10,9,9,8,8,7,7,6,6,5,5};
const  static UINT2 s_usPFSpeedDown[UP_DOWN_STEP] = {5,5,6,6,7,7,8,8,9,9,10,10,11,12};
/*-----------------------------------------------------------------*/
#define WAIT_TS() 	 { while (!g_ucprntTimerInt); g_ucprntTimerInt = 0; }

/*
********************************************************
*
* 函数名:bspTSPrntInit
*
* 功  能:打印机底层初始化函数
*
* 输  入:g_ucprntHeatTime
*
* 输  出:s_ucprntStepTime
*
* 返  回:SUCCESS ---初始化完成
*
********************************************************
*/
UINT1 bspTSPrntInit(void)
{ 
	/* 初始化打印机相序 LHHH */
	LF_MTA_NON_INT();
	LF_MTA_INT();
	LF_MTB_INT();		
	LF_MTB_NON_INT();
	g_ucprntPFphase = 0;
	/* 根据加热时间参数计算打印走步时间 */
	s_ucprntStepTime = (g_ucprntHeatTime + 6/ADJUST_TIMER_SCALE)/4 ; 
	HEAT_DISABLE1;
	HEAT_DISABLE2;
	s_ucprntPFRunSign = 1;
	bspTSPrntPFMotorInit(0);
	return SUCCESS;
}

/*
**************************************************
*
* 函数名:bspTSPrntPFmotorInit
*
* 功  能:热敏打印机进纸电机初始化定位函数
*
* 输  入:g_ucprntCheckBM
*         g_ucPrntCheckBMInt
*
* 输  出:无
*
* 返  回:SUCCESS----处理成功
*		  FAULT------参数输入失败
*
***************************************************
*/
INT1 bspTSPrntPFMotorInit
(
	UINT1 _ucPaperType       /* 打印纸类型 0 非黑标纸  1 黑标纸 */
)
{
	if (0 == _ucPaperType)
	{
		bspTSPrntPFLineSpace(1, 200);
		bspTSPrntPFLineSpace(0, 200);
	}
	else if (1 == _ucPaperType)
	{
		/* 黑标纸进纸找黑标操作 */
		g_ucprntCheckBM = 1;
		g_ucPrntCheckBMInt = 1;
		bspTSPrntPFLineSpace (1 , 50);
	}
	else
	{
		return FAULT;
	}
	return SUCCESS;
}

/*
********************************************************
*
* 函数名:bspTsGetSpiMark
*
* 功  能:获取热敏占用SPI情况
*
* 输  入:s_ucTSSwitchSpiMark
*
* 输  出:无
*
* 返  回:0:未占用
*
*		  1:占用
*
********************************************************
*/
UINT1 bspTsGetSpiMark(void)
{
	if (s_ucTSSwitchSpiMark == 1)
	{
		return 1;	/* 热敏打印正占用SPI */
	}
	else
	{
		return 0;	/* 热敏打印已释放SPI */
	}
}

/*
********************************************************
*
* 函数名:bspTsResponseKey
*
* 功  能:热敏打印是否允许进退纸键操作
*
* 输  入:s_ucRsponseKey
*
* 输  出:无
*
* 返  回:1:热敏打印禁止按走纸键
*
*		  0:热敏打印结束允许按走纸键
*
********************************************************
*/
UINT1 bspTsResponseKey(void)
{
	if (s_ucRsponseKey == 1)
	{
		return 1; /* 热敏打印禁止按走纸键 */
	}
	else
	{
		return 0;/* 热敏打印结束允许按走纸键 */
	}
}

#pragma arm section code = "bspTSTimerISTR"
/*
********************************************************
*
* 函数名:bspTSTimerISTR
*
* 功  能:热敏打印机中断服务函数
*
* 输  入:s_ucprntTimerStepCnt
*         s_ucprntTimerHeatCnt
*
* 输  出:s_usprntPFStepCnt
*         s_usprntDotLineDealed
*
* 返  回:SUCCESS----处理成功
*
********************************************************
*/
INT1 bspTSTimerISTR(void)
{
	s_ucprntTimerStepCnt ++;
	s_ucprntTimerHeatCnt ++;
	/* 当s_ucprntPrintEnable被置起时,热敏打印机处于打印状态  */
	if (( s_ucprntPrintEnable) && (s_ucprntTimerStepCnt >= s_ucprntTimerNeedStepCnt))
	{			
		s_ucprntTimerStepCnt = 0;
		bspTSPrntPFPhase(1, g_ucPaperType);
		s_usprntPFStepCnt ++;
		bspPrntCheckBM(1);
		
		/* 第4步开始加热第一行,之后每4步加热一行 */
		if ((s_usprntPFStepCnt >= 4) && (s_usprntPFStepCnt % 4 == 0))
		{
			if (!s_ucAdapterPowder)/* 锂电池供电 */
			{
				/*确定是否更改定时器条件 */
				if ((!s_ucNextDoubleHeat)&&(s_ucDoubleHeat ==1))
				{
					s_ucDoubleHeat = 0; 
					s_ucprntStepTime = (g_ucprntHeatTime + 4/ADJUST_TIMER_SCALE)/4;
					s_ucprntStepTime = s_ucprntStepTime + 1;
					bspTSprntSetISRTimer(s_ucprntStepTime);
				}
				else if ((s_ucNextDoubleHeat)&&(s_ucDoubleHeat ==0))
				{
					s_ucDoubleHeat = 1; 
					s_ucprntStepTime = (g_ucprntHeatTime + 4/ADJUST_TIMER_SCALE)/2;
					s_ucprntStepTime = s_ucprntStepTime + 1;
					bspTSprntSetISRTimer(s_ucprntStepTime);
				}
				if (s_ucPrntAdjEffect)
				{
					/* 点行数据太少加热时间适当地修正 */
					s_ucPrntHeatAdjVal = g_ucprntHeatTime*1/8;
				}
				else
				{
					s_ucPrntHeatAdjVal = 0;
				}
			}
			OPERATE_LAT;								/* 拉锁存信号 */
			/* 分段打印 */
			if (s_ucDoubleHeat)
			{
				HEAT_ENABLE1;                           /* 打开加热闸门 */	
				s_ucprntTimerHeatCnt = 0;
			}
			else
			{
				HEAT_ENABLE;
			}
			s_ucTSSwitchSpiMark = 2;					/* 置热敏占用SPI结束 */
			if ((s_ucFirstArrayHeatEnd == 1)||(s_ucFirstArrayHeatEnd == 3)||(s_ucAdapterPowder))
			{
				s_ucFirstArrayHeatEnd = 2;
				if (s_ucPrntBlankLine)
				{
					s_ucPrntBlankLine = 0;
				}
				else
				{
					INC(s_usTSprntLinePrinted, DOTLINE_LIMIT);	/* 已成功打印行数 */
					g_usTSPrintedLine ++;
				}
				/* 是否允许继续打印判断 */
				if (s_usTSprntLinePrinted != s_usprntDotLineDealed)
				{
					s_ucprntHeatEnable = 1;
					s_ucprntTimerHeatCnt = 0;
					s_ucTSSendOneLine = 1;
				}
				else
				{
					s_ucprntPrintEnable = 0;
					s_ucprntPFRunSign = 0;
					s_ucOverFlowPrinted = 1;
					HEAT_DISABLE1;
					HEAT_DISABLE2;
				}
			}
		}		
	}
	if ((s_ucTSSendOneLine)&&(s_ucprntTimerHeatCnt >= 4/ADJUST_TIMER_SCALE))
	{
		bspTSSendOneLine();
	}
	else	/* 下面操作由于SPI共用所引起 */
	{
		if (s_ucTSSwitchSpiMark == 2)			/* 热敏占用结束时需要判断有没有中断所引起的SPI操作 */
		{
			if (g_uc865Ex0Irq == 1)				/* 865外部中断来不及处理 */
			{
				bspCmx865ReadStatusRegIrq();
			}
			
			if (g_uc865CircuitSpiIrq == 1)		/* 线路检测接收865信号没来得及处理 */
			{
				bspCircuitUseInIrq();
			}
			s_ucTSSwitchSpiMark = 0;			/* 置为无意义状态 */
		}
	}
	/* 加热定时时间到,停止加热信号 */
	if ((s_ucprntHeatEnable) && (s_ucprntTimerHeatCnt >= (g_ucprntHeatTime - s_ucPrntHeatAdjVal)))
	{
		/* 锂电池供电分段打印 */
		if (s_ucDoubleHeat)
		{
			if (s_ucFirstArrayHeatEnd == 0)
			{
				HEAT_DISABLE2;
				s_ucprntHeatEnable = 0;
				s_ucFirstArrayHeatEnd = 1;
			}
			else 
			{
				HEAT_DISABLE1;
				s_ucFirstArrayHeatEnd = 0;
				HEAT_ENABLE2;
			}
		}
		else
		{
			HEAT_DISABLE;
			s_ucprntHeatEnable = 0;
			s_ucFirstArrayHeatEnd = 3;
		}
		s_ucprntTimerHeatCnt = 0;
	}
	if ((s_ucprntPFRunSign) && (s_ucprntTimerStepCnt == s_ucprntTimerNeedStepCnt))
	{
		g_ucprntTimerInt = 1;
		s_ucprntTimerStepCnt = 0;
	}
	return SUCCESS;
}
#pragma arm section code

/*
******************************************************
*
* 函数名:bspTSprntSetTimer
*
* 功  能:热敏机芯设置定时器定时时间
*
* 输  入:s_ucprntTimerStepCnt 
*
* 输  出:s_ucprntTimerNeedStepCnt  
*
* 返  回:SUCCESS----处理成功
*
******************************************************
*/
INT1 bspTSprntSetTimer
(
	UINT1  _ucTime         /* 定时时间,100us倍数 */
)
{
	s_ucprntTimerStepCnt = 0;
	s_ucprntTimerNeedStepCnt = _ucTime;
	/* 打开中断定时器 */
	bspTimer1Start(100);
	return SUCCESS;
}

/*
******************************************************
*
* 函数名:bspTSprntSetISRTimer
*
* 功  能:热敏机芯设置中断服务函数循环定时器定时时间
*
* 输  入:s_ucprntTimerStepCnt 
*
* 输  出:s_ucprntTimerNeedStepCnt  
*
* 返  回:SUCCESS----处理成功
*
******************************************************
*/
INT1 bspTSprntSetISRTimer
(
	UINT1  _ucTime         /* 定时时间,(100*ADJUST_TIME_GRANULARITY)us倍数 */
)
{
	s_ucprntTimerStepCnt = 0;
	s_ucprntTimerNeedStepCnt = _ucTime;
	/* 打开中断定时器 */
	bspTimer1Start(100 * ADJUST_TIMER_SCALE);
	return SUCCESS;
}

/*
******************************************************
*
* 函数名:bspTSPrntPFPhase
*
* 功  能:热敏打印机进纸电机正、反向驱动相序
*
* 输  入:无
*
* 输  出:g_ucprntPFphase
*
* 返  回:SUCCESS	  时序处理成功
*		  FAULT		  函数参数输入不合法
*
*******************************************************
*/
INT1 bspTSPrntPFPhase
(
	UINT1 _ucDirection,		/* 正反向进纸选择 1 正向 0 反向 */
	UINT1 _ucPaperType 		/* 纸类型 0 非黑标纸 1 黑标纸 */
)
{
	if ((_ucDirection > 1)||(_ucPaperType > 1))
	{
		return FAULT;
	}
	if (_ucDirection == 1)
	{		
		if (g_ucprntPFphase == 0)
		{
			g_ucprntPFphase = 7;
		}
		else
		{
			g_ucprntPFphase --;
		}
	}    
	switch (g_ucprntPFphase)     
	{
		/* A- A B B-*/
		case 0: /*0110*/
			LF_MTB_NON();
			break;
			
		case 1: /*1110*/
			LF_MTA_NON();
			break;
			
		case 2: /*1010*/
			LF_MTA();
			break;
			
		case 3: /*1011*/
			LF_MTB_NON();
			break;
			
		case 4: /*1001*/
			LF_MTB();
			break;
			
		case 5: /*1101*/
			LF_MTA();
			break;
			
		case 6: /*0101*/
			LF_MTA_NON();
			break;
			
		case 7: /*0111*/
			LF_MTB();
			break;
			
		default:
			break;
	}
	if (_ucDirection == 0)
	{
		g_ucprntPFphase ++;
		if (g_ucprntPFphase >= 8)
		{
			g_ucprntPFphase = 0;
		}
	}
	bspTSPrntStepTotal(_ucDirection, _ucPaperType);
	return SUCCESS;
}

/*
******************************************************
*
* 函数名:bspTSPrntStepTotal

⌨️ 快捷键说明

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