单片机
返回首页

51单片机——8X8点阵显示

2020-03-24 来源:eefocus

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);

}

进入单片机查看更多内容>>
相关视频
  • RISC-V嵌入式系统开发

  • SOC系统级芯片设计实验

  • 云龙51单片机实训视频教程(王云,字幕版)

  • 2022 Digi-Key KOL 系列: 你见过1GHz主频的单片机吗?Teensy 4.1开发板介绍

  • TI 新一代 C2000™ 微控制器:全方位助力伺服及马达驱动应用

  • MSP430电容触摸技术 - 防水Demo演示

精选电路图
  • 红外线探测报警器

  • 短波AM发射器电路设计图

  • RS-485基础知识:处理空闲总线条件的两种常见方法

  • 如何调制IC555振荡器

  • 基于ICL296的大电流开关稳压器电源电路

  • 基于TDA2003的简单低功耗汽车立体声放大器电路

    相关电子头条文章