|
|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
lpc1114热敏打印机源程序 . I, ~& [; n5 S) _2 `, N
5 H; |! g1 a) Q z- t* Q1 c$ g# l4 R//本文件主要定义可程序的入口函数main, main函数里主要对系统、参数、硬件接口进新初始化,之后等待读取串口数据2 S- f2 T. U# S5 x0 `1 g
#include <stdio.h>. ~5 m9 Z- G; J2 D: Z. C7 v1 P; j+ y
#include <stdlib.h>
3 Z/ A) U0 V* z/ d y; G, ^#include <string.h>
3 `; m% X* L9 B5 s1 l9 `#include "LPC11xx.h" /* LPC11xx definitions */; l" C( A* d/ F6 t) T# y/ [8 L( I
#include "uart.h" 5 p2 E3 `. p7 L5 F% z
#include "timer32.h"& }& u# A4 ~7 P
#include"aw_print.h"
2 d/ z( j: p; D: x#include"aw_init_printHead.h"
$ V0 p! U" c2 b H% o) _ ]#include "aw_config.h"
2 S" V7 l& T0 ^7 t#include "aw_font.h"5 K* P8 w8 z S7 e2 Y8 ]
#include"aw_key_led.h"
% O' d1 t W: T6 ]- O* p#include "user.h"
* ]4 z& o0 I; b& P#include"aw_char_app.h", ?6 l8 M9 W& X5 T' t- l1 V
#include"aw_graph_app.h"
) D/ T9 y- W. {: T" r9 P. r#include"aw_barcode_app.h"
- d: H w( W0 _: _#include "aw_command.h"
/ h/ p* j( }% S, e) f#include "pmu.h"$ O, v. c8 x# x8 l, j0 U$ _
//初始化系统中的部分全局变量3 O" ?& X; N3 W" q
void init_Global_Variables(void)
0 U' \. I, b1 j! o{
4 O0 ], a2 y' u$ X( v; h current_char_index=0;& M3 A( `8 _7 T4 Y, y# q, h& G$ j
DealBuffer_counter=0;
$ Y+ y1 o1 J: B' O {/ e$ | memset((low_power_t *)&low_power_Paramter,0,sizeof(low_power_t));
9 m" Y/ Z( u+ j J memset((printer_work_Parameter_t *)&printer_work_Parameter,0,sizeof(printer_work_Parameter_t));
7 T' D/ r4 {- m3 }0 V! [" m. u printer_work_Parameter.printer_work_model=PRINTER_IDLE;
2 R" ]; K) o) j( V7 A7 @ feed_dot_step=0;: R: L v' d; L9 g2 L" g( E
paper_out_flag=0;5 }: p! l5 Z% |% P
head_up_flag=0;
: B- P& a# U8 c- f! c) R7 V! e l clear_buffer();
' m Q. Q6 |% R% \! `2 U" T memset((Key_IRQ_Parameter *)key_IRQ_Parameter,0,KEY_NUM*sizeof(Key_IRQ_Parameter));
1 x9 I x9 N: Y* K$ ?. e}+ y- w3 ^" j! `
int main(void)
0 F( x* w- C& i: d8 q{
. B' a6 u( L- B0 c; }/ d #if UART_DEBUG
/ L0 X8 t4 T1 v+ y* e9 \& ], K char buffer[1024];
9 Z# \- Q2 Y6 V* M* |3 G: t uint32_t counter,timer;6 X/ ?6 I9 t# N/ ^' o0 i! b
SystemInit();, y* j) ]1 {! H3 a! ?+ R# Q- ^/ P
Init_Sys_Parameter();* k4 c. L) F% d% |! l
init_Global_Varibles();8 U; ?) O2 B/ |- ^+ U
UARTInit(sys_Parameter.uart_para.baudrate);0 V0 J2 \* t/ L/ m" Z% p& C* ?
#ifdef PROJECT_DEBUG* z- X( ]" p4 F1 k+ n Y. D4 l4 C
printf("\n\r-- Printer_Project V1.0 --\n\r");4 Q; K: ^9 g1 S( }+ a
printf("\n\r-- Serial Communication test --\n\r");
# R% B( w+ s/ K* B e& _. `( |( N- m #endif
5 b) @, z' V8 \9 C$ {0 M( @ counter=0;
: h& Q9 M! @, Z9 Z" e, f1 T timer=0;# U' g, ]: t* Q! C$ G. n
memset(buffer,0,1024);1 ? N3 x% p6 o1 Q
while(1)
7 m$ C$ }' l0 g- R {
A" `6 @9 S0 |) h& e y6 ^ if(UartBuffer_read()==1)
# j& Q( p- L) R3 B R {
- J% S/ R: o! D" }" B/ f timer=0;mEMCpy(buffer+counter,&DealBuffer,DealBuffer_counter);
( p- Z. d) N7 M5 W counter+=DealBuffer_counter;7 B5 D. ^$ D4 Q; b+ j0 o
}0 z6 o. \- F$ X+ ]
else
- b1 @! ?0 r! W$ C' {{
( ]4 p- W# q6 m$ j if(timer<10)
9 w8 ~% n0 H2 o$ |/ G" l: \ {
2 K% |7 z {! G) U timer++;$ i6 q: k8 `; Z; j' h
}/ a2 R- T: m0 A7 K. }) K, H! d* y
else if(timer==10)' z V1 q7 E/ \1 z% C: }6 p- M* j7 b
{
1 R# Y9 A" Z. N( o& `2 k if(counter!=0)
* Z& s* ^. D7 J {1 ^# X# n! N9 l5 \( l1 L
#ifdef PROJECT_DEBUG
9 C, h `, q3 ~5 N+ _ printf("%s",buffer);
! c3 P9 O1 v; R8 R8 @# C$ W2 M #endif6 v2 M2 [" Q7 q# B s
counter=0;
7 s: W3 u' f j8 ?: j memset(buffer,0,1024);
. y; K) e7 u ~/ O timer=11;: _: `, E2 J2 g7 J" ~
}
4 G6 h5 B8 H* q3 M$ Q3 a, M P}3 m: f0 C( R( I5 K; W
}
$ {2 c) N% t4 ^5 u# l: i: Z+ j; ^0 }#elif SPIFLASH_DEBUG8 R6 }' O: {! s$ |* z. v
uint32_t BaseAdd;
0 }& m! M! N; suint32_t Address;+ ^' T Y* t2 s0 K0 }8 b
uint8_t MSB=0xce,LSB=0xa1;
& c, ^; G% C9 z7 Q/ Fuint8_t dot[118];
5 h+ T( }( q2 W& [& bSystemInit();
: r7 D: ^$ m+ g( N; H! _) uspi_flash_init();;
3 y7 A. D3 T- ~7 Awhile(1)# `) p5 Q2 s( L! U* V" i( ^
{
+ `! u3 @1 ~' Q ~7 }. s5 y* p BaseAdd=BASEADD_GB2312_11X12;
3 i( g( D# }: b; ?" o9 k! w* Z; c if(MSB>=0xA1&&MSB<=0Xa9&&LSB>=0xA1)
5 _$ V8 b4 q! K' I1 o0 G0 P {
2 ?4 Z8 G9 S9 y& a; v) @ e+ K Address=((MSB-0xA1)*94+(LSB-0xA1))*24+BaseAdd;
7 u* l: C4 g' {' Q}
% _& [2 L8 _6 U( ]& Aelse if(MSB>=0xB0&&MSB<=0xF7&&LSB>=0xA1)) O1 `. \) ~; v2 c' J' x
{* B# w: Q9 O' y! W5 K# |, i
Address=((MSB-0xA1)*94+(LSB-0xA1)+846)*24+BaseAdd;
, t$ r1 @ Y' w, c1 b2 ]}6 Y3 g2 _* ?% h; C& L9 T- b+ n
read_spi_flash(Address,&dot[0],118); /*取点阵*/4 B4 X4 r# p2 C+ s+ E
LSB++;$ o4 Z+ |, m# H
}# L9 Q) n( F8 ~3 C! o# V
#elif PRINTER_HEAD_DEBUG" B4 Y; n8 a+ R1 A l" {4 z Q
int i,keyval,keyval_bak;" F: z3 {. T @- w7 y3 |* ^
uint32_t j;
8 c7 ]' X9 S6 a: t: J. j$ C/ GSystemInit();
, ~7 T" |3 ~3 }Init_Sys_Parameter();
: H5 M) } y; F2 [# h: yinit_Global_Variables();
' ^% N4 m, v6 g& einit_Printer_port();+ [: z1 T, p# q. m* N
init_key(); /*4、按键初始化*/6 b' I! n9 @; l, d& q
while(1)' D @1 O: {6 W' ?% R9 Q, E0 e
{' p) Y' ~) r' }2 t- u1 I2 B% F) N3 V
# o. a- V& T1 O}
/ L+ L/ O* v( }9 Z$ |; ^ P#elif TIMER_TEST- I; ~+ y+ d7 L) J8 O, d, k) E7 u
uint16_t time;
. L3 @) e7 K2 ~7 _. I5 S Kuint8_t i;
6 L/ ]& _ G, n' _# |SystemInit();
# q" g3 i4 Q9 U( _- n( VInit_Sys_Parameter();% r( C2 H% }4 Q. m0 C4 m# U% B4 N* Y
init_Global_Variables();7 ^) q3 x6 v- v+ Z, z
UARTInit(115200);. u$ ^1 k" L0 Q4 v0 Z
common_timer(1,1000);
* u+ H1 L5 |8 l( E7 g0 K; |while(1);- l# t/ s2 B: ~3 E% O
#else
) {* o3 b G( ]0 u* T* c4 B9 Quint32_t timer=0; /*用于记录连续读不到串口数据的次数*/
7 A6 `* _2 N* q6 N; G2 vuint16_t get_dot_count;
2 f) g1 f, W' |/ L( [% quint16_t effective_dot,num; /*可以用于打印的点的个数*/
# T2 Z$ ?# g+ ?5 r( TSystemInit();
" V& d0 A" b9 W# y; u& W5 hInit_Sys_Parameter();
2 ]* L- G+ c! o2 KInit_project_Parameter();
" r& t1 N0 ~5 s+ i3 R* i6 ?init_Global_Variables();
) Q/ O* F8 ~5 o, p8 L3 qUARTInit(sys_Parameter.uart_para.baudrate); /*1、数据终端通讯串口初始化*/) ~- M1 ~3 o: a. {% x# |2 r
init_Printer_port(); /*2、热敏打印头接口初始化 */
/ ?, {0 h) T5 T- a" J! Tspi_flash_init(); /*3、字库芯片通讯初始化 */
; a/ d, |! W. Binit_key(); /*4、按键led 初始化*/7 D) M! F. Z. y6 c* ]5 n
init_led();
+ A5 f0 _/ k4 j* ?* E! K9 I" |7 Mcommon_timer(1,COMMON_TIME); /*启动公共定时器*/
& v5 @3 T& s$ Q, ] j3 u8 E/ vfor(timer=0;timer<0xf000;timer++) //延时,保证先前的初始化起作用
9 @2 y' w7 p# S& J' u& w{
$ g2 y: c* l: H' B$ a$ F6 m' E1 s ;4 X; s& @6 H) |; y X
}. m3 V; q' ]6 s$ [
init_cutter_position(); /*让切纸刀回到 限位开关的位置 */) `5 \6 j, ~$ C9 {" E) J7 ~
motor_driver_step40(); /*让电机先反正转40 步*/ 1 X' g2 F: I, h1 H1 T
Hardware_flow_control(UART_FREE); /*初始化结束,允许串口接收数据*/4 q: S" \3 \( E8 v+ q
timer=0;# L9 {2 i6 E6 K
while(1)7 ~& ~; l* J7 W, y
{
h* H" @/ ?1 r6 a current_char_index=0;
' @2 j# M* r6 m if(UartBuffer_read()==1) /*读取串口数据*/
1 N1 h P6 X, }) v. p {
% d1 A) ?1 @8 T5 I0 j5 a timer=0; /*串口有数据时,将此计数器复位*/) }7 C8 I. ^9 x: O
while(current_char_index<DealBuffer_counter)
4 r' f( S0 P* ?- n7 `5 A; v {0 w; f. i5 _3 R
switch(project_Parameter.print_type) /*处理串口读出的数据*/
! V S% @2 _- e6 v6 I {( R8 ?1 y: p) j; f
case DATA_TYPE_CHAR_COMMAND: /*字符或、命令*/" s4 Z1 o. I5 z3 M5 K; h+ R
if(determine_data_command((uint8_t *)(DealBuffer+current_char_index))==0)9 A. O1 n& H: S4 @1 z
{
& c( k, t. f0 `2 R9 ?. s4 a8 N if(Save_char()==0); w3 c7 U& E' \& j9 |" Z1 `6 ^
{! L8 }$ b8 y: F7 Y y+ ?# z9 V
continue;
! {) M/ C( n" b9 B" N, H& e# R$ Q}
$ ?& a8 g% P. c0 ] hif(printer_work_Parameter.printer_work_model==PRINTER_IDLE) /*空闲*/ I: v5 c% g+ V( D# \
{( x; X9 H3 \6 I( I% F& }
if(calculate_get_char_num(&num,&get_dot_count)==1) /*有一行数据需要打印*/2 p a- `7 _ o6 q% L# |8 n* I
{
& C. ]- n& D8 c+ m! F6 K start_print(PRINT_CHAR);
' k& [8 V3 U# h: T8 ^$ r' [7 }}
4 |+ Y+ p6 }# a$ i9 o9 a}1 X' n6 l9 r* \
}
. \+ e% M' z/ w$ k, K- [else /*命令处理*/" E5 t# A+ N# z
{
, n& B! d6 P( V( i: r5 _6 a3 C% i command_deal((uint8_t *)DealBuffer);
2 U+ n; O y" j! n$ a$ `- q' D}
# ^; N' j% ^# U: I8 bbreak;0 S- r8 v, B4 H7 [; }7 ?
#ifdef VERTICAL_GRAPH
; M' N( E1 \8 C7 [% j8 c- u! i: ecase DATA_TYPE_VERTICAL_GRAPH: /*垂直取模图形*// i* p+ l4 V7 _2 i( H: M. n% H$ X1 k
if(save_graph()==DATA_ENOUGH) /*数据取完,恢复默认数据类型*/* d) l" } j+ ?& ~6 ^. d
{
/ B2 U/ N! h+ y5 _4 k4 @ project_Parameter.print_type=DATA_TYPE_CHAR_COMMAND;3 h+ V4 S$ [4 D
}
. G/ O8 q' b( F, D$ J$ Hbreak;
# K3 b- h3 M: i3 u' X#endif
0 L- ~7 N: c$ m8 Y8 wcase DATA_TYPE_HORIZONTAL_GRAPH: /*水平取模图形*/% H' P) L j! x5 @
if(save_graph()==DATA_ENOUGH) /*数据取完*/
2 n0 m4 H9 N; O4 _4 y) I9 @. p% z {( N4 N! G6 C. r. I6 K" f
graph_data.data_finish=1;. e6 p7 y3 I/ t) h
project_Parameter.print_type=DATA_TYPE_CHAR_COMMAND;4 a, l$ M. y7 i7 [
} /*空闲时,并且有一行以上的数据需要打印*/
* x7 ]- c+ }, M6 p8 z! ?5 \$ tif((printer_work_Parameter.printer_work_model==PRINTER_IDLE)&&(graph_data.buffer_counter/graph_data.horizontal_mode.horizontal_byteCount>0))& J3 [) E) Y; E9 K1 x3 l" S7 S5 }
{
# d/ L- H! ]! r start_print(PRINT_HORIZONTAL_GRAPH);$ }- |0 ]6 T a8 C3 W' ~$ T
}
4 |% D/ y$ q) E5 R+ S1 \8 lelse if((printer_work_Parameter.printer_pause==1)&&(printer_work_Parameter.printer_work_model==PRINT_HORIZONTAL_GRAPH))3 L7 p. `# w4 n
{ /*从暂停状态恢复打印*/ /* 数据接收结束*/& L0 p* U( z M/ M. f( ?% i1 s
if((graph_data.data_finish==1)||((graph_data.buffer_counter-graph_data.printed_byteCount)/graph_data.horizontal_mode.horizontal_byteCount>0))7 {8 p# v: M m2 s, J$ N
{ /*还有至少一整行数据*/
1 U) P* T* q* _# u8 Y Resume_Print_from_pause(printer_work_Parameter.printer_work_model);
% d( K5 T# }7 p% i}
( t4 |& _1 u) K6 f" ]/ x1 V}3 J8 z* \$ A: @% s& `+ T5 r- M' ~
else if((graph_data.data_finish==1)&&(printer_work_Parameter.printer_work_model!=PRINT_HORIZONTAL_GRAPH))
5 Y, M# I5 ^+ k) F# M5 v5 l{ /*图片数据接收完,并且打印机还在做别的工作, 取消本次图片打印*/+ _& q! M; T$ N j7 o% i' S
memset((graph_data_t *)&graph_data,0,sizeof(graph_data_t));# Z& P. |- ^5 N: V
}* {; ~$ ^! n( k1 ]/ n K' B$ @
break;6 s( m. z, Q J/ V# ]( ^
//case DATA_TYPE_BARCODE: /*条形码图形*/. d9 Z, {8 ]% M5 ]0 l; `5 I
// num=save_barcode((uint8_t *)(DealBuffer+current_char_index));
- A3 Q" _ n* d0 t7 W" D$ n4 w4 g//if(num==DATA_ENOUGH)1 b# }' Z$ t# s: S) Q/ Z9 B+ l$ S
//{
1 h, g- G0 \, U5 Y R4 X8 \// save_barcode_parity_bit(); /*数据取完开始打印*/
+ D2 U& i Y3 E1 [// while(printer_work_Parameter.printer_work_model!=PRINTER_IDLE)
6 _7 s* K- E2 w# C3 E. u// {3 |/ T$ ?$ ?* G9 P% J
// ;
$ [+ |% N4 [5 p" A, |5 ]//} /*条形码超出打印范围不打印*/1 [/ ?8 l7 _7 S( q; z- l9 M4 n
//if(project_Parameter.cursor_position==0) /*本行还是空的*/4 M' C r; u9 }; ^9 N
//{: O2 z& A0 f/ X
// effective_dot=MAX_DOT_PERLINE-project_Parameter.print_position-project_Parameter.Limited_width_left_para-project_Parameter.Limited_width_right_para;* [$ s6 F4 l2 {* S: [9 v- r1 s
//} M9 ?$ e& t+ t2 Z' O V
//else/ R; B1 [7 h" q' B5 t% [# L
//{
6 O) c V, j$ [/ I, _2 W" o/ u// effective_dot=MAX_DOT_PERLINE-project_Parameter.Limited_width_right_para-project_Parameter.cursor_position;
5 E/ a n3 X+ j7 B7 K$ R- J! u! V+ J//}
. h9 f# m, B2 W& ] d' S2 L//if(get_barcode_dot_width()<=effective_dot)
}# x( [5 d+ ~' [" Q7 y. K+ d//{
$ E1 ~- A9 Z; q! l$ b// start_print(PRINT_BARCODE);. ?, R+ s; c# ]8 P5 o; p
//}
7 |. E" l. S+ G1 Y0 X//else1 m; d# Q+ W1 } f2 t6 |/ p; Z
//{
) s- g2 i3 x5 w3 d// memset((barcode_data_t *)&barcode_data,0,sizeof(barcode_data_t));, q3 P$ ?5 R8 S O6 ~8 s7 W, @
//}
" w; U6 C) P& |: l) o/ W1 Q//project_Parameter.print_type=DATA_TYPE_CHAR_COMMAND;
x& g1 K' q/ N" l$ X! ^& ^/ {//}7 K2 p; ^) t8 I/ i( H4 q
//else if(num==DATA_ERROR) /*条码数据出错*/
& O; k4 p; D( v, ^0 ^4 X7 x//{
5 p; W/ q' D( s; W// goto barcode_error;( R! g" q. B: N( u
//}) L& R; a+ x% a9 M
//current_char_index++;2 @' l6 H2 `; p. z% A: x% m8 O
//break;! I6 _, ^7 \ [9 i: t
}
/ e8 A5 T7 V8 d$ \5 |}
6 x, f2 C+ p( n* r}' B2 I4 F) L% F0 j9 S
else /*串口中无数据*/* E9 a; |: Y" U& ] h
{
% S r. c1 c% @: F$ l( G# |2 \ if(timer<5)1 C, y, m" Q7 g1 P- a
{
1 |' x6 k) W$ D# T" w: ]& _0 B timer++;
7 k" ?, f8 T( S continue;/ H7 W1 ?! I! S+ ~/ x$ _
}
* U4 u: U3 \ {8 Lswitch(project_Parameter.print_type)/ [+ Z, \, n* [1 b1 W
{+ d2 B3 J9 m. M
case DATA_TYPE_CHAR_COMMAND: 6 o# z3 z. r1 y/ {2 d
if((printer_work_Parameter.printer_work_model==PRINTER_IDLE)&&(char_data.printed_byteCount<char_data.buffer_counter))% d) }+ ? u. L
{ /*空闲时,并且还有数据*/
* L3 o2 x4 H* N0 S3 a, P, M start_print(PRINT_CHAR);
; O0 x6 d( L! }0 U}
6 L. j) r$ I* N( r5 s: ^. j9 hbreak;2 G0 b; @4 m, B. {& T
#ifdef VERTICAL_GRAPH* h( ?7 h& K u7 f2 f) v( P2 W4 T
case DATA_TYPE_VERTICAL_GRAPH: /*垂直取模图形*/1 a9 m+ M5 }9 [" r
project_Parameter.print_type=DATA_TYPE_CHAR_COMMAND; /*丢弃原来的数据*/1 M& A7 _* X3 ^! D9 h; H
memset((graph_data_t *)&graph_data,0,sizeof(graph_data_t));/ W4 P6 w2 R7 e+ R# \- R3 C
break;9 t0 @% s+ p+ h' K
#endif
9 V1 u( F2 Q4 g$ N% wcase DATA_TYPE_HORIZONTAL_GRAPH:- e7 R7 R( M& d1 R2 S2 H; R
project_Parameter.print_type=DATA_TYPE_CHAR_COMMAND; /*三次读不到数据,认为结束*/# D9 }. A6 A9 o* b) [4 M
graph_data.data_finish=1;
) Q! d# k" {) ^& O8 g- K4 Cif((printer_work_Parameter.printer_pause==1)&&(printer_work_Parameter.printer_work_model==PRINT_HORIZONTAL_GRAPH)) /*图片打印过程中暂停*/: I! a; t" S$ `8 \7 M
{
7 l/ f4 c! ^- j0 W& N6 A) \ n* {9 n Resume_Print_from_pause(printer_work_Parameter.printer_work_model);, f2 U6 e6 `' s
}
: f- M# p% F# p* Q! }( ebreak;# q! t. n3 z0 q' K7 X3 b6 [' \
case DATA_TYPE_BARCODE:
# g, s: X/ q) w3 a/ ]6 D5 N barcode_error:
; m2 b% V! s" m1 q2 l3 Uproject_Parameter.print_type=DATA_TYPE_CHAR_COMMAND;+ G0 p2 ~3 z4 L$ D4 [/ s
memset((barcode_data_t *)&barcode_data,0,sizeof(barcode_data_t));
8 r1 |: S! t5 ] P3 jbreak;
1 n: A+ s. K) N% C" f l& gdefault:
& r! S) I# _! W) g3 V/ H7 t break;
4 x5 k: K) G( q: Z- N* Q8 n- \$ O2 M7 ]}$ F! d6 g( M, A/ d+ Z% v
}
3 H! X; ]2 k5 K8 v3 C8 b; ^}6 I3 \1 @5 y& r* Z
#endif3 i0 a! o2 B/ B' {) y
}7 O. u0 `- p3 c# e
; d2 l1 k/ c9 j9 a' M# Q0 p& g9 w$ z1 `5 ~0 [
|
|