|
EDA365欢迎您!
您需要 登录 才可以下载或查看,没有帐号?注册
x
#include "periph_lcd.h" ; V7 M! H1 u4 S7 U
8 h8 m0 A; I2 W" c4 F7 y
lcd_code_item_t LCD_CODE_TAB[]= : ~7 `- n: T7 a9 Q
{
/ q7 a2 H3 d2 j% `4 \% w/ ] [LCD_CHAR_0] ={.COM0_L=1,.COM0_H=0,.COM1_L=1,.COM1_H=1,.COM2_L=0,.COM2_H=1,.COM3_L=1,.COM3_H=1,},
1 t. U2 s5 J% Q0 o8 Y# Z! G [LCD_CHAR_1] ={.COM0_L=0,.COM0_H=0,.COM1_L=0,.COM1_H=1,.COM2_L=0,.COM2_H=1,.COM3_L=0,.COM3_H=0,}, $ P& A6 x4 v% i- @+ F) }
[LCD_CHAR_2] ={.COM0_L=1,.COM0_H=0,.COM1_L=1,.COM1_H=0,.COM2_L=1,.COM2_H=1,.COM3_L=0,.COM3_H=1,},
, V- T F: I2 z9 o9 k" P [LCD_CHAR_3] ={.COM0_L=1,.COM0_H=0,.COM1_L=0,.COM1_H=1,.COM2_L=1,.COM2_H=1,.COM3_L=0,.COM3_H=1,},
9 N) Z1 q; i7 D; h2 {- t. ]( m [LCD_CHAR_4] ={.COM0_L=0,.COM0_H=0,.COM1_L=0,.COM1_H=1,.COM2_L=1,.COM2_H=1,.COM3_L=1,.COM3_H=0,}, & f1 Z* }- i9 \" b9 p# a% u
[LCD_CHAR_5] ={.COM0_L=1,.COM0_H=0,.COM1_L=0,.COM1_H=1,.COM2_L=1,.COM2_H=0,.COM3_L=1,.COM3_H=1,},
r( k M6 G6 c4 t% j* V4 x8 o [LCD_CHAR_6] ={.COM0_L=1,.COM0_H=0,.COM1_L=1,.COM1_H=1,.COM2_L=1,.COM2_H=0,.COM3_L=1,.COM3_H=1,}, 1 K; \' L8 `; l2 I9 j! ]
[LCD_CHAR_7] ={.COM0_L=0,.COM0_H=0,.COM1_L=0,.COM1_H=1,.COM2_L=0,.COM2_H=1,.COM3_L=0,.COM3_H=1,},
( N& I* N" J5 N8 _ [LCD_CHAR_8] ={.COM0_L=1,.COM0_H=0,.COM1_L=1,.COM1_H=1,.COM2_L=1,.COM2_H=1,.COM3_L=1,.COM3_H=1,},
g7 l+ F d8 k0 m* u' m8 O [LCD_CHAR_9] ={.COM0_L=1,.COM0_H=0,.COM1_L=0,.COM1_H=1,.COM2_L=1,.COM2_H=1,.COM3_L=1,.COM3_H=1,}, 7 O) z+ S2 j9 q- \
. Q( V# Y4 ^4 I. t [LCD_CHAR_OFF]={.COM0_L=0,.COM0_H=0,.COM1_L=0,.COM1_H=0,.COM2_L=0,.COM2_H=0,.COM3_L=0,.COM3_H=0,},
o; l$ W* R2 Y* k' x |};
) G+ g6 g2 w& w5 a' P3 C! A1 G8 F! P: y* Y
void LCD_Open(void) + j- Z9 T- u1 p% x9 ` ^
{ ' n. l- } R% n# x# w P
CLK_PeripheralClockConfig(CLK_Peripheral_LCD,ENABLE); / p( H6 G, t! t1 `& p
CLK_RTCClockConfig(CLK_RTCCLKSource_HSI,CLK_RTCCLKDiv_64);
. M5 v" Y5 h3 k( D LCD_Init(LCD_Prescaler_8,LCD_Divider_18,LCD_Duty_1_4,LCD_Bias_1_3,LCD_VoltageSource_External);
5 o3 H8 y8 j, Y; M* z LCD_PortMaskConfig(LCD_PortMaskRegister_0, 0xff); , F, x2 M# g) ^% f
LCD_PortMaskConfig(LCD_PortMaskRegister_1, 0x03);
4 q2 N* X+ C+ \9 [+ G5 M4 Z+ A+ v; Y* ~' i3 ~* v
LCD_ContrastConfig(LCD_Contrast_3V0);
: ^' G, ^4 B0 H0 f LCD_DeadTimeConfig(LCD_DeadTime_0); . A5 P/ U& t3 ^, q6 U3 N
LCD_PulseOnDurationConfig(LCD_PulseOnDuration_7);
" s5 J2 O, [6 Z9 L0 _! \# M$ K LCD_Cmd(ENABLE);
$ x# I1 i8 g% |6 z, Z} ! ]6 }% i- Y0 ^8 l' r! z3 g7 k
8 ~1 x4 z8 ~4 h9 Q/ L9 U. Vvoid LCD_DispCharOnIndex(uint8ch, uint8 index) ; Y/ [0 I2 n. J" ~- m# D
{
% S) X& |2 a8 I if(index>=LCD_INDEX_MAX_COUNT) $ ^8 Z0 I7 Q2 x/ l
{ / V0 ?2 @) D K0 d( _
return ;
8 a; k! {7 ^( |8 Z `4 R4 P% `- m: @# D } - K) u# c# z2 ~: p2 b0 s
: L" `; g, _" V0 Q2 n( @
uint8lcd_code=LCD_CODE_TAB[ch].Byte;
7 B9 H" ]6 }+ }. ^1 K) t ' q: R0 _6 o& y( u. ~- I
if(lcd_code & BIT_MAST_COM0_L)
0 b! M/ i: q5 O& p1 P {
9 z4 ]' X% ^0 E( \/ ~- g3 d bit_arry_set_bit((void *)LCD->RAM,28*0+index*2);
9 [$ g: b2 C3 n& k } ) Y1 ~% x- M L1 I# }
else % a6 j1 W) R5 j! z) q+ K
{ 6 R _" Q4 X+ ^5 m3 J# T- l% F
bit_arry_clr_bit((void *)LCD->RAM,28*0+index*2); 4 `. i4 @5 d3 v) d3 Z! l
}
# \9 c9 K; J- N: g- P) l, F! @ P , y0 r- x3 X5 r/ Q1 N4 \) s
if(lcd_code & BIT_MAST_COM0_H)
6 ? l |6 v% e8 Y7 _7 T& c. X {
" s. Y M, D$ S& {$ w8 h bit_arry_set_bit((void *)LCD->RAM,28*0+index*2+1);
. C' A: ^9 I9 @ { }
' m2 u6 ?* l' u5 j1 L else $ I9 v8 T# `# T" d7 F9 U* m
{
+ w" f. z3 k' @* q bit_arry_clr_bit((void *)LCD->RAM,28*0+index*2+1);
5 c; ?4 W+ I5 d$ I3 q; {$ }' ` } ; C+ X) }) j; w! L( V
, Y( @$ h0 [! [. h$ m" [! U, O( C
if(lcd_code & BIT_MAST_COM1_L) ) N( v+ s( ~; M. C
{
0 V( J- ?9 B: K" n! d bit_arry_set_bit((void *)LCD->RAM,28*1+index*2); 9 }. l) E9 @) e, y0 O
}
5 R- ?+ Q9 W" `* z# i else % @2 O6 c6 x; c- @
{
5 V" S z J! V( s bit_arry_clr_bit((void *)LCD->RAM,28*1+index*2);
; M% n( G/ h( K9 ~ H A } & Z" i6 L. d/ }& h" L; W
1 l. g6 z0 c: o
if(lcd_code & BIT_MAST_COM1_H) 4 `4 ^% K1 o8 q$ J! L
{ / y$ F% l1 E+ T4 k, z! g' F
bit_arry_set_bit((void *)LCD->RAM,28*1+index*2+1);
$ Z0 ?3 L% k" C( u X) g } 4 w0 f) x5 F9 Y9 N- s* E& T
else . J' M2 q+ e- r1 M% n
{ / B9 K# e0 i' L, ^1 F. J$ p
bit_arry_clr_bit((void *)LCD->RAM,28*1+index*2+1);
1 h! L |' o! P# A6 o. s% { }
, |4 {4 E9 R; ?2 d6 R* R: [! J$ G * P$ o% G4 p1 u- D i# H7 ?& B( a
if(lcd_code & BIT_MAST_COM2_L) % e6 p& C6 {# U) i2 `$ I
{ # D. J: a6 N1 y0 u0 f4 q! L
bit_arry_set_bit((void *)LCD->RAM,28*2+index*2); - q6 u5 g4 x* D
}
+ _; o- W* r; z% Q) W/ o( N else
! j4 G/ a, O# D l$ W { 2 j5 ?/ Z. D* V4 d" M
bit_arry_clr_bit((void *)LCD->RAM,28*2+index*2);
% p7 Q) W* u, R7 y. E2 D } . t$ {5 J; B' v6 G% s& V
/ K9 k+ h$ a) _* D" U _" [4 _2 A if(lcd_code & BIT_MAST_COM2_H)
) d* c$ A* v! r2 m) N9 H- ] { # Q9 y' W% N9 T
bit_arry_set_bit((void *)LCD->RAM,28*2+index*2+1);
: C1 L4 h8 @, y* p$ M }
3 g9 T9 a. k5 E% Y9 z4 f# s else
9 T7 b# N* X7 w3 i5 e2 { {
$ t( v$ M7 A+ S" a$ `+ Z) { bit_arry_clr_bit((void *)LCD->RAM,28*2+index*2+1);
3 ?4 C* F5 Z' I0 b$ ]9 D; V" b }
& C& o5 O6 w! p; P" P0 O! Y
2 k. d, x. b3 q& ` if(lcd_code & BIT_MAST_COM3_L) & X" X4 l5 [$ j6 \0 J( w6 _3 J
{ 0 n1 t2 K( V! G, y
bit_arry_set_bit((void *)LCD->RAM,28*3+index*2); 5 g8 e6 C: Z/ o
} . R( a( ]' A; `+ V
else
9 v7 X; d; `0 ^) d6 t' z) e { ! w+ w, n) g0 G% V# j) C
bit_arry_clr_bit((void *)LCD->RAM,28*3+index*2);
r( T' o3 n+ y; D! A+ ~* f& X M } : k/ d, ]1 _2 L
5 b, S E3 G# I5 D# ~# T if(lcd_code & BIT_MAST_COM3_H)
. c; I2 S4 O; i. N# n6 J { 6 }' J! W$ g$ D `& v k
bit_arry_set_bit((void *)LCD->RAM,28*3+index*2+1);
) k I) {! `( Q t* {9 N }
! t; O9 F( P- s+ ]6 s$ f1 X2 @; c% J else ) @" b. y4 @# c9 h7 ~; g7 |
{ 5 V ]! ^% i& ^0 T; O ` l
bit_arry_clr_bit((void *)LCD->RAM,28*3+index*2+1); 4 T9 }8 ^' C! U, [! |& Q8 u
}
0 J4 A) c7 k; e m, N: a" l+ s9 u1 a$ Q0 X} - q+ v# I7 \6 b7 {6 n& i$ d
% x4 Q& _# w8 ~ ]3 n9 S/ U
void LCD_DispOffOnIndex(uint8index) 0 @9 s1 }% B' {; Z0 D* j
{
5 Z1 a2 L- t! E+ N LCD_DispCharOnIndex(LCD_CHAR_OFF,index); " F; k* o8 A# T6 k: O0 k
} 7 o$ l! M- B; _. {5 g T
5 Z* w6 m( Q @
7 V6 a: P K: L: f: P& K, rvoid LCD_DispOffOnAllIndex(void)
8 D" u$ t$ h' t$ Q2 s1 f{
: q1 X2 q3 h2 C for(uint8 i=0;i<lcd_index_max_count;i++)[size][="" font][="" backcolor][=""color][color="#333333][backcolor=rgb(242," 250,=""254)][size="11.818181991577148px]" [="" color]
" t2 L: z+ w |- g% s _$ f8 ~" M { % o0 ?8 X! p @; d" M1 C
LCD_DispCharOnIndex(LCD_CHAR_OFF,i); 4 G6 _5 z! x1 g! ?- i" y6 u
} , F V7 N1 v0 o$ N4 k+ o0 M
} 1 f% ` j# D& d. m( ^: \, E
A6 t3 \8 o9 m/ ^
void LCD_DispUint16(uint16num, uint8 blank) . T+ `- E5 ~4 ]' S# J
{
% D9 i6 k6 F4 I: Q uint8 bcd[__MAX(5,LCD_INDEX_MAX_COUNT)]={0};
. ~. Z! ~/ Z' T uint8 bcd_index; 7 f% T4 ] e' W* `, r
uint8 lcd_index;
7 {' K4 l7 Y% r0 q % K3 N2 [: c% S: K( w: s
uint8 index_max_count=__MAX(5,LCD_INDEX_MAX_COUNT);
6 n x' {8 P$ C8 H
- _0 ?' C2 V: E* Q* J& E+ y, Y u16_to_bcd_5(num,bcd);
$ h4 {! {* c. W( D* L+ O+ _
_- x l9 b7 v; F# q( j6 p bcd_index=index_max_count-1; 8 W) B# r1 `- ~
# N: Q Q8 L+ f, J" S) L for(;(bcd[bcd_index]==0)&&(bcd_index!=0);bcd_index--)
- @. x+ E- ?: c3 W {
- x" X. B% _% t lcd_index=index_max_count-1-bcd_index;
: B0 C. `( y/ w' W9 G" |8 i LCD_DispCharOnIndex(LCD_CHAR_OFF,lcd_index); : \2 k- K) g! t
}
+ ]" U% s8 v; k- x) _9 q
) Y) c- T u, S7 o$ ? for(;bcd_index!=0xff;bcd_index--) 5 |. e1 d1 x7 q$ b0 e5 W- i
{
( ~- h0 r6 R" Q3 H$ `) g! ] lcd_index=index_max_count-1-bcd_index;
% z* k3 k4 G9 h: A4 k8 D LCD_DispCharOnIndex(bcd[bcd_index],lcd_index);
9 L6 R9 }4 o9 w' z& R( q) M6 J }
8 ]0 D* ^; J2 x1 C! L% \; G% e} 8 F& l1 p- C6 W& @) W) H8 O
; ^ x& B8 H B
#include "stm8l15x.h" 1 f* k9 Z4 C2 q* b% A7 w8 }) G
#include "uni_int.h" 0 W8 h" E2 _+ _2 Z( H( Y
#include "delay.h"
, p$ v1 |- T L+ S#include "periph_lcd.h" 8 w' O G6 O7 |
T0 O8 D% ^6 f3 D1 [4 d5 S1 q$ b* o6 e
int main() ' [& o: h, J4 ]( K+ u! j
{ - V$ \) O( X- x1 Y$ x
LCD_Open(); ; N9 L3 L: {7 k
* z9 f' n& a* }) I& G
uint16 num=100; / w! ]+ R, p3 N3 B0 P6 q. _
/ [ f% ?$ I1 y# T5 H1 J
while(1)
8 W/ M9 }2 N6 x0 w: w$ { { , X" P' I7 q H m# O5 h9 }
num--;
$ ~) p9 P V% E5 a- _- Y: | LCD_DispUint16(num,LCD_CHAR_OFF);
5 C; ?; m6 z' m9 c delay(); # H" I8 ~4 s7 h) ~. h
} ' H1 S5 q3 Q4 ~
}
" s2 L+ `% O1 T[size=11.818181991577148px][size=11.818181991577148px]: i6 M6 N& L* \$ T0 M& C) \2 U; J, F
|
|