适合新手学习仿真38译码器驱动的数码管原理图如下(proteus仿真工程文件可到本帖附件中下载)
单片机源程序如下:
- #include<reg51.h>
- #define uchar unsigned char
- #define uint unsigned int
- uchar duanma[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
- sbit A0=P2^2;
- sbit A1=P2^3;
- sbit A2=P2^4;
- uchar a,t,x,y;
- void delay(void)
- {
- unsigned char i=0,j=0;
- for(i=0;i<100;i++);
- for(j=0;j<20;j++);
- }
- void Timer0() interrupt 1 //中断函数 中断方式1
- {
- t++;
- TH0=0x4C; //计数器赋初值 下同
- TL0=0x00;
- }
- void data_tim()
- {
- if(t==20)
- {
- a--;
- t=0;
- }
- x=a/10;
- y=a%10;
- }
- void display()
- {
- A1=A2=A0=0; //38译码器的位码
- P0=duanma[x]; //八个数码管的段码
- delay();
- P0=0;
- A1=A2=0;A0=1;
- P0=duanma[y];
- delay();
- P0=0; //消隐
- }
- void init_t()
- {
- TMOD=0x01;
- TH0=0x4C;
- TL0=0x00;
- ET0=1;
- TR0=1;
- EA=1;
- }
- void main(void)
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
38译码器驱动数码管.rar
(31.3 KB, 下载次数: 32)
|