8*8点阵Led的刷新显示

写在前面

  这段时间在研究点阵LED,写这篇博客来记录一下,以便以后回忆。
  代码如下:

#include 
#include 
typedef unsigned char uint8;		//作用类似#define uchar unsigned char
typedef unsigned int  uint16;		

sbit power_onoff = P3^0;
code uint8 charcode[4][8]={
	{0x10,0x28,0x44,0x82,0x10,0x28,0x44,0x82},
	{0x28,0x44,0x82,0x10,0x28,0x44,0x82,0x10},
	{0x44,0x82,0x10,0x28,0x44,0x82,0x10,0x28},
	{0x82,0x10,0x28,0x44,0x82,0x10,0x28,0x44}
	};

uint8 i,j,flag;

void Key_down()interrupt 0{			//用外部中断来检测按键按下
	P0 = 0xff;
	P1 = 0x80;
	TR0 = 1;						//有按键按下则开启定时器0
}

void timer0()interrupt 1{
	TH0 = (65536-2000)/256;
	TL0 = (65536-2000)%256;
	flag++;
	if(flag >= 100){
		flag = 0;
		i++;				//每100次中断,i+1
	}
	if(i > 3) i = 0;
	P1 = _crol_(P1,1);		//每次选通一列
	P0 = ~charcode[i][j];	//哪行为0则对应的LED亮
	j = (j + 1) % 8;		//控制j在0-7循环递增,遍历数组
}

void main(){
	TMOD = 0x01;
	TH0 = (65536-2000)/256;
	TL0 = (65536-2000)%256;
	IT0 = 1;
	IE  = 0x83;
	i = 0;
	j = 0;
	P0 = 0xff;
	P1 = 0x80;
	while(1);
}

电路图如下:
  8*8点阵Led的刷新显示_第1张图片
  实现的是点阵中箭头的不停向左滚动,汉字滚动同理,根据每一帧需要哪些LED亮,添加相应的数组即可。
  另:proteus中8*8点阵上面8个脚控制的是行,下面8个脚控制的是列,行为共阳,列为共阴。

你可能感兴趣的:(技术分享)