搞明白了怎么显示了,先写个显示的demo显示数字0,为了便于仿真,不停输出,实际使用的时候,是可以锁在的,不改变数字时,不用写入,然后再用proteus仿真一下,因为proteus里没有SAA1060这个元件,要不可直接看数码管显示,现在只能看虚拟仪器里的时序了,代码附后,代码写得效率可能不是很好,但看仿真的结果应该是没有问题。
& N/ y; f6 _9 Q5 K- d4 T" v% H& s" G- S2 s* K1 M
# C1 d: \! p i3 j
$ M" Y% x" F) \( m- v5 Q) o
( u$ g D, L, `# A/ M5 ]* D" J
7 n% o. T2 V% p
3 ^) ^/ M# V# t% n% `% H. xdemo 的代码在这里4 a7 {0 m/ A1 A) s# ]3 E
/ |2 e. U; ^ a2 f4 l7 Z0 ~& I& W1 Q
#include "reg52.h" //此文件中定义了单片机的一些特殊功能寄存器+ q/ b r' b& x8 r4 ]- k4 |
1 m4 ]; ^) Q0 ]8 @sbit yData = P2^0;" \4 z a: _- @" p
sbit yDLEN = P2^2;
$ ~# n( z$ ]. O1 msbit yCLK = P2^1;
1 D% X; W( ~ yconst int dailyCount = 200;
4 [+ H1 q2 L3 G, J. n3 h9 P) F
" q' t5 D; _2 m. r; q1 ~4 I0 t0 e7 U
' j( b/ J# n1 ?2 f
void delay(unsigned int i)9 A8 o; l; M0 h3 t
{7 A2 Y4 B: a& t8 V% \/ ^6 r
while(i--);
/ e/ B1 C2 s5 j7 p5 z2 i. W2 }% F U, L}0 t- N, a i% g$ b: c3 m) e' N
1 K& m! H2 |/ b0 u
; R( X8 q$ K: e( ]! svoid disp(unsigned int num )7 G+ Z# W2 z+ t
{
0 S1 a4 w7 N* {" ~ unsigned char i ;! ]3 o X7 s" L$ k( b! A+ \
% [" I5 F4 I! T! {; g% Y
unsigned char dispA[20];
- v% v* {6 U. O' [. }; j. T unsigned char dispB[20];$ U0 t5 b9 {4 A; k
- P& ?9 y* R8 @7 A' } unsigned char num1;
& `1 ^% o3 N0 b) V unsigned char num2; " j2 I& y2 w% k6 Y
unsigned char num3;
8 Y* \9 S- I3 W# U unsigned char num4;( s6 q4 ]1 g9 K' y6 d1 @
unsigned char segR[10] ; //右
* C/ d( ^: t3 a! n1 w" n unsigned char segL[10]; //左) \$ v' e. m* I! c) v) ]
5 G) ^- s7 b8 P" Z5 b" x* F //左
" b, P2 ], |0 l segL[0] = 0x12;
6 H6 K& F2 e- I5 g1 W; S2 F8 r segL[1] = 0xFA;! f& G$ d, q" K3 y' i. c# X
segL[2] = 0x0E;, ?% M0 d0 @6 \0 l! l$ Y! f8 ?
segL[3] = 0x2A;
3 ~, X6 }7 A9 r1 o8 M segL[4] = 0xE2;) L# g/ s4 S2 o/ ?% Z/ ]
segL[5] = 0x63;1 t% F/ D0 Q: {5 d; c' E+ a2 z
segL[6] = 0x2A;( u3 l7 b7 V- m2 b; n+ B4 L; _
segL[7] = 0x7A;
6 t9 a7 m1 X% i$ Z! B9 f segL[8] = 0x02;
* \& T1 Y& F% H. |( `# R segL[9] = 0x22;
6 q& L2 F" [" w, g' V
6 b' E$ |( I9 y' _: z% {; k" J 9 D% A3 Y1 O: m9 Q- Z3 f
1 S1 `/ [% {' Y+ j: p; N' ?
//右. @, ^& W+ k- k* d. R- T
segR[0] = 0x88;
7 ~5 J0 l/ N Z/ D segR[1] = 0xEB;
0 q% z* l/ B4 M! y segR[2] = 0x85;& A- `. g% \3 X( g: c
segR[3] = 0x83;6 T: j5 E4 N$ d. C
segR[4] = 0xE2;' I6 \. R/ M7 C) E. ? i
segR[5] = 0x92;/ z% o! z. d. x
segR[6] = 0x90;
( F, G) p; n9 T8 B- } segR[7] = 0xCB;
, N9 ?' h. q& X1 s segR[8] = 0x80;
2 l! E% n7 A5 x+ E2 x6 D$ f1 { segR[9] = 0x82;9 |' N, F1 _) \. ~' r: ~, Z
1 y0 q0 ?. L2 g+ V, x
9 t- e7 w- |! x6 Y4 D! {/ ~ num1=num /1000;
A# x- d) n6 y num2=(num /100)%10;;
) B4 r/ j7 z" F& }# \ num3=(num /10)%100;;;
; [1 b" }- S% j: B* E num4=num%10;- Q) W. ^/ H7 `
( E0 |+ r8 d0 I) y3 O+ m% F Y+ f, E; {) p8 l7 N
$ N+ r% s8 d, {( D: g' r
% l6 x- w' |! D! Y, x; s
dispA[0] = 0;
: ^: `! T( G! O# I0 Y9 D dispB[0] = 0;2 Y) z! A L4 w2 z1 f$ z0 C
4 |( |) h+ v8 w3 E- Y$ ?) m( {
. x- s0 r* y; E5 I& d for (i=0;i<8;i++)+ f) \4 o, i5 _
{
: }/ ^" h3 Q! Y; r6 X dispA[i+1] = (segR[num2]>>i)&0x01;' t5 q( v& e: j
dispB[i+1] = (segR[num1]>>i)&0x01; I4 C( s* w# y! h' o ^
; E6 G: T! n0 t3 w& ^' H dispA[i+9] = (segL[num4]>>i)&0x01;
( f/ m) D) v8 f1 P+ N dispB[i+9] = (segL[num3]>>i)&0x01;
, ]" w( b$ ~, i2 L$ K% d }
# b: r4 ]0 r+ \" l, y0 S' T; L . R- \# P( H K( f9 k
6 S- ^+ w6 G: j- d8 K$ \7 E! n7 Q6 \" ?$ A$ x
dispA[17] = 1;
: t8 s% Q; S. j dispB[17] = 0;! x/ g- ~2 Y: y
( \: i+ v3 h) B9 H7 f3 | dispA[18] = 0;
7 l& }8 U5 A* G- \5 H dispB[18] = 0;6 D" W/ K' { v; b4 i
. E6 \2 U; E2 q& p2 ^; _
dispA[19] = 0;, X' E+ W" u; M q3 K! F }
dispB[19] = 0;& M u6 n1 F; W9 [5 O x2 X
. G" d, _* P$ L yCLK = 1;
. }2 n& [# v& n0 g$ B& r( W5 }. {+ M) c; w! g
@2 O5 n5 s! x- Z1 N+ r7 g. F7 F
7 d4 O s( c9 H, B' D+ f$ l+ K for (i = 0;i<20;i++)
" g+ l+ ?+ I, e {: b* {- q' i1 R K
yCLK = 1;
: [9 {3 a0 S1 g- K4 U- y yData = dispA;4 g# Z, s7 L" a( _ @$ W
delay(2);" z# p& h( D2 A; K
if(i>17)
y$ A0 Z- ^( m/ ? {yDLEN=0;}
5 C7 X2 }. I% ?; X b else2 d7 W2 K- |% r; Q' Q
{yDLEN=1;}
7 c; u5 x) K) {+ W7 f, {! `$ z! [
4 W6 \" p4 f5 N% g1 ]6 H2 t delay(dailyCount);
& m1 Y$ G K9 ]" r9 ^) C) T yCLK = 0 ;! G0 {6 e) Y% e( v5 r0 M; f
delay(dailyCount);7 M/ w3 l+ \6 s
}1 F. e& t. o& d
2 G% W, r- w1 `0 H2 J yCLK=0;
* ]8 W0 y) {) I5 z9 \& j yData=0;) P' K; W# X; B! ~9 D# e! v
yDLEN=0;
& E/ {6 ~/ a2 X delay(dailyCount*10);9 Z' o1 u1 ~6 L- J+ g
' H7 m( A0 R0 J6 D- O1 [+ i0 B
( D6 m6 {% m P7 z: g. I
3 @4 G4 D$ |5 Z! ~/ B$ k for (i = 0;i<20;i++)$ x( W5 t8 _2 K. i# ^
{+ t: x6 C y+ H7 T; Y) D6 G: L) s
yCLK = 1;* m' a' C U1 B2 _" h
yData = dispB;
& F% D+ L4 Q+ Q- F+ f delay(dailyCount/10);* T: T: L: G9 z* b
if(i>17)
7 v( H5 m) _$ m+ X2 n& n3 N {yDLEN=0;}
' P$ q1 u" L8 C( T" F else
# ^( _( A( Y) ~% N4 _4 Y; | {yDLEN=1;}$ u" \3 Y5 C, I& X Q
+ w) O. e$ H) Y2 f, q# b B
delay(dailyCount);4 n/ X) G- R6 f% H G) {4 r A
yCLK = 0 ;1 {: _, _. Z6 T+ a1 `
delay(dailyCount);
+ E2 r' }! i% S0 H& j0 ` }$ Y% N* c2 ?' r' u; f g8 I7 A+ Y4 o
6 b' E% j# Z3 Y( Q. a. ^. [1 T yCLK=0;( A6 L' \( `6 b) z# Z. ^
yData=0;! m/ D2 z9 g8 b
yDLEN=0;
5 v; m( ~/ Z/ p" C delay(dailyCount*10);
9 w$ s* V3 ~8 S, E) b1 S% v! z/ O {; K}
& J* P1 z- h: a
, |1 e5 h- ^) Y8 n
2 i! B8 M. i9 Q4 P& S: J
2 D2 G1 d* N6 K5 B, S: \& Q/ N, ~, T4 l& i( S' Q9 B' {+ i0 v
void main()
8 W4 C6 n' E! D8 @4 s" Y+ l- q{& H2 @ U7 x' R" g: x# \
while(1)
- f) U# r3 S. Q7 B {. O7 i9 ?) @7 `, b9 g6 d( f
delay(4000);2 P% ?6 D" |8 e$ T" O
disp(0);& X9 _' C+ X# e1 C+ |4 z
}
! y+ B+ k+ [4 h}
+ p: x& r F( s( I: N
2 J: K$ g M+ G8 y4 e) C
6 ]/ _) `) f& b- t |