单片机控制打印机例程北京荣达串口.docx
- 文档编号:27784185
- 上传时间:2023-07-05
- 格式:DOCX
- 页数:17
- 大小:17.17KB
单片机控制打印机例程北京荣达串口.docx
《单片机控制打印机例程北京荣达串口.docx》由会员分享,可在线阅读,更多相关《单片机控制打印机例程北京荣达串口.docx(17页珍藏版)》请在冰豆网上搜索。
单片机控制打印机例程北京荣达串口
/*********************************************************
// 新荣达电子打印机测试程序
// 51单片机,晶振11.0592
// 时间:
2009-7-10
// 用与测试串行接口打印机
// 常用打印机指令以函数行式体现
// 可根据需要自行调用单一函数
**********************************************************/
#include
#include
#include
#defineucharunsignedchar
sbitBUSY=P3^4; //并口打印机的BUSY,串口打印机的CTS
/**************************单字节打印函数************************************/
voidprint(unsignedcharch)
{
while(BUSY==1) //busy为1时,等待,如数据量小,可不判BUSY
{;}
SBUF=ch; //busy=0,将数据送到P1口
while(TI==0) //当TI为0时,表示数据未发送完成,一直等待,直到为1
{;}
TI=0; //将TI清0
}
/*********************串口初始化**********************************************/
voidcom_init(void)
{
TH1=0XFD; //波特率值装入计数器,9600BPS
TMOD=0X20; //串口设置,定时器1,设为方式2,8位自动重载,用于产生波特率
SCON=0X50; //串口发送方式1,8位数据位,1位停止位
TR1=1; //开启定时器1
}
/**********************字符打印函数********************************************/
voidprint_chs(ucharch[])
{
uchari;
for(i=0;i print(ch[i]); } /*************************汉字打印例程***************************************/ voidhanzitest(void) { uchari; print(0x1b);print(0x40); //初始化打印机 print(0x1b);print(0x38);print(0x00); //调用16*16点阵汉字,24点阵为24*24 print_chs("汉字命令测试: \n"); for(i=0;i<5;i++) //搋环打印5次 { print(0x1b);print(0x38);print(0x00); //调用16*16点阵汉字,24点阵为24*24 print(0xd0);print(0xc2); //打印数据"新" print(0x1b);print(0x38);print(0x04); //调用12*12点阵汉字,24点阵为24*24 print(0xc8);print(0xd9);print(0xb4);print(0xef); //打印数据“荣达” print(0x0d); //回车 } } /*************************行间距例程************************************/ voidhangjianju(void) { uchari; print(0x1b);print(0x40); //初始化打印机 print(0x1b);print(0x38);print(0x00); //调用16*16点阵汉字,24点阵为24*24 print_chs("行间距测试: \n"); for(i=0;i<11;i=i+2) //循环打印 { print(0x1b);print(0x31);print(i); //ESC1,设置行间距 print_chs("LINESPACING");print(0x0a); //打印字符串和换行 } } /*************************水平造表例程***************************************/ voidshuipingzhaobiao(void) { print(0x1b);print(0x40); //初始化打印机 print(0x1b);print(0x38);print(0x00); //调用16*16点阵汉字,24点阵为24*24 print_chs("水平造表测试: \n"); print_chs("1234567890123456");// '标尺 print(0x0d); print(0x1b);print(0x44);print (2);print(9);print(14);print(0);//ESC D print(9); //HT命令 print_chs("HT1"); //打印字符串 print(9); //HT命令 print_chs("HT2"); //打印字符串 print(9); //HT命令 print_chs("HT3"); //打印字符串 print(0x0d); } /*************************打印空格或换行例程**********************************/ voidkonggehuanhang(void) { print(0x1b);print(0x40); //初始化打印机 print(0x1b);print(0x38);print(0x00); //调用16*16点阵汉字,24点阵为24*24 print_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); //回车 } /*************************右限例程**********************************/ voidyouxian(void) { print(0x1b);print(0x40); //初始化打印机 print(0x1b);print(0x38);print(0x00); //调用16*16点阵汉字,24点阵为24*24 print_chs("右限测试: \n"); print_chs("12345678901234567890123456789012");//标尺 print(0x1b);print(0x51);print(0x06); //ESC Q命令,右限为6 print_chs("12345678901234567890123456789012");//打印字串 print(0x0d); //回车 } /*************************左限例程**********************************/ voidzhuoxian(void) { print(0x1b);print(0x40); //初始化打印机 print(0x1b);print(0x38);print(0x00); //调用16*16点阵汉字,24点阵为24*24 print_chs("左限测试: \n"); print_chs("12345678901234567890123456789012");//标尺 print(0x1b);print(0x6c);print(0x06); //ESCI命令,左限为6 print_chs("12345678901234567890123456789012");//打印字串 print(0x0d); //回车 } /*************************放大指令例程**********************************/ voidfangda(void) { uchari; print(0x1b);print(0x40); //初始化打印机 print(0x1b);print(0x38);print(0x00); //调用16*16点阵汉字,24点阵为24*24 print_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); //回车 } } /*************************划线指令例程**********************************/ voidhuaxian(void) { print(0x1b);print(0x40); //初始化打印机 print(0x1b);print(0x38);print(0x00); //调用16*16点阵汉字,24点阵为24*24 print_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); //打印回车 } /*************************上下标指令例程**********************************/ voidshangxiabiao(void) { print(0x1b);print(0x40); //初始化打印机 print(0x1b);print(0x38);print(0x00); //调用16*16点阵汉字,24点阵为24*24 print_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); //回车 } /*************************横纵向指令例程**********************************/ voidhengzhong(void) { print(0x1b);print(0x40); print(0x1b);print(0x38);print(0x00); //调用16*16点阵汉字,24点阵为24*24 print_chs("横纵向测试: \n"); print(0x1c);print(0x4a); //设置纵向打印 print_chs("ABCDEFGHI"); //打印字符 print(0x0d); //回车 print(0x1b);print(0x40); print(0x1C);print(0x4B); //设置横向打印 print_chs("ABCDEFGHI"); //打印字符 print(0x0d); //回车 } /*************************自定义指令例程**********************************/ voidzidingyi(void) { print(0x1b);print(0x40); //初始化指令 print(0x1b);print(0x38);print(0x00); //调用16*16点阵汉字,24点阵为24*24 print_chs("自定义字符测试: \n"); print(0x1b);print(0x36); //如是24点阵机器,在自定义字符前面要加一个1B36指令才行 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); } /*************************图形指令例程**********************************/ voidtuxing(void) { ucharcodetch[]={0x7c,0x44,0x44,0xff,0x44,0x44,0x7c,0x00,0x41,0x62,0x54,0xc8,0x54,0x62,0x41}; uchari; print(0x1b);print(0x40); //初始化指令 print(0x1b);print(0x38);print(0x00); //调用16*16点阵汉字,24点阵为24*24 print_chs("图形测试: \n"); // print(0x1b);print(0x57);print (2); //横向纵向放大2倍 print(0x1b);print(0x4b);print(15);print(0); //ESCK命令 for(i=0;i<15;i++) //输入15个字节数据 print(tch[i]); p
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 单片机 控制 打印机 例程 北京 串口
![提示](https://static.bdocx.com/images/bang_tan.gif)