#define uint unsigned int
#define uchar unsigned char
sbit DAT=P1^1; //模拟串口数据发送端
sbit CLK=P1^2;//模拟时钟控制端
uchar co
void sendbyte(uchar byte)
{
uchar num,c;
num=tab[byte];
for(c=0;c<8;c++)
{
CLK=0;
DAT=num&0x80; //(0x80即十进制的128, 二进制的10000000 按位发送)
CLK=1;
num<<=1;
}
}
void delay_50ms(unsigned int t) //50MS演示程序
{
unsigned int j;
for(;t>0;t--)
for(j=6245;j>0;j--)
{;}
}
main()
{
unsigned char h;
while(1){
for(h=0;h<10;h++){
delay_50ms(1);
sendbyte(h);
delay_50ms(10);
}
h=0;
}
}
下面这段是74ls164驱动共阴数码管的程序源码
#i nclude
#define uint unsigned int
#define uchar unsigned char
sbit DAT=P1^1;
sbit CLK=P1^2;
uchar co
void sendbyte(uchar byte)
{
uchar num,c;
num=tab[byte];
for(c=0;c<8;c++)
{
CLK=0;
DAT=num&0x01;
CLK=1;
num>>=1;
}
}
void delay_50ms(unsigned int t)
{
unsigned int j;
for(;t>0;t--)
for(j=6245;j>0;j--)
{;}
}
main()
{
unsigned char h;
while(1){
for(h=0;h<10;h++){
delay_50ms(1);
sendbyte(h);
delay_50ms(10);
}
h=0;
}
}