串口方式0

#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;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值