文章目录[隐藏]
左上角led点亮代码
#include "reg52.h"
#include "intrins.h"
#define WELA P0
typedef unsigned char u8;
typedef unsigned int u16;
sbit SRCLK=P3^6;
sbit RCLK595=P3^5;
sbit SER=P3^4;
u8 ledDuan[]={0x00,0x00,0x3e,0x41,0x41,0x41,0x3e,0x00};
void hc595Send(u8 dat)
{
u8 a;
SRCLK=0;
RCLK595=0;
for(a=0;a<8;a++)
{
SER=dat>>7;
dat <<=1;
SRCLK=1;
_nop_();
_nop_();
SRCLK=0;
}
RCLK595=1;
_nop_();
_nop_();
RCLK595=0;
}
void delayus(u16 i)
{
while(i--);
}
void main()
{
hc595Send(0x80);
WELA=0x7f;
while(1);
}
动态显示数字0
#include "reg52.h"
#include "intrins.h"
#define WELA P0
typedef unsigned char u8;
typedef unsigned int u16;
sbit SRCLK=P3^6;
sbit RCLK595=P3^5;
sbit SER=P3^4;
u8 ledDuan[]={0x00,0x00,0x3e,0x41,0x41,0x41,0x3e,0x00};
u8 ledWei[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};
void hc595Send(u8 dat)
{
u8 a;
SRCLK=0;
RCLK595=0;
for(a=0;a<8;a++)
{
SER=dat>>7;
dat <<=1;
SRCLK=1;
_nop_();
_nop_();
SRCLK=0;
}
RCLK595=1;
_nop_();
_nop_();
RCLK595=0;
}
void delayus(u16 i)
{
while(i--);
}
void main()
{
u8 a;
while(1)
{
for(a=0;a<8;a++)
{
WELA=ledWei[a];
hc595Send(ledDuan[a]);
delayus(10);
hc595Send(0x00); //消影
}
}
}
版权声明:本文为CSDN博主「acktomas」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/acktomas/article/details/104167683
暂无评论