📄 print.c
字号:
/****************************************Copyright (c)**************************************************
**
**
**
**
**--------------File Info-------------------------------------------------------------------------------
** File name: PRINT.c
** Last modified Date:
** Last Version: 1.0
** Descriptions: 打印机驱动
**
**------------------------------------------------------------------------------------------------------
** Created by: 潘妙青
** Created date: 2002-2-25
** Version: 1.0
** Descriptions: The original version
**
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
** Version:
** Descriptions:
**
********************************************************************************************************/
#include "config.h"
#define __SRC
#include"PRINT.h"
#undef __SRC
#define PRINT_ADDRESS 0x83FEFFFF
//#define PRINT_ACKCOM (0x00000000 | (1 << 23))
#define PRINT_STBCOM (0x00000000 | (1 << 23))
#define PRINT_BUSYCOM (0x00000000 | (1 << 24))
void print_port_init(void)
{
// PINSEL0 = PINSEL0 & (~PRINT_STBCOM); //SET P0.23 GPIO
// PINSEL0 = PINSEL0 & (~PRINT_BUSYCOM); //SET P0.24 GPIO
IO0DIR = IO0DIR | PRINT_STBCOM; //SET P0.23 OUT
// IO0DIR = IO0DIR & (~PRINT_ACKCOM); //SET P0.23 IN
IO0DIR = IO0DIR & (~PRINT_BUSYCOM); //SET P0.24 IN
}
/****************************************************************************
* 名称:print_busy()
* 功能:查询打印机状态
* 入口参数:
* 出口参数:
****************************************************************************/
int print_busy(void)
{
if(IO0PIN & PRINT_BUSYCOM)
return 1;
else
return 0;
}
/****************************************************************************
* 名称:print_ack()
* 功能:查询打印机应答
* 入口参数:
* 出口参数:
****************************************************************************/
//int print_ack(void)
//{
// if(!(IO0PIN & PRINT_ACKCOM))
// return 1;
// else
// return 0;
//}
/****************************************************************************
* 名称:print_byte()
* 功能:打印一字节
* 入口参数:打印数据
* 出口参数:
****************************************************************************/
void print_byte(uint8 data)
{
volatile uint8 *print_addr = (volatile uint8 *)PRINT_ADDRESS;
while(print_busy()); //等待打印机空闲
IO0CLR = PRINT_STBCOM; //选通打印机
*print_addr = data;
IO0SET = PRINT_STBCOM; //选通打印机
}
/****************************************************************************
* 名称:print_init()
* 功能:打印接口初始化
* 入口参数:
* 出口参数:
****************************************************************************/
void print_init(void)
{
print_port_init();
print_byte(0x1B);
print_byte(0x40); //初始化打印机
// print_byte(0x1B);
// print_byte(0x61);
// print_byte(0x00); //设定左边界对齐
// print_byte(0x1B);
// print_byte(0x63);
// print_byte(0x34);
// print_byte(0x01); //设定无纸停止打印
// print_byte(0x1B);
// print_byte(0x4C);
// print_byte(0x04); //设定左边界对齐为4mm
return;
}
void entry_chinese_print_mode(void)
{
print_byte(0x1C);
print_byte(0x26); //设定汉字模式
return;
}
void leave_chinese_print_mode(void)
{
print_byte(0x1C);
print_byte(0x2E); //退出汉字模式
return;
}
void reset_print(void)
{
print_byte(0x1B);
print_byte(0x40); //清除打印缓冲
//恢复默认值
//选择字符打印方式
}
void set_left_justify(void)
{
print_byte(0x1B);
print_byte(0x61);
print_byte(0x00); //设定左对齐,一直有效到下一次重新设定
}
void set_center_justify(void)
{
print_byte(0x1B);
print_byte(0x61);
print_byte(0x01); //设定中心对齐,一直有效到下一次重新设定
}
void set_right_justify(void)
{
print_byte(0x1B);
print_byte(0x61);
print_byte(0x02); //设定右对齐,一直有效到下一次重新设定
}
void cansel_justify_mode(void)
{
print_byte(0x1B);
print_byte(0x61);
print_byte(0x03); //取消对齐方式
}
void start_print(void)
{
print_byte(0x0A); //打印并换行
}
void print_and_forward(uint8 mm)
{
print_byte(0x1B);
print_byte(0x4A);
print_byte(8 * mm); //打印并向前走n毫米,只对本行有效
}
void print_and_backward(uint8 mm)
{
print_byte(0x1B);
print_byte(0x6A);
if(mm > 225)
mm = 225;
print_byte(8 * mm); //打印并向后走n毫米,只对本行有效
print_byte(0x0A);
}
void set_row_space_4mm(void) //设定行间距为4毫米
{
print_byte(0x1B);
print_byte(0x32);
}
void set_row_space(uint8 mm)
{
print_byte(0x1B);
print_byte(0x33);
if(mm > 225)
mm = 225;
print_byte(8 * mm); //设定行间距为mm毫米
}
void set_right_space(uint8 mm)
{
print_byte(0x1B);
print_byte(0x20);
print_byte(8 * mm); //设定西文字符右边空mm毫米
}
void set_print_mode(uint8 mode) //0:不放大 1:倍高 2:倍宽 3:倍宽 + 倍高
{
print_byte(0x1B);
print_byte(0x21);
switch(mode)
{
case 0:
print_byte(0x00);
break;
case 1:
print_byte(0x10);
break;
case 2:
print_byte(0x20);
break;
case 3:
print_byte(0x30);
break;
default:
print_byte(0x00);
}
}
void set_row_double_width(void) //一行内该命令后字符以正常宽度2倍打印
{
print_byte(0x1B);
print_byte(0x0E);
print_byte(0x0A);
}
void set_nopaper_stop(void)
{
print_byte(0x1B);
print_byte(0x63);
print_byte(0x34);
print_byte(0x01);
print_byte(0x0A);
}
void forward_cut_all(uint8 mm) //flag = 0:直接切纸 flag = 1:走纸n毫米切纸
{
print_byte(0x1D);
print_byte(0x56);
print_byte(0x42); //走纸n毫米切纸
print_byte(mm * 8);
print_byte(0x0A);
}
void cut_all(void)
{
print_byte(0x1B);
print_byte(0x69);
print_byte(0x0A);
}
void cut_half(void)
{
print_byte(0x1B);
print_byte(0x6D);
print_byte(0x0A);
}
void set_absolute_position()
{
}
void set_print_pic()
{
}
void print_pic()
{
}
/****************************************************************************
* 名称:print_string()
* 功能:打印字符串
* 入口参数:打印字符,长度
* 出口参数:
****************************************************************************/
void print_string(char *data, int datalen)
{
int i;
if(data == NULL || datalen == 0)
return;
for(i = 0; i < datalen; i++)
print_byte(*(data + i));
return;
}
void print_chinese_string(char *data, int datalen)
{
int i;
if(data == NULL || datalen == 0)
return;
entry_chinese_print_mode();
for(i = 0; i < datalen; i++)
print_byte(*(data + i));
leave_chinese_print_mode();
return;
}
void print_picture(char *string, int strlen)
{
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -