搞明白了怎么显示了,先写个显示的demo显示数字0,为了便于仿真,不停输出,实际使用的时候,是可以锁在的,不改变数字时,不用写入,然后再用proteus仿真一下,因为proteus里没有SAA1060这个元件,要不可直接看数码管显示,现在只能看虚拟仪器里的时序了,代码附后,代码写得效率可能不是很好,但看仿真的结果应该是没有问题。
+ H5 L# [% I+ c& A* G/ G9 F, q" m5 Y' o: k+ o. g$ P# m- E
6 M/ Y+ I' R) H# L* S
( B2 o, f$ R) \. \) G
% _0 a" K' }/ ]$ r
I, F% i2 w* g* H
' N3 K2 V$ C: H3 c K/ ?) Z/ Qdemo 的代码在这里
* @3 D8 `. x7 G9 T" Q/ ^ d7 B
! |! [+ b1 k9 u/ w1 Z0 [" X6 l! z: o! n# @; |" J+ `
#include "reg52.h" //此文件中定义了单片机的一些特殊功能寄存器. ^3 s( ^. Z) }7 w8 F5 @# C* s
+ o/ V% \) s4 n. L" O# w
sbit yData = P2^0;
! O) {: u1 T0 @sbit yDLEN = P2^2;
1 h- G C& C( ?6 l0 }sbit yCLK = P2^1;
& p+ ~$ E, Z$ f! C P2 q4 z$ nconst int dailyCount = 200;7 R; @) |- o3 B3 Y7 v+ q
( P' U0 Y9 e6 ?+ t
5 d) e- W3 B4 t" g8 y. M
* m% j# N7 z: J* G$ P# Bvoid delay(unsigned int i)) r1 L/ ?6 ?" x4 M
{6 S4 U1 s) B6 c, f w3 y3 ]/ a2 L
while(i--);
/ c! N, R% h: c: t% o, B3 G8 |}! H6 a* k; s9 E
7 \" ~, L2 v( r9 i; b$ ~, L! A, P# r M8 n' M* M
void disp(unsigned int num )* [- a6 l; m& \8 K
{
8 l+ m1 a0 m7 z. P unsigned char i ;. x; ^/ l" P' W' R3 H8 P/ s9 S4 {
- Z0 A9 `- d5 q5 d$ r unsigned char dispA[20];! I) p; p. Q! ^) G& M# \
unsigned char dispB[20];
8 C' R3 Y3 I. P2 K5 a
, ?1 O# |, N3 |$ L unsigned char num1;
! f& t l6 g: {. M unsigned char num2;
5 E2 Y4 c( a6 @- L unsigned char num3;, ?) A3 ~ }% g/ m
unsigned char num4;
. X6 n) a T. Y h0 j# d4 g unsigned char segR[10] ; //右
3 E; I4 Z5 m+ R4 h) { ~ unsigned char segL[10]; //左
4 z# H p6 Z2 b6 o0 _& z, o
# q1 Q: G/ W, z, r; f //左 * ~4 @1 R0 @# s7 |' E4 [ O7 {
segL[0] = 0x12;% o# E1 A& t, \ C/ n8 ?4 \
segL[1] = 0xFA;+ a1 J! @( B0 u# ? Z2 C
segL[2] = 0x0E;) H* R. `) m2 e6 N
segL[3] = 0x2A;
- ?6 d, s4 c! T% _& R segL[4] = 0xE2;2 L. ~% V; s s7 T4 P9 f* {9 o
segL[5] = 0x63;
" k& O/ F5 ]3 q; H2 Y% w4 S segL[6] = 0x2A;! w1 b7 L' j% l
segL[7] = 0x7A;
0 F2 T' S& |4 j: v* f1 S( P V3 ~+ g segL[8] = 0x02; t. C8 t& z1 ]6 n, t
segL[9] = 0x22;( C: W' m5 n6 |
* _, {, d0 L1 S+ X. w
: y7 i- L1 X# C7 o3 t! o 9 i+ S; X, X2 W( e
//右
1 Y3 y3 E* q; d1 a1 { segR[0] = 0x88;' S0 l/ b4 k. _+ q7 k4 w
segR[1] = 0xEB;
& d7 V: T5 a3 G: E4 S& } segR[2] = 0x85;
& X4 f1 [7 M5 t; P9 J0 q+ i segR[3] = 0x83;+ t9 l' X; A2 d8 u) z# d& [* O
segR[4] = 0xE2;
3 L) l0 x9 L$ k: c n segR[5] = 0x92;+ e+ F! F5 j! B" Q' O" R
segR[6] = 0x90;# ^5 B( t7 X9 O0 l5 b
segR[7] = 0xCB;
! t* G9 i7 ]; g, A4 }8 E- n' W segR[8] = 0x80;
d( s2 g2 M+ W, `$ y segR[9] = 0x82;3 |2 W8 ~' K- Q3 V
, E3 ?* a& V( ^( R
$ c0 U- y4 ^% d$ J: [, r! K! u num1=num /1000;
$ I: ?3 C, r" p7 g" ^' Q num2=(num /100)%10;;
" ~. D9 }* r- v+ u6 E- C num3=(num /10)%100;;;' ?$ a# V% |9 Z4 l
num4=num%10;) b9 U# m* n- P5 {) h* @$ E
0 R( [' h3 S4 \: i& b0 k
% E7 Z( h! A( A( q! y, P/ D1 o b; ?2 u8 J0 g. c
9 `* U1 l6 D: X" E! b7 R8 f* ^
dispA[0] = 0;
0 O8 Q t0 E2 I* H3 f; O dispB[0] = 0;
7 i3 k8 g- y' k9 _( N( R) M9 }# q: G; @
4 I: v5 a/ r# l5 @$ P5 b
for (i=0;i<8;i++)/ T9 F0 H( P. l3 T
{/ K+ D/ u8 N |
dispA[i+1] = (segR[num2]>>i)&0x01;9 i3 y* L. z* r; L/ ]
dispB[i+1] = (segR[num1]>>i)&0x01;
$ [5 B i6 b' e* B5 V* m$ \6 k1 L: P- \2 W# w
dispA[i+9] = (segL[num4]>>i)&0x01;6 ~& ~- `( T$ }/ D, x5 M
dispB[i+9] = (segL[num3]>>i)&0x01;
, C* m; F: e/ r' m }) s* r/ m( M0 D8 I5 ~6 z( J Z8 P
$ i& Y- t, U& a0 B- v) z, O0 w" g v- L1 s' Z4 q) T
0 `) F; z+ n& D a+ V dispA[17] = 1;
2 Y5 {+ _& G1 f( h- i8 F" v" B+ U dispB[17] = 0;
& {. u+ M1 X! D2 x/ q! w9 D: e W H+ Y
dispA[18] = 0;/ [8 r7 }( u6 c* D) a0 L
dispB[18] = 0;8 c6 A% E2 `; Q
% ~3 R1 y& C/ F; z0 t) L$ y5 p3 }6 o dispA[19] = 0;
, S1 I) C) x2 _5 \! v dispB[19] = 0;' Z7 M8 A/ b1 n+ Y/ o8 n) }
( T7 s7 c: a+ Q1 C6 a yCLK = 1;
( X0 T+ ~; k$ t4 D& q3 l1 ]3 ~" k$ L# ?5 e( }
% E2 f: h( W4 W" H+ ?3 t- r8 O$ u9 C
. n% O& }6 V, w# `: E for (i = 0;i<20;i++)5 e+ M& H; B( i( c4 d
{+ y5 o A" m% p: M9 I
yCLK = 1;
. r( y! I4 L& F" H8 e! z yData = dispA;9 W9 f9 a9 ^# u# ~, r; b; m: F. I
delay(2); F- O+ K& `2 F* i- d
if(i>17)) s2 Y# c( k' R! G
{yDLEN=0;}) `+ M+ d* H) u, U& ~$ Q
else. k9 u7 y. o+ ]% d6 e
{yDLEN=1;}. L# Y" W! s* ^' m3 W9 I ?' f
& `( F6 O( j) d delay(dailyCount);
- J4 v( o$ ^1 Q3 D yCLK = 0 ;
6 J4 w/ c _$ K delay(dailyCount);
$ ^4 o) s. U" Z7 |' J1 T }) B+ ]) h4 L: S6 A* W9 n
6 _6 h' j4 i! Y7 [# w9 Y+ k yCLK=0;8 o% }- F \( s* g2 O
yData=0;% o# q8 m* W7 p
yDLEN=0;
4 m. _, n, ]7 V, t5 s delay(dailyCount*10);& U' j( M1 \1 d. `8 _2 V7 }
4 V/ f( B( w% h
, L( b& @% V$ X9 x! u
. m K; i& r3 U2 Y for (i = 0;i<20;i++)
% a( I9 w0 z0 f% f {+ Y' G$ j; {6 k% R, W) \
yCLK = 1;
! J4 L4 [6 Q3 q' ?( ` yData = dispB;+ S( f% B% ]) w; c
delay(dailyCount/10);
% S3 y* I6 m+ t- _: Z if(i>17)
/ J, ^+ }+ S5 u& d {yDLEN=0;}) d3 [: Q9 A# U* U
else9 d3 b9 l. p/ F R9 p6 X' ^
{yDLEN=1;}0 w' I$ t, [5 Y4 R5 N+ g
$ W# @9 s- I( Y0 o
delay(dailyCount);' s% V: q1 Y7 U8 g
yCLK = 0 ;
2 ^- V* Y: C* P- L9 a& A delay(dailyCount);& c: W/ D; _. a: K+ W7 O
}
3 ^" I+ C8 B8 e( s
& A# Z1 `* e& Q& X yCLK=0;# A, t8 D5 C8 P m
yData=0; S% w, q C$ Z) A; t
yDLEN=0;
m& } T# g0 P" K0 U' Q* L3 Z delay(dailyCount*10);
$ s: w" H; N6 G9 A* G+ v2 ?& Q}) v( H. w7 b6 l; S b# V# b
4 K+ {, B- Z0 q
8 z; B" W! Y( L- ~
% _% M9 ^# q7 _$ l
* g* p' d" o Z9 d$ j1 m& i5 evoid main()
0 D: L, j7 E+ x{' l- M4 l9 p2 ]
while(1)
+ s. M" i/ x7 a0 `8 x. s0 e! s {9 g! O0 R; |& s) W: W
delay(4000);
+ O: ?9 w& W$ A2 q' E1 |3 A1 d disp(0);
& F0 A+ s& }& ?! j8 N+ Z: f } 5 H' H- g3 k) ^2 K5 g0 S! l
}
h/ e0 p" }4 h" Y s1 i, z Y/ Z7 r3 @1 w- P3 p4 M- S
" Y0 _- D- E9 u |