51单片机LED点阵屏动画学习笔记

设备:普中51单片机stc89c52rc

视频:

利用51单片机实现LED点阵屏动画

代码:

//Delay.c
//延时函数,可用stc-isp中软件延时计算器
void Delay(unsigned int xms)
{
	unsigned char i, j;

	while(xms)
	{
		i = 2;
		j = 239;
		do
		{
			while (--j);
		} while (--i);
		xms--;
	}
}
//Delay.h

#ifndef __DELAY_H__
#define __DELAY_H__

void Delay(unsigned int xms); 

#endif
//MartrixLED.c

#include <STC89C5xRC.H>
#include "Delay.h"

sbit RCK=P3^5;	//RCLK
sbit SCK=P3^6;	//SRCLK
sbit SER=P3^4;	//SER

#define MARTIX_LED_PORT P0

/**
  * @brief  74HC595写入一个字节
  * @param  Byte 要写入的字节
  * @retval 无
  */
void _74HC595_WriteByte(unsigned char Byte)
{
	unsigned char i;
	for(i=0;i<8;i++)
	{
		SER=Byte&(0x80>>i);//取第8-i位
		SCK=1;
		SCK=0;
	}
	RCK=1;
	RCK=0;
}

/**
  * @brief  点阵屏初始化
  * @param  无
  * @retval 无
  */
void MartrixLED_Init()
{
	SCK=0;
	RCK=0;
}

/**
  * @brief  LED点阵屏显示一列数据
  * @param  Column 要选择的列,范围:0~7,0在最左边
	* @param  Data 选择列显示的数据,高位在上,1为亮,0为灭
  * @retval 无
  */
void MartrixLED_ShowColumn(unsigned char Column,unsigned char Data)
{
	_74HC595_WriteByte(Data);
	P0=~(0x80>>Column);
	Delay(1);
	P0=0xFF;
}
//MartrixLED.h

#ifndef __MartrixLED_H__
#define __MartrixLED_H__

void MartrixLED_Init();
void MartrixLED_ShowColumn(unsigned char Column,unsigned char Data);

#endif
//main.c

#include <STC89C5xRC.H>
#include "Delay.h"
#include "MartrixLED.h"

unsigned char code Animation[]={
	0xFF,0x08,0x08,0x08,0xFF,0x00,0x00,0x0E,
	0x15,0x15,0x15,0x08,0x00,0x7E,0x01,0x02,
	0x00,0x7E,0x01,0x02,0x00,0x0E,0x11,0x11,
	0x0E,0x00,0x7D,0x00,0x00,0x00,0x00,0x00,
};//用字模提取软件提取动画数据

void main()
{
	unsigned char i,offset=0,count=0;
	MartrixLED_Init();
	
	while(1)
	{
		for(i=0;i<8;i++)
		{
			MartrixLED_ShowColumn(i,Animation[(i+offset)%32]);
		}
		count++;
		if(count>10)
		{
			count=0;
			offset++;
		}
	}
}

  • 5
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值