单片机控制打印机例程(北京荣达-串口).doc

上传人:可****阿 文档编号:42293883 上传时间:2022-09-15 格式:DOC 页数:9 大小:40KB
返回 下载 相关 举报
单片机控制打印机例程(北京荣达-串口).doc_第1页
第1页 / 共9页
单片机控制打印机例程(北京荣达-串口).doc_第2页
第2页 / 共9页
点击查看更多>>
资源描述

《单片机控制打印机例程(北京荣达-串口).doc》由会员分享,可在线阅读,更多相关《单片机控制打印机例程(北京荣达-串口).doc(9页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、/*/ 新荣达电子打印机测试程序/ 51单片机,晶振11.0592/时间:2009-7-10/用与测试串行接口打印机/常用打印机指令以函数行式体现/可根据需要自行调用单一函数*/#include/51头文件#include /字串处理函数头文件 #include#define uchar unsigned charsbit BUSY=P34; /并口打印机的BUSY,串口打印机的CTS /*单字节打印函数*/void print(unsigned char ch)while (BUSY=1) /busy为1时,等待,如数据量小,可不判BUSY ; SBUF= ch; /busy=0,将数据送到

2、P1口while(TI=0)/当TI为0时,表示数据未发送完成,一直等待,直到为1;TI=0;/将TI清0/*串口初始化*/void _init(void) TH1=0XFD; /波特率值装入计数器,9600BPSTMOD=0X20; /串口设置,定时器1,设为方式2,8位自动重载,用于产生波特率SCON=0X50; /串口发送方式1,8位数据位,1位停止位TR1=1;/开启定时器1 /*字符打印函数*/void print_chs(uchar ch)uchar i;for(i=0;istrlen(ch);i+)print(chi);/*汉字打印例程*/void hanzitest(void)

3、uchar i;print(0x1b);print(0x40); /初始化打印机print(0x1b);print(0x38);print(0x00); /调用16*16点阵汉字,24点阵为24*24print_chs(汉字命令测试:n);for(i=0;i5;i+) /搋环打印5次print(0x1b);print(0x38);print(0x00); /调用16*16点阵汉字,24点阵为24*24print(0xd0);print(0xc2);/打印数据新print(0x1b);print(0x38);print(0x04);/调用12*12点阵汉字,24点阵为24*24print(0xc

4、8);print(0xd9);print(0xb4);print(0xef);/打印数据“荣达”print(0x0d);/回车/*行间距例程*/void hangjianju(void)uchar i;print(0x1b);print(0x40); /初始化打印机print(0x1b);print(0x38);print(0x00); /调用16*16点阵汉字,24点阵为24*24print_chs(行间距测试:n);for(i=0;i11;i=i+2) /循环打印print(0x1b);print(0x31);print(i); /ESC 1,设置行间距print_chs(LINE SPA

5、CING);print(0x0a); /打印字符串和换行/*水平造表例程*/void shuipingzhaobiao(void)print(0x1b);print(0x40); /初始化打印机print(0x1b);print(0x38);print(0x00); /调用16*16点阵汉字,24点阵为24*24print_chs(水平造表测试:n);print_chs(23456);/ 标尺print(0x0d);print(0x1b);print(0x44);print(2);print(9);print(14);print(0);/ESC Dprint(9); /HT命令print_ch

6、s(HT1); /打印字符串print(9); /HT命令print_chs(HT2); /打印字符串print(9); /HT命令print_chs(HT3); /打印字符串print(0x0d);/*打印空格或换行例程*/void konggehuanhang(void)print(0x1b);print(0x40); /初始化打印机print(0x1b);print(0x38);print(0x00); /调用16*16点阵汉字,24点阵为24*24print_chs(换行或空格测试:n);print_chs(TE); /打印字符串“TE”print(0x1b);print(0x66);

7、print(0);print(0x06);/空六格print_chs(ST); /打印字符串“ST”print(0x0d); /回车print_chs(TE); /打印字符串“TE”print(0x1b);print(0x66);print(0x01);print(0x06);/换6行print_chs(ST); /打印字符串“ST”print(0x0d); /回车/*右限例程*/void youxian(void)print(0x1b);print(0x40); /初始化打印机print(0x1b);print(0x38);print(0x00); /调用16*16点阵汉字,24点阵为24*

8、24print_chs(右限测试:n);print_chs(9012);/标尺print(0x1b);print(0x51);print(0x06); /ESC Q 命令,右限为6print_chs(9012);/打印字串print(0x0d); /回车/*左限例程*/void zhuoxian(void)print(0x1b);print(0x40); /初始化打印机print(0x1b);print(0x38);print(0x00); /调用16*16点阵汉字,24点阵为24*24print_chs(左限测试:n);print_chs(9012);/标尺print(0x1b);print

9、(0x6c);print(0x06); /ESC I 命令,左限为6print_chs(9012);/打印字串print(0x0d); /回车/*放大指令例程*/void fangda(void)uchar i;print(0x1b);print(0x40); /初始化打印机print(0x1b);print(0x38);print(0x00); /调用16*16点阵汉字,24点阵为24*24print_chs(放大测试:n);for(i=1;i4;i+) /从1到3倍print (0x1b);print(0x55);print(i); /横向放大print_chs(RD); /打印字符pri

10、nt(0x0d); /回车命令print(0x1b);print(0x40); /初始化打印机for(i=1;i4;i+) /从1到3倍print (0x1b);print(0x56);print(i); /纵放命令print_chs(RD); /打印字符print(0x0d); /回车print(0x1b);print(0x40); /初始化打印机for(i=1;i4;i+) /从1到3倍 print (0x1b);print(0x57);print(i); /横纵向同时放大print_chs(RD); /打印字符print(0x0d); /回车/*划线指令例程*/void huaxian(

11、void)print(0x1b);print(0x40); /初始化打印机print(0x1b);print(0x38);print(0x00); /调用16*16点阵汉字,24点阵为24*24print_chs(划线测试:n);print(0x1b);print(0x57);print(2);/放大两倍打印,便于观察划线print_chs(RD); /打印字串print(0x1b);print(0x2d);print(1);/允许下划线打印print_chs(UPT); /UPT打印下划线print(0x1b);print(0x2d);print(0);/禁止下划线打印print_chs(R

12、D); /打印字串print(0x0d); /回车print(0x1b);print(0x40); /初始化打印机print(0x1b);print(0x57);print(2);/放大两倍打印,便于观察划线print_chs(RD); /打印字串print(0x1b);print(0x2b);print(1);/允许上打印线打印print_chs(UPT); /UPT上打印上划线print(0x1b);print(0x2b);print(0);/禁止上划线 print_chs(RD);/打印字串print(0x0d);/打印回车/*上下标指令例程*/void shangxiabiao(voi

13、d)print(0x1b);print(0x40); /初始化打印机print(0x1b);print(0x38);print(0x00); /调用16*16点阵汉字,24点阵为24*24print_chs(上下标测试:n);print(0x1b);print(0x57);print(0x02); /放大两倍print(M); /打印字符Mprint(0x1b);print(0x57);print(0x01); /原倍print(0x1c);print(0x72);print(0); /上标命令print(2); /打印字符2print(0x0d); /回车print(0x1b);print(

14、0x57);print(0x01); /原倍print(0x1b);print(0x57);print(0x02); /放大两倍print(M); /打印字符Mprint(0x1c);print(0x72);print(1); /上标命令print(0x1b);print(0x57);print(0x01); /原倍print(2); /打印字符2print(0x0d); /回车/*横纵向指令例程*/void hengzhong(void)print(0x1b);print(0x40);print(0x1b);print(0x38);print(0x00); /调用16*16点阵汉字,24点阵

15、为24*24print_chs(横纵向测试:n);print(0x1c);print(0x4a); /设置纵向打印print_chs(ABCDEFGHI); /打印字符print(0x0d); /回车 print(0x1b);print(0x40);print(0x1C);print(0x4B); /设置横向打印print_chs(ABCDEFGHI); /打印字符print(0x0d); /回车 /*自定义指令例程*/void zidingyi(void)print(0x1b);print(0x40); /初始化指令print(0x1b);print(0x38);print(0x00); /

16、调用16*16点阵汉字,24点阵为24*24print_chs(自定义字符测试:n);print(0x1b);print(0x36); /如是24点阵机器,在自定义字符前面要加一个1B 36 指令才行print(0x1b);print(0x57);print(2); /横向纵向放大2倍print(0x1b);print(0x26);print(65); /ESC & 命令print(0x02);print(0x7C);print(0x40); /字模数据print(0xC0);print(0x40);print(0x00); /字模数据print(0x1b);print(0x25);print

17、(65);print(65);print(0); /ESC %print(65); /打印定义字符print(0x1b);print(0x3a); /ESC:命令print(65); /复符集中的字符print(0x0d);/*图形指令例程*/void tuxing(void)uchar code tch =0x7c,0x44,0x44,0xff,0x44,0x44,0x7c,0x00,0x41,0x62,0x54,0xc8,0x54,0x62,0x41;uchar i;print(0x1b);print(0x40);/初始化指令print(0x1b);print(0x38);print(0x

18、00); /调用16*16点阵汉字,24点阵为24*24print_chs(图形测试:n);/print(0x1b);print(0x57);print(2);/横向纵向放大2倍print(0x1b);print(0x4b);print(15);print(0); /ESC K命令for(i=0;i15;i+)/输入15个字节数据print(tchi);print(0x0d);/输入回车/*曲线II指令例程*/仅适用于热敏打印机void quxian_2(void) float X;unsigned int Y,YY;/Y1=50+40*abs(-0.01*X)*sin(X/10)/Y2=50

19、-40*abs(-0.01*X)*sin(X/10)/Y3=50/Y4=50+40*abs(-0.1*X)/Y5=50-40*abs(-0.01*X)/你可以用C语言编写如下的程序:/#include /unsigned int Y,YY,X;print(0x1b);print(0x40);/初始化指令print(0x1b);print(0x38);print(0x00); /调用16*16点阵汉字,24点阵为24*24print_chs(曲线1测试:n);for(X=0;X150;X+)/打印150点行 Y= 40*exp(-0.01*X); YY= Y*sin(X/10); print(0

20、x1b);print(39);print(5);print(0); /ESC命令,M=5,0 print(50+YY);print(0);print(50-YY);print(0);print(50);print(0); print(50+Y);print(0);print(50-Y);print(0);print(13); /*曲线I指令例程*/仅适用于针式打印机void quxian_1(void) float X;unsigned int Y,YY;/Y1=50+40*abs(-0.01*X)*sin(X/10)/Y2=50-40*abs(-0.01*X)*sin(X/10)/Y3=50

21、/Y4=50+40*abs(-0.1*X)/Y5=50-40*abs(-0.01*X)/你可以用C语言编写如下的程序:/#include /unsigned int Y,YY,X;print(0x1b);print(0x40);/初始化指令print(0x1b);print(0x38);print(0x00); /调用16*16点阵汉字,24点阵为24*24print_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命令,

22、M=5 print(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); /回车/*反白指令例程*/

23、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);print(0x63);print(i);p

24、rint(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(8);/打印长度为8的CODE39码print(0x2a);print

25、(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码数据print(0x30);print(0x39);print(0x32);print(0x34

26、);print(0x38);print(0x00);print(0x0d);/回车Main()_init();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); /死循环9 / 9

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 应用文书 > 工作计划

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁