lpc1114 thermal printer source program

Publisher:Yuexin888Latest update time:2019-10-14 Source: eefocusKeywords:lpc1114 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere


 

Main program preview:

//This file mainly defines the programmable entry function main, which initializes the system, parameters, and hardware interfaces, and then waits to read serial port data

#include

#include  

#include

#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"

// Initialize some global variables in the system

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("nr-- Printer_Project V1.0 --nr");

        printf("nr-- Serial Communication test  --nr");

        #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); /*Get dot matrix*/

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. Key initialization*/

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; /*Used to record the number of times the serial port data cannot be read continuously*/

uint16_t get_dot_count;

uint16_t effective_dot,num; /*Number of dots that can be used for printing*/

SystemInit();

Init_Sys_Parameter();

Init_project_Parameter();

init_Global_Variables();

UARTInit(sys_Parameter.uart_para.baudrate); /*1. Initialize the data terminal communication serial port*/

init_Printer_port(); /*2. Initialize the thermal print head interface */

spi_flash_init(); /*3. Font chip communication initialization */

init_key(); /*4, button LED initialization*/

heat_led();

common_timer(1,COMMON_TIME); /*Start the common timer*/ 

for(timer=0;timer<0xf000;timer++) //delay to ensure that the previous initialization takes effect

{

        ;

}

init_cutter_position(); /*Let the paper cutter return to the position of the limit switch*/

motor_driver_step40(); /*Let the motor rotate 40 steps in reverse direction*/        

Hardware_flow_control(UART_FREE); /* Initialization completed, allow the serial port to receive data*/

timer=0;

while(1)

{

        current_char_index=0;

        if(UartBuffer_read()==1) /*Read serial port data*/

        {

                timer=0; /*When there is data in the serial port, reset this counter*/

                while(current_char_index                {

                        switch(project_Parameter.print_type) /*Process the data read from the serial port*/                        

                        {

                                case DATA_TYPE_CHAR_COMMAND: /* character or 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) /*There is a line of data to be printed*/

        {

                start_print(PRINT_CHAR);

}

}

}

else /*Command processing*/

{

        command_deal((uint8_t *)DealBuffer);

}

break;

#ifdef VERTICAL_GRAPH

case DATA_TYPE_VERTICAL_GRAPH: /*Vertical modulus graphics*/

        if(save_graph()==DATA_ENOUGH) /*After data is retrieved, restore the default data type*/

        {

                project_Parameter.print_type=DATA_TYPE_CHAR_COMMAND;

}

break;

#endif

case DATA_TYPE_HORIZONTAL_GRAPH: /*Horizontal modulus graphics*/

        if(save_graph()==DATA_ENOUGH) /*Data is retrieved*/

        {

                graph_data.data_finish=1;

                project_Parameter.print_type=DATA_TYPE_CHAR_COMMAND;

} /*When idle, and there is more than one line of data to be printed*/

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))

{ /*Resume printing from pause state*/ /*End of data receiving*/

        if((graph_data.data_finish==1)||((graph_data.buffer_counter-graph_data.printed_byteCount)/graph_data.horizontal_mode.horizontal_byteCount>0))

        {/*There is at least one full row of data*/

                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))

{ /*The image data has been received, and the printer is still doing other work, cancel this image printing*/

        memset((graph_data_t *)&graph_data,0,sizeof(graph_data_t));

}

break;

//case DATA_TYPE_BARCODE: /*Barcode graphic*/

//        num=save_barcode((uint8_t *)(DealBuffer+current_char_index));

//if(num==DATA_ENOUGH)

//{

// save_barcode_parity_bit(); /*Start printing after data is retrieved*/

//        while(printer_work_Parameter.printer_work_model!=PRINTER_IDLE)

//        {

        //        ;

//} /*The barcode is out of the printing range and will not be printed*/

//if(project_Parameter.cursor_position==0) /*This row is still empty*/

//{

//        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) /*Barcode data error*/

//{

//        goto barcode_error;

//}

//current_char_index++;

//break;

}

}

}

else /*No data in the serial port*/

{

        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                { /*When idle and there is data*/

                        start_print(PRINT_CHAR);

}

break;

#ifdef VERTICAL_GRAPH

case DATA_TYPE_VERTICAL_GRAPH: /*Vertical modulus graphics*/

        project_Parameter.print_type=DATA_TYPE_CHAR_COMMAND; /*Discard the original data*/

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; /*No data can be read for three times, it is considered finished*/

graph_data.data_finish=1;

if((printer_work_Parameter.printer_pause==1)&&(printer_work_Parameter.printer_work_model==PRINT_HORIZONTAL_GRAPH)) /*Pause during image printing*/

{

        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

}




Keywords:lpc1114 Reference address:lpc1114 thermal printer source program

Previous article:Advice for college students on learning ARM and FPGA
Next article:How to port uCOS-II to LPC17XX

Recommended ReadingLatest update time:2024-11-16 15:04

LPC1114 Deep power-down mode Deep power-down mode
In deep power-down mode, except for the WAKUP pin (P1.4), the entire chip stops working, and only four 32-bit registers are available to store user data, and the data in the internal SRAM will be lost. 1. How to enter deep power-down mode To enter Deep power-down mode, follow these steps: 1. Set the DPDEN bit of the P
[Microcontroller]
LPC1114 Deep power-down mode Deep power-down mode
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号