74hc595.h:
#ifndef __74hc595_H__
#define __74hc595_H__
/************************************位定义************************************/
sbit DATA_IN = P1^0; //串行数据输入
sbit ST_CK = P1^1; //存储寄存器时钟输入
sbit SH_CK = P1^2; //移位寄存器时钟输入
/***********************************函数声明***********************************/
void Ser_IN(unsigned char Data); //串行数据输入
void Par_OUT(void); //串行数据输出
void Ser_IN(unsigned char Data)
{
unsigned char i;
for(i = 0; i < 8; i++)
{
SH_CK = 0; //CLOCK_MAX=100MHz
DATA_IN = Data & 0x80;
Data <<= 1;
SH_CK = 1;
}
}
void Par_OUT(void)
{
ST_CK = 0;
ST_CK = 1;
}
#endif
8x8LED.c
#include
#include "74hc595.h"
unsigned char i;
unsigned int m,n;
#define num sizeof(Digit_Tab) //代码长度
unsigned char code table[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
unsigned char code Digit_Tab[]= {//取模方式 阴码 列扫描 逆向
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x06,0x18,0x60,0x1D,0x60,0x18,0x06,0x00,
0x06,0x18,0x60,0x1C,0x60,0x18,0x06,0x00,
0x0B,0x1F,0x60,0x1C,0x60,0x18,0x06,0x00,
0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,
0x00,0x04,0x04,0x7E,0x4E,0x24,0x00,0x00,
0x00,0x44,0x28,0x10,0x28,0x44,0x00,0x00,
0x7C,0x02,0x02,0x7C,0x02,0x02,0x7C,0x00,
0x00,0x3C,0x42,0x42,0x42,0x24,0x00,0x00,
0x00,0x3E,0x40,0x40,0x40,0x3E,0x00,0x00,
0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,
0x0A,0x3C,0x42,0x4C,0x42,0x24,0x00,0x00,
0x00,0x3C,0x42,0x42,0x42,0x3C,0x00,0x00,
0x7C,0x02,0x02,0x7C,0x02,0x02,0x7C,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x88,0x49,0x2A,0x1F,0xB9,0x49,0x8E,0x00,
0x0A,0xFF,0x1A,0x22,0x2B,0xFE,0x2B,0x22,
0x00,0x3E,0x2E,0x2A,0x7F,0xAA,0xAA,0xBF,
0x00,0x08,0x09,0x89,0x8D,0x7B,0x09,0x08,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
void Display(void)
{
Ser_IN((table[i])); //列扫描数据
Ser_IN(Digit_Tab[i + n]); //查表取出行扫描数据
Par_OUT(); //输出显示
i++;
if(i == 8)
{
i = 0;
}
//循环扫描
m++;
if(m == 300)
{
m = 0;
n++;
} //滚动速度控制
if(n == num - 7)
{
n = 0; //循环显示
}
}
void Timer0_init(void)
{
TMOD = 0xf8;
TH0 = 0xcc;
TL0 = 0x00;
IE = 0x82;
TR0 = 1;
}
void Timer0_intservice(void) interrupt 1 using 0
{
TH0 = 0xf8;
TL0 = 0xcc;
Display();
}
void main (void)
{
Timer0_init();
while(1);
}