周立功的增强型80c51单片机速成与实践中的Hello代码,经过加工后,实现一个简单的拉幕效果很简单的代码,虽然只是一小步,同时也是一大步
#include
<
REG52.h
>
#include
<
stdio.h
>
#include
<
intrins.h
>
sbit SDA
=
P1
^
0
;
sbit CLK
=
P1
^
1
;
unsigned
char
data display_bit;
unsigned
char
code led[
20
]
=
{
0xC0
,
0xF9
,
0xA4
,
0xB0
,
0x99
,
0x92
,
0x82
,
0xF8
,
0x80
,
0x90
,
0x88
,
0x83
,
0xc6
,
0xa1
,
0x86
,
0x8e
,
0xbf
,
0x89
,
0x8C
};
void
delay(unsigned
int
k)
{
unsigned
int
i,j;
for
(i
=
0
;i
<
k;i
++
)
for
(j
=
0
;j
<
100
;j
++
);
}
void
send(unsigned
char
a)
{
unsigned
char
i;
for
(i
=
0
;i
<
8
;i
++
)
{
if
(_crol_(a,i)
&
0x80
)
SDA
=
1
;
else
SDA
=
0
;
CLK
=
0
;
CLK
=
1
;
}
}
main()
{
unsigned
char
display_buffer[
5
]
=
{
0x00
,
0x0d
,
0x12
,
0x05
,
0x01
};
int
counter;
while
(
1
)
{
unsigned
char
i,k;
int
lay
=
0
;
for
(lay
=
0
;lay
<
100
;lay
++
)
{
for
(i
=
0
;i
<
5
;i
++
)
{
int
discnt
=
(counter
+
i)
%
5
;
k
=
led[display_buffer[discnt]];
send(k);
P1
=
display_bit;
delay(
0x01
);
P1
=
0xff
;
display_bit
=
_cror_(display_bit,
1
);
}
display_bit
=
0x7f
;
}
counter
++
;
//
delay(0x3f);
}
}