热敏打印机应用笔记
热敏电打印机在PS机上应用比较广泛。造型需要考滤的参数有:
1、打印方式:热敏,针式等等;
2、打印纸度:影响一行能打的字数;
3、打印密度:影响线的粗细,单位 点/mm 或是 点/行
4、打印头的寿命:
5、有效打印宽度:实际可打印的字符宽度;
6、走纸速度:即打速度;
7、支持的字符集: 中文 / 英文
8、接口形式:并/串 TLL/232
9、功耗:
10、外形及安装方式:
11、资质认证:如防爆场合
*炜-煌 *E9* (多来点星星以免打广告) 打印机适用防爆场合,硬件连接很简单,主要是代码调试,格式对齐上比较费纸,呵呵:
1、调试时最就是单片机与打印机独立供电,在电打印过程序中打印机电流很厉害(热敏打印的缺点),1.5A左右,搞不好会把单片机搞死掉或是会导致打印终止。最好用线性电源供电可以观察电流;
2、程序中发送打印数据前先选择字库码的类型;
3、打印应该注意打印机最长能打印多少个字符,以免加上行间距;
#include "stm32f10x.h"
#include "misc.h"
#include "system_stm32f10x.h"
#include "stm32f10x_gpio.h"
#include "stm32f10x_rcc.h"
#include "stm32f10x_usart.h"
#include "fifo.h"
#include "string.h"
#define MAX_LINE 13
#define EnableData() USART_ITConfig(TicketPrintUart, USART_IT_TXE, ENABLE)
#define IsPrinterBusy() GPIO_ReadInputDataBit(TicketPrintBusyGPIO, TicketPrintBusyPin)
void TicketPrinterInit(void);
u8 TicketPrinterWrite(u8 **dp);
void TicketPrinterTest(void);
#define TicketPrintIRQ USART2_IRQHandler
#define TicketPrintUartIOClk RCC_APB2Periph_GPIOA
#define TicketPrintUartClk RCC_APB1Periph_USART2
#define TicketPrintTxGPIO GPIOA
#define TicketPrintBusyGPIO GPIOA
#define TicketPrintTxPin GPIO_Pin_2
#define TicketPrintBusyPin GPIO_Pin_3
#define TicketPrintUart USART2
#define TicketPrintIRQn USART2_IRQn
static void TicketPrinterIOInit(void)
{
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(TicketPrintUartIOClk | RCC_APB2Periph_AFIO, ENABLE);
RCC_APB1PeriphClockCmd(TicketPrintUartClk, ENABLE);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
NVIC_InitStructure.NVIC_IRQChannel = TicketPrintIRQn;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
GPIO_InitStructure.GPIO_Pin = TicketPrintBusyPin; //Printor Busy
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(TicketPrintBusyGPIO, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = TicketPrintTxPin; //TX2
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(TicketPrintTxGPIO, &GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = 9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl =
USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(TicketPrintUart, &USART_InitStructure);
FifoInit(&PrintFifo, sizeof(PrintFifo.data));
USART_Cmd(TicketPrintUart, ENABLE);
}
void TicketPrintIRQ(void)
{
u8 ch;
if (USART_GetITStatus(TicketPrintUart, USART_IT_TXE) != RESET)
{
if(!IsPrinterBusy())
{
if(!FifoRead(&PrintFifo, &ch))
TicketPrintUart->DR = (uint16_t)0x01FF & ch;
else
USART_ITConfig(TicketPrintUart, USART_IT_TXE, DISABLE);
}
}
}
//测试代码
test[] = {“stm32 单片机”};
for(y = 0; y < sizeof(test); y++)
FifoWrite(&PrintFifo, test[y]);
FifoWrite(&PrintFifo, '\n');
EnableData();