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

📄 bspdotprnt.c

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

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

#include "bspDotPrnt.h"
#include "bspTimer.h"


/*------------------ ----全局变量定义-- ----------------------*/
UINT1 	g_ucprntPattern1[PRNT_WIDTH] = {0};		/* 穿孔打印从左到右的字模缓存 */		
UINT1 	g_ucprntPattern2[PRNT_WIDTH] = {0};		/* 穿孔打印从右到左的字模缓存 */
UINT1   g_ucprntPattern3[PRNT_WIDTH] = {0};	
UINT2	g_usprntPaperLen1 = 0;					/* 黑标进纸步数统计计数器,走纸起始位置和切纸位置函数与g_uiprntPaperLen2同步 */
UINT2	g_usprntPaperLen2 = 0;					/* 黑标纸进纸步数统计计数器,遇黑标清0 */
UINT2   g_usprntPaperLen3 = 0;					/* 纸总长计数器1,非定长票据步数统计用,打印票据设定参数后步数清0 */
UINT1 	g_ucPrntCheckBMInt = 0;					/* 打印机初始化检测黑标流程 */
UINT1   g_ucprntPFphase;						/* 进纸电机运转相序变化 */			        
UINT1 	g_ucprntState = 0;						/* 打印机的状态 */
UINT2   g_usPrintLocatOffset = 0;				/* 打印起始位置 */
UINT1   g_ucPrntWidthAdjust = 0;                /* 打印宽度调整点数,通过调整打印点,实现打印宽度调节 */
UINT1	g_ucprntAdjustLevel = 4;				/* 打印效果调节参数 */
UINT1	g_ucprntCheckedBMark = 0;				/* 是否找到黑标标志 0 未找到 1找到黑标 */
UINT1   g_ucprntCheckBM = 0;					/* 进纸检测黑标标志 */
UINT2   g_usPrntBMCounter = 0; 			        /* 黑标步数统计 */
/*------------------ ----静态全局变量定义-- ----------------------*/
static UINT2  s_usprntPatternCount = 0; 		/* 打印机缓存填充计数寄存器 */
static UINT1  s_ucprntDataBuffer[100];			/* 字模处理缓存缓冲区 (穿孔、热敏),存放待打印内容区位码 */
static UINT1  s_ucprntBuffDataIn = 0;			/* 缓冲区索引 (穿孔、热敏) */
static UINT1  s_ucprntBufferFull = 0; 			/* 打印缓冲区满标志 0打印缓冲区未满、 1打印缓冲区已装满 */
static UINT1  s_ucprntCRphase;					/* 字车电机运转相序变化 */
static UINT1  s_ucprntCharSpace = 0;			/* 字符间距 */
static UINT1  s_ucDataBufferFull = 0;			/* 打印字模区位码接收缓冲区满 */
static UINT1  s_ucPrntDoubleWidth = 0;			/* 倍宽打印标志(0 正常打印 1倍宽打印) */
static UINT1  s_ucPrntDoubleHigh = 0;			/* 倍高打印标志(0 正常打印 1倍高打印) */
static UINT1  s_ucRequestDoubleHigh = 0;		/* 打印数据含倍高处理需求(0 无、1有 )*/
/*-----------------------------------------------------------------*/

#define WAIT() 	 { while (!g_ucprntTimerInt); g_ucprntTimerInt = 0; }
const UINT2  prntCRSpeedUp[21] = 
	{5850, 4260 ,2150 ,1630 ,1420 ,1290 ,1200 ,1140 ,1090 ,1050 ,
	   1020, 990 ,990 ,990 ,990 ,990 ,940 ,940 ,940 ,940 ,940};
const UINT2  prntCRSpeeddown[21] = 
	{2150 ,1630 ,1420 ,1290 ,1200 ,1140 ,1090 ,1050 ,1020, 940 ,
		940 ,940 ,940 ,940 ,940 ,940 ,940 ,940 ,940,940,940};

/*
********************************************************
*
* 函数名:bspDotPrntInit
*
* 功  能:打印机底层初始化函数
*
* 输  入:g_ucPaperType
*
* 输  出:s_ucprntCRphase
*		  g_ucprntPFphase
*         g_ucprntTimerInt
*
* 返  回:SUCCESS ---初始化完成
*
********************************************************
*/
UINT1 bspDotPrntInit(void)
{
	/* 变量初始化 */
	bspDotPrntParaInit();
	/* 初始化字车电机HLLH、进纸电机初始相序 LHHL */
	s_ucprntCRphase = 0;
	CR_M_CAINT();
	CR_M_CBINT();
	g_ucprntPFphase = 0;

	LF_STEPB_INT();      
	LF_STEPB_NON_INT(); 
	LF_STEPA_INT();	
	LF_STEPA_NON_INT();	
	/* 打开机芯控制电源 */
	bspDotPrntPowerOn ();
	bspDotprntControlPins(0xff);
	/* 初始化电流水平 */
	bspDotPrntSetCurrentLevel(ZERO_CURRENT);	
	g_ucprntTimerInt = 0;	
	/* 字车电机、进纸电机初始化 */
	bspDotPrntCRmotorInit();
	bspDotPrntPFMotorInit(g_ucPaperType);

	return SUCCESS;
	
}

/*
********************************************************
*
* 函数名:bspDotPrntFonts
*
* 功  能:打印机自测打印完整汉字库
*
* 输  入:无
*
* 输  出:s_ucprntBuffDataIn
*
* 返  回:SUCCESS  ---处理成功
*
********************************************************
*/
INT1 bspDotPrntFonts(void)
{
	UINT1 temp[198];
	UINT1 i,m;
	UINT1 j,k ;
	
	m = 0;
	while (1)
	{
		mem_set(temp, 0 , 198);
		j = 0;
		for (k = 0; k < 5; k++ )
		{	
			for (i = 0; i < 19; i ++)
			{
				temp[j] = 0xb0 + m;
				temp[j+1] = 0xa1 + 19*k + i;
				bspDotprntPutDataToBuff (&temp[j], 2);
				if (temp[j+1]==0xfe)
				{
					m ++;
				}
				j = j + 2;
				if ((0xb0 + m) > 0xf7) return SUCCESS;
			}
			bspDotprntAndNewline(1, 24);
			if (g_ucprntState&0x0f)
			{
				s_ucprntBuffDataIn = 0;
				return FAULT;
			}
		}
	}
}

/*
*****************************************************
*
* 函数名:bspDotPrntParaInit
*
* 功  能:打印机底层变量初始化函数
*
* 输  入:g_ucPrntWidthAdjust
*
* 输  出:s_ucprntBuffDataIn
*		  s_ucprntBufferFull
*         s_usprntPatternCount
*
* 返  回:N/A
*
*****************************************************
*/
void bspDotPrntParaInit(void)
{
	s_ucprntBuffDataIn = 0;	
	s_ucprntBufferFull = 0;
	mem_set(s_ucprntDataBuffer, 0 , sizeof(s_ucprntDataBuffer));
	mem_set(g_ucprntPattern1, 0 , sizeof(g_ucprntPattern1));
	mem_set(g_ucprntPattern2, 0 , sizeof(g_ucprntPattern2));
	mem_set(g_ucprntPattern2, 0 , sizeof(g_ucprntPattern3));
	return ;
}

/*
******************************************************
*
* 函数名:bspDotPrntCRmotorInit
*
* 功  能:穿孔打印机CR电机初始化定位函数
*
* 输  入:g_ucprntTimerInt
*         g_ucprntState
*
* 输  出:
*
* 返  回:FAULT ------打印机故障
*		  SUCCESS-----初始化成功
*
******************************************************
*/
INT1 bspDotPrntCRmotorInit(void)
{
	UINT1 ucCRRunFlag;
	UINT1 ucCRRunMode = 0;
	UINT2 uiCRRunSteps;
	
	bspDotPrntPowerOn();
	bspDotPrntSetCurrentLevel(HIGH_CURRENT);
	if (1 == bspDotPrntCheckHP())
	{
		ucCRRunMode = 2; /* 当前处于HP位置 */
	}

	/* 变量初始化 */
	g_ucprntTimerInt = 0;
	bspDotprntSetTimer(PU);
	uiCRRunSteps = 0;
	ucCRRunFlag = 1;
	
	while (ucCRRunFlag)
	{
		if (g_ucprntTimerInt)
		{
			g_ucprntTimerInt = 0;
			switch (ucCRRunMode)
			{
				case 0: /*字车向左运行,去寻找HP*/
				{
					bspDotPrntCRPhase(0);
					uiCRRunSteps ++;
					/* 触发HP信号,转到Mode3清步数 */
					if (1 == bspDotPrntCheckHP())
					{
						ucCRRunMode = 3;
 					}
					else if (uiCRRunSteps >= 300)
					{
						g_ucprntState = g_ucprntState|MALFUNCTION;/* 故障 */
						bspDotPrntCRStop();
						ucCRRunFlag = 0;
						break;
						return FAULT;
					}
					
					bspTimer1Start(INIT_TIMER);
					break;
				}
				
				case 1: /* 触发HP并调整后从HP去打印的起始位置 初始位置在HP位置左侧n步 */
				{
					bspDotPrntCRPhase(0);
					uiCRRunSteps ++;
					/* 走偶数步,停留在双线圈通电处 */
					if (uiCRRunSteps < INIT_STEP)
					{
 						bspDotprntSetTimer(INIT_TIMER);
					}
					else
					{
						bspDotprntSetTimer(PD);
						WAIT();
						bspDotPrntCRStop();
 						/* 如果向左运行14步后,未检测到HP信号,则认为机械故障 */
						if (0 == bspDotPrntCheckHP())
						{
							g_ucprntState = g_ucprntState|MALFUNCTION;/* 故障 */
						}
						ucCRRunFlag = 0;
					}
					break;
				}
				
				case 2: /* 在HP位置向右运动100步,然后向左运动检测HP之后运动14步 */
				{
					bspDotPrntCRPhase(1);
					uiCRRunSteps ++;
 					if (uiCRRunSteps < 100)
					{
						bspDotprntSetTimer(INIT_TIMER);
					}
					else
					{
						bspDotprntSetTimer(PD);
						WAIT();
						g_ucprntTimerInt = 0;
						ucCRRunMode = 0;
						uiCRRunSteps = 0;
					}
					break;
				}
				case 3: /*触发HP位置后的调整*/
				{
					bspDotprntSetTimer(PD);
					WAIT();
					g_ucprntTimerInt = 0;
					ucCRRunMode = 1;
					uiCRRunSteps = 0;
 					break;
				}
				default:
					break;
			}
		}
	}
	return SUCCESS;
}

/*
**************************************************
*
* 函数名:bspDotPrntPFmotorInit
*
* 功  能:穿孔打印机进纸电机初始化定位函数
*
* 输  入:g_ucprntCheckBM
*         g_ucPrntCheckBMInt
*
* 输  出:无
*
* 返  回:SUCCESS----处理成功
*
***************************************************
*/
INT1 bspDotPrntPFMotorInit
(
	UINT1 _ucPaperType
)
{
	if (0 == _ucPaperType)
	{
		/* 非黑标纸进纸、退纸操作判断无纸 */
		bspDotPrntPFLineSpace(1, 100);
		bspDotPrntPFLineSpace(0, 100);
	}
	else
	{
		/* 黑标纸进纸找黑标操作 */
		g_ucprntCheckBM = 1;
		g_ucPrntCheckBMInt = 1;
		bspDotPrntPFLineSpace (1 , 50);
	}
	return SUCCESS;
}

/*
**************************************************
*
* 函数名:bspCKPrntCRLRPhase
*
* 功  能:穿孔打印机CR电机正、反向驱动相序
*
* 输  入:s_ucprntCRphase
*
* 输  出:无
*
* 返  回:SUCCESS----处理成功
*
***************************************************
*/
INT1 bspDotPrntCRPhase
(
	UINT1 _ucDirection     /* 0 反向驱动相序, 1 正向驱动相序 */
)
{
	if (_ucDirection == 0)
	{
		switch (s_ucprntCRphase)
		{
			case 0:
				CR_M_CA();
				s_ucprntCRphase = 1;
				break;

			case 1:
				CR_M_CB();
				s_ucprntCRphase = 0;
				break;

			default:
				break;
		}
	}
	else if (_ucDirection== 1)
	{
		switch (s_ucprntCRphase)
		{
			case 0:
				CR_M_CB();
				s_ucprntCRphase = 1;
				break;

			case 1:
				CR_M_CA();
				s_ucprntCRphase = 0;
				break;

			default:
				break;
		}
	}	
	return SUCCESS;
}

/*
**************************************************
*
* 函数名:bspDotPrntPFPhase
*
* 功  能:穿孔打印机进纸电机正、反向驱动相序
*
* 输  入: g_ucprntPFphase
*
* 输  出:g_usprntPaperLen3
*		  g_usprntPaperLen1
*         g_usprntPaperLen2	
*
* 返  回:N/A
*
***************************************************
*/
void bspDotPrntPFPhase
(
	UINT1 _ucDirection,		/* 正反、向进纸选择 */
	UINT1 _ucPaperType      /* 打印纸类型 */
)
{
	if (_ucDirection == 1)
	{
		switch (g_ucprntPFphase)
		{
			case 0:
				LF_STEPB();
				LF_STEPB_NON();
				g_ucprntPFphase = 1;
				break;

			case 1:
				LF_STEPA();
				LF_STEPA_NON();
				g_ucprntPFphase = 0;
				break;

			default:
				break;
		}
	}
	else if (_ucDirection == 0)
	{
		switch (g_ucprntPFphase)
		{
			case 0:
				LF_STEPA();
				LF_STEPA_NON();
				g_ucprntPFphase = 1;
				break;

			case 1:
				LF_STEPB();
				LF_STEPB_NON();
				g_ucprntPFphase = 0;
				break;

			default:
				break;
		}

	}

	if (0 == _ucPaperType)  /* 非黑标纸进纸步数统计 */
	{
		if (_ucDirection)
		{
			g_usprntPaperLen3 ++;
		}
		else if ((!_ucDirection) && ( g_usprntPaperLen3 >= 2 ))
		{
			g_usprntPaperLen3 --;
		}
	}
	else  /* 黑标纸步数统计 */
	{
		if (_ucDirection)
		{
			g_usprntPaperLen1 ++;
			g_usprntPaperLen2 ++;
		}
		else if ((!_ucDirection) && ( g_usprntPaperLen2 >= 2 ))
		{
			g_usprntPaperLen1 --;
			g_usprntPaperLen2 --;
		}
	}
	return;
}

/*
***************************************************
*
* 函数名:bspDotCRLeft2RightDrive
*
* 功  能:穿孔打印机正向打印一行数据
*
* 输  入:g_ucprntPattern1
*
* 输  出:无
*
* 返  回:N/A
*
***************************************************
*/
void bspDotCRLeft2RightDrive(void)
{
	UINT1 ucCRRunFlag = 1;
	UINT2 ucCRRunSteps = 0;
	UINT1 ucCRRunMode = 0;
	
	bspDotPrntSetCurrentLevel(LOW_CURRENT);
	/* 设置PU时间,让出CPU执行 */
	OSTimeDly(1);
	/*禁止任务切换  */
	OSSchedLock();
	bspDotPrntSetCurrentLevel(HIGH_CURRENT);
	
	while (ucCRRunFlag)
	{
		switch (ucCRRunMode)
		{
			case 0:	/* 设置驱动电流为满电流 */
				bspDotPrntCRPhase(1);
				DelayXus(prntCRSpeedUp[ucCRRunSteps]);
				ucCRRunSteps ++;
				if (ucCRRunSteps == 16)
				{
					ucCRRunMode = 1;
					ucCRRunSteps = 0;
					bspDotPrntSetCurrentLevel(MIDDLE_CURRENT);
				}
				break;

			case 1: /*正向匀速运动并打印*/
				bspDotPrntCRPhase(1);
				ucCRRunSteps ++;
				PRT_TRIG_ON();
				PSOLENIO(~g_ucprntPattern1[ucCRRunSteps * 2 - 2]);
				Delay350us();
				PSOLENIO(0xff);		/* 收针操作 */
				PRT_TRIG_OFF();
				Delay135us();
				PRT_TRIG_ON();
				PSOLENIO(~g_ucprntPattern1[ucCRRunSteps * 2 - 1]);
				Delay350us();
				PSOLENIO(0xff);		/* 收针操作 */
				PRT_TRIG_OFF();
				Delay115us();
				/* 打印完毕,准备减速 */
				if (ucCRRunSteps == (PRNT_WIDTH / 2))
				{
					ucCRRunMode = 2;
					ucCRRunSteps = 0;
				}

⌨️ 快捷键说明

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