|
|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
lpc1114热敏打印机源程序 9 ]$ p# W! |$ r, x" c" \
7 i( U# F$ q" @! J//本文件主要定义可程序的入口函数main, main函数里主要对系统、参数、硬件接口进新初始化,之后等待读取串口数据
+ ^: k% Q9 ^ U1 g+ X#include <stdio.h>& g1 v9 n+ ^2 C6 s4 Y
#include <stdlib.h> 1 r: g. x3 Q% z6 T4 a7 R, e) ?
#include <string.h>+ h" a5 D* ?) n
#include "LPC11xx.h" /* LPC11xx definitions */
( q/ M& @3 W# ^# {3 `9 E#include "uart.h"
# d" X/ y t+ \5 ~: ^9 ?#include "timer32.h"% t, h3 h0 l2 b% t% k
#include"aw_print.h"
+ A9 U6 z! T0 E% P3 `/ s#include"aw_init_printHead.h" H. u8 d5 ~! u- H( O: C
#include "aw_config.h"1 L! ]3 j" N# S% d! n
#include "aw_font.h"6 ]3 b8 Q4 a5 O0 d9 @, ?+ w: a |
#include"aw_key_led.h") j! Y- u% o* K5 M; E
#include "user.h"& w4 i5 ]( Z* W u' C
#include"aw_char_app.h"6 i* `- z: _# _2 y! B
#include"aw_graph_app.h"5 a% k/ |. k6 x$ V" h6 @8 G2 M3 B
#include"aw_barcode_app.h"6 ]8 J4 S2 J2 X' O" ]% p
#include "aw_command.h"7 ]% Q: g, \4 @& F
#include "pmu.h"
4 e5 t; F- E8 i7 Y9 m; Z. V//初始化系统中的部分全局变量
& ]2 z5 S: \; b( r/ Z# W) Xvoid init_Global_Variables(void)& K* E+ O- `& y
{; D' ~/ H0 s! D! u) r" P
current_char_index=0;
; u( S. I# x! g( R" Y0 w DealBuffer_counter=0;: g! U6 m+ w7 Q" @2 Q
memset((low_power_t *)&low_power_Paramter,0,sizeof(low_power_t));7 Z. ~9 E2 E. J- F
memset((printer_work_Parameter_t *)&printer_work_Parameter,0,sizeof(printer_work_Parameter_t));
6 ^. l3 t f! y& U. { printer_work_Parameter.printer_work_model=PRINTER_IDLE;3 H! u% R' K9 L( r
feed_dot_step=0;3 N! R9 }) T# w. W h0 n2 |- t
paper_out_flag=0;$ F. Y4 a2 E' }, R6 R9 n
head_up_flag=0; H5 _" h* m5 K9 Q
clear_buffer();" e5 a. l( ~1 b" ?
memset((Key_IRQ_Parameter *)key_IRQ_Parameter,0,KEY_NUM*sizeof(Key_IRQ_Parameter));/ O+ s9 r- c* ~+ q5 C: ^+ d8 H) Q
}
Y5 b1 o7 Q, N9 x8 S/ ~int main(void)4 X, N2 m' C; S( w! e5 E. r5 `/ B0 k
{
" c: f) u1 ^( { #if UART_DEBUG
$ d S- C) ]" G, ^& J4 }1 J E+ B char buffer[1024];- {/ e3 C. t$ U
uint32_t counter,timer;2 i& d6 X- L+ k, k! i, m9 T
SystemInit();6 H: z! N: Q$ o S8 [3 b. |
Init_Sys_Parameter();
: {/ T. m- r/ v init_Global_Varibles();" {7 y2 B; g5 `0 O0 I6 |: F6 A* f% t
UARTInit(sys_Parameter.uart_para.baudrate);6 z( ^1 e2 z# `3 [4 x9 r+ {8 i L( C
#ifdef PROJECT_DEBUG
3 e/ q3 ?( T' H3 v printf("\n\r-- Printer_Project V1.0 --\n\r");
! `$ V; k- U, s, f printf("\n\r-- Serial Communication test --\n\r");
4 v6 b+ q8 T5 x #endif
' y# t: c( ?3 ]9 n( |$ x; P, D counter=0;
0 L6 W" F2 x9 }: O7 k7 w. ` timer=0;) P0 R! X) F ?, i* G9 d6 Y
memset(buffer,0,1024);! M3 Y! p+ l9 o* _' u
while(1)4 k3 Q. @7 \1 k t: g, a& V
{2 d, E5 z& ]' z6 q
if(UartBuffer_read()==1)4 J2 o8 n& O" i* X7 B
{
' D' j6 u# P9 I, o# R& v timer=0;mEMCpy(buffer+counter,&DealBuffer,DealBuffer_counter);; A8 B5 }+ T% P
counter+=DealBuffer_counter;7 J' Z8 L9 `" z# f. S
}, n1 Q: B b+ U9 {: \. C
else. k( D, c! g8 m* G" ?3 ~
{
' L. Y# T5 `4 ? if(timer<10)
: W7 W- ?% u0 d4 i {
' B% i6 W' O' D# k/ I timer++;) |; U/ ?' M, i+ Y
}# ?) I$ I$ z6 P; _
else if(timer==10)
5 E$ T" x0 e- M; B7 O{
y) F& ^5 s; M0 D if(counter!=0)
3 Y. T; t8 }. v8 R3 n3 u; `. l {
& q9 E5 q. x7 ^! f( k7 x' ?1 Z$ l #ifdef PROJECT_DEBUG1 n* ~# O8 a4 T: d8 _
printf("%s",buffer);3 }5 p5 A `# d" S+ p9 b& x
#endif2 b: Z9 W4 w# w$ H
counter=0;
# J; R& p7 a% U2 ]5 A memset(buffer,0,1024);% X! S/ c9 R' O& L$ T1 w$ _# ~
timer=11;. O! Y0 s1 ]3 ^& B1 x: A1 o( H
}$ \! J3 b" A" U# h {
}
" {* S- a9 q% k1 H2 }# x5 G}
, |: b# \: m2 S1 T2 K#elif SPIFLASH_DEBUG- f" X: }6 P1 U
uint32_t BaseAdd;+ s5 T. i# [# M7 P7 N5 ?
uint32_t Address;/ n, b2 n @- h H
uint8_t MSB=0xce,LSB=0xa1;
2 g* k3 d2 h+ @5 Xuint8_t dot[118];7 u2 I! E! ]; x& @! T+ ?
SystemInit();% U4 j! f6 \5 y
spi_flash_init();;
) k, ~$ Q+ @# n: V- l. dwhile(1)
$ X* H& L% ?' S! Y! U! s{. G- e9 X) d6 t( U
BaseAdd=BASEADD_GB2312_11X12;$ ^! z0 Q# W. c, f
if(MSB>=0xA1&&MSB<=0Xa9&&LSB>=0xA1)
& F& Z9 |& m5 C) O" F5 Z* O% q2 S {
; _- I; p" N% J1 ~; E4 e Address=((MSB-0xA1)*94+(LSB-0xA1))*24+BaseAdd;
! i5 D6 r# ]" J" c}3 S6 ~) G" j0 q5 G
else if(MSB>=0xB0&&MSB<=0xF7&&LSB>=0xA1)1 r1 B6 Q3 O% B! P& z& x
{
$ u- m. Y1 a/ r2 H Address=((MSB-0xA1)*94+(LSB-0xA1)+846)*24+BaseAdd;' R/ a9 U! Q# ^4 a+ W$ P/ a
}- [# C: q* |& V; d5 X' {$ w6 ]
read_spi_flash(Address,&dot[0],118); /*取点阵*/( s, f/ }; h$ e% b ]- w
LSB++;
& m Y& n# v9 |' n' J$ u}
6 e2 }' @3 C$ _: m5 N6 e#elif PRINTER_HEAD_DEBUG( [! x$ B: k* @. A. P7 S N# X1 }
int i,keyval,keyval_bak;4 G2 P' U2 d/ M" O- D- e+ j
uint32_t j;
+ y" |7 B% I% d5 _# E4 PSystemInit();- y/ @ f0 _4 P# v
Init_Sys_Parameter();
; V* R4 r, n% w" @; r# D f3 Vinit_Global_Variables();
. y. }3 H' M- D+ dinit_Printer_port();
: }8 W# [ k! j; m9 ?. k- `2 ~( H# Q2 `init_key(); /*4、按键初始化*/2 a- z h9 n/ T& P2 y9 {$ s+ x+ L) \
while(1)1 @4 O8 n# i9 z+ Z% S
{
9 H( C* @5 M; a; Y8 j# M 5 U; m1 S, M& r1 N2 w& P$ r
}$ l7 X% L+ @* H
#elif TIMER_TEST
/ w! e3 |3 c; x4 T. K, H! juint16_t time;
' v' L o( K! x8 j2 z0 I- y9 zuint8_t i;
* T2 c8 N/ F& k, D4 \$ uSystemInit();
# r" r! g8 @" |" r7 O4 PInit_Sys_Parameter();
: j! D! a7 \, Y' n. m, M9 Q7 w/ M1 kinit_Global_Variables();& D; O* I$ F! Q+ r ?
UARTInit(115200);
/ g) z9 t8 ^6 I6 q% q3 b- q3 o5 Hcommon_timer(1,1000);' X2 t% P! x' m, G& y, z
while(1);
+ R; J! R! ^% _* d9 t7 x#else
9 E" a1 L J; t) Xuint32_t timer=0; /*用于记录连续读不到串口数据的次数*/
& K2 j3 ^5 j y r. J- luint16_t get_dot_count;$ Y3 b, t$ l( ]( J' q. j5 ]0 ]& q: }% }
uint16_t effective_dot,num; /*可以用于打印的点的个数*/4 C. ]3 \+ y: s3 a; a
SystemInit();
. H4 _% h$ W) E4 h1 QInit_Sys_Parameter();' c( J9 ~: D8 j1 m) q1 r7 T
Init_project_Parameter();7 | H, |/ d1 a" l0 B6 Q8 V/ q+ S
init_Global_Variables();
9 O- A! A( i+ O6 I5 PUARTInit(sys_Parameter.uart_para.baudrate); /*1、数据终端通讯串口初始化*/1 H% V. H) v+ `
init_Printer_port(); /*2、热敏打印头接口初始化 */
, L. H2 ]: A, F# D* vspi_flash_init(); /*3、字库芯片通讯初始化 */
6 }( |! b) A7 d, minit_key(); /*4、按键led 初始化*/
5 V4 e' A8 l+ j, `init_led();
3 v/ H$ M+ p9 A7 Z9 P5 V3 Gcommon_timer(1,COMMON_TIME); /*启动公共定时器*/ ' N) m) V) e( c9 l
for(timer=0;timer<0xf000;timer++) //延时,保证先前的初始化起作用
: u4 v/ f/ v3 H; M) @4 Z{
1 C+ C- M* D- T+ ]' H ;
2 z4 O. j% e/ _- K$ v' V}' K, p% E7 D ~% R5 u6 d
init_cutter_position(); /*让切纸刀回到 限位开关的位置 */
0 S& L' e& w: z% R/ H; F* jmotor_driver_step40(); /*让电机先反正转40 步*/ p3 x4 A6 Q/ h* I/ X) e( M( y/ P
Hardware_flow_control(UART_FREE); /*初始化结束,允许串口接收数据*/
; K# z& K* _2 Ntimer=0;. {0 F' j$ B3 }0 S! f! S2 c0 [
while(1)2 X' I) n3 T# l% s8 j) t; }
{
' ?6 @0 x w" C- x; }4 W; G current_char_index=0;: z/ Z6 c, ]9 N/ R$ ]
if(UartBuffer_read()==1) /*读取串口数据*/( g0 `' z$ S. J( H" M! l& t
{: C8 A6 \) Z$ m0 ~
timer=0; /*串口有数据时,将此计数器复位*/
7 j5 ?, Z9 W0 |: B while(current_char_index<DealBuffer_counter)
+ O y# Q1 _/ Z- [5 A {
) C, S3 y- P& f: c5 } switch(project_Parameter.print_type) /*处理串口读出的数据*/ \# E2 F/ ]4 v& P
{4 m a/ p& o# K/ `# b; p
case DATA_TYPE_CHAR_COMMAND: /*字符或、命令*/. M0 P/ _! a b1 h0 o) F! [0 o
if(determine_data_command((uint8_t *)(DealBuffer+current_char_index))==0): J B0 l8 h3 N/ a
{
) @6 ]2 ?/ V- z# p+ Z if(Save_char()==0)
8 ?! [ S ]& C) Q {
( \" I5 [! X& ?0 i* }/ j- Y continue;( J ?( x6 ?+ G' a/ ]1 l4 F
}4 l& U6 d2 c1 g9 \
if(printer_work_Parameter.printer_work_model==PRINTER_IDLE) /*空闲*/9 b, h: U; c5 e0 K1 ~: D+ n
{
) A- N! A+ w5 Y! U if(calculate_get_char_num(&num,&get_dot_count)==1) /*有一行数据需要打印*/( u% L3 r+ {) c* g$ q$ m/ ~
{# D# N: D4 s5 c: M; _. v/ `0 D% Y
start_print(PRINT_CHAR);; Z2 O5 o% |; h% D4 `. |9 [: p8 w
}
5 e3 C% M$ \: }}
6 G v" b7 ?* ~- X4 {5 e) P1 T1 S}$ ~# A+ u. j7 h. u
else /*命令处理*/
6 p; X& D# v) v& s9 G3 I, v{
+ w: k+ m( l/ T command_deal((uint8_t *)DealBuffer);
$ ^* v5 u& J" [" S2 M" O! c9 K5 K}0 {& g# Z* x. n$ @, ^& L* S& p1 g0 L
break;
# H2 F: K1 c7 ]& V8 G/ j#ifdef VERTICAL_GRAPH
2 s4 }! q: d( j( |( e9 g3 W$ bcase DATA_TYPE_VERTICAL_GRAPH: /*垂直取模图形*/- }5 \1 v- t% D& }
if(save_graph()==DATA_ENOUGH) /*数据取完,恢复默认数据类型*/
0 M( V M( C# C* p& R+ [7 j: o2 A {
2 c) {" S' F% g( ~: D Y# Q project_Parameter.print_type=DATA_TYPE_CHAR_COMMAND;" ^3 `7 h6 M+ M7 s+ S
}2 e# Q# G! L; g8 l( j
break;
& q# z9 t# b5 V+ |: L* Y7 x6 Q; A#endif5 c {$ d( y1 }% }7 a3 e% X- x# a
case DATA_TYPE_HORIZONTAL_GRAPH: /*水平取模图形*/
. Z! W6 I$ ~. h6 x$ S: j2 L if(save_graph()==DATA_ENOUGH) /*数据取完*/
0 M9 {, f4 ^8 m9 _1 i0 ?: J {, U# y7 Y) k" o% K
graph_data.data_finish=1;1 ~5 h- V9 w1 n0 f
project_Parameter.print_type=DATA_TYPE_CHAR_COMMAND;! F9 O! r7 m5 M1 U! g" R: d/ P
} /*空闲时,并且有一行以上的数据需要打印*/$ B1 ~" z5 p. L$ r/ E% Q! Q, a7 Q
if((printer_work_Parameter.printer_work_model==PRINTER_IDLE)&&(graph_data.buffer_counter/graph_data.horizontal_mode.horizontal_byteCount>0))
t2 e5 G0 o9 ]: E- u2 T0 |{
7 I9 y+ |- @0 g start_print(PRINT_HORIZONTAL_GRAPH);
! i( r( C0 |8 X}
1 n2 `2 a/ |$ g. Lelse if((printer_work_Parameter.printer_pause==1)&&(printer_work_Parameter.printer_work_model==PRINT_HORIZONTAL_GRAPH))
% ~% J, K6 S* w+ s7 [' y! O{ /*从暂停状态恢复打印*/ /* 数据接收结束*/! o4 g4 v5 w7 n" {- f; @, Z& g
if((graph_data.data_finish==1)||((graph_data.buffer_counter-graph_data.printed_byteCount)/graph_data.horizontal_mode.horizontal_byteCount>0))
6 i9 z, c% ~+ X% U: o7 j { /*还有至少一整行数据*/
; G8 {. B9 M: [, q Resume_Print_from_pause(printer_work_Parameter.printer_work_model);
, k. k4 i; i* E% w! T3 {' F}2 }7 z5 {2 K- t7 M
}
: e2 b3 a$ `+ y3 Delse if((graph_data.data_finish==1)&&(printer_work_Parameter.printer_work_model!=PRINT_HORIZONTAL_GRAPH))+ t, A6 q& Y# R/ p! i# K8 ]: I
{ /*图片数据接收完,并且打印机还在做别的工作, 取消本次图片打印*/
9 U- |( i+ v8 b% p3 | memset((graph_data_t *)&graph_data,0,sizeof(graph_data_t));
; i7 e8 B# m" s* h& q! @" [}
9 F1 `6 p8 k! D% Tbreak;. R: Y/ o) M$ n4 G8 t+ @6 k
//case DATA_TYPE_BARCODE: /*条形码图形*/
; u/ m4 V; k* ?0 Y// num=save_barcode((uint8_t *)(DealBuffer+current_char_index));
/ U' t# @! D% D3 S//if(num==DATA_ENOUGH)
& x+ y1 i9 C W( s$ H- _//{
$ a& m: g9 g& Y* J- w// save_barcode_parity_bit(); /*数据取完开始打印*/
: |; Z: b) e) H' U) @// while(printer_work_Parameter.printer_work_model!=PRINTER_IDLE)7 _0 W- S7 f0 c9 B6 a6 ?, q
// {
0 J, P* E/ B9 p& r. U6 X$ J% n: I2 H // ;, ?& C* x! T w& Q- q. j
//} /*条形码超出打印范围不打印*// J/ d- f5 @- G0 S6 O0 \) f
//if(project_Parameter.cursor_position==0) /*本行还是空的*/1 b1 z7 g; N5 s% i
//{# ~3 g7 a4 ?( h0 b4 }+ C0 ~
// effective_dot=MAX_DOT_PERLINE-project_Parameter.print_position-project_Parameter.Limited_width_left_para-project_Parameter.Limited_width_right_para;/ Q+ b* u- o8 x& e
//}! r& n) v3 l+ `# L. s' b
//else$ O8 c6 K7 Q+ I5 {. W: t
//{" B5 j/ M1 Y2 W$ b9 T1 p
// effective_dot=MAX_DOT_PERLINE-project_Parameter.Limited_width_right_para-project_Parameter.cursor_position;" }- k- s4 O8 Y- H8 A7 C5 N4 r$ ]) V
//}& c2 E+ |0 Q- x
//if(get_barcode_dot_width()<=effective_dot)+ Y3 F7 G1 q" f1 C2 E
//{
/ F; `7 a$ W, i5 `// start_print(PRINT_BARCODE);! w& h. p6 }& z9 G4 W; ~; ?6 z
//}4 M$ O6 b# @5 u1 i& Y2 g: n
//else
! z' ~& A# }/ k2 v7 O3 Q Q, `//{
- o5 M& \! {) T, X3 [0 \// memset((barcode_data_t *)&barcode_data,0,sizeof(barcode_data_t));
- I' b5 h8 t. b; q' h3 M//}5 q& F! u# p% }- N
//project_Parameter.print_type=DATA_TYPE_CHAR_COMMAND;, S" ]" i% a* x* v
//}
' [/ }( v X' Y" j//else if(num==DATA_ERROR) /*条码数据出错*/
Y" s- @& q0 w9 O& _' L6 G//{8 n" o* \. D' E0 i+ }/ m$ Q6 T
// goto barcode_error;
4 | V9 y& s; d6 _# \+ E2 e3 x! N//}
# b0 @! r+ J7 Q5 G2 R" h//current_char_index++;" t8 n8 F: H8 _9 M5 J
//break;0 m6 k c0 \9 |$ N
}6 W6 `* s' T* \: A4 F/ |, W+ j
}& a, n6 K, P1 A @% t
}0 L; a1 e1 N7 ^. d6 L* k* M
else /*串口中无数据*/& n G" x& v4 B6 r4 Y
{% D7 @ ?1 V' @: |* z* v
if(timer<5)
; N+ X* i: J1 S4 P3 y {9 C0 E* ?& S) B
timer++;6 z9 H5 i2 v% W* x( d( t
continue;. a/ u6 ^ B E# j; M2 s
}5 j; M7 N% c3 p0 p! d
switch(project_Parameter.print_type)7 {: t) C$ i7 c- j- b
{
1 z) [: S4 S. y; }& h2 ?9 I4 ?; C& @ case DATA_TYPE_CHAR_COMMAND:
8 I5 v5 u! x$ d6 z, k/ w if((printer_work_Parameter.printer_work_model==PRINTER_IDLE)&&(char_data.printed_byteCount<char_data.buffer_counter))
1 P& O9 i# }5 ~' }5 i+ T) D { /*空闲时,并且还有数据*/
5 Y4 h. h4 o( ]! G( s. _5 t start_print(PRINT_CHAR);
$ s! s. H* w; Z+ u8 }& h# P8 D}
/ e+ U( n. ^. E' {0 j$ M3 Zbreak;/ n. K- I8 E" ]8 I. F" |) U1 z
#ifdef VERTICAL_GRAPH6 [; o' O$ s* Q0 m/ j3 O. [
case DATA_TYPE_VERTICAL_GRAPH: /*垂直取模图形*/
' M5 l$ s. m6 U) C5 g project_Parameter.print_type=DATA_TYPE_CHAR_COMMAND; /*丢弃原来的数据*/
- U; |5 j7 s+ [; |/ _7 _' Kmemset((graph_data_t *)&graph_data,0,sizeof(graph_data_t));$ r1 B5 k# @0 d+ ]3 V ?$ K4 D
break;
1 g. B% v1 ]* [6 u0 H#endif) K" s: u: u, E+ d; m. n3 F
case DATA_TYPE_HORIZONTAL_GRAPH:
7 y- ?1 K- k' {: ?3 P project_Parameter.print_type=DATA_TYPE_CHAR_COMMAND; /*三次读不到数据,认为结束*/
- x2 H# z! V' K, C& _( Fgraph_data.data_finish=1;# K. E9 k8 d* k( @% [
if((printer_work_Parameter.printer_pause==1)&&(printer_work_Parameter.printer_work_model==PRINT_HORIZONTAL_GRAPH)) /*图片打印过程中暂停*/
6 b9 K/ F2 e1 {- Z{( v" L, n$ m- E; w8 j4 V- x: q% t
Resume_Print_from_pause(printer_work_Parameter.printer_work_model);
, W; @% d' W# S& x p}
$ L9 n% \! }5 pbreak;
% D( J4 f1 ^0 Ccase DATA_TYPE_BARCODE:
& ^% _& U& u5 p! b7 \' q barcode_error:
6 V- B% p& R5 ]# X. |5 r" ]0 S- Yproject_Parameter.print_type=DATA_TYPE_CHAR_COMMAND;
) b! L8 a' {% O6 t1 N* zmemset((barcode_data_t *)&barcode_data,0,sizeof(barcode_data_t));
3 G" \4 m; y; l2 Qbreak;
0 R, J6 ~' l1 \! q& Idefault:6 V' M ? Q! G# P
break;9 @ i" b0 i- {2 ]
}/ M$ E6 R+ d& \' N% ^; @8 b) j
}
. i6 V* T* }6 s; D6 l' Q0 b}2 L1 A* r/ G C$ n! F& C! q c
#endif
0 n7 _3 e% M$ M, T}+ `: X Y/ k2 h) [7 q1 ~
; n0 {- ^) A. x( _3 C3 N" j' R7 @2 Y$ K" c7 B
|
|