sbit prn_busy=P1^3; //打印机是否忙P3.0 sbit stb=P3^0; //数据选通 bit PRN_TAG; code unsigned char word_buf1[]="测试时间";
void WAIT_PRN(char tem) //等待打印机空闲 打印一个字符 { unsigned char i,prn_return; prn_return=0; for(i=0;i<40;i++) { if(prn_busy==0) //prn_busy=0打印机空闲;prn_busy=1打印机忙 { P2=0x1f; P0=tem; stb=0; _nop_(); _nop_(); _nop_(); stb=1; prn_busy=1; prn_return=1; break; } } if (prn_return==1) PRN_TAG=1; //PRN_TAG=1 打印结束;PRN_TAG=0 打印没有结束 else PRN_TAG=0; } void INIT_PRN() //初始化打印机 { WAIT_PRN(0x1B); //初始化命令 WAIT_PRN(0x40); WAIT_PRN(0x1B); // WAIT_PRN(0x31); WAIT_PRN(0xff); WAIT_PRN(0x1B); // WAIT_PRN(0x20); WAIT_PRN(0x05); } void PRN_DISP_0808(bit TYPE,unsigned char *p,unsigned char longness) //打印8*8点阵汉字 { unsigned char m; m=TYPE; WAIT_PRN(0X1B); //图形打印命令 WAIT_PRN(0x38); WAIT_PRN(0X00); for(;longness>0;) { WAIT_PRN((*p++)); //直接向打印机送内码 } WAIT_PRN(0X0d); } main() { delay_time(1); INIT_PRN(); while(1) { PRN_DISP_0808(1,word_buf1,sizeof(word_buf0)); } } |