📄 printfunction.c
字号:
#include "upsd3200.h"
#include "printfunction.h"
#include "main.h"
//8*8
u8 code zimu[]={0x1F,0x61,0x18,0x07,0x18,0x61,0x1F,0x01};/*"w",0*/
//#define
u16 code PACCTime[]={700,463,355,300,264,239,219,204,192,181,173,165
,158,152,147,142,138,134,130,127};
u16 code PDECTime[]={125,125,167,250};
u16 code ACCTime[]={490,236,189,164,149,138,130,124,119,114,105,105,105};
u16 code DECTime[]={105,105,108,114,122,131,142,157,178,211,275,600,620};
/*******************************************************************************
* Function Name :PressKeyPaperIn
* Description :按键进纸
* Input :none
* Return :none
*******************************************************************************/
void PressKeyPaperIn(void)
{
}
/*******************************************************************************
* Function Name :PrintInitial
* Description :打印机初始化
* Input :none
* Return :none
*******************************************************************************/
void PrintInitial(void)
{
struct buffer xdata *buf=printbufferaddr;
u8 *pbuf;
u16 buflength=printbufferlength;
pbuf=buf->pb;
while(buflength!=0)
{
*pbuf=0;
buflength++;
}
DataInitial();
}
/*******************************************************************************
* Function Name :AutoPaperIn
* Description :自动送纸
* Input :none
* Return :none
*******************************************************************************/
void AutoPaperIn(void)
{
u8 data paper, data temp,i;
paper=PaperSensor;
if(paper==FALSE)
{
temp=1;
}
if(temp==TRUE)
{
if(paper!=FALSE)
{
temp=0;
for(i=0;i<4;i++)
{
delay(50000);//等待500毫秒
}
PaperSpeedUpForward(PFP);//走纸加速前进20步
PaperConstantSpeedForward(PFP,240);//走纸常速前进60步
PaperConstantSpeedForward(PFP,240);//走纸常速前进60步
PaperConstantSpeedForward(PFP,240);//走纸常速前进60步
PaperSpeedDownForward(PFP);//走纸减速前进2步
PaperIOFF;
}
}
}
/*******************************************************************************
* Function Name :NoPaperDeal
* Description :无纸处理
* Input :none
* Return :none
*******************************************************************************/
void NoPaperDeal(void)
{
u8 data temp;
if(PaperSensor==FALSE)
{
PaperSpeedUpForward(PFP);//走纸加速前进20步
PaperConstantSpeedForward(PFP,40);//走纸常速前进60步
PaperSpeedDownForward(PFP);//走纸减速前进2步
PaperIOFF;
temp=0;
XBYTE[havepapertime]=0;
while(temp==FALSE)
{
if(PaperSensor!=0&&XBYTE[havepapertime]>=100)
{
PaperSpeedUpForward(PFP);//走纸加速前进20步
PaperConstantSpeedForward(PFP,240);//走纸常速前进60步
PaperConstantSpeedForward(PFP,240);//走纸常速前进60步
PaperConstantSpeedForward(PFP,240);//走纸常速前进60步
PaperSpeedDownForward(PFP);//走纸减速前进2步
PaperIOFF;
if(PaperSensor==FALSE)
{
temp=0;
XBYTE[havepapertime]=0;
}
else
{
temp=1;
}
}
else
{
temp=0;
}
if(PaperSensor==FALSE)
{
temp=0;
XBYTE[havepapertime]=0;
}
}
}
}
/*******************************************************************************
* Function Name :WriteStatusMessage
* Description :写状态信息
* Input :statussignal position,u8 context
* Return :none
*******************************************************************************/
void WriteStatusMessage(statussignal position,u8 context)
{
XBYTE[signaladdr+position]=context;
}
/*******************************************************************************
* Function Name :ReadStatusMessage
* Description :状态信息
* Input :statussignal position
* Return :状态内容
*******************************************************************************/
u8 ReadStatusMessage(statussignal position)
{
return(XBYTE[signaladdr+position]);
}
/*******************************************************************************
* Function Name :ReceiveData
* Description :接收数据
* Input :none
* Return :none
*******************************************************************************/
/*******************************************************************************
* Function Name :GoBeginPosition
* Description :去打印开始位置
* Input :none
* Return :none
*******************************************************************************/
void GoPrintBeginPosition(void)
{
CarriageSpeedUpLeftToRight(PhaseDirectionSwitch(CRLP));//字车右加速12步
CarriageConstantSpeedLeftToRight(CLRP,218);//字车右常速218步
CarriageSpeedDownLeftToRight(CLRP);//字车右减速12步
CarriageIOFF;
}
void ReceiveData(void)
{
struct buffer xdata *buf=printbufferaddr;
u8 *pbuf;
u16 count=0;
pbuf=buf->pb+buf->length;
//buf->length=0;
//if(ReadStatusMessage(BUSY)==FALSE)
XBYTE[receivelength]=0;
while(count!=20000)
{
if(RI==TRUE)
{
RI=0;
count=0;
*pbuf=SBUF;
pbuf++;
buf->length++;
XBYTE[receivelength]++;
if(buf->length==printbufferlength)//打印缓冲满
{
buf->length=0;
pbuf=buf->pb;
//WriteStatusMessage(ERR,1);//置溢出错
}
if(SBUF>0X1f)
XBYTE[receivemark]=1;
}
count++;
}
}
/*******************************************************************************
* Function Name :PrinterDefaltCommand
* Description :缺省命令处理
* Input :none
* Return :none
*******************************************************************************/
void PrinterDefaltCommand(void)
{
struct buffer xdata *buf=printbufferaddr;
struct rowbuffer xdata *rowbuf=rowbufferaddr;
u16 bufend;
bufend=buf->pb+printbufferlength;
XBYTE[defaltcommandmark]=1;//缺省命令标记
PrintBuffer();
if(rowbuf->count!=FALSE)
{
if(rowbuf->rowbufaddr+XBYTE[printcharcount]>=bufend)
buf->count=rowbuf->rowbufaddr+XBYTE[printcharcount]-bufend;
else
buf->count-=(rowbuf->count-XBYTE[printcharcount]);
}
}
/*******************************************************************************
* Function Name :BufferCodeDeal
* Description :缓冲代码处理
* Input :none
* Return :none
*******************************************************************************/
void BufferCodeDeal(void)
{
struct buffer xdata *buf=printbufferaddr;
struct rowbuffer xdata *rowbuf=rowbufferaddr;
u8 temp,temp1,tempreceivemark,*pbuf,endmark=0;
u16 buflength,bufend;
WriteStatusMessage(BUSY,1);
pbuf=buf->pb+buf->count;//下一个待处理的代码
bufend=buf->pb+printbufferlength;
rowbuf->count=0;//初始打印的代码个数
if(buf->length<buf->count)
{
buflength=printbufferlength-buf->count+buf->length;//代码
}
else
{
if(buf->count+XBYTE[receivelength]>printbufferlength)
buflength=0;//buf->length-buf->count+printbufferlength;置错
else
buflength=buf->length-buf->count;
}
tempreceivemark=XBYTE[receivemark];//接收数据标记
while(buflength!=0&&tempreceivemark==1)
{
if(*pbuf<0x20)
{
temp=*pbuf;
buflength--;
pbuf++;
if(pbuf==bufend)
{
pbuf=buf->pb;
}
if(temp==0x0A)//打印并换行
{
PrinterCommand(LF);
}
if(temp==0x1B)//
{
temp1=*pbuf;
buflength--;
pbuf++;
if(pbuf==bufend)
{
pbuf=buf->pb;
}
switch(temp1)
{
case 0x3C://回HOME位置
{
PrinterCommand(ESCHome);
break;
}
case 0x40://初始化打印机
{
//PrinterCommand(ESCPrintInitial);
break;
}
case 0x4A://打印并走纸1/144英寸
{
XBYTE[forwardstep]=*pbuf;
buflength--;
pbuf++;
if(pbuf==bufend)
{
pbuf=buf->pb;
}
PrinterCommand(ESCPaperForwardStep);
break;
}
case 0x4B://打印并退纸1/144英寸
{
XBYTE[backstep]=*pbuf;
buflength--;
pbuf++;
if(pbuf==bufend)
{
pbuf=buf->pb;
}
PrinterCommand(ESCPaperBackStep);
break;
}
case 0x64://打印并进纸n字符行
{
XBYTE[forwardchar]=*pbuf;
buflength--;
pbuf++;
if(pbuf==bufend)
{
pbuf=buf->pb;
}
PrinterCommand(ESCPaperForwardByte);
break;
}
case 0x65://打印并退纸n字符行
{
XBYTE[backchar]=*pbuf;
buflength--;
pbuf++;
if(pbuf==bufend)
{
pbuf=buf->pb;
}
PrinterCommand(ESCPaperBackByte);
break;
}
case 0x55://设置/取消单向打印
{
//暂未做
buflength--;
pbuf++;
if(pbuf==bufend)
{
pbuf=buf->pb;
}
break;
}
defalut:
{
break;
}
}
}
if(temp==0x1C)
{
temp1=*pbuf;
buflength--;
pbuf++;
if(pbuf==bufend)
{
pbuf=buf->pb;
}
switch(temp1)
{
case 0x26:
{
PrinterCommand(FSEnterChinese);
break;
}
case 0x2E:
{
PrinterCommand(FSExitChinese);
break;
}
// defalut:{break;}
}
}
if(temp==0x1d)
{
temp1=*pbuf;
buflength--;
pbuf++;
if(pbuf==bufend)
{
pbuf=buf->pb;
}
switch(temp1)
{
case 0x0c:
{
break;
}
case 0x28:
{
break;
}
}
}
buf->count=pbuf-buf->pb;
rowbuf->count=0;//初始行缓冲大小
}
else
{
if(rowbuf->count==FALSE)
rowbuf->rowbufaddr=pbuf; //指向行缓冲首地址
rowbuf->count++;
buflength--;
pbuf++;
buf->count=pbuf-buf->pb;
if(pbuf==bufend)
{
pbuf=buf->pb;
}
}
if(buflength==FALSE)
endmark=1;
}
if(rowbuf->count!=0)//&&XBYTE[receivemark]==1)
{
PrinterDefaltCommand();
}
if(endmark==TRUE)
{
if(tempreceivemark==TRUE)
{
XBYTE[receivemark]=0;
XBYTE[receivelength]=0;
}
}
//rowbuf->count=0;
PaperIOFF;
CarriageIOFF;
}
/*******************************************************************************
* Function Name :PrinterCommand
* Description :打印命令
* Input :commands command
* Return :none
*******************************************************************************/
void PrinterCommand(commands command)
{
u8 temp;
switch(command)
{
case LF:
{
//PaperSlowSpeedForward(PFP,XBYTE[charrowinterval]);//慢速走纸n步
XBYTE[defaltcommandmark]=0;//缺省命令标记置0
PrintBuffer();//打印缓冲
PaperSlowSpeedForward(PFP,XBYTE[charrowinterval]+16);//慢速走纸16步
PaperHold(0);//走纸相位保持
break;}
case ESCHome:
{
PrinterPowerUpInitial();//回HOME位置
break;}
case ESCPrintInitial:
{
PrintInitial();
break;}
case ESCPaperForwardStep:
{
XBYTE[defaltcommandmark]=0;//缺省命令标记置0
PrintBuffer();//打印缓冲
temp=XBYTE[forwardstep];
if(temp<8)
PaperSlowSpeedForward(PFP,16+temp);//走纸n步
else
{
PaperSpeedUpForward(PFP);//走纸加速20步
PaperConstantSpeedForward(PFP,temp-8);//走纸常速temp步
PaperSpeedDownForward(PFP);//走纸减速4步
}
PaperHold(0);//走纸相位保持
break;}
case ESCPaperBackStep:
{
XBYTE[defaltcommandmark]=0;//缺省命令标记置0
PrintBuffer();//打印缓冲
temp=XBYTE[backstep];
if(temp<8)
PaperSlowSpeedBack(PhaseDirectionSwitch(PFP),16+temp);//退纸n步
else
{
PaperSpeedUpBack(PhaseDirectionSwitch(PFP));//退纸加速20步
PaperConstantSpeedBack(PBP,temp-8);//退纸常速temp步
PaperSpeedDownBack(PBP);//退纸减速4步
}
PaperHold(0);//走纸相位保持
break;}
case ESCPaperForwardByte:
{
XBYTE[defaltcommandmark]=0;//缺省命令标记置0
PrintBuffer();//打印缓冲
temp=XBYTE[forwardchar];
temp=temp<<3;
if(temp==FALSE)
PaperSlowSpeedForward(PFP,16);//走纸n步
else
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -