|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
lpc1114热敏打印机源程序 5 R4 k* t" \1 r) P1 o( a
' V9 j( u4 ^8 a$ l; ?- {3 s2 F) H% L//本文件主要定义可程序的入口函数main, main函数里主要对系统、参数、硬件接口进新初始化,之后等待读取串口数据& x$ Y# Q7 H& R
#include <stdio.h>. g( @. Q& U4 p
#include <stdlib.h>
" g" m3 p _2 q9 Q/ @#include <string.h>8 D( J9 y. a! q# j: r. g
#include "LPC11xx.h" /* LPC11xx definitions */
4 n4 `/ i$ B) m/ R. {#include "uart.h"
. A7 J) u- u3 ^#include "timer32.h"
5 v& N/ }* r3 n' b7 a, w' [#include"aw_print.h"
6 g- Q6 u/ L$ \" @) y#include"aw_init_printHead.h"
# V- z& s E; c#include "aw_config.h"
* S4 {4 t; q) q) P0 `" l( Z( w; I/ {- k#include "aw_font.h"8 |0 s" u1 P* N+ D/ L% H) Z
#include"aw_key_led.h"
# ~6 z. w# n. p. P#include "user.h"1 B3 B1 p) A1 i5 m' a7 W
#include"aw_char_app.h"
* f6 l% U) f6 s* ?#include"aw_graph_app.h"
x1 N3 h, ^2 A' Y$ [#include"aw_barcode_app.h") @; L* d' n- n4 I6 {- p
#include "aw_command.h"( f3 N4 |% D" m: e
#include "pmu.h"* Q- z5 f, e; _; b8 \8 F
//初始化系统中的部分全局变量, I, J" z- M3 g0 `6 S S/ [
void init_Global_Variables(void)
3 |+ L. E' W& Q* |: g( }8 U; C{
* `( d) b5 U5 ?; b2 Y4 s current_char_index=0;
0 M" d; \! W+ U& w2 H7 z. M DealBuffer_counter=0;1 n4 Z4 T) W, I
memset((low_power_t *)&low_power_Paramter,0,sizeof(low_power_t));# x8 H2 X. r% F4 t4 l3 H
memset((printer_work_Parameter_t *)&printer_work_Parameter,0,sizeof(printer_work_Parameter_t));3 f/ W9 g+ J, Q( W; k- f
printer_work_Parameter.printer_work_model=PRINTER_IDLE;
- H% T4 w9 |' a- U, @3 Y: i feed_dot_step=0;7 r9 [, ` E, V5 Y$ T
paper_out_flag=0;1 J7 R! | [9 s2 f, Y
head_up_flag=0;$ a; u: a/ U7 m" y! p% f
clear_buffer();
+ F, {/ [* V. {2 E. f memset((Key_IRQ_Parameter *)key_IRQ_Parameter,0,KEY_NUM*sizeof(Key_IRQ_Parameter));
. U9 X; i- V) [) e8 k. \}
9 Y% y9 l F: @7 }% G9 ]- Jint main(void)9 D" ^: c l7 J3 H
{
5 _0 m" b; W8 w( i* H #if UART_DEBUG4 e: m$ P: O F- h. t( U
char buffer[1024];
# K J' D, F1 e/ g9 n uint32_t counter,timer;
; P( s) [7 y s+ G SystemInit();
, h) x8 u+ _9 q; i1 {& t9 Z Init_Sys_Parameter();
2 A7 f! T4 T! N) R1 y init_Global_Varibles();2 L7 u8 E$ t2 `0 _; |9 z0 C
UARTInit(sys_Parameter.uart_para.baudrate);7 H! E0 P1 N; x) P) K: S5 @
#ifdef PROJECT_DEBUG
; K J7 w i/ ?& a/ w$ u, j5 w printf("\n\r-- Printer_Project V1.0 --\n\r");
w$ V' x3 `0 K9 z7 C, D: x printf("\n\r-- Serial Communication test --\n\r");, h5 D( w, m) v9 `
#endif: x0 I, `- T& f6 ~( \& h
counter=0;
k$ [0 m' Z7 O5 f) V ?) K timer=0;
- m) F# L% m- O! V, T. V( I; u, b$ p memset(buffer,0,1024);; D( D+ h" M% q
while(1)$ K6 g' n5 S, W
{, ?# |5 R. u( d' u& s( B" L5 E
if(UartBuffer_read()==1), k, M9 ]) `) b# t: a, o
{
( O6 q' G" k8 L3 a% a timer=0;mEMCpy(buffer+counter,&DealBuffer,DealBuffer_counter);7 i' ^' l0 v$ M5 C+ Y) c
counter+=DealBuffer_counter;* r0 I$ l) i5 {1 A! f
}/ ~1 N& _( u/ P+ |' j! t x
else
! }9 Y _# ], j6 L5 v: n+ f{
# t4 a/ F3 E' ] if(timer<10)
. a. _, D9 _7 U! o( w6 S! e {
2 f8 P( f* q1 Z; [" @& Q timer++;+ R2 F$ X0 @3 q4 T
}
4 [. v1 I) j5 P- y5 helse if(timer==10)
+ M5 J _. N! {( Z& B: y{) e9 W0 t2 p6 w. M' Y9 ]. D0 C3 T' B
if(counter!=0)" t: R6 z/ W! g5 X+ @$ X3 [
{
7 K! K2 ~) v, B) }9 L #ifdef PROJECT_DEBUG
' X% s) T' Q& O printf("%s",buffer);
) p/ L( X r/ p6 u #endif+ Y/ F% P+ P9 q4 R1 d2 n
counter=0;
, N& h) q* F8 @* b# m/ @' w/ n memset(buffer,0,1024);
' e9 ]0 w! j* Q2 A8 z timer=11;# U& x; p1 x/ S0 y' Z" x# }
}
* f; j. ~/ ?6 v. H}
8 v- B: ~( [% X4 _% E3 x}
1 u9 b4 s* }1 |0 [) ^! L- X) f" a#elif SPIFLASH_DEBUG4 f k( s7 L4 S/ ?7 Z
uint32_t BaseAdd;* Y) |; k2 i" Q
uint32_t Address;" M q; T' h. X# e S
uint8_t MSB=0xce,LSB=0xa1;0 W' h. A3 A. S8 E7 b
uint8_t dot[118]; r( ]! G! N. |( U1 \ e: O
SystemInit();" Y# O* k' I4 t8 J S. c% K
spi_flash_init();;2 t4 a( ]) j/ @* C
while(1)
5 b; l/ u- O5 x- K2 h) m{ y* s3 ?, }8 Z4 u5 @( l2 E
BaseAdd=BASEADD_GB2312_11X12;8 U/ {: G. F4 U8 Z
if(MSB>=0xA1&&MSB<=0Xa9&&LSB>=0xA1)% g m- h0 I2 s; v
{
" w* U, A; p$ x4 N! e Address=((MSB-0xA1)*94+(LSB-0xA1))*24+BaseAdd;( x1 F: m# I8 M8 v3 x* p
}
5 V8 o& K m, F4 a' s3 |, J" delse if(MSB>=0xB0&&MSB<=0xF7&&LSB>=0xA1)6 M! r* t+ e+ s7 Y* g' A3 O2 d
{
% j) x8 N. c; \ Address=((MSB-0xA1)*94+(LSB-0xA1)+846)*24+BaseAdd;
% a8 |: Y H3 ` S3 Q5 V. s- B}
6 n5 N! L' ]$ U: _read_spi_flash(Address,&dot[0],118); /*取点阵*/; }: B) H- n4 m. I
LSB++;' I1 o& D6 Z) R& p9 m
}/ Y6 J* n- e) \7 |: V2 b; k
#elif PRINTER_HEAD_DEBUG
4 a) Y; M" ^2 \% @4 W7 M# Bint i,keyval,keyval_bak;+ {/ ^# T7 s* \' ~7 c
uint32_t j;: `% N9 m2 ]! W6 H( z: M
SystemInit();
. z. `% y5 I( y0 DInit_Sys_Parameter();
4 B! \, ^, _: F1 U! [! @init_Global_Variables(); @3 ]! u# c0 C% D1 u$ h0 o& {
init_Printer_port();* t( Q# o% j% e+ j
init_key(); /*4、按键初始化*/
3 z8 d) Z0 z5 g5 n5 c1 Bwhile(1)* m9 ^9 z, a8 i$ G7 f, ~
{/ u7 ^! s0 b8 R, O9 O! j; d; h$ Q2 z
# b; d5 N- R2 b4 v2 [2 S}
& x) s8 b _8 {, @! i4 I/ M0 T4 V#elif TIMER_TEST& p$ H' [3 @; Q, M f1 V
uint16_t time;: p8 O$ `0 U: c8 @: V# ?
uint8_t i;& s# k# L) k2 O; d5 D
SystemInit();9 t3 X7 b- U8 h
Init_Sys_Parameter();' e, H' P3 v+ K' ?. h) h. Q
init_Global_Variables();" s6 H0 n5 a3 O1 f1 K( I5 v
UARTInit(115200);8 }% L7 o4 ?1 M0 \. `
common_timer(1,1000);
, s/ s/ n4 [* k- K; V( uwhile(1);6 W) z5 L+ m5 z# z. }/ S+ T
#else* J/ Q8 r3 _) O/ d! r
uint32_t timer=0; /*用于记录连续读不到串口数据的次数*/
/ U& E! d: t5 ~! R! r& K4 h Zuint16_t get_dot_count;! K/ h2 u7 N) Q4 F3 E Z5 n/ p8 R& l
uint16_t effective_dot,num; /*可以用于打印的点的个数*/4 r; j. i0 b1 \$ h0 u# Z6 q
SystemInit();
/ M) L; r& E" M$ J6 P# K+ e% sInit_Sys_Parameter();2 @2 q8 g1 N" W: x# C
Init_project_Parameter();3 [* B) g9 L5 \+ ~1 u, e
init_Global_Variables();
1 z& O7 k0 y) d F `UARTInit(sys_Parameter.uart_para.baudrate); /*1、数据终端通讯串口初始化*/9 B+ u4 M. u+ D$ b* ]) z6 ?
init_Printer_port(); /*2、热敏打印头接口初始化 */
" M- m6 i* ~" G' P- a4 jspi_flash_init(); /*3、字库芯片通讯初始化 */% Z; h7 h; B+ M
init_key(); /*4、按键led 初始化*/+ T: W! v! }& {% p% I' C
init_led();
( D8 `$ d/ q. @5 Z1 Gcommon_timer(1,COMMON_TIME); /*启动公共定时器*/ 7 b/ B7 w' b: g+ Q
for(timer=0;timer<0xf000;timer++) //延时,保证先前的初始化起作用7 o# x! S _( h4 L2 `
{, t" ` f; D3 J# `! r
;* r- }. ~2 ?1 m- F7 }7 b
}$ q) S R7 S h8 d* B* n# l
init_cutter_position(); /*让切纸刀回到 限位开关的位置 */6 _% G( \9 n# H- W3 B6 O+ f. J
motor_driver_step40(); /*让电机先反正转40 步*/ 9 t3 \: [0 j$ N& L7 i- l
Hardware_flow_control(UART_FREE); /*初始化结束,允许串口接收数据*/
5 T% R; j9 d `, R% Ptimer=0;
, J* T: V A5 H) V# kwhile(1); F6 R; r/ D0 e* s& l
{: a$ K0 i4 ]$ Z3 @0 ~
current_char_index=0;
" c9 P* O1 w& j/ t. o, _! V if(UartBuffer_read()==1) /*读取串口数据*/1 t }; @7 v* I0 u O
{2 ~; |* L( j. m% l1 T; [
timer=0; /*串口有数据时,将此计数器复位*/
1 B1 H' a% m# D; w while(current_char_index<DealBuffer_counter)
5 X' ?! t6 h' i5 V5 C {* F- I8 c' l$ f& h0 t7 \
switch(project_Parameter.print_type) /*处理串口读出的数据*/
& I3 ?: p6 W9 p* Y {& ^1 T) I; j) J7 W9 M
case DATA_TYPE_CHAR_COMMAND: /*字符或、命令*/1 c5 `1 M: @2 U) r7 u
if(determine_data_command((uint8_t *)(DealBuffer+current_char_index))==0)" L( h5 E- E& n y) Q; t5 U% b) t8 a0 u
{9 c# k- I0 ^2 s5 ]! E
if(Save_char()==0)
& g$ C8 U+ k( g. B {
# l' c; z% n, r) w. v continue;5 J) _% Q& W+ S" Y6 F8 P* `
}
9 l8 c3 _/ R& Z' W3 @* Gif(printer_work_Parameter.printer_work_model==PRINTER_IDLE) /*空闲*/
4 C" p- j/ c M' U{# b; y) N- s8 @+ x1 X
if(calculate_get_char_num(&num,&get_dot_count)==1) /*有一行数据需要打印*/
- i8 c e' @5 V) j. {, s {
$ @9 u3 s% C# v1 Y4 A5 J3 ? start_print(PRINT_CHAR);- w& b( i- l' n" @: |
}
* K+ d# e1 j3 n}& O5 N( _5 m' C! d
}- {5 f9 S* P+ T* J4 V3 L. ^
else /*命令处理*/" _- ~8 o2 @# U! L1 ?, M+ @
{4 w, y% o, D, w$ ]7 |% L$ y( C( R
command_deal((uint8_t *)DealBuffer);
( @, ]8 X6 R+ R7 U! [- h3 J}
! A+ S: l4 ^& K. y4 L+ V* \9 o; Vbreak;! v, w( k/ Z; T1 N" F' [! f3 L
#ifdef VERTICAL_GRAPH9 V$ n5 U8 J& Z( C x h5 o" M8 E
case DATA_TYPE_VERTICAL_GRAPH: /*垂直取模图形*/
* l: M) y/ \4 y$ V if(save_graph()==DATA_ENOUGH) /*数据取完,恢复默认数据类型*/
* O/ }- |, e. g S {
% C" P% s# R8 i j/ r: D: N+ f8 S project_Parameter.print_type=DATA_TYPE_CHAR_COMMAND;
) e8 V4 }6 v* G% P}! U ^$ l' g. v0 }, ?; h
break;
+ K/ W( s8 ]) M7 r0 G; O7 f; W#endif
+ r4 u. {$ j8 L6 |6 u" s/ Tcase DATA_TYPE_HORIZONTAL_GRAPH: /*水平取模图形*/, M, o1 X/ i9 @" G% Q; f
if(save_graph()==DATA_ENOUGH) /*数据取完*/3 h$ \ k$ E% L5 g
{' T4 F6 V: v7 `$ `7 d/ K
graph_data.data_finish=1; ^8 P1 @5 T: K1 \& h
project_Parameter.print_type=DATA_TYPE_CHAR_COMMAND;5 h0 `& V: b# Y+ Q5 C
} /*空闲时,并且有一行以上的数据需要打印*/& r+ H! h- u( d3 H! }) K. |
if((printer_work_Parameter.printer_work_model==PRINTER_IDLE)&&(graph_data.buffer_counter/graph_data.horizontal_mode.horizontal_byteCount>0))
. | t' ~5 R5 E$ o7 T6 t" }% ~! ^{
* [7 O; q6 x; F& K0 a start_print(PRINT_HORIZONTAL_GRAPH);* e' b. S r2 b" F+ J! r
}# J# ?7 ?. ~) |1 i: H1 P
else if((printer_work_Parameter.printer_pause==1)&&(printer_work_Parameter.printer_work_model==PRINT_HORIZONTAL_GRAPH)): ?& s- x8 L& ^" v/ |3 ^3 m
{ /*从暂停状态恢复打印*/ /* 数据接收结束*/. `2 S' p, l; R& D& T5 M% Y
if((graph_data.data_finish==1)||((graph_data.buffer_counter-graph_data.printed_byteCount)/graph_data.horizontal_mode.horizontal_byteCount>0))
8 x2 W' P/ d) m/ z% ^ a5 E. _1 z- d { /*还有至少一整行数据*/
9 D$ s2 P! L- P2 Z" m" W F Resume_Print_from_pause(printer_work_Parameter.printer_work_model);
5 a: `* l) u. C}& n; B, s9 u# a5 O8 f% M" b% S
}
5 C4 Z- H, m& E0 Pelse if((graph_data.data_finish==1)&&(printer_work_Parameter.printer_work_model!=PRINT_HORIZONTAL_GRAPH))5 o4 S( c1 H. p
{ /*图片数据接收完,并且打印机还在做别的工作, 取消本次图片打印*/
& G2 \" q# Y! I3 n7 t memset((graph_data_t *)&graph_data,0,sizeof(graph_data_t));+ I* H3 E. ^; }
}
& x6 Y" g; v4 ^$ a& G* E& W6 ^9 kbreak;$ E. Q9 V4 w* P8 `' E. k
//case DATA_TYPE_BARCODE: /*条形码图形*/3 J/ y2 T9 p8 T
// num=save_barcode((uint8_t *)(DealBuffer+current_char_index));
7 `* Y, p. e' o7 @3 v- S" E& t//if(num==DATA_ENOUGH)- I' o. z$ t# D2 U* K' g3 |
//{0 l+ q2 f6 _ \/ r1 j) ~ J
// save_barcode_parity_bit(); /*数据取完开始打印*/2 M9 J8 _! I2 `% u: E7 G
// while(printer_work_Parameter.printer_work_model!=PRINTER_IDLE)3 u& i' C: P2 J. k# Z
// {0 n- h- v) Z; C6 b
// ;* T: V7 w# x& i$ ?' j2 V
//} /*条形码超出打印范围不打印*/
5 C5 B0 V0 E5 Q9 R1 A7 U//if(project_Parameter.cursor_position==0) /*本行还是空的*/, f" u. F: {; P% V$ K) w, Q
//{
0 X- F9 I7 ?; s: a: F// effective_dot=MAX_DOT_PERLINE-project_Parameter.print_position-project_Parameter.Limited_width_left_para-project_Parameter.Limited_width_right_para;9 E1 j) q3 U: t8 I
//}: [) `/ Q* z. x1 t
//else* Q3 P; k$ z' Z0 P
//{
# Z: E+ h- N" v// effective_dot=MAX_DOT_PERLINE-project_Parameter.Limited_width_right_para-project_Parameter.cursor_position;
6 G6 K- v6 A+ S7 m7 {8 K+ J//}7 F8 h! G9 `* [3 D! Y
//if(get_barcode_dot_width()<=effective_dot)7 N. w& G% y: [0 y6 M& Y
//{* }8 K- f7 ]' a* ?
// start_print(PRINT_BARCODE);
' W1 O0 F1 T/ Z//}3 E0 A" v5 z: O/ o i
//else
/ t" i5 I" O8 o//{
2 }9 N5 R# n0 |: J5 d// memset((barcode_data_t *)&barcode_data,0,sizeof(barcode_data_t));
. P0 v" U: @- o, ~: H" I+ e//}0 t7 f; u+ x t
//project_Parameter.print_type=DATA_TYPE_CHAR_COMMAND;
# m! }; h' a+ Z( s1 S% s( r- r& N+ a//}
* E3 Z+ {/ Q& M//else if(num==DATA_ERROR) /*条码数据出错*/% \ |4 U9 e! t- z/ J( W
//{
* ~+ l# }% n2 f! O9 E- v// goto barcode_error;0 G; h1 ?0 U; R2 U" S
//}
; s0 ?9 K E& m2 v5 b//current_char_index++;
3 U! Y& F3 D8 u F% r" B9 f3 W//break;' H3 [3 P8 ]. u
}
0 R! }( v$ s8 p' P5 T0 [}
; A* V/ G t6 b/ ?6 r! o}
6 S5 \" B' ~5 Z( q, _else /*串口中无数据*/
& u5 g4 B! x3 f& |{# y3 G9 M" k# \/ C7 z4 ]. P! m( O( E
if(timer<5)
: T4 T6 D0 _9 e* l) W& t {
1 T6 ?: U& {( c. i" [# F# M timer++;
7 x9 O @8 [# C( r y s continue;
* ~- ]" A) F/ w, H) X* K: X}& [. `8 d0 @) r, g* a, i& M( O7 E
switch(project_Parameter.print_type)
8 E# w) U, J2 `{4 o" q- x+ ~6 K% c' i
case DATA_TYPE_CHAR_COMMAND: % I2 m3 g9 Z# `$ V: L
if((printer_work_Parameter.printer_work_model==PRINTER_IDLE)&&(char_data.printed_byteCount<char_data.buffer_counter))
! U+ w/ {3 S2 r& v+ P { /*空闲时,并且还有数据*/; D) \8 s8 d1 B
start_print(PRINT_CHAR);
7 [* j h, v! X8 p' m}
) k( k+ @$ `5 V7 V% v9 n2 T$ D# S9 ebreak;
. z/ O. Z9 r! _/ x# T#ifdef VERTICAL_GRAPH+ c; h* o% W# b% E3 i
case DATA_TYPE_VERTICAL_GRAPH: /*垂直取模图形*/
& t/ H6 g5 d& ?4 [7 C! ]" x/ I1 b project_Parameter.print_type=DATA_TYPE_CHAR_COMMAND; /*丢弃原来的数据*/
& q4 e* u) e4 i& smemset((graph_data_t *)&graph_data,0,sizeof(graph_data_t));
1 r% o. I/ P2 e# ybreak;1 j/ M( f& R6 L1 ~0 r
#endif
0 f- |) [: U; [+ Q. c, Y0 icase DATA_TYPE_HORIZONTAL_GRAPH:
6 |2 u& h7 m4 n0 k* ]7 o project_Parameter.print_type=DATA_TYPE_CHAR_COMMAND; /*三次读不到数据,认为结束*/5 e0 b T9 v3 s. Q8 |
graph_data.data_finish=1;
+ u4 a1 b1 i7 w0 L/ F6 bif((printer_work_Parameter.printer_pause==1)&&(printer_work_Parameter.printer_work_model==PRINT_HORIZONTAL_GRAPH)) /*图片打印过程中暂停*/
8 Z3 E* U8 w7 p: c0 O% A% w* ^{
( u/ f8 h" C9 G5 C; M \! K Resume_Print_from_pause(printer_work_Parameter.printer_work_model);# d7 z8 \% R V
}
7 U9 R4 v0 ?- N( J* z' mbreak;2 R4 ~0 V4 V' C2 K0 i' ?: R# g2 |6 {, _- M
case DATA_TYPE_BARCODE:# E5 N7 U& e. \9 f. ]
barcode_error:0 s: M$ V) r6 Q) A1 D
project_Parameter.print_type=DATA_TYPE_CHAR_COMMAND;" Q! t0 [% E9 H( r! {; r
memset((barcode_data_t *)&barcode_data,0,sizeof(barcode_data_t));
5 D/ s/ q8 c* i6 ?break;! N, b) C! S( x% o- E
default:
5 D; g# i0 f' }4 y/ L break;, d! J2 g" ?3 J7 {& {3 ^
}' B9 {6 x( z8 k: n" S! ]
}, f; I) b, ]/ w( d9 ~7 K
}
2 q( ?0 K! f. x: \1 C2 {#endif
m6 g3 w( N* `) C$ e! q5 Z( n9 d}
$ w- P, o8 {1 k% a* U, v/ v2 e1 S1 y H2 ^: l; ~
( @' K% V* u8 G7 J! m6 J) b, ]. N
|
|