找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 5955|回复: 8
打印 上一主题 下一主题
收起左侧

lpc1114热敏打印机源程序

  [复制链接]
跳转到指定楼层
楼主
lpc1114单片机做的热敏打印机程序

完整源码下载:
printer.rar (807.16 KB, 下载次数: 56)




主程序预览:
  1. //本文件主要定义可程序的入口函数main, main函数里主要对系统、参数、硬件接口进新初始化,之后等待读取串口数据
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include "LPC11xx.h" /* LPC11xx definitions */
  6. #include "uart.h"  
  7. #include "timer32.h"
  8. #include"aw_print.h"
  9. #include"aw_init_printHead.h"
  10. #include "aw_config.h"
  11. #include "aw_font.h"
  12. #include"aw_key_led.h"
  13. #include "user.h"
  14. #include"aw_char_app.h"
  15. #include"aw_graph_app.h"
  16. #include"aw_barcode_app.h"
  17. #include "aw_command.h"
  18. #include "pmu.h"
  19. //初始化系统中的部分全局变量
  20. void init_Global_Variables(void)
  21. {
  22.         current_char_index=0;
  23.         DealBuffer_counter=0;
  24.         memset((low_power_t *)&low_power_Paramter,0,sizeof(low_power_t));
  25.         memset((printer_work_Parameter_t *)&printer_work_Parameter,0,sizeof(printer_work_Parameter_t));
  26.         printer_work_Parameter.printer_work_model=PRINTER_IDLE;
  27.         feed_dot_step=0;
  28.         paper_out_flag=0;
  29.         head_up_flag=0;
  30.         clear_buffer();
  31.         memset((Key_IRQ_Parameter *)key_IRQ_Parameter,0,KEY_NUM*sizeof(Key_IRQ_Parameter));
  32. }
  33. int main(void)
  34. {
  35.         #if UART_DEBUG
  36.         char buffer[1024];
  37.         uint32_t counter,timer;
  38.         SystemInit();
  39.         Init_Sys_Parameter();
  40.         init_Global_Varibles();
  41.         UARTInit(sys_Parameter.uart_para.baudrate);
  42.         #ifdef PROJECT_DEBUG
  43.         printf("\n\r-- Printer_Project V1.0 --\n\r");
  44.         printf("\n\r-- Serial Communication test  --\n\r");
  45.         #endif
  46.         counter=0;
  47.         timer=0;
  48.         memset(buffer,0,1024);
  49.         while(1)
  50.         {
  51.                 if(UartBuffer_read()==1)
  52.                 {
  53.                         timer=0;memcpy(buffer+counter,&DealBuffer,DealBuffer_counter);
  54.                         counter+=DealBuffer_counter;
  55. }
  56. else
  57. {
  58.         if(timer<10)
  59.         {
  60.                 timer++;
  61. }
  62. else if(timer==10)
  63. {
  64.         if(counter!=0)
  65.         {
  66.                 #ifdef PROJECT_DEBUG
  67.                 printf("%s",buffer);
  68.                 #endif
  69.                 counter=0;
  70.                 memset(buffer,0,1024);
  71.                 timer=11;
  72. }
  73. }
  74. }
  75. #elif SPIFLASH_DEBUG
  76. uint32_t BaseAdd;
  77. uint32_t Address;
  78. uint8_t MSB=0xce,LSB=0xa1;
  79. uint8_t dot[118];
  80. SystemInit();
  81. spi_flash_init();;
  82. while(1)
  83. {
  84.         BaseAdd=BASEADD_GB2312_11X12;
  85.         if(MSB>=0xA1&&MSB<=0Xa9&&LSB>=0xA1)
  86.         {
  87.                 Address=((MSB-0xA1)*94+(LSB-0xA1))*24+BaseAdd;
  88. }
  89. else if(MSB>=0xB0&&MSB<=0xF7&&LSB>=0xA1)
  90. {
  91.         Address=((MSB-0xA1)*94+(LSB-0xA1)+846)*24+BaseAdd;
  92. }
  93. read_spi_flash(Address,&dot[0],118);          /*取点阵*/
  94. LSB++;
  95. }
  96. #elif PRINTER_HEAD_DEBUG
  97. int i,keyval,keyval_bak;
  98. uint32_t j;
  99. SystemInit();
  100. Init_Sys_Parameter();
  101. init_Global_Variables();
  102. init_Printer_port();
  103. init_key();                          /*4、按键初始化*/
  104. while(1)
  105. {
  106.        
  107. }
  108. #elif TIMER_TEST
  109. uint16_t time;
  110. uint8_t i;
  111. SystemInit();
  112. Init_Sys_Parameter();
  113. init_Global_Variables();
  114. UARTInit(115200);
  115. common_timer(1,1000);
  116. while(1);
  117. #else
  118. uint32_t timer=0;                          /*用于记录连续读不到串口数据的次数*/
  119. uint16_t get_dot_count;
  120. uint16_t effective_dot,num;                /*可以用于打印的点的个数*/
  121. SystemInit();
  122. Init_Sys_Parameter();
  123. Init_project_Parameter();
  124. init_Global_Variables();
  125. UARTInit(sys_Parameter.uart_para.baudrate);   /*1、数据终端通讯串口初始化*/
  126. init_Printer_port();                         /*2、热敏打印头接口初始化         */
  127. spi_flash_init();                           /*3、字库芯片通讯初始化         */
  128. init_key();                                /*4、按键led 初始化*/
  129. init_led();
  130. common_timer(1,COMMON_TIME);              /*启动公共定时器*/
  131. for(timer=0;timer<0xf000;timer++)         //延时,保证先前的初始化起作用
  132. {
  133.         ;
  134. }
  135. init_cutter_position();   /*让切纸刀回到 限位开关的位置 */
  136. motor_driver_step40();    /*让电机先反正转40        步*/       
  137. Hardware_flow_control(UART_FREE);  /*初始化结束,允许串口接收数据*/
  138. timer=0;
  139. while(1)
  140. {
  141.         current_char_index=0;
  142.         if(UartBuffer_read()==1)  /*读取串口数据*/
  143.         {
  144.                 timer=0;    /*串口有数据时,将此计数器复位*/
  145.                 while(current_char_index<DealBuffer_counter)
  146.                 {
  147.                         switch(project_Parameter.print_type)  /*处理串口读出的数据*/                       
  148.                         {
  149.                                 case DATA_TYPE_CHAR_COMMAND:   /*字符或、命令*/
  150.                                         if(determine_data_command((uint8_t *)(DealBuffer+current_char_index))==0)
  151.                                         {
  152.                                                 if(Save_char()==0)
  153.                                                 {
  154.                                                         continue;
  155. }
  156. if(printer_work_Parameter.printer_work_model==PRINTER_IDLE)  /*空闲*/
  157. {
  158.         if(calculate_get_char_num(&num,&get_dot_count)==1)  /*有一行数据需要打印*/
  159.         {
  160.                 start_print(PRINT_CHAR);
  161. }
  162. }
  163. }
  164. else  /*命令处理*/
  165. {
  166.         command_deal((uint8_t *)DealBuffer);
  167. }
  168. break;
  169. #ifdef VERTICAL_GRAPH
  170. case DATA_TYPE_VERTICAL_GRAPH:           /*垂直取模图形*/
  171.         if(save_graph()==DATA_ENOUGH)   /*数据取完,恢复默认数据类型*/
  172.         {
  173.                 project_Parameter.print_type=DATA_TYPE_CHAR_COMMAND;
  174. }
  175. break;
  176. #endif
  177. case DATA_TYPE_HORIZONTAL_GRAPH:  /*水平取模图形*/
  178.         if(save_graph()==DATA_ENOUGH)  /*数据取完*/
  179.         {
  180.                 graph_data.data_finish=1;
  181.                 project_Parameter.print_type=DATA_TYPE_CHAR_COMMAND;
  182. }   /*空闲时,并且有一行以上的数据需要打印*/
  183. if((printer_work_Parameter.printer_work_model==PRINTER_IDLE)&&(graph_data.buffer_counter/graph_data.horizontal_mode.horizontal_byteCount>0))
  184. {
  185.         start_print(PRINT_HORIZONTAL_GRAPH);
  186. }
  187. else if((printer_work_Parameter.printer_pause==1)&&(printer_work_Parameter.printer_work_model==PRINT_HORIZONTAL_GRAPH))
  188. {     /*从暂停状态恢复打印*/    /*        数据接收结束*/
  189.         if((graph_data.data_finish==1)||((graph_data.buffer_counter-graph_data.printed_byteCount)/graph_data.horizontal_mode.horizontal_byteCount>0))
  190.         {     /*还有至少一整行数据*/
  191.                 Resume_Print_from_pause(printer_work_Parameter.printer_work_model);
  192. }
  193. }
  194. else if((graph_data.data_finish==1)&&(printer_work_Parameter.printer_work_model!=PRINT_HORIZONTAL_GRAPH))
  195. {      /*图片数据接收完,并且打印机还在做别的工作, 取消本次图片打印*/
  196.         memset((graph_data_t *)&graph_data,0,sizeof(graph_data_t));
  197. }
  198. break;
  199. //case DATA_TYPE_BARCODE:  /*条形码图形*/
  200. //        num=save_barcode((uint8_t *)(DealBuffer+current_char_index));
  201. //if(num==DATA_ENOUGH)
  202. //{
  203. //        save_barcode_parity_bit();  /*数据取完开始打印*/
  204. //        while(printer_work_Parameter.printer_work_model!=PRINTER_IDLE)
  205. //        {
  206.         //        ;
  207. //}   /*条形码超出打印范围不打印*/
  208. //if(project_Parameter.cursor_position==0)  /*本行还是空的*/
  209. //{
  210. //        effective_dot=MAX_DOT_PERLINE-project_Parameter.print_position-project_Parameter.Limited_width_left_para-project_Parameter.Limited_width_right_para;
  211. //}
  212. //else
  213. //{
  214. //        effective_dot=MAX_DOT_PERLINE-project_Parameter.Limited_width_right_para-project_Parameter.cursor_position;
  215. //}
  216. //if(get_barcode_dot_width()<=effective_dot)
  217. //{
  218. //        start_print(PRINT_BARCODE);
  219. //}
  220. //else
  221. //{
  222. //        memset((barcode_data_t *)&barcode_data,0,sizeof(barcode_data_t));
  223. //}
  224. //project_Parameter.print_type=DATA_TYPE_CHAR_COMMAND;
  225. //}
  226. //else if(num==DATA_ERROR)   /*条码数据出错*/
  227. //{
  228. //        goto barcode_error;
  229. //}
  230. //current_char_index++;
  231. //break;
  232. }
  233. }
  234. }
  235. else  /*串口中无数据*/
  236. {
  237.         if(timer<5)
  238.         {
  239.                 timer++;
  240.                 continue;
  241. }
  242. switch(project_Parameter.print_type)
  243. {
  244.         case DATA_TYPE_CHAR_COMMAND:     
  245.                 if((printer_work_Parameter.printer_work_model==PRINTER_IDLE)&&(char_data.printed_byteCount<char_data.buffer_counter))
  246.                 {     /*空闲时,并且还有数据*/
  247.                         start_print(PRINT_CHAR);
  248. }
  249. break;
  250. #ifdef VERTICAL_GRAPH
  251. case DATA_TYPE_VERTICAL_GRAPH:           /*垂直取模图形*/
  252.         project_Parameter.print_type=DATA_TYPE_CHAR_COMMAND;  /*丢弃原来的数据*/
  253. memset((graph_data_t *)&graph_data,0,sizeof(graph_data_t));
  254. break;
  255. #endif
  256. case DATA_TYPE_HORIZONTAL_GRAPH:
  257.         project_Parameter.print_type=DATA_TYPE_CHAR_COMMAND;   /*三次读不到数据,认为结束*/
  258. graph_data.data_finish=1;
  259. if((printer_work_Parameter.printer_pause==1)&&(printer_work_Parameter.printer_work_model==PRINT_HORIZONTAL_GRAPH))  /*图片打印过程中暂停*/
  260. {
  261.         Resume_Print_from_pause(printer_work_Parameter.printer_work_model);
  262. }
  263. break;
  264. case DATA_TYPE_BARCODE:
  265.         barcode_error:
  266. project_Parameter.print_type=DATA_TYPE_CHAR_COMMAND;
  267. memset((barcode_data_t *)&barcode_data,0,sizeof(barcode_data_t));
  268. break;
  269. default:
  270.         break;
  271. }
  272. }
  273. }
  274. #endif
  275. }
复制代码


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏4 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:234818 发表于 2018-1-31 13:02 | 只看该作者
用的是哪款打印机机芯???
回复

使用道具 举报

板凳
ID:427771 发表于 2018-11-16 15:48 | 只看该作者
有没有硬件图纸
回复

使用道具 举报

地板
ID:438978 发表于 2018-12-6 15:01 | 只看该作者
这个不官网上的吗?
回复

使用道具 举报

5#
ID:124631 发表于 2019-10-8 13:54 | 只看该作者
谢谢分享
回复

使用道具 举报

6#
ID:82944 发表于 2019-10-27 14:27 | 只看该作者
这个不官网上的吗?
回复

使用道具 举报

7#
ID:612877 发表于 2019-11-12 13:22 | 只看该作者
非常厉害
回复

使用道具 举报

8#
ID:665260 发表于 2019-12-16 15:58 | 只看该作者
热敏打印机的选型是什么?
回复

使用道具 举报

9#
ID:421595 发表于 2019-12-18 08:25 | 只看该作者
用的是哪款打印机机芯
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表