|
EDA365欢迎您!
您需要 登录 才可以下载或查看,没有帐号?注册
x
#include "periph_lcd.h" . Z) d! ^3 M3 E. F: d9 j9 d
2 O: k+ _& W0 S6 m- T3 |
lcd_code_item_t LCD_CODE_TAB[]=
8 h- y: Z1 t- T% j( U3 o{ ) B |# N. L; I' {
[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,},
. d6 R2 q: S5 Y2 |6 A [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,}, % [6 c1 l7 z: b, k2 V6 G4 H9 g3 G5 i
[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,}, 6 z3 b- O# [9 r% u
[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,},
- G7 J! B* }# {( S" o; ?( u [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,}, 6 [$ X9 y; D! d
[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,}, % j( a. k1 O3 Z
[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,}, 3 ~8 S' E. n3 G. c1 f# l
[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,},
0 `; J" l V* m" U1 Z [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,},
$ G6 {3 x& x, B# w8 s [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,}, O- z9 u3 Z; b' L
% E& l' N) @! I
[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,},! N0 y$ C2 E1 }4 e
}; % O. x9 |8 m3 _# ~9 j. t( A4 Z
: I4 T4 w, k( |# y
void LCD_Open(void)
) M* a2 Y9 k8 K{
4 [, L) @6 z: C) Q3 ? CLK_PeripheralClockConfig(CLK_Peripheral_LCD,ENABLE);
2 Z y' M' P- v1 q CLK_RTCClockConfig(CLK_RTCCLKSource_HSI,CLK_RTCCLKDiv_64);
3 m c: O" m& j LCD_Init(LCD_Prescaler_8,LCD_Divider_18,LCD_Duty_1_4,LCD_Bias_1_3,LCD_VoltageSource_External);4 U' Q% ]: T% W. c) ?( ~
LCD_PortMaskConfig(LCD_PortMaskRegister_0, 0xff); . |% o8 m; H+ y4 g5 C* t
LCD_PortMaskConfig(LCD_PortMaskRegister_1, 0x03);
# G3 G. u* j) ^+ T4 u; S5 z- W+ n* Y$ K" d2 Z
LCD_ContrastConfig(LCD_Contrast_3V0); 3 }4 i* j: o( {- w
LCD_DeadTimeConfig(LCD_DeadTime_0); ' Y2 u9 ^: \" e# q
LCD_PulseOnDurationConfig(LCD_PulseOnDuration_7);
: H" {) V& G4 i) M8 t9 _ LCD_Cmd(ENABLE);
6 {4 W. i+ l9 V2 p* }8 `( a}
- Q Y8 F/ w$ G' k$ M7 p% O4 W' L) ?4 B: N6 v$ i
void LCD_DispCharOnIndex(uint8ch, uint8 index) $ ]$ Z6 Q/ k3 V
{
% P5 i0 O$ g4 L& i. i( A if(index>=LCD_INDEX_MAX_COUNT) * l/ n7 T7 c8 n$ `! J
{ ! o5 l! b* r0 Y X$ n/ \
return ;
: f9 i/ `' d( {. N8 M' J } ; T( x6 q; h8 I& z3 D( L( a
# I" Y+ P: \9 [/ Z0 q
uint8lcd_code=LCD_CODE_TAB[ch].Byte;
% X/ r, q. B/ V" d0 j2 A2 j3 r; a3 d 0 O( j6 T: b0 w% E! p0 A# y
if(lcd_code & BIT_MAST_COM0_L)
- x' f. a7 w" V/ R2 C9 v3 E {
( q0 ?& T# r4 x# o bit_arry_set_bit((void *)LCD->RAM,28*0+index*2);
3 `, Y' k! Q, ]: R& c- ^5 Q } * P& t1 k1 e- M! N' n0 \3 A7 q; P
else / c! @0 w2 R, ?9 z
{
: e1 `9 R6 K" U bit_arry_clr_bit((void *)LCD->RAM,28*0+index*2); ) x+ V- Q, h: i0 H
} * J3 ?6 d( N, i
' r& y1 C2 z, f
if(lcd_code & BIT_MAST_COM0_H) / c# m5 Q1 J0 }& b5 y3 a7 y
{
9 \5 Q" D$ S% B6 @, X0 ^+ [ bit_arry_set_bit((void *)LCD->RAM,28*0+index*2+1);
& h( i5 W* C- k6 n2 ` }
0 X" X+ P' g+ O, ]0 U9 h4 R else
7 L0 J, G% F3 R( N4 {% }: _ { ' z+ ]1 N! y7 Q2 L* x
bit_arry_clr_bit((void *)LCD->RAM,28*0+index*2+1);
9 Z& G$ ?, q( a+ |; S( }) U# k }
n# m$ f* x# k. R* }1 p 5 X7 @# Y" D* X" \* K: `
if(lcd_code & BIT_MAST_COM1_L) 3 b0 R" D: g ]0 B# ?8 M: u
{
2 S5 {8 g' r% i; g4 X- E bit_arry_set_bit((void *)LCD->RAM,28*1+index*2); , k* e x% x) F7 E- x4 Y
} & r( n+ f S |2 C, E
else
9 J) O% z' q+ P9 U J2 L { % h# P' C+ ^ q0 A3 R
bit_arry_clr_bit((void *)LCD->RAM,28*1+index*2);
* L' j) P3 [* I! `$ H1 e } ) h1 X% n) G/ i1 b9 ^
! i2 x: i6 d6 c
if(lcd_code & BIT_MAST_COM1_H) : }& R6 T$ k% J
{ ' f7 {+ b+ c2 P" w# l( Y
bit_arry_set_bit((void *)LCD->RAM,28*1+index*2+1);
: Z. L5 r1 \* o" Z" a4 P2 u } % @7 A6 @" r. n3 i2 O
else
3 w2 F3 W; I1 q# X8 Q' \- d7 ? {
4 F. ^# Z% t& ?9 o' @+ A+ c" S2 T bit_arry_clr_bit((void *)LCD->RAM,28*1+index*2+1); ' D) B$ H: e- h& Z. c2 t& Z
}
3 Q9 x1 T& y6 v3 D ' j3 N+ F9 b6 z9 Z8 i
if(lcd_code & BIT_MAST_COM2_L)
. F7 K5 w2 ~' s( i" C {
; L0 V( z8 j# h bit_arry_set_bit((void *)LCD->RAM,28*2+index*2);
2 h0 q1 M, m- z) j7 O7 `1 A } 3 U% U2 f! w" ?& o V
else
. b- k$ F- |9 L7 _7 K% T U { $ F' w1 [' {4 k) h* u% ]
bit_arry_clr_bit((void *)LCD->RAM,28*2+index*2); ' U' u' c( f7 q5 H0 v
} & \# L: }& R2 p$ V- b& k" o
+ S5 R! u m. Q1 `1 M if(lcd_code & BIT_MAST_COM2_H)
6 U5 }; o; F: ~* N: w$ t/ y9 W {
: \9 C+ }/ y- n8 Y4 }% G! Y bit_arry_set_bit((void *)LCD->RAM,28*2+index*2+1); & L6 Z# S6 ^) M, k( {! f/ @
} 8 |* G9 y: v5 g4 I1 n+ J
else
U: M. T1 ~" J% ], V( I { 5 G- u& G; ^* | `: B
bit_arry_clr_bit((void *)LCD->RAM,28*2+index*2+1); ! w! B5 a. G2 W
} 6 O H8 L( f; }% H1 o, P: \; Q
9 N( l) {2 l L; T4 g if(lcd_code & BIT_MAST_COM3_L) % |# p. r/ l7 I/ [/ \! V
{ ! L$ m- @$ X7 m; E" w+ _5 ~
bit_arry_set_bit((void *)LCD->RAM,28*3+index*2);
0 X$ q5 ^0 k$ E$ u. t }
- d d. z( h- @3 V: x. G+ A7 X else
$ P/ V& I2 d; ?/ v* i8 I { / j7 |" q3 u9 l8 Q' K
bit_arry_clr_bit((void *)LCD->RAM,28*3+index*2);
8 [) ^& `2 e# ^/ V# ]* X } - F2 Z# J: ^9 b! b
9 C* n' z1 E0 R
if(lcd_code & BIT_MAST_COM3_H)
' [1 f) l/ Z0 Z) b { ) l% [7 } W, X$ V1 ?
bit_arry_set_bit((void *)LCD->RAM,28*3+index*2+1);
|5 W$ K" Y- D( f2 v }
8 v0 }& K' d# o) |% Q- B8 I; H% y else / m8 z! Z. I; R W
{ 8 ^+ E9 u& H( ~" V0 E& d9 X0 g
bit_arry_clr_bit((void *)LCD->RAM,28*3+index*2+1);
% \; |- E B0 n5 k }
' ]# Z+ @( w5 {}
& }( O3 L! R/ K5 b2 D
9 F V) A' i3 E9 \! r! h/ \void LCD_DispOffOnIndex(uint8index) . k: @2 k2 T5 V/ \0 J: k9 ^% M
{ , \1 P' a8 w1 @. |2 T* m: j7 c
LCD_DispCharOnIndex(LCD_CHAR_OFF,index);
% Q- U- k3 S; h8 q- a% t} # J# M% {- N$ }! G3 J6 q$ A
. z f3 y8 s6 @
7 ~$ g% s) ~. g5 I2 \3 \void LCD_DispOffOnAllIndex(void) & v: ~+ o) d8 }$ P: Y9 D1 s
{ 3 E7 g& G& w9 |0 N
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]1 d/ ]# `- r$ O$ c( C) v+ s
{ 1 c: t% O+ |/ ]) Z4 b& }7 s3 y
LCD_DispCharOnIndex(LCD_CHAR_OFF,i); / g6 }6 z% i- D. X. c
} ; J% e. u7 `" K
} ( J {. T* i4 K
" e* i2 s0 p6 w7 s5 B6 rvoid LCD_DispUint16(uint16num, uint8 blank)
$ E5 N! p1 f0 }7 a1 D# e{
8 U; Q7 U8 u! [8 D# |3 W, G uint8 bcd[__MAX(5,LCD_INDEX_MAX_COUNT)]={0};
k1 [1 y- Y2 r uint8 bcd_index;
* ^7 W: C) ~2 |, N7 m' R" O uint8 lcd_index; # R9 ^; @3 v a- T
* L0 r% r/ u: |: v5 E. _
uint8 index_max_count=__MAX(5,LCD_INDEX_MAX_COUNT);
) Z7 ?) p6 E0 \0 \- V* t6 o 9 i' U3 u2 ~( ?# ~+ J6 V, j4 E
u16_to_bcd_5(num,bcd); : l i2 h% ~# Z
& [' W# N3 Q6 N& p3 R% i bcd_index=index_max_count-1;
6 e5 V0 c: i8 ^" q. ` 7 ?( I# U' H' W
for(;(bcd[bcd_index]==0)&&(bcd_index!=0);bcd_index--) 1 r+ x O% ]3 H5 w( l5 J
{ ' m/ `3 d& c$ o! O- z9 m
lcd_index=index_max_count-1-bcd_index; 8 k- {, i2 M7 V- z9 o6 t2 P6 I0 @
LCD_DispCharOnIndex(LCD_CHAR_OFF,lcd_index);
6 z3 ]- s2 F) w" l4 N; o0 @ } ; C, p* q+ b9 ~) L" F6 L
8 O" X9 M! j0 {& I+ ?; h for(;bcd_index!=0xff;bcd_index--) 9 ]" a/ J5 B' d6 Z4 _+ a9 f6 k* f
{
4 y1 n9 r2 C9 K6 e. I- T lcd_index=index_max_count-1-bcd_index; 6 |4 ~0 u8 z: O
LCD_DispCharOnIndex(bcd[bcd_index],lcd_index); , a( j! z, a" o, f5 P, |2 Y% y
}
$ {/ n6 B: U w8 K+ Z/ r5 D}
0 v, t+ N5 |$ M' a0 S/ n( Q0 C) c/ ?( }# m- M
#include "stm8l15x.h" : I Z; G( Z3 `! }6 d% v! X5 X
#include "uni_int.h" 2 z6 f! N& i" o! o
#include "delay.h" " ^1 I. D) t5 U9 h r$ {0 T
#include "periph_lcd.h"
. e2 z0 }1 u* [- I2 k' l
" E. _2 n4 N# g2 ^0 V3 Y/ Jint main()
% h' ~! @0 w& ]/ B, N. `9 Q, P{
5 n* u4 v' ]" J+ R; X$ j$ n. U, H LCD_Open();
% b, q: M& @% a- {0 a
. L/ i, K4 c1 Q u+ ]3 M# Z uint16 num=100;
% W0 j8 S! m; _3 l& x, Z; k
% x7 T( N5 n, q$ b( V2 W while(1) 5 \ V: m+ e# T5 Z; u
{
% H2 I6 ]( R4 G, \$ I num--;
5 T5 Q- S+ H4 S2 z( {1 ~. z% U, C4 d LCD_DispUint16(num,LCD_CHAR_OFF);
) I7 n; ^/ K4 H9 h* b9 ^' c$ }9 | delay();
: @: Y5 B! v5 z" w3 I! b) O7 { } : J, m' U- z* c8 G
}' \1 o9 r- L* C: Z: Q' W0 Y
[size=11.818181991577148px][size=11.818181991577148px]; [. p- K( u% A! Y$ r
|
|