用51单片机连接max7219芯片做秒计时器,求帮看下程序
答案:2 悬赏:30 手机版
解决时间 2021-03-23 10:41
- 提问者网友:精神病院里
- 2021-03-22 13:53
用51单片机连接max7219芯片做秒计时器,求帮看下程序
最佳答案
- 五星知识达人网友:春色三分
- 2021-03-22 15:12
#include
#include
#define uchar unsigned char
sbit pinDIN = P3^0;//DIN 串行数据输入端口。在时钟上升沿时数据被载入内部的16位寄存器。
sbit pinLOAD = P3^1;//LOAD (MAX7219) 载入数据。连续数据的后16位在LOAD端的上升沿时被锁定。
sbit pinCLK = P3^2;//在时钟的上升沿, 数据移入内部移位寄存器。 下降沿时, 数据从DOUT端输出。
uchar code LEDcode[] = { 0x7e, 0x30, 0x6d, 0x79, 0x33, 0x5b, 0x5f, 0x70, 0x7f, 0x7b, 0x00 };
//【增加】 延时1秒 函数
void delay1s(void) //@12MHz
{
unsigned char a,b,c;
for(c=46;c>0;c--)
for(b=152;b>0;b--)
for(a=70;a>0;a--);
_nop_(); //if Keil,require use intrins.h
}
void sendbyte( uchar dat )
{
uchar i, temp;
_nop_();
for ( i = 0; i < 8; i++ )
{
temp = dat & 0x80;
dat = dat << 1;
if ( temp )
pinDIN = 1;
else
pinDIN = 0;
pinCLK = 0;
_nop_();
pinCLK = 1;
}
}
void sendword( uchar addr, uchar dat )
{
pinLOAD = 0;
_nop_();
sendbyte( addr );
_nop_();
sendbyte( dat );
_nop_();
pinLOAD = 1;
delay1000();
}
void init7219( void )
{
sendword( 0x0c, 0x01 );
sendword( 0x0a, 0x09 );
sendword( 0x0b, 0x03 );
sendword( 0x09, 0x00 );
sendword( 0x0f, 0x00 );
}
void clear7219( void )
{
uchar i; for ( i = 8; i > 0; i-- )
{
sendword( i, 0x00 );
}
}
void main( void )
{
int n = 60;
int s = 0;
int g = 0;
init7219();
while ( 1 )
{
//clear7219(); //【屏蔽】不然不显示
if ( n > 0 )
{
n = n - 1;
s = n / 10;
g = n % 10;
//LEDcode[s]; //【屏蔽】
//LEDcode[g]; //【屏蔽】
}
sendword( 0x01, LEDcode[s] );//【增加】显示十位数
sendword( 0x02, LEDcode[g] );//【增加】 显示个位数
delay1s();//【增加】 延时一下,不然变化太快,看不到效果
}
}已在protues中仿真通过。
#include
#define uchar unsigned char
sbit pinDIN = P3^0;//DIN 串行数据输入端口。在时钟上升沿时数据被载入内部的16位寄存器。
sbit pinLOAD = P3^1;//LOAD (MAX7219) 载入数据。连续数据的后16位在LOAD端的上升沿时被锁定。
sbit pinCLK = P3^2;//在时钟的上升沿, 数据移入内部移位寄存器。 下降沿时, 数据从DOUT端输出。
uchar code LEDcode[] = { 0x7e, 0x30, 0x6d, 0x79, 0x33, 0x5b, 0x5f, 0x70, 0x7f, 0x7b, 0x00 };
//【增加】 延时1秒 函数
void delay1s(void) //@12MHz
{
unsigned char a,b,c;
for(c=46;c>0;c--)
for(b=152;b>0;b--)
for(a=70;a>0;a--);
_nop_(); //if Keil,require use intrins.h
}
void sendbyte( uchar dat )
{
uchar i, temp;
_nop_();
for ( i = 0; i < 8; i++ )
{
temp = dat & 0x80;
dat = dat << 1;
if ( temp )
pinDIN = 1;
else
pinDIN = 0;
pinCLK = 0;
_nop_();
pinCLK = 1;
}
}
void sendword( uchar addr, uchar dat )
{
pinLOAD = 0;
_nop_();
sendbyte( addr );
_nop_();
sendbyte( dat );
_nop_();
pinLOAD = 1;
delay1000();
}
void init7219( void )
{
sendword( 0x0c, 0x01 );
sendword( 0x0a, 0x09 );
sendword( 0x0b, 0x03 );
sendword( 0x09, 0x00 );
sendword( 0x0f, 0x00 );
}
void clear7219( void )
{
uchar i; for ( i = 8; i > 0; i-- )
{
sendword( i, 0x00 );
}
}
void main( void )
{
int n = 60;
int s = 0;
int g = 0;
init7219();
while ( 1 )
{
//clear7219(); //【屏蔽】不然不显示
if ( n > 0 )
{
n = n - 1;
s = n / 10;
g = n % 10;
//LEDcode[s]; //【屏蔽】
//LEDcode[g]; //【屏蔽】
}
sendword( 0x01, LEDcode[s] );//【增加】显示十位数
sendword( 0x02, LEDcode[g] );//【增加】 显示个位数
delay1s();//【增加】 延时一下,不然变化太快,看不到效果
}
}已在protues中仿真通过。
全部回答
- 1楼网友:街头电车
- 2021-03-22 15:48
程序没有格式,太乱,没法看
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯