#include<reg51.h>
#include<stdio.h>
sbit P1_0=0x90;
unsigned char nSendByte;
void delay(unsigned int i) //延时子程序
{
unsigned char j;
for(;i>0;i--) //变量i由实际参数传入一个值
for(j=0;j<125;j++);
}
main( ) //主程序
{
SCON = 0x00; // 设置串行口为方式0
EA = 1; //全局中断允许
ES = 1; //允许串行口中断
nSendByte = 0xc0; // 点亮数据初始为0000 0001送入nSendByte
SBUF = nSendByte; // 触发串行中断
P1_0 = 0;
while(1) {;}
}
void Serial_Port( ) interrupt 4 using 0 //串行口中断服务程序
{
if(TI) { // 如果TI=1,1个字节串行发送完毕
P1_0=0xc0; // 允许向74LS164串行输入且并行输出
SBUF=nSendByte; // 向SBUF写入数据,启动串行发送
delay(500); // 延时,点亮二极管持续一段时间
P1_0=0; // 关闭74LS164输入输出(不关闭也行)
nSendByte=nSendByte>>2; // 点亮数据左移1位
if(nSendByte==0x00) //左移8次则重新送点亮数据
nSendByte=0xc0; //触发串行中断
SBUF=nSendByte;
}
TI=0;
}