搞明白了怎么显示了,先写个显示的demo显示数字0,为了便于仿真,不停输出,实际使用的时候,是可以锁在的,不改变数字时,不用写入,然后再用proteus仿真一下,因为proteus里没有SAA1060这个元件,要不可直接看数码管显示,现在只能看虚拟仪器里的时序了,代码附后,代码写得效率可能不是很好,但看仿真的结果应该是没有问题。
5 |7 C/ s" g, }, i
- B+ `, {3 Q9 B% {. m
\# w0 e4 ]) ~6 l8 [9 {
$ s# k5 x5 K# R* W% g
) f: r* @# W% ~1 Z1 T5 s' X8 d: A5 b! \
" S! r! {& ]2 j, w6 v; j$ Z- F. edemo 的代码在这里9 Q- q! l5 s* b" C
, R/ K' q" q( k8 }) p: e+ f
/ ^" f3 ^" e4 s- i#include "reg52.h" //此文件中定义了单片机的一些特殊功能寄存器
" a7 m- L- l0 {. I4 n4 Q* Y
2 r6 x: Z) F& e% h' x3 Jsbit yData = P2^0;6 r/ \+ r" Y7 w
sbit yDLEN = P2^2;1 w# e/ z+ B" h) `( d* [: ]
sbit yCLK = P2^1;
* b' A( @" u1 i. g( m% |const int dailyCount = 200;" |% r) i1 F6 G& [8 g; W
- [$ s$ E% W' \' S; T1 I9 F; h- G! I
7 g# E' s5 V2 h( n7 evoid delay(unsigned int i)2 r8 ?: g0 x& a( w
{
" i8 y0 S5 v7 l$ [9 E) f while(i--);
4 l/ p1 q( M* ], R! \- j- y5 ^}% \) h4 N* |" m4 E; A4 K
9 s0 j; P. n4 X4 J) K6 c( }
& b$ P) m1 x' K c0 H6 m& q1 J$ Lvoid disp(unsigned int num )+ A+ ^# l r8 f
{
+ ?. Q8 D$ b' L' o) B B" v unsigned char i ;
% T- p1 v! S8 u* n9 }
. j/ v6 ]* o9 ^1 L m7 J! A9 m1 h2 ]8 } unsigned char dispA[20];$ a% `: }/ S: I8 d* E
unsigned char dispB[20];1 W3 `6 c9 J8 f
5 M; K% _" @3 c( N% U2 j4 d unsigned char num1;0 P1 w" s; ?0 T" S" i5 |
unsigned char num2;
3 e) { Z, k- y2 d unsigned char num3;
7 x2 ^1 G- b* l unsigned char num4;
, w; G/ K* G/ P( D$ b& P, C. S4 ]( f# T unsigned char segR[10] ; //右
; U; l- p9 O" z4 _ unsigned char segL[10]; //左
7 q1 k+ Y- u, W! Q& R; e5 O" U# s& a; r! x
//左 5 j1 c9 D' Y& g! G9 u. G$ }
segL[0] = 0x12;
; }& ?. U3 f8 x% M+ U2 J2 n segL[1] = 0xFA;
( A- _/ \& a- a; N3 o segL[2] = 0x0E;
5 s- Z* b' |& v& h6 z: y segL[3] = 0x2A;8 i4 Q5 d5 j7 z" O% i i
segL[4] = 0xE2;
9 O! _+ {5 _* z$ }/ B% g# z/ H segL[5] = 0x63;
& [! y6 O3 W% `9 ~: ? segL[6] = 0x2A;# V& ]0 R8 L/ }4 y4 f* }
segL[7] = 0x7A;) B# f+ T' L6 [" {; `1 t
segL[8] = 0x02;# I X+ \7 O/ x, s- l3 Q
segL[9] = 0x22;
, f5 H6 ^% d% I # L ?% T. d" b( D7 l
/ \# k; F4 Q; v& K# H7 @" } M
) Q2 j$ E/ M" D# ?) G //右; G: ` p) `0 `. V
segR[0] = 0x88;
2 n: [, ?" X- @" G segR[1] = 0xEB;
" [4 l8 v3 k% l! O segR[2] = 0x85;; o( b8 l% [/ v) f9 B# I
segR[3] = 0x83;
: ~% x3 v/ `# Q _ segR[4] = 0xE2;
8 W" j3 p0 H" [% Z# c8 [! c segR[5] = 0x92;+ W- V$ u2 A+ o* }
segR[6] = 0x90;
' d- w; n. ~' N, Z9 o segR[7] = 0xCB;
+ S, K1 X( B/ e; V9 q segR[8] = 0x80;
* F: ?3 W% g" J8 k/ z: Z: z* j segR[9] = 0x82;
. X6 n' R: |( w
2 w1 o. i2 n( ` n1 a. u
' ~" q4 u# U5 O( U4 V: W/ t num1=num /1000;
5 p1 c9 d) y; L; e num2=(num /100)%10;;
3 M9 I; d2 }" V8 Y q' ^ num3=(num /10)%100;;;5 ~' H+ R; a" T% J/ _# U _
num4=num%10;3 p8 H- v4 ]- P6 \/ l; p S7 T. l
/ G) N2 W0 G& L, N
, y1 ]9 Z" E4 a, {
) E( d7 g: `$ S6 s2 L- {% ?& a; f9 n1 T6 f" q
dispA[0] = 0;* A; o Y& N3 S& b Q; P- G4 h" b: X$ f
dispB[0] = 0;
3 z9 x* d* ]# q4 d% S% D
. P2 ?! b2 G# n& V F. J
9 e$ C) i; Y4 H! W+ B for (i=0;i<8;i++)( U8 i+ b3 \4 S4 \/ Y
{- k+ v% A& c4 X$ H& \
dispA[i+1] = (segR[num2]>>i)&0x01;
* h/ R: N6 l" x3 K dispB[i+1] = (segR[num1]>>i)&0x01; F. z0 y4 [" E+ e* d
2 P! @6 P& b# o) O1 C1 K9 Y8 \ dispA[i+9] = (segL[num4]>>i)&0x01;) f% t3 c( z6 a
dispB[i+9] = (segL[num3]>>i)&0x01;; O4 `4 }" F% {9 {: o
}# \! O% n/ q" g G, ]" H
2 G1 l, D& Q% l" t# E- E
3 F/ S- v; u; |& [/ {9 \, Z3 B5 @# S2 R$ p( `5 V
dispA[17] = 1;2 Y1 N* Q& O) t4 f9 u: N% ]# R
dispB[17] = 0;
* |9 P r( O+ t: `& X! m6 K7 Z
5 l9 t& ?' t/ S) R5 r4 ]% | dispA[18] = 0;: g# Y4 W. @( z& K# S$ e( }+ o
dispB[18] = 0;. q- f4 k# A! q1 e/ Y6 y
3 k' R6 B2 f1 E! Z, @/ t! R L dispA[19] = 0;( L/ \4 B/ W6 a# m
dispB[19] = 0;8 I2 j0 R7 j% j7 M L9 o
2 O4 `7 F1 |' @# W+ Z yCLK = 1;' c5 W; P) ~9 B/ k, N: B$ {
2 g- e+ N+ R5 {& v7 _5 L& F+ Z5 N2 _8 w
, m* i+ Q# P2 N0 f5 I% B% } v& B for (i = 0;i<20;i++)1 P% i- _% W0 ]# h6 M
{4 S7 L0 K- }/ _3 o7 ?
yCLK = 1;
/ G9 b7 [ p! k) k0 y4 Z M yData = dispA;
3 A% `5 ^# x! n1 N% g9 x! q0 R delay(2);
7 t5 m" B( m) }' K" d if(i>17)
+ b1 r+ x. c: c4 i% k& @ {yDLEN=0;}
0 v$ x$ _2 [+ x5 \' t! E else3 i9 y; `7 K( o, t6 d8 B
{yDLEN=1;}8 G( Z8 K: m- N4 G- s J
* K* _2 \/ w; g& U* D Q
delay(dailyCount);
b8 x; \( [0 A) S) { yCLK = 0 ;) U$ C, R7 l1 M4 J, [
delay(dailyCount);$ k8 y! D* @( K1 J* D4 |% T
}
8 Y W& P! H; u) y3 i- V+ Y' A% e& R; L5 a; G- e2 N7 }; h. u
yCLK=0;: H% b+ a0 {6 y& B3 J( b2 T6 l, n9 U
yData=0;
. G3 O: ]8 `; e yDLEN=0;5 V. v2 k1 ?" p6 S- a) D* K9 @! f
delay(dailyCount*10);
( T# `6 p9 x# A8 @, L; i, e# l ' M5 @2 d8 V7 L0 `
- f8 Y( `$ |/ w- g# O
# m- S' a; O( i2 v for (i = 0;i<20;i++)& U# |: K% I3 X Q( }5 R: t
{; L& W- W# P% c% v+ ]
yCLK = 1;
8 k, b: \- `! i3 @" F9 K yData = dispB;
6 q3 }8 G% K: R% F, c4 X delay(dailyCount/10);
6 ?; E$ g& x2 |: S$ r, t- D4 b# |3 ` if(i>17)
" V+ D) s% M! R8 l3 X3 w {yDLEN=0;}) M# {8 j6 r! g9 L' ~$ w
else
! ~+ `' T9 s! Z8 i {yDLEN=1;}
, [0 f5 P% |2 }4 [" w- g9 X* D& P* o. p& O1 C% A/ \5 z1 n
delay(dailyCount);
8 o7 n1 X' I: u: s$ o yCLK = 0 ;
3 x; e ]( z0 ?5 p& M. o B+ f delay(dailyCount);! i4 i4 p7 X" @
}9 ]$ ~, k( r; W. {! J1 `2 H
2 l, `% D. U6 \) h& c) e i8 l
yCLK=0;
0 o) L" a4 a8 a9 j% N5 V yData=0;: V6 h$ C; V% c* x- ~
yDLEN=0;
8 J5 K5 n6 }7 y. g: W delay(dailyCount*10);
/ f1 v( {3 w; X$ f. U}" V3 a# ~! |% v, K; S" S
! q: _% S% J; P' }6 w, w
% V. l3 G" ]" L" _. Z4 H3 r) S
' K6 M0 ]7 s3 _! q5 v' J C3 q C
: g9 w6 h/ q$ P3 lvoid main()$ D+ {, E. L _' i! G
{1 P3 o9 v; e3 Q+ {- h" o
while(1)
6 o. F; i8 w3 L! o/ ? {& r' F, L# {6 P3 G
delay(4000);
% E/ s- o+ z6 u disp(0);
$ Z$ D7 l5 o- q+ ~$ q }
b9 O; O5 b& d a}; X9 U4 B" b6 C
+ A* r3 M( {8 }$ y! Q
# j( [6 w3 P- [3 Y, V+ n |