|
lpc1114單片機(jī)做的熱敏打印機(jī)程序
完整源碼下載:
printer.rar
(807.16 KB, 下載次數(shù): 60)
2017-4-14 13:00 上傳
點(diǎn)擊文件名下載附件
代碼
主程序預(yù)覽:
- //本文件主要定義可程序的入口函數(shù)main, main函數(shù)里主要對(duì)系統(tǒng)、參數(shù)、硬件接口進(jìn)新初始化,之后等待讀取串口數(shù)據(jù)
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include "LPC11xx.h" /* LPC11xx definitions */
- #include "uart.h"
- #include "timer32.h"
- #include"aw_print.h"
- #include"aw_init_printHead.h"
- #include "aw_config.h"
- #include "aw_font.h"
- #include"aw_key_led.h"
- #include "user.h"
- #include"aw_char_app.h"
- #include"aw_graph_app.h"
- #include"aw_barcode_app.h"
- #include "aw_command.h"
- #include "pmu.h"
- //初始化系統(tǒng)中的部分全局變量
- void init_Global_Variables(void)
- {
- current_char_index=0;
- DealBuffer_counter=0;
- memset((low_power_t *)&low_power_Paramter,0,sizeof(low_power_t));
- memset((printer_work_Parameter_t *)&printer_work_Parameter,0,sizeof(printer_work_Parameter_t));
- printer_work_Parameter.printer_work_model=PRINTER_IDLE;
- feed_dot_step=0;
- paper_out_flag=0;
- head_up_flag=0;
- clear_buffer();
- memset((Key_IRQ_Parameter *)key_IRQ_Parameter,0,KEY_NUM*sizeof(Key_IRQ_Parameter));
- }
- int main(void)
- {
- #if UART_DEBUG
- char buffer[1024];
- uint32_t counter,timer;
- SystemInit();
- Init_Sys_Parameter();
- init_Global_Varibles();
- UARTInit(sys_Parameter.uart_para.baudrate);
- #ifdef PROJECT_DEBUG
- printf("\n\r-- Printer_Project V1.0 --\n\r");
- printf("\n\r-- Serial Communication test --\n\r");
- #endif
- counter=0;
- timer=0;
- memset(buffer,0,1024);
- while(1)
- {
- if(UartBuffer_read()==1)
- {
- timer=0;memcpy(buffer+counter,&DealBuffer,DealBuffer_counter);
- counter+=DealBuffer_counter;
- }
- else
- {
- if(timer<10)
- {
- timer++;
- }
- else if(timer==10)
- {
- if(counter!=0)
- {
- #ifdef PROJECT_DEBUG
- printf("%s",buffer);
- #endif
- counter=0;
- memset(buffer,0,1024);
- timer=11;
- }
- }
- }
- #elif SPIFLASH_DEBUG
- uint32_t BaseAdd;
- uint32_t Address;
- uint8_t MSB=0xce,LSB=0xa1;
- uint8_t dot[118];
- SystemInit();
- spi_flash_init();;
- while(1)
- {
- BaseAdd=BASEADD_GB2312_11X12;
- if(MSB>=0xA1&&MSB<=0Xa9&&LSB>=0xA1)
- {
- Address=((MSB-0xA1)*94+(LSB-0xA1))*24+BaseAdd;
- }
- else if(MSB>=0xB0&&MSB<=0xF7&&LSB>=0xA1)
- {
- Address=((MSB-0xA1)*94+(LSB-0xA1)+846)*24+BaseAdd;
- }
- read_spi_flash(Address,&dot[0],118); /*取點(diǎn)陣*/
- LSB++;
- }
- #elif PRINTER_HEAD_DEBUG
- int i,keyval,keyval_bak;
- uint32_t j;
- SystemInit();
- Init_Sys_Parameter();
- init_Global_Variables();
- init_Printer_port();
- init_key(); /*4、按鍵初始化*/
- while(1)
- {
-
- }
- #elif TIMER_TEST
- uint16_t time;
- uint8_t i;
- SystemInit();
- Init_Sys_Parameter();
- init_Global_Variables();
- UARTInit(115200);
- common_timer(1,1000);
- while(1);
- #else
- uint32_t timer=0; /*用于記錄連續(xù)讀不到串口數(shù)據(jù)的次數(shù)*/
- uint16_t get_dot_count;
- uint16_t effective_dot,num; /*可以用于打印的點(diǎn)的個(gè)數(shù)*/
- SystemInit();
- Init_Sys_Parameter();
- Init_project_Parameter();
- init_Global_Variables();
- UARTInit(sys_Parameter.uart_para.baudrate); /*1、數(shù)據(jù)終端通訊串口初始化*/
- init_Printer_port(); /*2、熱敏打印頭接口初始化 */
- spi_flash_init(); /*3、字庫芯片通訊初始化 */
- init_key(); /*4、按鍵led 初始化*/
- init_led();
- common_timer(1,COMMON_TIME); /*啟動(dòng)公共定時(shí)器*/
- for(timer=0;timer<0xf000;timer++) //延時(shí),保證先前的初始化起作用
- {
- ;
- }
- init_cutter_position(); /*讓切紙刀回到 限位開關(guān)的位置 */
- motor_driver_step40(); /*讓電機(jī)先反正轉(zhuǎn)40 步*/
- Hardware_flow_control(UART_FREE); /*初始化結(jié)束,允許串口接收數(shù)據(jù)*/
- timer=0;
- while(1)
- {
- current_char_index=0;
- if(UartBuffer_read()==1) /*讀取串口數(shù)據(jù)*/
- {
- timer=0; /*串口有數(shù)據(jù)時(shí),將此計(jì)數(shù)器復(fù)位*/
- while(current_char_index<DealBuffer_counter)
- {
- switch(project_Parameter.print_type) /*處理串口讀出的數(shù)據(jù)*/
- {
- case DATA_TYPE_CHAR_COMMAND: /*字符或、命令*/
- if(determine_data_command((uint8_t *)(DealBuffer+current_char_index))==0)
- {
- if(Save_char()==0)
- {
- continue;
- }
- if(printer_work_Parameter.printer_work_model==PRINTER_IDLE) /*空閑*/
- {
- if(calculate_get_char_num(&num,&get_dot_count)==1) /*有一行數(shù)據(jù)需要打印*/
- {
- start_print(PRINT_CHAR);
- }
- }
- }
- else /*命令處理*/
- {
- command_deal((uint8_t *)DealBuffer);
- }
- break;
- #ifdef VERTICAL_GRAPH
- case DATA_TYPE_VERTICAL_GRAPH: /*垂直取模圖形*/
- if(save_graph()==DATA_ENOUGH) /*數(shù)據(jù)取完,恢復(fù)默認(rèn)數(shù)據(jù)類型*/
- {
- project_Parameter.print_type=DATA_TYPE_CHAR_COMMAND;
- }
- break;
- #endif
- case DATA_TYPE_HORIZONTAL_GRAPH: /*水平取模圖形*/
- if(save_graph()==DATA_ENOUGH) /*數(shù)據(jù)取完*/
- {
- graph_data.data_finish=1;
- project_Parameter.print_type=DATA_TYPE_CHAR_COMMAND;
- } /*空閑時(shí),并且有一行以上的數(shù)據(jù)需要打印*/
- if((printer_work_Parameter.printer_work_model==PRINTER_IDLE)&&(graph_data.buffer_counter/graph_data.horizontal_mode.horizontal_byteCount>0))
- {
- start_print(PRINT_HORIZONTAL_GRAPH);
- }
- else if((printer_work_Parameter.printer_pause==1)&&(printer_work_Parameter.printer_work_model==PRINT_HORIZONTAL_GRAPH))
- { /*從暫停狀態(tài)恢復(fù)打印*/ /* 數(shù)據(jù)接收結(jié)束*/
- if((graph_data.data_finish==1)||((graph_data.buffer_counter-graph_data.printed_byteCount)/graph_data.horizontal_mode.horizontal_byteCount>0))
- { /*還有至少一整行數(shù)據(jù)*/
- Resume_Print_from_pause(printer_work_Parameter.printer_work_model);
- }
- }
- else if((graph_data.data_finish==1)&&(printer_work_Parameter.printer_work_model!=PRINT_HORIZONTAL_GRAPH))
- { /*圖片數(shù)據(jù)接收完,并且打印機(jī)還在做別的工作, 取消本次圖片打印*/
- memset((graph_data_t *)&graph_data,0,sizeof(graph_data_t));
- }
- break;
- //case DATA_TYPE_BARCODE: /*條形碼圖形*/
- // num=save_barcode((uint8_t *)(DealBuffer+current_char_index));
- //if(num==DATA_ENOUGH)
- //{
- // save_barcode_parity_bit(); /*數(shù)據(jù)取完開始打印*/
- // while(printer_work_Parameter.printer_work_model!=PRINTER_IDLE)
- // {
- // ;
- //} /*條形碼超出打印范圍不打印*/
- //if(project_Parameter.cursor_position==0) /*本行還是空的*/
- //{
- // effective_dot=MAX_DOT_PERLINE-project_Parameter.print_position-project_Parameter.Limited_width_left_para-project_Parameter.Limited_width_right_para;
- //}
- //else
- //{
- // effective_dot=MAX_DOT_PERLINE-project_Parameter.Limited_width_right_para-project_Parameter.cursor_position;
- //}
- //if(get_barcode_dot_width()<=effective_dot)
- //{
- // start_print(PRINT_BARCODE);
- //}
- //else
- //{
- // memset((barcode_data_t *)&barcode_data,0,sizeof(barcode_data_t));
- //}
- //project_Parameter.print_type=DATA_TYPE_CHAR_COMMAND;
- //}
- //else if(num==DATA_ERROR) /*條碼數(shù)據(jù)出錯(cuò)*/
- //{
- // goto barcode_error;
- //}
- //current_char_index++;
- //break;
- }
- }
- }
- else /*串口中無數(shù)據(jù)*/
- {
- if(timer<5)
- {
- timer++;
- continue;
- }
- switch(project_Parameter.print_type)
- {
- case DATA_TYPE_CHAR_COMMAND:
- if((printer_work_Parameter.printer_work_model==PRINTER_IDLE)&&(char_data.printed_byteCount<char_data.buffer_counter))
- { /*空閑時(shí),并且還有數(shù)據(jù)*/
- start_print(PRINT_CHAR);
- }
- break;
- #ifdef VERTICAL_GRAPH
- case DATA_TYPE_VERTICAL_GRAPH: /*垂直取模圖形*/
- project_Parameter.print_type=DATA_TYPE_CHAR_COMMAND; /*丟棄原來的數(shù)據(jù)*/
- memset((graph_data_t *)&graph_data,0,sizeof(graph_data_t));
- break;
- #endif
- case DATA_TYPE_HORIZONTAL_GRAPH:
- project_Parameter.print_type=DATA_TYPE_CHAR_COMMAND; /*三次讀不到數(shù)據(jù),認(rèn)為結(jié)束*/
- graph_data.data_finish=1;
- if((printer_work_Parameter.printer_pause==1)&&(printer_work_Parameter.printer_work_model==PRINT_HORIZONTAL_GRAPH)) /*圖片打印過程中暫停*/
- {
- Resume_Print_from_pause(printer_work_Parameter.printer_work_model);
- }
- break;
- case DATA_TYPE_BARCODE:
- barcode_error:
- project_Parameter.print_type=DATA_TYPE_CHAR_COMMAND;
- memset((barcode_data_t *)&barcode_data,0,sizeof(barcode_data_t));
- break;
- default:
- break;
- }
- }
- }
- #endif
- }
復(fù)制代碼
|
|