|
|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
lpc1114热敏打印机源程序 x' Q( d' Z2 V& q: _( g
, Y7 I' U; C" u/ n' @//本文件主要定义可程序的入口函数main, main函数里主要对系统、参数、硬件接口进新初始化,之后等待读取串口数据
6 P6 r( k( T' J5 L" _#include <stdio.h>- B o$ l" j7 ^
#include <stdlib.h> * d$ d4 h0 h# I' j6 p9 W2 I
#include <string.h>3 @4 W. y" f" [' M; ~, }
#include "LPC11xx.h" /* LPC11xx definitions */% X" s; I" @9 Y$ f/ ] C
#include "uart.h"
8 g8 z) T( o9 Q J& S3 C% C" {#include "timer32.h"0 I/ P2 v/ K- N$ x0 t
#include"aw_print.h" % T+ C8 ]: p* P* M+ {
#include"aw_init_printHead.h"$ l& W& P1 s/ P( V9 d5 H' E! o
#include "aw_config.h"7 G, E( L" E2 ]6 W2 q
#include "aw_font.h"1 M' ?4 x) p2 o; T; m! ]: I
#include"aw_key_led.h"+ M+ x2 f3 e/ E$ c. I/ x
#include "user.h"
% \4 c9 y" b+ n; t8 b7 I9 q#include"aw_char_app.h"1 N% m A! E z. x
#include"aw_graph_app.h"
6 [+ ?* Z$ w- p9 R, z#include"aw_barcode_app.h"$ N2 O( U9 ]- U$ h
#include "aw_command.h"
* \) j' I p: X. S1 |#include "pmu.h"1 k1 w% \4 X1 n9 |0 U/ U
//初始化系统中的部分全局变量( S$ r2 o: x; H3 I& W! t& c6 I
void init_Global_Variables(void)
4 O6 P; B0 Z ~# C, d. J{6 }1 w! N5 e+ g/ S$ _1 M
current_char_index=0;4 Z2 O5 Y" F( f
DealBuffer_counter=0;/ t1 w* i9 B/ E i% E6 b# E
memset((low_power_t *)&low_power_Paramter,0,sizeof(low_power_t));) ]+ K6 t Q% B8 M9 P J
memset((printer_work_Parameter_t *)&printer_work_Parameter,0,sizeof(printer_work_Parameter_t));
5 A: P9 t1 x4 h printer_work_Parameter.printer_work_model=PRINTER_IDLE;
# e8 p0 u8 @( o+ p( g feed_dot_step=0;
8 k9 b/ H! v1 U+ A* [ paper_out_flag=0; h. V( M$ {9 b! T8 x
head_up_flag=0;" j( @ e" G# _) m
clear_buffer();
* ]! w, L8 A: P9 p memset((Key_IRQ_Parameter *)key_IRQ_Parameter,0,KEY_NUM*sizeof(Key_IRQ_Parameter));! l( y ?; m6 i4 V. }8 O
}* P1 f& m4 v" L: J" v6 V
int main(void)
+ d' K9 r6 Q/ c' P& ]& a{. K H& {4 s/ j6 T. g+ y
#if UART_DEBUG
8 a J/ b) [) @) J7 {3 m char buffer[1024];9 a @% m* G w
uint32_t counter,timer;+ _9 v9 \" U e2 f4 Y" w' g) W/ p
SystemInit();
/ X/ l9 H( _3 k' ^8 z" R- L; l: h. w Init_Sys_Parameter();: U2 D: l) v6 D3 X
init_Global_Varibles();
- z" G6 \# z; `- t1 W; u1 c UARTInit(sys_Parameter.uart_para.baudrate);
6 I4 G- R9 {2 p* j #ifdef PROJECT_DEBUG( R$ i' [ g& s" }1 |& W
printf("\n\r-- Printer_Project V1.0 --\n\r");! l2 A' z/ o$ L6 C! O, h
printf("\n\r-- Serial Communication test --\n\r");
! ?# J" |/ v ]* T! H) n' \8 A! M #endif; o1 G6 {4 I" ^1 s7 Z
counter=0;
; L( }# ~4 R8 }' ^ s timer=0;5 a% u4 x3 @4 F' @% ^( I) ^
memset(buffer,0,1024);! ` ~6 ?) Q, c% |: m( x
while(1)) m& `2 ?. y8 n! \: t9 ?
{
9 B/ H3 E/ o4 o, P" v if(UartBuffer_read()==1)
1 U% a7 w6 f7 B3 N; `1 h {5 ?' k0 a0 R2 c6 }; ^
timer=0;mEMCpy(buffer+counter,&DealBuffer,DealBuffer_counter);* c! `* U% K: c& K0 H/ A
counter+=DealBuffer_counter;
4 A& z! J' Q( @5 Q( M- o}6 O* p( B9 x; e @
else
6 ~6 t" s, Q! c' _* O7 `% p# G, r{
2 t4 W; @5 z# |) l: s if(timer<10)
r" q1 p0 Z/ {: F4 f2 l {
7 _ ~# M k( C4 p2 S timer++;; p/ G$ l" V. s% s4 C# c" _, e, n
}
# ?$ N5 C \$ h8 _: m! ?" Y) Melse if(timer==10)7 C, j- L+ K3 ~; [
{- }* ~2 a. R. }0 |( z0 m1 n
if(counter!=0)
: G9 T5 E' d; w! E3 Z, M {$ a( {& p$ `) a$ s' n' S" V! b
#ifdef PROJECT_DEBUG: T# m& K$ m9 |/ |
printf("%s",buffer);* t/ N3 [) A* B7 p/ \ }! a
#endif8 v! E9 D) _' x4 i
counter=0;' [% B5 x2 X( V
memset(buffer,0,1024);2 z6 u b. w* a! K8 {# u; U* B( y
timer=11;
) ?. i0 \4 w$ s, B}
7 X' X' _; f, m8 n}$ c8 [# |* X! X9 }/ O+ p# X. @1 y9 R
}
8 L5 T! k2 w+ h" t#elif SPIFLASH_DEBUG
" e* P2 O3 F' B4 m2 huint32_t BaseAdd;
5 m! d* A9 I2 i L4 nuint32_t Address;
% m$ I/ S# O: n8 yuint8_t MSB=0xce,LSB=0xa1;3 K4 r3 r; r- X6 K5 @8 C/ n
uint8_t dot[118];
B) v; d4 w: a/ \( c& Q+ A m4 M, sSystemInit();; F& U5 S0 m) A/ W1 ]) W, u% ~. g
spi_flash_init();;. Y; T0 e( B6 Z
while(1)5 o: W+ F2 {8 P, f0 i! B. T
{& P7 M* m2 v3 M' Q4 ]' W* M! ]
BaseAdd=BASEADD_GB2312_11X12;
, C/ \5 `) ? q' N- }; l if(MSB>=0xA1&&MSB<=0Xa9&&LSB>=0xA1)
, ~4 P9 C$ K+ v. J: _( o {- B" n: A# i H* j
Address=((MSB-0xA1)*94+(LSB-0xA1))*24+BaseAdd;
# w8 H0 a- |, I9 R; o1 q}
' P% J4 R& s: q+ r [6 K, Aelse if(MSB>=0xB0&&MSB<=0xF7&&LSB>=0xA1)2 y$ R* z: X; N$ [2 A! \+ ^3 K
{
6 Z3 A% g. u- T: K( a) Z Address=((MSB-0xA1)*94+(LSB-0xA1)+846)*24+BaseAdd;
' o. X$ Y( [& B- I5 j+ l3 r t}2 ?# H( H* C. x* q) {7 b5 o6 @' W- s* J7 H
read_spi_flash(Address,&dot[0],118); /*取点阵*/
6 V; c f* F' {$ lLSB++;) \' u4 T$ ]0 n) q7 m l
}
/ V% A) C, d. s% X5 }#elif PRINTER_HEAD_DEBUG( h$ e7 }; S& u+ E
int i,keyval,keyval_bak;
% O$ Q8 R5 q) i" }' buint32_t j;
4 q" R) E/ N$ |5 q' ~, B9 FSystemInit();
4 Z. \* M# j! A$ _1 J F# ^5 yInit_Sys_Parameter();; m( s7 X3 M9 h
init_Global_Variables();) d, Q5 ^" i6 [$ E& b
init_Printer_port();3 W& X3 Z7 ?. v$ k4 _- D8 K
init_key(); /*4、按键初始化*/
' }1 b! j0 z! H$ |: c0 E# Pwhile(1)
2 T1 s( a7 F7 l1 @{1 q! i' m# L. E, O# \% |' T
1 }+ Y6 F" y3 n+ b" ?' z, @+ g, P}' e3 f4 Y, ]" J8 I5 }% @
#elif TIMER_TEST
% c3 Z% B- `$ c f$ ruint16_t time;
" R( K+ H2 F' K8 d* F6 b9 k- o5 Guint8_t i;
- }* i) @5 k% aSystemInit();
. A8 e8 R: z( @% `, `Init_Sys_Parameter();
) Z! b9 o2 |" Pinit_Global_Variables();- a4 K4 ^3 E$ [, d) P
UARTInit(115200);
. d: \, q! G( H' r) ?common_timer(1,1000);; `: J- X1 B/ ~3 N# s# r
while(1);
. z7 r7 S% R# G% x* S#else
- Z% j! O2 m5 S5 H; Z1 ?( Muint32_t timer=0; /*用于记录连续读不到串口数据的次数*/8 M, q# _# \ R9 ?
uint16_t get_dot_count;" L* j( w2 |4 U0 V* g
uint16_t effective_dot,num; /*可以用于打印的点的个数*/
. I* |: H- S, W/ K, B. vSystemInit();
1 x; H- z% C6 v$ M) rInit_Sys_Parameter();
2 r/ `* O6 B+ C, [; M+ K6 GInit_project_Parameter();; @* {! Y3 U# V, h6 t5 j
init_Global_Variables();
9 x! B3 L' t5 \- S& B! J$ oUARTInit(sys_Parameter.uart_para.baudrate); /*1、数据终端通讯串口初始化*/' P6 j o; e7 k- E
init_Printer_port(); /*2、热敏打印头接口初始化 */
( Q8 _ D( Y# d- h% u- J6 yspi_flash_init(); /*3、字库芯片通讯初始化 */
9 \( y2 e2 O& g" ~7 U- K1 D9 tinit_key(); /*4、按键led 初始化*/
' J4 m" i. h7 s7 O/ f) @0 Dinit_led();
7 k- ` Q; U2 E4 H) y! D- o4 Zcommon_timer(1,COMMON_TIME); /*启动公共定时器*/
) t1 P& h$ |5 L4 H: J6 s" ifor(timer=0;timer<0xf000;timer++) //延时,保证先前的初始化起作用
2 H& `2 m) z2 i{
% _! y! x- d( a ;
) R* T4 K( H1 ~) A/ i. v3 F}
0 b: m- V5 @+ M- v* b' Qinit_cutter_position(); /*让切纸刀回到 限位开关的位置 */3 @7 ]7 ]( N& j0 Q/ A" e( E0 d
motor_driver_step40(); /*让电机先反正转40 步*/
' u( N+ H! t/ n% c! T8 F) B2 ?Hardware_flow_control(UART_FREE); /*初始化结束,允许串口接收数据*/7 X4 A, U, Q* T( F# t/ [% ^( A# V. e
timer=0;( a) V9 W) ~, x# k
while(1)
2 ]2 o0 Q& Q6 \{
3 Z! c1 T% B- A' ~- M/ ]: ?1 W current_char_index=0;
( B; W# A+ Z9 u2 t2 n7 P if(UartBuffer_read()==1) /*读取串口数据*/& D. G6 x# }* T! G3 o
{2 c7 J/ D ?# a! a- i1 P8 E
timer=0; /*串口有数据时,将此计数器复位*// \) w2 N) G$ j! r: @. A6 s L
while(current_char_index<DealBuffer_counter)5 z7 S7 ~* [1 F
{+ X- t8 o8 f$ o( |: [3 c' a% ]
switch(project_Parameter.print_type) /*处理串口读出的数据*/ 3 I4 y6 A; l9 Z v* ]4 M; M0 T/ e
{
2 {6 C5 ~, R5 t8 x! l case DATA_TYPE_CHAR_COMMAND: /*字符或、命令*/
- C" d) x& u/ s! v' M: s2 R# P if(determine_data_command((uint8_t *)(DealBuffer+current_char_index))==0)
2 O9 M5 z$ C# O6 i: `+ } {7 {: L- Q6 B7 d0 p: W8 u- ^
if(Save_char()==0)
( G: r" w9 g- ] {5 g6 C, k+ T) X
continue;9 B: W% Y* |. C$ g& j" ?6 y; A. Y
}
: l% [6 a# \+ ], j2 u7 m. L2 {6 zif(printer_work_Parameter.printer_work_model==PRINTER_IDLE) /*空闲*/, h7 N. F5 |: Q
{& ~& ?" ? L) T, V! n' T
if(calculate_get_char_num(&num,&get_dot_count)==1) /*有一行数据需要打印*/
+ H2 w# }1 [# B- `$ g6 B {
2 v8 b+ Y; d; J' Y% _1 d" Q" o start_print(PRINT_CHAR);
, C% v* W$ y! N1 N' h4 W}8 t8 L- l1 u4 y: E
}7 X c. T- j4 H7 K) l8 Q
}
. l* z! B: E7 q/ jelse /*命令处理*/
. x8 M: e/ z8 m{7 B6 s2 l% ?6 Y& ^1 R- g
command_deal((uint8_t *)DealBuffer);
( s x/ O7 i( v( _5 p( k* s' H5 W6 A}
+ w- c& D/ l5 [break; N' o6 l& t1 e+ m* J
#ifdef VERTICAL_GRAPH2 M' a" b9 r3 o5 }
case DATA_TYPE_VERTICAL_GRAPH: /*垂直取模图形*/3 g% Y& @7 x3 k* a* b3 f* b
if(save_graph()==DATA_ENOUGH) /*数据取完,恢复默认数据类型*/
# i6 s. h4 W' S4 l: J {$ e2 V2 R# ~' O0 t( l) g9 a
project_Parameter.print_type=DATA_TYPE_CHAR_COMMAND;
8 m, [* R! O( z, L+ ]( D7 L}
* Q; {5 C" F5 p9 g; Q5 ^break;
* C8 ?$ f. \" D4 z, p0 m b$ M#endif
6 F/ h, ]$ y: ^. J* \+ h$ S5 Rcase DATA_TYPE_HORIZONTAL_GRAPH: /*水平取模图形*/$ L/ g2 L0 Y: f; P
if(save_graph()==DATA_ENOUGH) /*数据取完*/+ V6 _1 a7 S/ N; R7 \
{
& b. b& |/ `, @. E$ @& S3 G graph_data.data_finish=1;
4 [; f# J$ n" A/ I project_Parameter.print_type=DATA_TYPE_CHAR_COMMAND;$ D1 ~) Q$ b$ o) B: A5 i
} /*空闲时,并且有一行以上的数据需要打印*/
* B8 R0 e+ a$ s t, E/ M" bif((printer_work_Parameter.printer_work_model==PRINTER_IDLE)&&(graph_data.buffer_counter/graph_data.horizontal_mode.horizontal_byteCount>0))- l0 V' s. P; A6 F4 _! ?
{
! _ V, |2 S$ h6 o# T start_print(PRINT_HORIZONTAL_GRAPH);
2 H3 s" Q+ l7 V. w# d" L8 |, m}
2 N; [2 G) m3 r" n5 C! }else if((printer_work_Parameter.printer_pause==1)&&(printer_work_Parameter.printer_work_model==PRINT_HORIZONTAL_GRAPH))- n- P8 T! m) u
{ /*从暂停状态恢复打印*/ /* 数据接收结束*/
& k, S( I. x+ T# Z! M# _, R if((graph_data.data_finish==1)||((graph_data.buffer_counter-graph_data.printed_byteCount)/graph_data.horizontal_mode.horizontal_byteCount>0))
4 O5 |, L1 X- B. y- I { /*还有至少一整行数据*/- K/ Y. m& ~4 v% \3 q
Resume_Print_from_pause(printer_work_Parameter.printer_work_model);
a3 t# z) L8 M2 ?; U}) a. T y2 e% W+ J
}) V1 T% k3 ^& s! f
else if((graph_data.data_finish==1)&&(printer_work_Parameter.printer_work_model!=PRINT_HORIZONTAL_GRAPH))
5 d* x* W' A' H4 j' B* X{ /*图片数据接收完,并且打印机还在做别的工作, 取消本次图片打印*/3 b$ k/ `* h" J
memset((graph_data_t *)&graph_data,0,sizeof(graph_data_t));! k9 ?2 c: ` g4 F! d. p
}4 @- ^3 Z1 @% K2 w
break;# [3 i7 _/ \/ R( P, U5 Z
//case DATA_TYPE_BARCODE: /*条形码图形*/# n0 p% h8 `' B/ z; e2 ~
// num=save_barcode((uint8_t *)(DealBuffer+current_char_index));
( k4 L% C3 ?. ?( A: Z. B' ~//if(num==DATA_ENOUGH)
7 F% L; h; }4 r//{0 U& \! l4 Z0 D2 a8 d# g7 J
// save_barcode_parity_bit(); /*数据取完开始打印*/9 |. t# `. v% d* c! b
// while(printer_work_Parameter.printer_work_model!=PRINTER_IDLE)
9 S) X& d2 y# i& F// {
4 t5 F) H4 I1 ]* m1 g9 d' W. |% h7 T // ;
, T. u# D+ h D* n! h9 S! ~/ g0 j//} /*条形码超出打印范围不打印*// D9 e5 K8 q) x+ J2 _7 n" g! B% k
//if(project_Parameter.cursor_position==0) /*本行还是空的*/: O( `2 F- X6 ^* X% s7 J3 u
//{
" D) G- C/ f; w3 m) v/ G4 r. b3 T// effective_dot=MAX_DOT_PERLINE-project_Parameter.print_position-project_Parameter.Limited_width_left_para-project_Parameter.Limited_width_right_para;# R: h F6 F5 [* U. _, n v% P/ U: E
//}: S& P- W" h& ?7 m8 t5 f* @
//else
$ x" _! g0 Q& o" _% A" Q//{* Y# J% r8 G6 s+ D1 |
// effective_dot=MAX_DOT_PERLINE-project_Parameter.Limited_width_right_para-project_Parameter.cursor_position;0 ], _- _) l4 e9 u
//}
6 m/ @# A) @9 j+ ]9 C//if(get_barcode_dot_width()<=effective_dot)
" a/ V; K* h' Y& f0 S, S" m//{
& X% F# D2 K' y( s8 ~// start_print(PRINT_BARCODE);
, Z4 e% F) d% ?" s' y5 H//}
% I/ Y8 |, ]4 d0 _4 ]( R4 {% V//else. P, ^- {* Z; [/ S7 x
//{
; ]8 `# ~ o$ ^6 d+ o// memset((barcode_data_t *)&barcode_data,0,sizeof(barcode_data_t));
' o2 K( P) Q) U4 R) s. }( ^! D//}
8 D4 j; [/ f' k5 {# f3 j. L N9 K//project_Parameter.print_type=DATA_TYPE_CHAR_COMMAND;8 p/ F7 W. ^7 R! X' e& D- T
//}" L3 B. n# R. L% V0 H( k
//else if(num==DATA_ERROR) /*条码数据出错*/+ t5 B8 r; T* O5 x2 t. i
//{8 m+ V- k- e/ [% o' _1 f2 n g
// goto barcode_error;
) k9 \2 {/ y1 u$ B* p( i6 Z//}
' w4 ~( S8 L( f; s0 i- o. g//current_char_index++;
( i, a4 ^1 t6 C$ v//break;! \/ U! ^- a5 v5 u
}
$ H& h$ m# R! J, M3 C' G- B}% ~7 Z9 k9 w6 C" j9 Q
}% S2 S0 g# A* |% t& l2 _
else /*串口中无数据*/
* X# s6 @" e4 o( j{: R' ?2 N* t" A$ K
if(timer<5)1 D8 ~. q9 Q. H! g5 @% Q
{
/ q% N8 x0 A/ E6 _3 O timer++;
7 _: V6 x. u! a continue;
$ s: r6 u) D7 v: d}9 \. p! U8 i- I% X- ]2 C" ^5 b
switch(project_Parameter.print_type)0 k+ \4 p! X/ K. ]( D
{
$ D4 ~) x! r) ^; F9 q6 @% d case DATA_TYPE_CHAR_COMMAND: q" \/ t- K1 @3 _
if((printer_work_Parameter.printer_work_model==PRINTER_IDLE)&&(char_data.printed_byteCount<char_data.buffer_counter))" [3 s4 q6 s( t; C$ z- \
{ /*空闲时,并且还有数据*/: l% v# p1 X" K& m
start_print(PRINT_CHAR);0 r' I7 u! x7 M5 I
}' O& R! c% p. Q2 M% @
break;+ v" Z$ N3 o/ F. y, c
#ifdef VERTICAL_GRAPH
* z _7 d/ Z+ _# E% @case DATA_TYPE_VERTICAL_GRAPH: /*垂直取模图形*/
2 j/ m# \' I8 t% m+ z project_Parameter.print_type=DATA_TYPE_CHAR_COMMAND; /*丢弃原来的数据*/; F" a: q1 R$ L) {. X( D
memset((graph_data_t *)&graph_data,0,sizeof(graph_data_t));9 } m7 Y2 X) h, x: x" m8 Y
break;
) n8 g7 W+ D2 G8 l: Q#endif( j9 a x! }( v/ L9 z
case DATA_TYPE_HORIZONTAL_GRAPH:
3 F% m! q% K" w- n7 A( {3 Y1 o project_Parameter.print_type=DATA_TYPE_CHAR_COMMAND; /*三次读不到数据,认为结束*/" e' \" r& }, A* c, Z5 Z
graph_data.data_finish=1;( Q" F. E, O, z) q) e
if((printer_work_Parameter.printer_pause==1)&&(printer_work_Parameter.printer_work_model==PRINT_HORIZONTAL_GRAPH)) /*图片打印过程中暂停*/7 S9 v0 x$ M& { r. i& Y$ l
{, i. b/ G) v0 A" S
Resume_Print_from_pause(printer_work_Parameter.printer_work_model);
; p- L# k3 M5 Z4 L+ b}7 b$ A; B2 F, P
break;
' {" y: t; k% V+ Scase DATA_TYPE_BARCODE: \- S! h+ k6 x/ h
barcode_error:
9 I8 K9 ?' u8 v: q9 Zproject_Parameter.print_type=DATA_TYPE_CHAR_COMMAND;
) ]# w% t6 o% U/ ]$ gmemset((barcode_data_t *)&barcode_data,0,sizeof(barcode_data_t));
; _$ k7 k6 a8 e0 kbreak;
" C4 L. l* B" } u8 odefault:" d0 u8 l t! c0 ~
break;1 _: @+ ~: H& f
}7 }. A- E$ k4 K' U
}' j6 X" B8 P0 n9 E Q
}6 Z% B! g2 K$ n1 Y9 G3 G
#endif
: H( @+ D3 A9 b9 T}6 k) @7 w( K, f: W8 d% H1 w
, R, r C9 S) Q* s* R3 w# T0 H+ m5 d; J& u
|
|