Microcontroller internal and external resource operation chapter: digital tube dynamic display

Publisher:QianfengLatest update time:2017-01-08 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

    Assuming you have learned the static display of digital tubes, we know that six digital tubes can only display the same symbol at the same time.

    It is common to see several digital tubes that can display different numbers at the same time, such as clocks, etc. This is the topic to be discussed next - dynamic display of digital tubes.

    Let’s look at an example:

 1 #include

 2 #define uint unsigned int

 3 #define uchar unsigned char

 4 uchar code table[] = {

 5 0x3f,0x06,0x5b,0x4f,

 6 0x66,0x6d,0x7d,0x07,

 7 0x7f,0x6f,0x77,0x7c,

 8 0x39,0x5e,0x79,0x71};

 9 sbit WELA = P2^7;

10 sbit DULA = P2^6;

11 void delay(uint);

12 

13 void main()

14 {

15 while(1)

16 {

17 WELA = 1; //Let the first digital tube display 1

18 P0 = 0xfe;

19 WELA = 0;

20 P0 = 0xff; //Eliminate shadow

21 DULA = 1;

22 P0 = table[1];

23 DULA = 0;

24 delay(500);

25 

26 WELA = 1; //Let the second digital tube display 2

27 P0 = 0xfd;

28 WELA = 0;

29 P0 = 0xff;

30 DULA = 1;

31 P0 = table[2];

32 DULA = 0;

33 delay(500);

34 

35 WELA = 1; //Let the third digital tube display 3

36 P0 = 0xfb;

37 WELA = 0;

38 P0 = 0xff;

39 DULA = 1;

40 P0 = table[3];

41 DULA = 0;

42 delay(500);

43 

44 WELA = 1; //Let the fourth digital tube display 4

45 P0 = 0xf7;

46 WELA = 0;

47 P0 = 0xff; 

48 DULA = 1;

49 P0 = table[4];

50 DULA = 0;

51 delay(500);

52 

53 WELA = 1; //Let the fifth digital tube display 5

54 P0 = 0xef;

55 WELA = 0;

56 P0 = 0xff;

57 DULA = 1;

58 P0 = table[5];

59 DULA = 0;

60 delay(500);

61 

62 WELA = 1; //Let the sixth digital tube display 6

63 P0 = 0xdf;

64 WELA = 0;

65 P0 = 0xff;

66 DULA = 1;

67 P0 = table[6];

68 DULA = 0;

69 delay(500);

70 }

71 }

72 

73 void delay(uint ms) //delay function

74 {

75 uint i;

76 for(; ms > 0; ms --)

77 {

78 for(i = 114; i > 0; i --)

79 {

80 }

81 }

82 }

 This code is not difficult to understand. In the while() loop, first the first digital tube displays 1, delays 500ms, then the second digital tube displays 2, delays 500ms, and so on.

    After compiling this code, download it to the experimental board and observe it to see the expected phenomenon.

    Next, shorten the delay after each digital tube lights up to 100ms, that is, delay(100);. Compile and download, and you can see that the speed of digital tube display changes is much faster.

    Shorten it to 10ms again, compile and download, now you can vaguely see the numbers 123456 displayed on the 6 digital tubes at the same time, but they are flickering.

    Continue to shorten it to 1ms, compile and download, and now the six digital tubes will clearly display 123456.

    I think everyone should understand the concept and principle of dynamic display. The so-called dynamic display is to send font codes to each digital tube in turn, but the time is very fast, so that the human eye cannot feel it.

    They are displayed one by one in turn.


Reference address:Microcontroller internal and external resource operation chapter: digital tube dynamic display

Previous article:Introduction to MCU: Flowing Lights
Next article:51 MCU memory problem

Recommended ReadingLatest update time:2024-11-23 04:44

C51 dynamic display method of digital tube
Code: #include reg52.h #define uchar unsigned char #define uint unsigned int sbit dula=P2^6; sbit wela=P2^7; uchar num,dunum,wenum; uchar code table_du ={ 0x3f,0x06,0x5b,0x4f,0x66,0x6d, 0x7d,0x07,0x7f,0x6f,0x77,0x7c, 0x39,0x5e,0x79,0x71}; //Digital tube segment selection code uchar code table_we ={ 0xfe,0xfd,0xfb
[Microcontroller]
Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号