找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開始

搜索
查看: 7187|回復(fù): 8
收起左側(cè)

lpc1114熱敏打印機(jī)源程序

  [復(fù)制鏈接]
ID:189499 發(fā)表于 2017-4-14 13:00 | 顯示全部樓層 |閱讀模式
lpc1114單片機(jī)做的熱敏打印機(jī)程序
0.png
完整源碼下載:
printer.rar (807.16 KB, 下載次數(shù): 60)




主程序預(yù)覽:
  1. //本文件主要定義可程序的入口函數(shù)main, main函數(shù)里主要對(duì)系統(tǒng)、參數(shù)、硬件接口進(jìn)新初始化,之后等待讀取串口數(shù)據(jù)
  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. //初始化系統(tǒng)中的部分全局變量
  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);          /*取點(diǎn)陣*/
  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;                          /*用于記錄連續(xù)讀不到串口數(shù)據(jù)的次數(shù)*/
  119. uint16_t get_dot_count;
  120. uint16_t effective_dot,num;                /*可以用于打印的點(diǎn)的個(gè)數(shù)*/
  121. SystemInit();
  122. Init_Sys_Parameter();
  123. Init_project_Parameter();
  124. init_Global_Variables();
  125. UARTInit(sys_Parameter.uart_para.baudrate);   /*1、數(shù)據(jù)終端通訊串口初始化*/
  126. init_Printer_port();                         /*2、熱敏打印頭接口初始化         */
  127. spi_flash_init();                           /*3、字庫芯片通訊初始化         */
  128. init_key();                                /*4、按鍵led 初始化*/
  129. init_led();
  130. common_timer(1,COMMON_TIME);              /*啟動(dòng)公共定時(shí)器*/
  131. for(timer=0;timer<0xf000;timer++)         //延時(shí),保證先前的初始化起作用
  132. {
  133.         ;
  134. }
  135. init_cutter_position();   /*讓切紙刀回到 限位開關(guān)的位置 */
  136. motor_driver_step40();    /*讓電機(jī)先反正轉(zhuǎn)40        步*/       
  137. Hardware_flow_control(UART_FREE);  /*初始化結(jié)束,允許串口接收數(shù)據(jù)*/
  138. timer=0;
  139. while(1)
  140. {
  141.         current_char_index=0;
  142.         if(UartBuffer_read()==1)  /*讀取串口數(shù)據(jù)*/
  143.         {
  144.                 timer=0;    /*串口有數(shù)據(jù)時(shí),將此計(jì)數(shù)器復(fù)位*/
  145.                 while(current_char_index<DealBuffer_counter)
  146.                 {
  147.                         switch(project_Parameter.print_type)  /*處理串口讀出的數(shù)據(jù)*/                       
  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)  /*有一行數(shù)據(jù)需要打印*/
  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)   /*數(shù)據(jù)取完,恢復(fù)默認(rèn)數(shù)據(jù)類型*/
  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)  /*數(shù)據(jù)取完*/
  179.         {
  180.                 graph_data.data_finish=1;
  181.                 project_Parameter.print_type=DATA_TYPE_CHAR_COMMAND;
  182. }   /*空閑時(shí),并且有一行以上的數(shù)據(jù)需要打印*/
  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. {     /*從暫停狀態(tài)恢復(fù)打印*/    /*        數(shù)據(jù)接收結(jié)束*/
  189.         if((graph_data.data_finish==1)||((graph_data.buffer_counter-graph_data.printed_byteCount)/graph_data.horizontal_mode.horizontal_byteCount>0))
  190.         {     /*還有至少一整行數(shù)據(jù)*/
  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. {      /*圖片數(shù)據(jù)接收完,并且打印機(jī)還在做別的工作, 取消本次圖片打印*/
  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();  /*數(shù)據(jù)取完開始打印*/
  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)   /*條碼數(shù)據(jù)出錯(cuò)*/
  227. //{
  228. //        goto barcode_error;
  229. //}
  230. //current_char_index++;
  231. //break;
  232. }
  233. }
  234. }
  235. else  /*串口中無數(shù)據(jù)*/
  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.                 {     /*空閑時(shí),并且還有數(shù)據(jù)*/
  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;  /*丟棄原來的數(shù)據(jù)*/
  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;   /*三次讀不到數(shù)據(jù),認(rèn)為結(jié)束*/
  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. }
復(fù)制代碼


相關(guān)帖子

回復(fù)

使用道具 舉報(bào)

ID:234818 發(fā)表于 2018-1-31 13:02 | 顯示全部樓層
用的是哪款打印機(jī)機(jī)芯???
回復(fù)

使用道具 舉報(bào)

ID:427771 發(fā)表于 2018-11-16 15:48 | 顯示全部樓層
有沒有硬件圖紙
回復(fù)

使用道具 舉報(bào)

ID:438978 發(fā)表于 2018-12-6 15:01 | 顯示全部樓層
這個(gè)不官網(wǎng)上的嗎?
回復(fù)

使用道具 舉報(bào)

ID:124631 發(fā)表于 2019-10-8 13:54 | 顯示全部樓層
謝謝分享
回復(fù)

使用道具 舉報(bào)

ID:82944 發(fā)表于 2019-10-27 14:27 | 顯示全部樓層
這個(gè)不官網(wǎng)上的嗎?
回復(fù)

使用道具 舉報(bào)

ID:612877 發(fā)表于 2019-11-12 13:22 | 顯示全部樓層
非常厲害
回復(fù)

使用道具 舉報(bào)

ID:665260 發(fā)表于 2019-12-16 15:58 | 顯示全部樓層
熱敏打印機(jī)的選型是什么?
回復(fù)

使用道具 舉報(bào)

ID:421595 發(fā)表于 2019-12-18 08:25 | 顯示全部樓層
用的是哪款打印機(jī)機(jī)芯
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表