#include<reg51.h> #define uchar unsigned char #define uint unsigned int #define ulong ungigned long sbit MOSIO = P0^0; sbit R_CLK = P0^2; sbit S_CLK = P0^1; void BC595SendData( uchar BTO); void delayns(unsigned int i); void main(void) { unsigned char code led[]= { 0xC7,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, 0xC7,0xD7,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, 0xC7,0xD7,0xD7,0xFF,0xFF,0xFF,0xFF,0xFF, 0xC7,0xD7,0xD7,0xD7,0xFF,0xFF,0xFF,0xFF, 0xC7,0xD7,0xD7,0xD7,0xD7,0xFF,0xFF,0xFF, 0xC7,0xD7,0xD7,0xD7,0xD7,0xD7,0xFF,0xFF, 0xC7,0xD7,0xD7,0xD7,0xD7,0xD7,0xD7,0xFF, 0xD7,0xD7,0xD7,0xD7,0xD7,0xD7,0xC7,0xC7, }; unsigned char w; unsigned int i,j,k,m; while(1) { for(k=0;k<88;k++) //显示滚动行数控制变量 { for(m=0;m<100;m++) //每个字符扫描显示100次,控制每个字符显示时间 { w=0x01; j=k; for(i=0;i<8;i++) { P1=w; BC595SendData(led[j]); delayns(2); BC595SendData(0xff); w<<=1; j++; if(j>87) j=j-88; } } } } } void BC595SendData( uchar BT0) { uchar i; for(i=0;i<8;i++) { MOSIO = BT0 >>7; BT0 <<= 1; S_CLK = 0; S_CLK = 1; } R_CLK = 0; R_CLK = 1; R_CLK = 0; } void delayns(unsigned int i) { unsigned char k; while(i--); for(k=0;k<120;k++); }帮我检查一下这段代码
时间: 2024-01-27 12:04:34 浏览: 150
c#实现51单片机频率计的代码分享(数字频率计设计)
这段代码看起来没什么问题,但有两个小问题需要注意:
1. `ulong` 的拼写错误:在 `#define` 中定义 `ulong` 时,将“unsigned”拼写为“ungigned”。应该将其更正为 `unsigned`。
2. `delayns()` 函数中的循环次数可能会因为不同的编译器而不同。因此,为了更精确地控制延迟时间,应该使用定时器或其他更可靠的方式来实现延迟。
下面是修改后的代码:
```
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
sbit MOSIO = P0^0;
sbit R_CLK = P0^2;
sbit S_CLK = P0^1;
void BC595SendData(uchar BTO);
void delayns(unsigned int i);
void main(void)
{
unsigned char code led[] = {
0xC7,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xC7,0xD7,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xC7,0xD7,0xD7,0xFF,0xFF,0xFF,0xFF,0xFF,
0xC7,0xD7,0xD7,0xD7,0xFF,0xFF,0xFF,0xFF,
0xC7,0xD7,0xD7,0xD7,0xD7,0xFF,0xFF,0xFF,
0xC7,0xD7,0xD7,0xD7,0xD7,0xD7,0xFF,0xFF,
0xC7,0xD7,0xD7,0xD7,0xD7,0xD7,0xD7,0xFF,
0xD7,0xD7,0xD7,0xD7,0xD7,0xD7,0xC7,0xC7
};
unsigned char w;
unsigned int i,j,k,m;
while(1)
{
for(k=0;k<88;k++) //显示滚动行数控制变量
{
for(m=0;m<100;m++) //每个字符扫描显示100次,控制每个字符显示时间
{
w=0x01;
j=k;
for(i=0;i<8;i++)
{
P1=w;
BC595SendData(led[j]);
delayns(2);
BC595SendData(0xff);
w<<=1;
j++;
if(j>87) j=j-88;
}
}
}
}
}
void BC595SendData(uchar BT0)
{
uchar i;
for(i=0;i<8;i++)
{
MOSIO = BT0 >>7;
BT0 <<= 1;
S_CLK = 0;
S_CLK = 1;
}
R_CLK = 0;
R_CLK = 1;
R_CLK = 0;
}
void delayns(unsigned int i)
{
// 使用定时器或其他可靠的方式来实现延迟
// 这里使用空循环作为示例
while(i--);
}
```
希望这次能帮到您,如有其他问题,请随时提出。
阅读全文