原创 第十三课 LED数码管之四 滚动显示

2009-5-25 10:25 4862 11 11 分类: MCU/ 嵌入式

第十三课 LED数码管之四 滚动显示


程序讲解:


/*--------------------------------------------------------------*/
//LED八位数码滚动显示
//显示部分用中断方式,便于程序的拓展



/*--------------------------------------------------------------*/
//包含头文件
#include <reg52.h>
#include "74HC595.H"


//全局变量定义
#define  Num sizeof(LED_Seg) //代码长度
unsigned char LED_Pos;   //位扫描
unsigned char code LED_Seg[] = {0xff,0xff,0xff,0xff,0xff,0xff,0xff,       //空格
        0x89,0x86,0xC7,0xC7,0xc0,0xff,0xA4,0xC0,0xC0,0x10,0xff, //字符Hello2009.        
        0xff,0x92,0xA4,0xC0,0xF9,0xB0,0xF9,0x19,0xff,   //数字5201314.
        0xff,0xA4,0xC0,0xC0,0x90,0xBF,0xA4,0xBF,0x24,   //2009-2-2.
        0xff,0xF9,0x82,0xBF,0x99,0xB0,0xBF,0x92,0x30,   //16-43-53.
        0xff,0xC7,0xC0,0xC1,0x86,0xff,0x99,0xc0,0xC1,   //字符love you
        0xff,0x89,0xC1,0xCF,         //HUI


        0xff,0xff,0x8B,0x86,0x8B,0x86,0xff,0x3F,0xBF,0xff,0xDC,0xF7,0xDC,//字符hEhE-.-^_^
        0xff,0xff,0xff,0xff,0xff,0xff,0xff};      //空格


unsigned char Count;   //移位速度控制
unsigned char n;    //移位变量



/*--------------------------------------------------------------*/
//定时器初始化
void T0_init(void)                    
{
    TMOD = 0x01;    //定时器0工作在方式1
    TH0  = 0xf8;         //2000us 赋初值
    TL0  = 0x36;
    IE   = 0x82;          //打开总中断
    TR0  = 1;             //允许定时器0工作
}


/*--------------------------------------------------------------*/
//LED显示函数2
//offset为偏移量
volatile void LED_Display2(unsigned char offset)
{
  // Ser_IN(0x00); Ser_IN(0x00); Par_OUT();  //消影 
     Ser_IN(0x01 << LED_Pos);    //位选
     Ser_IN(LED_Seg[offset + LED_Pos]);  //段码
     Par_OUT();


     LED_Pos++;           //循环扫描
     if(LED_Pos == 8) LED_Pos = 0;
}


 


/*--------------------------------------------------------------*/
//定时器中断服务
void T0_intservice(void) interrupt 1 using 0
{
    TH0 = 0xf8;
    TL0 = 0x36;


 LED_Display2(n);
 Count++;
 if(Count == 250)    //速度调整
 {
  Count = 0;
  n++; if(n == Num-7 ) n = 0; 
 }
}



/*-------------------------------------------------------------*/
//主函数
void main(void)
{
 T0_init();
 while(1);
}


本节重点:


注:这节课的内容和上节课基本相同,只是LED_Seg[]里面的内容换成了字符。


1、数码管移位的理解和代码编写方法。


2、定时器/计数器的初始化和中断服务函数的编写格式。


演示视频:


http://v.youku.com/v_show/id_XOTIzNjM0NzY=.html


相关程序:https://static.assets-stash.eet-china.com/album/old-resources/2009/5/25/150ec005-233d-4228-9e30-61f239bb6cb3.rar


 

PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
我要评论
0
11
关闭 站长推荐上一条 /3 下一条