📄 main.c
字号:
/*****************************************************************************
* 热敏打印机入口模块
*
* 文件名:main.c
* 作者: 肖波
* 修改记录:2006.12.02
******************************************************************************/
#include "print.h"
extern void init_print(void);
extern void mainctrl(void);
extern unsigned char bdata STATUS;
extern bit no_paper;
extern bit rece_full;
rece_data txdata;
unsigned char xdata rece_buf[rece_buf_size];
#ifdef downhzk
static unsigned char iRcpStep=0;
static unsigned char bitRcpOver=0;
static unsigned char iRcpBuf=0;
static unsigned long int iHzkStep=0;
#endif
#ifdef hardtest
extern bit ReadFlashString(unsigned long int addr,unsigned char *xpBuf,unsigned int Number);
#endif
void sendsta(unsigned char iSta) //发送打印状态码(能接收下一个字符:不忙,XON)
{
TI = 0;
SBUF = iSta;
while(!TI); TI = 0;
}
//如果要采用软件或硬件流控制协议,此函数和串口中断均需修正
bit get_rece_data(unsigned char *rece_data)
{
if(txdata.head==txdata.tail)
{
if(rece_full)
{
*rece_data=read_byte(rece_buf[txdata.head]);
txdata.head=(txdata.head+1)%rece_buf_size;
rece_full=0;
return true;
}
else {return false;}
}
*rece_data=read_byte(rece_buf[txdata.head]);
txdata.head=(txdata.head+1)%rece_buf_size;
return true;
}
static void wait_start(void)
{
unsigned char cmd; //字符序列 startprint
while(1)
{
while(!get_rece_data(&cmd));
if(cmd!='s') continue;
sendsta('s');
while(!get_rece_data(&cmd));
if(cmd!='t') continue;sendsta('t');
while(!get_rece_data(&cmd));
if(cmd!='a') continue;sendsta('a');
while(!get_rece_data(&cmd));
if(cmd!='r') continue;sendsta('r');
while(!get_rece_data(&cmd));
if(cmd!='t') continue;sendsta('t');
while(!get_rece_data(&cmd));
if(cmd!='p') continue;sendsta('p');
while(!get_rece_data(&cmd));
if(cmd!='r') continue;sendsta('r');
while(!get_rece_data(&cmd));
if(cmd!='i') continue;sendsta('i');
while(!get_rece_data(&cmd));
if(cmd!='n') continue;sendsta('n');
while(!get_rece_data(&cmd));
if(cmd=='t') break;
}
sendsta('t');
}
void main(void)
{
#ifdef hardtest
unsigned char data loop,test,temp[16];
unsigned long int data addr;
#endif
AUXR=0X02; //STC89C52 DISABLE EXTERN RAM
STB123 = 0; STB456 = 0;
TMOD = B0001_0001; //T0,T1 方式1 16位计数器
//************串行口初始化**************************
T2CON = B0011_0100; //T2波特率发生器
// TH2 = RCAP2H = 0xff; //BAUT=9600, 11.0592M,
// TL2 = RCAP2L = 0xdc;
TH2 = RCAP2H = 0xff; //BAUT=9600, 40M,
TL2 = RCAP2L = 0x7e;
SCON = B0101_0000; //方式1; ren=1:允许串行接受
//**************************************
// 中 断 初 始 化
IE = B0001_0000; //ES=1, EA=0
// IP = B0000_0010; //高优先级:ET0,
IP = B0001_0000; //高优先级:ES,
txdata.tail=txdata.head=0;
LED_CTS=0;
EA = 1;
// wait_start();
#ifdef hardtest
while(1)
{
if(!get_rece_data(&test)) continue;
sendsta(test);
switch(test)
{
case 0x01:
while(!get_rece_data(&test));
addr=(unsigned long int)test<<24;
while(!get_rece_data(&test));
addr|=(unsigned long int)test<<16;
while(!get_rece_data(&test));
addr|=(unsigned long int)test<<8;
while(!get_rece_data(&test));
addr|=(unsigned long int)test;
if(!ReadFlashString(addr,temp,16)) {sendsta(0x55);break;}
for(loop=0;loop<16;loop++) sendsta(temp[loop]);
break;
}
}
#endif
#ifdef downhzk
for(;;) //下载字库
{
if(bitRcpOver)
{ ES=0;
bitRcpOver=0;
if(iHzkStep==0x0ffff) {sendsta(XON);break;}
if(WriteFlashString((unsigned long int)iHzkStep*256,txdata.rece_buf,256))
sendsta(XON);
else sendsta(XOFF);
ES=1;
}
}
while(1);
#endif
init_print();
LED_CTS=1;
mainctrl(); //主控循环
}
void INT_SIO(void) interrupt 4 //打印命令或数据
{
#ifdef downhzk
unsigned char i,icheck;
#endif
if(!RI) return;
RI = 0;
#ifdef downhzk
i = SBUF; //i <- 接收的数据
if(iRcpStep==0)
{
icheck = 0;
bitRcpOver = 0;iRcpStep++;
if(i==0xaa)return;
else
{iRcpStep = 0; return;}
}
if(iRcpStep==1)
{
iRcpStep++;
if(i==0xaa) return; //判断报文头
else
{iRcpStep = 0; return;}
}
if(iRcpStep==2)
{
iRcpStep++;
icheck ^=i;
iHzkStep = (unsigned long int)i;
iHzkStep<<=8;
return;
}
if(iRcpStep==3)
{
iRcpStep++;
icheck ^=i;
iHzkStep+= (unsigned long int)i;
if(iHzkStep==0xffff) iRcpStep++;
return;
}
if(iRcpStep==4)
{
icheck ^=i;
txdata.rece_buf[iRcpBuf]=i;
if(iRcpBuf==0xff) iRcpStep++;
else iRcpBuf++;
return;
}
if(iRcpStep==5)
{
if(icheck ==i)
bitRcpOver = 1;
iRcpStep = 0;
iRcpBuf = 0;
icheck = 0;
return;
}
#else
sendsta(SBUF); //ZS
rece_buf[txdata.tail]=SBUF;
//sendsta((&rece_buf[txdata.tail]));
// sendsta(rece_buf[txdata.tail]); //ZS
txdata.tail=(txdata.tail+1)%rece_buf_size;
if(txdata.head==txdata.tail)
rece_full=1;
return;
#endif
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -