51单片机 8X8点阵屏循环左移

使用定时器0中断控制8x8点阵屏循环左移

#include <reg51.h.>
#include <intrins.h>
typedef unsigned char u8;
typedef unsigned int u16;

sbit SRCLK=P3^6;
sbit RCLK=P3^5;
sbit SER=P3^4;

u16 i,k;
u16 time;
  
u8 code ledduan[][8]={{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x24},     
                      {0x00,0x00,0x00,0x00,0x00,0x00,0x24,0x6c},    
                      {0x00,0x00,0x00,0x00,0x00,0x24,0x6c,0xff},    
                      {0x00,0x00,0x00,0x00,0x24,0x6c,0xff,0xff}, 
                      {0x00,0x00,0x00,0x24,0x6c,0xff,0xff,0x6c},    
                      {0x00,0x00,0x24,0x6c,0xff,0xff,0x6c,0x24},     
                      {0x00,0x24,0x6c,0xff,0xff,0x6c,0x24,0x00},     
	                    {0x24,0x6c,0xff,0xff,0x6c,0x24,0x00,0x00},
                      {0x6c,0xff,0xff,0x6c,0x24,0x00,0x00,0x00},
                      {0xff,0xff,0x6c,0x24,0x00,0x00,0x00,0x00},			
											{0xff,0x6c,0x24,0x00,0x00,0x00,0x00,0x00},
											{0x6c,0x24,0x00,0x00,0x00,0x00,0x00,0x00},
											{0x24,0x00,0x00,0x00,0x00,0x00,0x00,0x00},};


u8 code ledwei[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};

void delay(u16 i)
{
	while(i--);
}

void timer0init()
{
	TMOD=0x01;
	TH0=(65536-50000)/256;
	TL0=(65536-50000)%256;
	ET0=1;
	TR0=1;
	EA=1;
}

void Hc595SendByte(u8 dat)
{
	u8 a;
	SRCLK=0;
	RCLK=0;
	for(a=0;a<8;a++)
	{
		SER=dat>>7;
		dat<<=1;
		
		SRCLK=1;
		_nop_();
		_nop_();
		SRCLK=0;
	}
	RCLK=1;
	_nop_();
	_nop_();
	RCLK=0;
}

void main()
{
	timer0init();
	{
		while(1)
		{
			for(i=0;i<8;i++)
			{
			  P0=ledwei[i];
			  Hc595SendByte(ledduan[k][i]);
			  delay(50);
			  Hc595SendByte(0x00);
			}
		}
	}
}

void timer0() interrupt 1
{
	TH0=(65536-50000)/256;
	TL0=(65536-50000)%256;
	time++;
	{
		if(time>=5)
		{
			k++;
			time=0;
		}
		if(k>12)
		{
			k=0;
		}
	}
}

  • 2
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值