?? 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 + -