欢迎来到淘文阁 - 分享文档赚钱的网站! | 帮助中心 好文档才是您的得力助手!
淘文阁 - 分享文档赚钱的网站
全部分类
  • 研究报告>
  • 管理文献>
  • 标准材料>
  • 技术资料>
  • 教育专区>
  • 应用文书>
  • 生活休闲>
  • 考试试题>
  • pptx模板>
  • 工商注册>
  • 期刊短文>
  • 图片设计>
  • ImageVerifierCode 换一换

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

    • 资源ID:42293883       资源大小:40KB        全文页数:9页
    • 资源格式: DOC        下载积分:8金币
    快捷下载 游客一键下载
    会员登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录   QQ登录  
    二维码
    微信扫一扫登录
    下载资源需要8金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

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

    /*/ 新荣达电子打印机测试程序/ 51单片机,晶振11.0592/时间:2009-7-10/用与测试串行接口打印机/常用打印机指令以函数行式体现/可根据需要自行调用单一函数*/#include<reg52.h>/51头文件#include<string.h> /字串处理函数头文件 #include<math.h>#define uchar unsigned charsbit BUSY=P34; /并口打印机的BUSY,串口打印机的CTS /*单字节打印函数*/void print(unsigned char ch)while (BUSY=1) /busy为1时,等待,如数据量小,可不判BUSY ; SBUF= ch; /busy=0,将数据送到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;i<strlen(ch);i+)print(chi);/*汉字打印例程*/void hanzitest(void)uchar i;print(0x1b);print(0x40); /初始化打印机print(0x1b);print(0x38);print(0x00); /调用16*16点阵汉字,24点阵为24*24print_chs("汉字命令测试:n");for(i=0;i<5;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(0xc8);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;i<11;i=i+2) /循环打印print(0x1b);print(0x31);print(i); /ESC 1,设置行间距print_chs("LINE SPACING");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_chs("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);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*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(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;i<4;i+) /从1到3倍print (0x1b);print(0x55);print(i); /横向放大print_chs("RD"); /打印字符print(0x0d); /回车命令print(0x1b);print(0x40); /初始化打印机for(i=1;i<4;i+) /从1到3倍print (0x1b);print(0x56);print(i); /纵放命令print_chs("RD"); /打印字符print(0x0d); /回车print(0x1b);print(0x40); /初始化打印机for(i=1;i<4;i+) /从1到3倍 print (0x1b);print(0x57);print(i); /横纵向同时放大print_chs("RD"); /打印字符print(0x0d); /回车/*划线指令例程*/void huaxian(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("RD"); /打印字串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(void)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'); /打印字符'M'print(0x1b);print(0x57);print(0x01); /原倍print(0x1c);print(0x72);print(0); /上标命令print('2'); /打印字符'2'print(0x0d); /回车print(0x1b);print(0x57);print(0x01); /原倍print(0x1b);print(0x57);print(0x02); /放大两倍print('M'); /打印字符'M'print(0x1c);print(0x72);print(1); /上标命令print(0x1b);print(0x57);print(0x01); /原倍print('2'); /打印字符'2'print(0x0d); /回车/*横纵向指令例程*/void hengzhong(void)print(0x1b);print(0x40);print(0x1b);print(0x38);print(0x00); /调用16*16点阵汉字,24点阵为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点阵汉字,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(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(0x00); /调用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;i<15;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-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 <math.h>/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;X<150;X+)/打印150点行 Y= 40*exp(-0.01*X); YY= Y*sin(X/10); print(0x1b);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/Y4=50+40*abs(-0.1*X)/Y5=50-40*abs(-0.01*X)/你可以用C语言编写如下的程序:/#include <math.h>/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;X<150;X+)/打印150点行 Y= 40*exp(-0.01*X); YY= Y*sin(X/10); print(0x1b);print(39);print(5); /ESC命令,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;i<4;i+) /0,90,180,270旋转print(0x1c);print(0x49);print(i); /旋转指令print(0x1b);print(0x38);print(0);/汉字调出指令print_chs("旋转测试");/打印汉字print(0x0d); /回车/*反白指令例程*/void fanbai(void)uchar i;print(0x1b);print(0x40);/初始化指令for(i=0;i<2;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;i<2;i+)/i为1时,禁止反向print(0x1b);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(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码数据print(0x30);print(0x39);print(0x32);print(0x34);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

    注意事项

    本文(单片机控制打印机例程(北京荣达-串口).doc)为本站会员(可****阿)主动上传,淘文阁 - 分享文档赚钱的网站仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知淘文阁 - 分享文档赚钱的网站(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于淘文阁 - 版权申诉 - 用户使用规则 - 积分规则 - 联系我们

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

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

    收起
    展开