?? bspdotprnt.c
字號:
#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; /* 黑標進紙步數(shù)統(tǒng)計計數(shù)器,走紙起始位置和切紙位置函數(shù)與g_uiprntPaperLen2同步 */
UINT2 g_usprntPaperLen2 = 0; /* 黑標紙進紙步數(shù)統(tǒng)計計數(shù)器,遇黑標清0 */
UINT2 g_usprntPaperLen3 = 0; /* 紙總長計數(shù)器1,非定長票據(jù)步數(shù)統(tǒng)計用,打印票據(jù)設(shè)定參數(shù)后步數(shù)清0 */
UINT1 g_ucPrntCheckBMInt = 0; /* 打印機初始化檢測黑標流程 */
UINT1 g_ucprntPFphase; /* 進紙電機運轉(zhuǎn)相序變化 */
UINT1 g_ucprntState = 0; /* 打印機的狀態(tài) */
UINT2 g_usPrintLocatOffset = 0; /* 打印起始位置 */
UINT1 g_ucPrntWidthAdjust = 0; /* 打印寬度調(diào)整點數(shù),通過調(diào)整打印點,實現(xiàn)打印寬度調(diào)節(jié) */
UINT1 g_ucprntAdjustLevel = 4; /* 打印效果調(diào)節(jié)參數(shù) */
UINT1 g_ucprntCheckedBMark = 0; /* 是否找到黑標標志 0 未找到 1找到黑標 */
UINT1 g_ucprntCheckBM = 0; /* 進紙檢測黑標標志 */
UINT2 g_usPrntBMCounter = 0; /* 黑標步數(shù)統(tǒng)計 */
/*------------------ ----靜態(tài)全局變量定義-- ----------------------*/
static UINT2 s_usprntPatternCount = 0; /* 打印機緩存填充計數(shù)寄存器 */
static UINT1 s_ucprntDataBuffer[100]; /* 字模處理緩存緩沖區(qū) (穿孔、熱敏),存放待打印內(nèi)容區(qū)位碼 */
static UINT1 s_ucprntBuffDataIn = 0; /* 緩沖區(qū)索引 (穿孔、熱敏) */
static UINT1 s_ucprntBufferFull = 0; /* 打印緩沖區(qū)滿標志 0打印緩沖區(qū)未滿、 1打印緩沖區(qū)已裝滿 */
static UINT1 s_ucprntCRphase; /* 字車電機運轉(zhuǎn)相序變化 */
static UINT1 s_ucprntCharSpace = 0; /* 字符間距 */
static UINT1 s_ucDataBufferFull = 0; /* 打印字模區(qū)位碼接收緩沖區(qū)滿 */
static UINT1 s_ucPrntDoubleWidth = 0; /* 倍寬打印標志(0 正常打印 1倍寬打印) */
static UINT1 s_ucPrntDoubleHigh = 0; /* 倍高打印標志(0 正常打印 1倍高打印) */
static UINT1 s_ucRequestDoubleHigh = 0; /* 打印數(shù)據(jù)含倍高處理需求(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};
/*
********************************************************
*
* 函數(shù)名:bspDotPrntInit
*
* 功 能:打印機底層初始化函數(shù)
*
* 輸 入: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;
}
/*
********************************************************
*
* 函數(shù)名: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;
}
}
}
}
/*
*****************************************************
*
* 函數(shù)名:bspDotPrntParaInit
*
* 功 能:打印機底層變量初始化函數(shù)
*
* 輸 入: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 ;
}
/*
******************************************************
*
* 函數(shù)名:bspDotPrntCRmotorInit
*
* 功 能:穿孔打印機CR電機初始化定位函數(shù)
*
* 輸 入: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 ++;
/* 觸發(fā)HP信號,轉(zhuǎn)到Mode3清步數(shù) */
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: /* 觸發(fā)HP并調(diào)整后從HP去打印的起始位置 初始位置在HP位置左側(cè)n步 */
{
bspDotPrntCRPhase(0);
uiCRRunSteps ++;
/* 走偶數(shù)步,停留在雙線圈通電處 */
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: /*觸發(fā)HP位置后的調(diào)整*/
{
bspDotprntSetTimer(PD);
WAIT();
g_ucprntTimerInt = 0;
ucCRRunMode = 1;
uiCRRunSteps = 0;
break;
}
default:
break;
}
}
}
return SUCCESS;
}
/*
**************************************************
*
* 函數(shù)名:bspDotPrntPFmotorInit
*
* 功 能:穿孔打印機進紙電機初始化定位函數(shù)
*
* 輸 入: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;
}
/*
**************************************************
*
* 函數(shù)名:bspCKPrntCRLRPhase
*
* 功 能:穿孔打印機CR電機正、反向驅(qū)動相序
*
* 輸 入:s_ucprntCRphase
*
* 輸 出:無
*
* 返 回:SUCCESS----處理成功
*
***************************************************
*/
INT1 bspDotPrntCRPhase
(
UINT1 _ucDirection /* 0 反向驅(qū)動相序, 1 正向驅(qū)動相序 */
)
{
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;
}
/*
**************************************************
*
* 函數(shù)名:bspDotPrntPFPhase
*
* 功 能:穿孔打印機進紙電機正、反向驅(qū)動相序
*
* 輸 入: 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) /* 非黑標紙進紙步數(shù)統(tǒng)計 */
{
if (_ucDirection)
{
g_usprntPaperLen3 ++;
}
else if ((!_ucDirection) && ( g_usprntPaperLen3 >= 2 ))
{
g_usprntPaperLen3 --;
}
}
else /* 黑標紙步數(shù)統(tǒng)計 */
{
if (_ucDirection)
{
g_usprntPaperLen1 ++;
g_usprntPaperLen2 ++;
}
else if ((!_ucDirection) && ( g_usprntPaperLen2 >= 2 ))
{
g_usprntPaperLen1 --;
g_usprntPaperLen2 --;
}
}
return;
}
/*
***************************************************
*
* 函數(shù)名:bspDotCRLeft2RightDrive
*
* 功 能:穿孔打印機正向打印一行數(shù)據(jù)
*
* 輸 入:g_ucprntPattern1
*
* 輸 出:無
*
* 返 回:N/A
*
***************************************************
*/
void bspDotCRLeft2RightDrive(void)
{
UINT1 ucCRRunFlag = 1;
UINT2 ucCRRunSteps = 0;
UINT1 ucCRRunMode = 0;
bspDotPrntSetCurrentLevel(LOW_CURRENT);
/* 設(shè)置PU時間,讓出CPU執(zhí)行 */
OSTimeDly(1);
/*禁止任務(wù)切換 */
OSSchedLock();
bspDotPrntSetCurrentLevel(HIGH_CURRENT);
while (ucCRRunFlag)
{
switch (ucCRRunMode)
{
case 0: /* 設(shè)置驅(qū)動電流為滿電流 */
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;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -