|
|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
lpc1114热敏打印机源程序
* q) n8 _, K0 T/ A2 }; J6 T2 T1 q! }# Y, z# e: J% i
//本文件主要定义可程序的入口函数main, main函数里主要对系统、参数、硬件接口进新初始化,之后等待读取串口数据 |4 M+ \/ a/ I$ b) U7 p% _; Q) ]
#include <stdio.h>
8 n! M/ M5 \. ?8 M, |#include <stdlib.h> % }+ b4 V* t. n1 F! z' s5 y& |5 W: o
#include <string.h>
7 b8 M( }; f9 A+ b- G#include "LPC11xx.h" /* LPC11xx definitions */
$ F5 Z4 a8 j6 w# r#include "uart.h" 9 _3 I4 o4 n0 {$ j9 n
#include "timer32.h"* b. W2 p% j: N m7 i
#include"aw_print.h"
. {2 U/ ]/ ?5 g# _5 ^$ W n1 o! y# @: `#include"aw_init_printHead.h", y! u/ h9 V8 q' @. h; a. v" n- y
#include "aw_config.h"% `8 G. c/ S/ P
#include "aw_font.h"$ Q+ P: H8 m% v o
#include"aw_key_led.h"
" v' n( \& I- U/ Z#include "user.h"$ d- e7 `! x8 z+ V% m7 \6 E( u* T
#include"aw_char_app.h"9 j C$ {) y: H H8 K5 a2 u& y
#include"aw_graph_app.h"
# k7 Z, G7 r8 `& k8 i#include"aw_barcode_app.h"( U1 f' e6 n+ v* Y
#include "aw_command.h"( W+ {" `) y+ \- l1 @
#include "pmu.h"% t% f6 H; \) _6 r7 K7 f
//初始化系统中的部分全局变量5 m! T! r; F) t: V. F1 b* l
void init_Global_Variables(void)% K# e: I7 v- X3 J# T
{2 i# i6 y, b7 g- D* s/ p- r u% u
current_char_index=0;( f& @( U! {; d
DealBuffer_counter=0;
/ H; Y8 P+ R/ ~: Y, t memset((low_power_t *)&low_power_Paramter,0,sizeof(low_power_t));
% p' S5 v( j J& B1 |3 n V7 J; J memset((printer_work_Parameter_t *)&printer_work_Parameter,0,sizeof(printer_work_Parameter_t));
; H, b- g2 E w printer_work_Parameter.printer_work_model=PRINTER_IDLE;5 S2 v0 D* N* t; \* P; I! ^
feed_dot_step=0;4 L0 _/ F& ?0 @) s: d4 @
paper_out_flag=0;* j& _+ I% a+ W0 O1 Z
head_up_flag=0;# L5 F- z3 K6 C$ H% p
clear_buffer();
+ b3 W( L0 ^; [6 [ memset((Key_IRQ_Parameter *)key_IRQ_Parameter,0,KEY_NUM*sizeof(Key_IRQ_Parameter));
! q! j, l; u c7 h}
; V1 S& ]) z5 T3 S9 B3 F1 U" R) X. _int main(void)+ ?) w2 C* b3 [8 q, n4 C$ _7 M
{9 \7 U* {5 T: `, m9 i# a8 Q
#if UART_DEBUG
- z/ H; W3 @' p2 K$ l7 G char buffer[1024];
1 }$ m$ j2 b7 _" B uint32_t counter,timer;9 V/ ^1 W" a! h2 u+ z4 J7 l- P
SystemInit();$ F1 o3 c* q% N* n
Init_Sys_Parameter();
/ [0 n, t' `5 R* t+ ?- s! s init_Global_Varibles();
3 L! _) o" u% Y1 c% J' m UARTInit(sys_Parameter.uart_para.baudrate);8 c/ t- a3 w5 P* l6 @0 l
#ifdef PROJECT_DEBUG1 ?; p ~9 w! F
printf("\n\r-- Printer_Project V1.0 --\n\r");
3 U+ t- g# y- n! J4 p& H/ m* n printf("\n\r-- Serial Communication test --\n\r");7 f% u5 N0 ?5 ~! S
#endif
7 ` J9 W; a/ _ counter=0;
- p; f# p3 \" ]9 @( U+ w3 | timer=0;/ [$ x& L# S' w: R# \& z7 O: P7 t
memset(buffer,0,1024);+ J$ L( d- q0 G8 c# H
while(1)$ t+ r/ a) j9 z+ R3 t w
{
+ y6 ~+ B+ |: ?0 q3 h9 u/ x if(UartBuffer_read()==1)2 |. H4 l* \& k$ T5 u5 r# l
{8 U2 {3 V! l4 C3 O* S9 }" J
timer=0;mEMCpy(buffer+counter,&DealBuffer,DealBuffer_counter);1 {. A( i1 h) x) p
counter+=DealBuffer_counter;2 z6 R) K2 o" E `
}
) E6 h6 N: I1 e* U) ]+ ~else
: ]$ E; M7 z- c" O) q$ }4 H; ?( g+ L{1 }, F' U! E" I4 Z/ R4 |& G
if(timer<10)
9 w" l8 m8 t/ T, n {
# Y. H0 E8 {/ n- ^ k% p timer++;
& o V' |5 w+ D6 u. {2 }! W7 Q}$ v" y5 {# u6 r' l' Y) @6 M
else if(timer==10)- p5 G8 w! @" ~& w/ ^4 B4 O
{
: X- I( R" L9 m5 Q+ G9 s5 m4 y6 p if(counter!=0)( ]5 e( c& K C- p
{
9 c8 g4 J/ r( s4 w( Y8 |% w #ifdef PROJECT_DEBUG
2 [+ g7 f9 @) B& c printf("%s",buffer);
& _* b8 X) `7 ~- l. c0 L7 \ #endif
& J1 `+ @* ?, l& j' ` counter=0;
7 m) [& A8 m3 i) F5 B memset(buffer,0,1024);
" g' H& N; S; O) w/ d7 @ timer=11;7 V( N5 J G: N5 u
}
0 z% _2 S' c" e6 r}
' [ ~+ e' ?( \% X}
: n2 Q; H/ _9 s& E7 i#elif SPIFLASH_DEBUG
9 ^+ K' b* S; T" W8 s; Buint32_t BaseAdd;5 T4 T7 m/ |& N$ F! w* U# d
uint32_t Address;5 o, O0 y# X. n; ?, G6 j
uint8_t MSB=0xce,LSB=0xa1;: F" r- ?3 ? H
uint8_t dot[118];
1 t1 z! v- L4 T" y. m% _SystemInit();
; X1 u- Q8 P6 U7 [0 h" d& g9 Rspi_flash_init();;* H, y7 t. h, p, a2 _ i$ G$ Q. D
while(1)6 B7 X+ R2 X; O% t
{
' ^$ Y& a# x# {- `$ u* u' ] BaseAdd=BASEADD_GB2312_11X12;" {/ m) F: p$ }! r+ [8 V
if(MSB>=0xA1&&MSB<=0Xa9&&LSB>=0xA1)4 A1 |' y& g; N q2 r% h0 l
{. j" X2 e9 l" s& |; t0 V
Address=((MSB-0xA1)*94+(LSB-0xA1))*24+BaseAdd;5 M1 }: z' x# Z8 e# f
}( Z$ ] k1 S8 @- L$ P! b
else if(MSB>=0xB0&&MSB<=0xF7&&LSB>=0xA1)
z/ X* B" g3 S% ]9 z{
c* g- k3 {) G1 l# J+ v) Q. E; ^ Z# t Address=((MSB-0xA1)*94+(LSB-0xA1)+846)*24+BaseAdd;& U# O# I! d, W h' V
}
$ U/ F* s7 W1 L/ n, }read_spi_flash(Address,&dot[0],118); /*取点阵*/" |9 h$ R+ `5 {, [
LSB++;7 T8 U* }( U% b# x$ V! ?; O q
}+ t" ]' A9 U, R9 L3 N
#elif PRINTER_HEAD_DEBUG
/ V* v$ [& O5 o# pint i,keyval,keyval_bak;7 h7 S" t. n2 \6 R: Z4 N
uint32_t j;
( v& m |$ J7 n0 MSystemInit();
2 l R0 Y1 r2 C' RInit_Sys_Parameter();
2 d; Y% W0 o N xinit_Global_Variables();; W/ a, b7 z! x3 l
init_Printer_port();: B: z0 V j" v B A
init_key(); /*4、按键初始化*// ?5 i! b8 `! n/ C, K9 n
while(1)
% w, q" }0 M+ o1 k6 f{% t# y5 |5 J* A- n
3 c" A! ?) ~6 |+ B0 I
}% r+ l" v: _& H% s9 }6 Q+ K
#elif TIMER_TEST
' Z3 @* A, q+ J& s4 r0 buint16_t time;
* e+ d. J8 {$ k1 u( M- juint8_t i;# ^& c- ]* Y* G5 Q
SystemInit();
# D& }7 Z0 m$ V3 [1 Q- {, y, e3 Y9 zInit_Sys_Parameter();
W% ~% I" m! Sinit_Global_Variables();8 a7 c9 F& z! b# q
UARTInit(115200);2 L% A" F" _$ S* [0 a* P
common_timer(1,1000);# Y% [! L, G1 {7 T7 z1 M, s
while(1);- o* n; ]+ I) Y, e F2 U
#else& A) B+ ^. T: P2 t# @8 t E
uint32_t timer=0; /*用于记录连续读不到串口数据的次数*/
; _" {+ J& u3 B* @uint16_t get_dot_count;7 J, Z0 ?6 N% X- m* N
uint16_t effective_dot,num; /*可以用于打印的点的个数*/7 F5 j+ k/ K! F0 |; p, x7 Z
SystemInit();/ f, N! Q& d/ d# }( h& j
Init_Sys_Parameter();% O$ @1 Q2 U( V: X3 N; K" X
Init_project_Parameter();
) a u @ b4 t# P; U* q& N/ finit_Global_Variables();1 H3 C3 O% t1 y: b& F- T* K; m! a
UARTInit(sys_Parameter.uart_para.baudrate); /*1、数据终端通讯串口初始化*/
+ e4 g' Y @; K* q# {5 Oinit_Printer_port(); /*2、热敏打印头接口初始化 */ c& S$ o6 m1 n+ s; I
spi_flash_init(); /*3、字库芯片通讯初始化 */
: y3 C; \* ~3 j/ jinit_key(); /*4、按键led 初始化*/
5 q) ^' H- W U" x/ D. vinit_led();
" R% D, ^8 F" h* D4 p+ o- Icommon_timer(1,COMMON_TIME); /*启动公共定时器*/
: l* r6 g+ N3 }1 m" `5 @7 W) w* Sfor(timer=0;timer<0xf000;timer++) //延时,保证先前的初始化起作用
1 y. I2 M( G0 H* ?) B1 t{
) T' c6 p/ n, L4 M. ]: k ;
- f# o+ n' s1 g0 v}
+ h" L) K- M3 j! G* }init_cutter_position(); /*让切纸刀回到 限位开关的位置 */
" e( p+ w& ^; f2 ymotor_driver_step40(); /*让电机先反正转40 步*/
& O# H7 U0 X& v6 V) }% [# n* ]Hardware_flow_control(UART_FREE); /*初始化结束,允许串口接收数据*/0 G! P* t5 ?% p/ W' k# s0 E
timer=0;. d1 m- \; X; Q) g8 r9 A
while(1)
) Y1 `1 ?) w" h0 h{
8 w- I; |! M1 W9 N5 K2 C7 ` current_char_index=0;
& p8 E' _7 S0 T' u3 E6 z) E if(UartBuffer_read()==1) /*读取串口数据*/
" `0 P0 E" g# V; }$ l, z( t: V' Y {- X. W3 `) B$ |9 V* t6 Z
timer=0; /*串口有数据时,将此计数器复位*/
/ T8 o( ^9 H3 B- } while(current_char_index<DealBuffer_counter)
7 j' \/ E, ] Y4 o" L {
/ c/ G/ l N+ o; f& x0 ` switch(project_Parameter.print_type) /*处理串口读出的数据*/ ) V: J: r* I. `. @# X/ F7 S2 E
{
h" {$ U' ^# I( \, r* H# s case DATA_TYPE_CHAR_COMMAND: /*字符或、命令*/
: X5 ]8 l1 A! |9 k2 J3 ^ if(determine_data_command((uint8_t *)(DealBuffer+current_char_index))==0)7 Q7 \' R$ J7 Y. h' y
{
/ B4 Y; R5 N2 y1 C" B* G; | if(Save_char()==0)
7 k1 ^2 h* D1 G4 P9 A; H& G {
* t+ [- ~- Z5 y: _! O* m continue;
6 {' {& F% ?4 \( C5 }# h}# b: F- F5 M5 }
if(printer_work_Parameter.printer_work_model==PRINTER_IDLE) /*空闲*/" E* x0 R% P7 d% L
{, W) E2 x" ?( w
if(calculate_get_char_num(&num,&get_dot_count)==1) /*有一行数据需要打印*/* \; w* U l# E6 @% m
{7 q5 G2 F6 M! o5 H% A
start_print(PRINT_CHAR);
7 R# E8 Q! X7 v. p8 ]/ _/ ^. o& T}# |+ w! w) G6 E! o; u; p( }6 y, x
}6 f% ~1 ]- q) Q8 v
}1 M! F, ^6 R+ C. G3 t/ V/ u n1 D
else /*命令处理*/+ t a7 M+ a0 \4 H# {
{
, J; i2 c9 U1 e7 \3 w command_deal((uint8_t *)DealBuffer);+ K, y3 P* P# G1 q T4 C4 h# ` u
}' A; B9 h2 J6 |& _
break;$ C5 K! k+ L- [3 u- u7 b
#ifdef VERTICAL_GRAPH2 {% B- E1 a9 R) [; t
case DATA_TYPE_VERTICAL_GRAPH: /*垂直取模图形*/
; N6 x; Z& G. Y0 A0 f if(save_graph()==DATA_ENOUGH) /*数据取完,恢复默认数据类型*/
7 X8 |! t, s9 Q {3 L: T8 q& W" G3 F. D( h |$ n4 F: w
project_Parameter.print_type=DATA_TYPE_CHAR_COMMAND;
3 t3 X! { [5 b: M' ~% L}
: F$ \* F8 p9 a/ Bbreak;+ {" T6 v. P- N. l
#endif
& G. G' U/ S! x8 p. Q2 F$ y4 Ncase DATA_TYPE_HORIZONTAL_GRAPH: /*水平取模图形*/
; R" |3 \" a$ l4 q4 s, V3 I4 L' q ` if(save_graph()==DATA_ENOUGH) /*数据取完*/
2 l# r% D2 z/ V9 [7 v0 W+ E$ }; v& Z {: r" h1 u, v( i3 X# R* k6 d
graph_data.data_finish=1;- M( J0 T$ D. q" _! v
project_Parameter.print_type=DATA_TYPE_CHAR_COMMAND;
1 K6 ^+ ?9 N4 n) E$ U} /*空闲时,并且有一行以上的数据需要打印*/
0 j" w& _3 }6 F+ O4 Qif((printer_work_Parameter.printer_work_model==PRINTER_IDLE)&&(graph_data.buffer_counter/graph_data.horizontal_mode.horizontal_byteCount>0))
+ k8 y+ x8 F) f: \{
9 ]( C/ Z7 Y* n! Y+ o; x start_print(PRINT_HORIZONTAL_GRAPH); U ~; G1 p$ _$ y- w
}/ g$ p6 h( E% E: B8 x l
else if((printer_work_Parameter.printer_pause==1)&&(printer_work_Parameter.printer_work_model==PRINT_HORIZONTAL_GRAPH))3 g' M$ V! z; [7 U( K
{ /*从暂停状态恢复打印*/ /* 数据接收结束*/" Y$ @5 p5 I0 X% g7 J2 O8 }3 I
if((graph_data.data_finish==1)||((graph_data.buffer_counter-graph_data.printed_byteCount)/graph_data.horizontal_mode.horizontal_byteCount>0))
0 ?/ X! t, L4 Z! |" i { /*还有至少一整行数据*/
2 ]8 k; D- Z( T3 L5 x9 k8 J Resume_Print_from_pause(printer_work_Parameter.printer_work_model);8 G! ?/ M* B4 n
}
3 o3 g' v+ s) k: h7 Z' }1 e1 @}
' I6 W8 h T( [* U: ^else if((graph_data.data_finish==1)&&(printer_work_Parameter.printer_work_model!=PRINT_HORIZONTAL_GRAPH))
! j4 G! E. Q6 O) W" F" S G{ /*图片数据接收完,并且打印机还在做别的工作, 取消本次图片打印*/8 X6 |, o3 o8 Z* u/ r6 D9 W- K
memset((graph_data_t *)&graph_data,0,sizeof(graph_data_t));
& p' x0 ^' p# d# w5 z}8 |( U! A8 D/ E
break;
2 z d. u, |! L# u" P1 f; b//case DATA_TYPE_BARCODE: /*条形码图形*/. C I* [3 R1 o, O
// num=save_barcode((uint8_t *)(DealBuffer+current_char_index));
: H, O: w8 Y2 I& A6 G7 K//if(num==DATA_ENOUGH)
* ?3 }+ u, G( v+ D& u+ q8 o//{0 o L" T- e5 S2 p X
// save_barcode_parity_bit(); /*数据取完开始打印*/7 \0 j' l9 M! z6 c% P/ M/ }& G
// while(printer_work_Parameter.printer_work_model!=PRINTER_IDLE)
, x3 J) v7 Y. z+ r0 W9 _9 m// {4 T7 W& q2 m' m1 M
// ;
# J8 Q& f3 K0 F9 w; x6 k7 {5 H//} /*条形码超出打印范围不打印*/
5 {# @# N6 ?2 ^6 _0 E+ L$ s% S+ ?//if(project_Parameter.cursor_position==0) /*本行还是空的*/
7 o$ U' e# d& L, X" W0 E//{
; V; g8 y: ]: R( n! T- i// effective_dot=MAX_DOT_PERLINE-project_Parameter.print_position-project_Parameter.Limited_width_left_para-project_Parameter.Limited_width_right_para;! z! s" o* ~, ?+ X
//}, i8 n; B/ F$ O$ h" W3 h6 N
//else4 P, C, ?# }9 Q# M# R9 a
//{
/ u' Y, a. \5 x// effective_dot=MAX_DOT_PERLINE-project_Parameter.Limited_width_right_para-project_Parameter.cursor_position;+ i/ |4 ~' x# p7 s% t
//}
. L; Z* Z' `8 n) N//if(get_barcode_dot_width()<=effective_dot)& o; P1 q5 C1 J \/ @
//{
% K1 r7 x, W( B, R9 a' I// start_print(PRINT_BARCODE);
+ v6 W4 o' f' d* X; u" p/ W/ I3 c- H//}
6 o; ~& Y# V# ?8 d: ?//else
! H! B: c, {0 i( B; p) D//{
3 m9 B" {: u! Z( R. a+ Y; u3 b// memset((barcode_data_t *)&barcode_data,0,sizeof(barcode_data_t));
5 ]. A) @& B/ x( L9 o/ [6 D) Z0 [. c//}
9 s9 H3 ^1 T* E" r//project_Parameter.print_type=DATA_TYPE_CHAR_COMMAND;9 Y0 {7 x$ ^' m- n8 u
//}
$ K. g/ m i( ~! W0 t//else if(num==DATA_ERROR) /*条码数据出错*/- r. t" f. u$ g0 X: e
//{- |: h3 o$ V' _& R
// goto barcode_error;% X( c8 e$ J0 A, J* a
//}
$ A" {$ o, d+ b9 Q O7 ~$ G7 K z8 t! U//current_char_index++;5 V) S, V, [4 o. W* B' E; x
//break;
& |4 A5 h8 ^+ I}
+ a% Q$ ?- D. n/ X( e) {} J) J( E9 M) D4 x7 G# N- S
}
% _0 p! B0 D2 D! ^4 Nelse /*串口中无数据*/
1 K+ V& B2 d) E{9 A- Z. @% }* \# o, V
if(timer<5)
$ s- j5 k8 K3 q# w9 {6 y7 H) B {
5 @! R& y9 h ?7 n' c8 C timer++;& S" h8 S s+ l; u+ ~& t
continue;
1 B; }: L" `9 `2 `( \* o. D" Z2 \2 o}# a! e; I( y: d+ d y/ J
switch(project_Parameter.print_type), |8 G' ^- P% f2 J
{3 k" d% ^5 |! r2 x% X
case DATA_TYPE_CHAR_COMMAND:
, {: I! F5 J% O# {$ _ if((printer_work_Parameter.printer_work_model==PRINTER_IDLE)&&(char_data.printed_byteCount<char_data.buffer_counter))
! N% K) V) E1 x" E' F3 R, ]; v q { /*空闲时,并且还有数据*/% N5 e$ K6 J% |2 g' k8 @( N
start_print(PRINT_CHAR);' W* r& [4 i+ t; J2 e, ~2 Q
}& Z' [0 J0 I2 Z/ N. }+ B
break;
; Y$ p5 l, l, D# V$ c, E3 f# A#ifdef VERTICAL_GRAPH0 F1 y) }( `" o4 R. Z% Y9 S/ ^
case DATA_TYPE_VERTICAL_GRAPH: /*垂直取模图形*/
$ }4 j$ S' r3 E* f6 F project_Parameter.print_type=DATA_TYPE_CHAR_COMMAND; /*丢弃原来的数据*/. h% g4 d, C4 Z* K3 q
memset((graph_data_t *)&graph_data,0,sizeof(graph_data_t));3 Q" F0 n" k' c; f8 W3 d$ Q
break;
+ n( m0 N% K+ y3 M( b#endif
5 u; h3 i+ G" ^( A2 h" R/ ~case DATA_TYPE_HORIZONTAL_GRAPH:
7 o7 x4 `/ Q0 \; D project_Parameter.print_type=DATA_TYPE_CHAR_COMMAND; /*三次读不到数据,认为结束*/# {0 u1 P j. ^* R. Q6 L' ^$ M
graph_data.data_finish=1;; L2 `+ P% g$ l% ?& e- k
if((printer_work_Parameter.printer_pause==1)&&(printer_work_Parameter.printer_work_model==PRINT_HORIZONTAL_GRAPH)) /*图片打印过程中暂停*/
4 R% }6 _5 e. d, ~* q9 x{! m/ @* R: f: D9 ]( m& k- t
Resume_Print_from_pause(printer_work_Parameter.printer_work_model);
4 ~7 C7 p* [. U. x/ u3 l2 c}
: y8 j9 c% x7 i: _# a8 E6 [) z ]) Ebreak;
) x$ X* N& |, I$ \! X" P% d7 d2 gcase DATA_TYPE_BARCODE:8 q) E* ^- O- x1 M; x* T
barcode_error:' Z* P- z$ u% E) N( q0 j0 e( `
project_Parameter.print_type=DATA_TYPE_CHAR_COMMAND;
, W4 I* { Z! |memset((barcode_data_t *)&barcode_data,0,sizeof(barcode_data_t));
0 v# |4 \1 `- Ubreak;
( v& L1 G* _7 ^' F$ ddefault:
0 g* x* K) t% Q break;% s6 {* E1 i7 W) _6 r
}
7 [0 Q8 q/ m; r" f6 t- N2 B- [% s}* ^' B; K4 @6 ~+ G O$ V- P9 {+ [( [
}
! t3 ]. r4 ?( B#endif* z; z: w) z5 V+ Z' ^; M9 O
}2 c& K+ i/ T |
$ ?. I) U$ q9 q' w: h. Z6 x8 k& H2 X1 u' t
|
|