04_单片机_动态数码管_38译码器

1. 单片机原理图,使用到元件:74LS138


2. 从Mouser官网查询相关零件的datasheet(Link: https://www.mouser.cn/ProductDetail/Texas-Instruments/SN74LS138NSR?qs=SL3LIuy2dWxJaqitUHoDGQ%3D%3D)  

 要能控制 Y0~Y7,G1 必须 High level,G2A & G2B 必须Low level。所以电路图中G1 接 Vcc,G2A & G2B 接 GND


3. 单片机Port1 接 J9

P1^0 J9.3  A
P1^1 J9.2  B
P1^2 J9.1  C

 根据上图,可忽略 P1^3~P1^7


4.  数码管显示和上一节一样,显示 ”1~8“

 1 #include <REG51.H>
 2 
 3     /**********************************
 4      * P1^0 接 A;P1^1 接 B;P1^2 接 C
 5     **********************************/
 6 
 7 // 延时函数
 8 void delay(void)
 9 {
10     unsigned char i, j;
11     for(i=10; i>0; i--)
12         for(j=10; j>0; j--);
13 }
14 
15 unsigned char dat[16] = {0x3f, 0x06, 0x5b, 0x4f,
16                     0x66, 0x6d, 0x7d, 0x27,
17                     0x7f, 0x6f, 0x77, 0x7c,
18                     0x39, 0x5e, 0x79, 0x71};
19 
20 unsigned char segment[8] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
21 
22 void main(void)
23 {
24 
25     unsigned char i;
26     
27     while(1)
28     {
29         for(i=0; i<8; i++)
30         {
31             P0 = dat[i+1];
32             P1 = segment[i];
33             delay();
34         }
35     }
36 }
View Code

 

posted on 2023-04-02 15:21  Ivan2023  阅读(78)  评论(0)    收藏  举报