51单片机8X8点阵滚动显示 - C51源代码

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

51单片机8X8点阵滚动显示- C51源代码
51单片机8X8点阵滚动显示- C51源代码
/*---------------------------------------------
-----------------*/
//LED8*8滚动显示
//列扫描,低电平有效
/*---------------------------------------------
-----------------*/
//包含头文件
#include <reg52.h>
#include "74HC595.H"
/*--------------------------------------------------------------*/
//全局变量定义
unsigned char i;
unsigned int m,n;
/*--------------------------------------------------------------*/
//代码库
#define num sizeof(table) //代码长度
unsigned char code
aa[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f}; unsigned char code table[]= {
//取模方式阴码列扫描逆向
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*" ",0*/
0x00,0x7F,0x7F,0x39,0x6F,0x46,0x00,0x00,/*"R",1 */
0x00,0x41,0x7F,0x7F,0x41,0x00,0x00,0x00,/*"I",2 */
0x00,0x3E,0x7F,0x41,0x63,0x22,0x00,0x00,/*"C",3 */
0x00,0x7F,0x7F,0x08,0x7F,0x7F,0x00,0x00,/*"H",4 */
0x00,0x7F,0x7F,0x06,0x7F,0x7F,0x00,0x00,/*"M",5 */
0x00,0x3E,0x7F,0x41,0x63,0x22,0x00,0x00,/*"C",6 */
0x00,0x3F,0x7F,0x40,0x7F,0x3F,0x00,0x00,/*"U",7 */
0x00,0x36,0x7F,0x49,0x7F,0x36,0x00,0x00,/*"8",9 */
0x00,0x63,0x7F,0x1C,0x7F,0x63,0x00,0x00,/*"X",1 0*/
1*/
0x00,0x01,0x7F,0x7F,0x01,0x01,0x00,0x00,/*"T",1 3*/
0x00,0x7F,0x7F,0x49,0x49,0x41,0x00,0x00,/*"E",1 4*/
0x00,0x26,0x6F,0x49,0x7B,0x32,0x00,0x00,/*"S",1 5*/
0x00,0x01,0x7F,0x7F,0x01,0x01,0x00,0x00,/*"T",1 6*/
0x00,0x7F,0x7F,0x39,0x6F,0x46,0x00,0x00,/*"R",1 8*/
0x00,0x61,0x79,0x5D,0x4F,0x43,0x00,0x00,/*"Z",1 9*/
0x00,0x08,0x08,0x08,0x08,0x08,0x00,0x00,/*"-",2 0*/
0x00,0x62,0x73,0x59,0x4F,0x46,0x00,0x00,/*"2",2 1*/
0x00,0x3E,0x7F,0x41,0x7F,0x3E,0x00,0x00,/*"0",2 2*/
0x00,0x3E,0x7F,0x41,0x7F,0x3E,0x00,0x00,/*"0",2 3*/
4*/
0x00,0x7F,0x7F,0x41,0x7F,0x3E,0x00,0x00,/*"D",2 6*/
0x00,0x7F,0x7F,0x49,0x49,0x41,0x00,0x00,/*"E",2 7*/
0x00,0x7F,0x7F,0x06,0x7F,0x7F,0x00,0x00,/*"M",2 8*/
0x00,0x7F,0x7F,0x41,0x7F,0x7F,0x00,0x00,/*"O",2 9*/
0x00,0x26,0x6F,0x49,0x7B,0x32,0x00,0x00,/*"S",3 1*/
0x03,0x07,0x7C,0x7C,0x07,0x03,0x00,0x00,/*"Y",3 2*/
0x00,0x26,0x6F,0x49,0x7B,0x32,0x00,0x00,/*"S",3 3*/
0x00,0x01,0x7F,0x7F,0x01,0x01,0x00,0x00,/*"T",3 4*/
0x00,0x7F,0x7F,0x49,0x49,0x41,0x00,0x00,/*"E",3 5*/
0x00,0x7F,0x7F,0x06,0x7F,0x7F,0x00,0x00,/*"M",3 6*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*" ",37*/
};
/*--------------------------------------------------------------*/
//显示函数
void Display(void)
{
Ser_IN((aa[i])); //列扫描数据
Ser_IN(table[i + n]); //查表取出行扫描数据
Par_OUT(); //输出显示
i++; if(i == 8) i = 0; //循环扫描
m++; if(m == 500) {m = 0; n++;} //滚动速度控制
if(n == num-7) n = 0; //循环显示
}
/*--------------------------------------------------------------*/
//定时器初始化
void T0_init(void)
{
TMOD = 0xf8;
TH0 = 0xcc; //5000us
TL0 = 0x00;
IE = 0x82;
TR0 = 1;
}
/*--------------------------------------------------------------*/
//定时器中断服务
void T0_intservice(void) interrupt 1 using 0 {
TH0 = 0xf8;
TL0 = 0xcc;
Display();
}
/*--------------------------------------------------------------*/
//主函数
void main (void)
{
T0_init();
while(1);
}
74HC595.H
//Note: 74HC595驱动
// __ __
//Note: MR 主复位接电源正极, OE 使能端,输出有效接电源负极
/*--------------------------------------------* /
#ifndef __74HC595_H__
#define __74HC595_H__
/*--------------------------------------------* /
sbit SD = P1^4; //串行数据输入
sbit ST_CK = P1^5; //存储寄存器时钟输入
sbit SH_CK = P1^6; //移位寄存器时钟输入
/*--------------------------------------------*
/
//数码管断码和位码的定义
//unsigned char code
seg[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,
0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0x00,0x ff};
//0 1 2 3 4 5 6 7 8 9 a b c d e f 8 无
//unsigned char code
pos[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}
;
//1 2 3 4 5 6 7 8
/*--------------------------------------------* /
//函数声明
void Ser_IN(unsigned char Data); //串行数据输入void Par_OUT(void); //串行数据输出
//void Ser_Par(unsigned char Data); //串行输入,并行输出
/*--------------------------------------------* /
//串行数据输入
void Ser_IN(unsigned char Data)
unsigned char i;
for(i = 0; i < 8; i++)
{
SH_CK = 0; //CLOCK_MAX=100MHz
SD = Data & 0x80;
Data <<= 1;
SH_CK = 1;
}
}
/*--------------------------------------------* /
//并行数据输出
void Par_OUT(void)
{
ST_CK = 0;
ST_CK = 1;
}
/*--------------------------------------------* /
//串行输入,并行输出
/*void Ser_Par(unsigned char Data)
{
Ser_IN(Data);
Par_OUT();
}
*/
/*--------------------------------------------* /
#endif
网站统计
Powered by Tiki Wiki CMS Groupware | Theme: Fivealive - Lemon。

相关文档
最新文档