《单片机控制打印机例程(北京荣达-并口)》由会员分享,可在线阅读,更多相关《单片机控制打印机例程(北京荣达-并口)(8页珍藏版)》请在金锄头文库上搜索。
1、/* / 新荣达电子打印机测试程序 / 51 单片机,晶振 11.0592 /时间:2009-7-10 /用与测试并行接口打印机 /常用打印机指令以函数行式体现 /可根据需要自行调用单一函数 */ #include/51 头文件 #include /字串处理函数头文件 #include #define uchar unsigned char sbit BUSY=P34; /并口打印机的 BUSY,串口打印机的 CTS sbit STB =P35; /打印机 STB 接 P3.5 unsigned char dat=“新荣达电子测试程序,ABCDEFG123456“; /测试数据/-单字节打印函
2、数-void print(unsigned char ch) while (BUSY=1) /busy 为 1 时,等待; P1= ch; /busy=0,将数据送到 P1 口STB = 0; /STB 置 0; /空语句,延时使 STB1umSTB = 1; /STB 置 1 /*打印字串函数*/ void print_chs(uchar ch) uchar i; for(i=0;i /unsigned int Y,YY,X; print(0x1b);print(0x40);/初始化指令 print(0x1b);print(0x38);print(0x00); /调用 16*16 点阵汉字,
3、24 点阵为 24*24 print_chs(“曲线 1 测试:n“); for(X=0;X /unsigned int Y,YY,X; print(0x1b);print(0x40);/初始化指令 print(0x1b);print(0x38);print(0x00); /调用 16*16 点阵汉字,24 点阵为 24*24 print_chs(“曲线 2 测试:n“); for(X=0;X150;X+)/打印 150 点行 Y= 40*exp(-0.01*X);YY= Y*sin(X/10);print(0x1b);print(39);print(5); /ESC 命令,M=5print(
4、50+YY);print(50-YY);print(50);print(50+Y);print(50-Y);print(13); /*旋转指令例程*/ void xuanzhuan(void) uchar i; print(0x1b);print(0x40);/初始化指令 for(i=0;i4;i+) /0,90,180,270 旋转 print(0x1c);print(0x49);print(i); /旋转指令 print(0x1b);print(0x38);print(0);/汉字调出指令 print_chs(“旋转测试“);/打印汉字 print(0x0d); /回车 /*反白指令例程*
5、/ void fanbai(void) uchar i; print(0x1b);print(0x40);/初始化指令 for(i=0;i2;i+) /i 为 1 时,反白打印 print(0x1b);print(0x69);print(i); print(0x1b);print(0x38);print(0); print_chs(“反白测试“); print(0x0d); /*反向指令例程*/ void fanxiang(void) uchar i; print(0x1b);print(0x40);/初始化指令 for(i=0;i2;i+)/i 为 1 时,禁止反向 print(0x1b);
6、print(0x63);print(i); print(0x1b);print(0x38);print(0); print_chs(“反向测试“); print(0x0d); /*条码指令例程*/ /只有部分型号的打印机支持此指令 void tiaoma(void) print(0x1b);print(0x40);/初始化指令print(0x1d);print(0x72);print(0x01);/打印条码字符 print(0x1d);print(0x68);print(0x60);/设置条码高度为 96 点 print(0x1d);print(0x6B);print(0x45);print(
7、8);/打印长度为 8 的 CODE39 码 print(0x2a);print(0x31);print(0x32);print(0x34);print(0x35);print(0x37);print(0x36);print(0x2a); /CODE39 码数据 print(0x0d);/回车 print(0x1d);print(0x6B);print(3); /打印 EAN13 码 print(0x32);print(0x37);print(0x30);print(0x38);print(0x35);print(0x38);print(0x35);print(0x30); /EAN13 码数
8、据 print(0x30);print(0x39);print(0x32);print(0x34);print(0x38);print(0x00); print(0x0d);/回车 Main() hanzitest(); hangjianju(); shuipingzhaobiao(); konggehuanhang(); youxian(); fangda(); huaxian(); shangxiabiao(); hengzhong(); zhuoxian(); zidingyi(); tuxing(); quxian_2();/如用针打打印机将此函数去掉 quxian_1();/如用热敏打印机将此函数去掉 xuanzhuan(); fanbai(); fanxiang(); tiaoma(); print(0x0d); /回车 print(0x0d); /回车 print(0x0d); /回车 while(1); /死循环