数码管动态显示+模块化设计+TX-1C

1 功能

  利用数码管动态显示,在数码管上显示”123456“;

2 硬件原理图

(1)系统框图

(2)原理图

3 参考程序

2.1 主函数-逻辑设计

#include <STC89C5xRC.H>
#include "disp.H"    //数码管驱动模块

void main()
{
    while(1)
    {
        disp(1,1);    //选通第一个数码管,送入"1"的字形码
        disp(2,2);
        disp(3,3);
        disp(4,4);
        disp(5,5);
        disp(6,6);
    }
}

2.2 数码管驱动函数(H文件和C文件)

(1)函数定义

#include <STC89C5xRC.H>
#include "delay.H"

sbit dula     = P2^6;        
sbit wela     = P2^7;

unsigned char  disp_num[]={    0x3f,0x06,0x5b,0x4f,
                            0x66,0x6d,0x7d,0x07,
                            0x7f,0x6f,0x77,0x7c,
                            0x39,0x5e,0x79,0x71};

void disp(unsigned char location,numble)
{
    dula    = 1;
    P0        = disp_num[numble];
    dula    = 0;
    P0        = 0xff;
    
    wela    = 1;
    switch(location)
    {
        case 1: P0 = 0xfe;     break;    //1111_1110
        case 2: P0 = 0xfd;    break;    //1111_1101
        case 3: P0 = 0xfb;    break;    //1111_1011
        case 4: P0 = 0xf7;    break;    //1111_0111
        case 5: P0 = 0xef;    break;    //1110_1111
        case 6: P0 = 0xdf;    break;    //1101_1111
        default: P0 = 0xff; break;
    }
    wela     = 0;
    P0        = 0x00;
    delay(1);
}

(2)头文件

#ifndef _DELAY_H_
#define _DELAY_H_

void delay(unsigned char  xms);

#endif

2.3 延时函数

(1)函数定义

void delay(unsigned char xms)        //@12.000MHz
{
    unsigned char i, j;
    while(xms--)
    {
        i = 2;
        j = 239;
        do
        {
            while (--j);
        } while (--i);
    }
}

(2)函数声明

#ifndef _DELAY_H_
#define _DELAY_H_

void delay(unsigned char  xms);

#endif
posted @ 2022-04-07 21:08  豌豆茶  阅读(358)  评论(0编辑  收藏  举报