版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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 com_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(vo
3、id)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(
4、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;i11;i=i+2) /循环打印print(0x1b);print(0x31);print(i); /ESC 1,设置行间距print_chs(LINE
5、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
6、_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(0x6
7、6);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点阵为
8、24*24print_chs(右限测试:n);print_chs();/标尺print(0x1b);print(0x51);print(0x06); /ESC Q 命令,右限为6print_chs();/打印字串print(0x0d); /回车/*左限例程*/void zhuoxian(void)print(0x1b);print(0x40); /初始化打印机print(0x1b);print(0x38);print(0x00); /调用16*16点阵汉字,24点阵为24*24print_chs(左限测试:n);print_chs();/标尺print(0x1b);print(0x6c);pr
9、int(0x06); /ESC I 命令,左限为6print_chs();/打印字串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); /打印字符print(0x0d); /回车
10、命令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(void)print(0x
11、1b);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); /打印字串prin
12、t(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)
13、;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(0x57);print(0
14、x01); /原倍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点阵为24*24print_c
15、hs(横纵向测试: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点阵汉字,2
16、4点阵为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
17、);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
18、点阵汉字,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-40*abs(-0.01
19、*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(0x1b);print(39
20、);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
21、(-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命令,M=5 print(50+
22、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); /回车/*反白指令例程*/void fanbai(v
23、oid)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);print(0x1b);print(0x38);print(0);print_chs(反向测试);print(0x0d);/*条码指令例程*/只有部分型号的打印机支持此指令void tiaoma(void) print(0x1b);print(0x40);/初始化指令print(0x1d);print(0x72);print(0x01);/打印条码字
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2024年花卉产业增值服务合作协议
- 2025版酒店物业管理租赁合同标准范本3篇
- 2024年租赁合同法律翻译3篇
- 2024年股份投资合作协议版B版
- 2024年跨境电商平台建设合同
- 2025版都市园林景观绿化项目咨询与全方位管理合同范本3篇
- 2024年甲乙双方关于城市供水管道建设的塑料管材采购合同
- 二零二五年城市绿化工程树木采购合同2篇
- 2024年跨界创意产业孵化器合作协议
- 北部湾大学《民间美术》2023-2024学年第一学期期末试卷
- 2023年昆明市重点中学物理高二上期末经典模拟试题含解析
- 试制过程记录表
- 2024届浙江省宁波市镇海区镇海中学高一物理第一学期期末质量检测试题含解析
- 耶鲁博弈论24讲全笔记
- 道路运输安全生产目标责任书
- 高中音乐-《锦鸡出山》教学课件设计
- (20)-土壤侵蚀原理-第六章混合侵蚀
- 国开大学2023年01月11026《经济学(本)》期末考试答案
- 南阳姜营机场
- 初中历史复习策略
- 常用介电常数
评论
0/150
提交评论