About 51 Single-Chip Microcomputer digital shadow, 51 Single-Chip Microcomputer digital

Source: Internet
Author: User

About 51 Single-Chip Microcomputer digital shadow, 51 Single-Chip Microcomputer digital

I learned the interrupted part by using a single-chip microcomputer. When I use a digital tube to dynamically display the refreshing frequency, there will be a shadow. To eliminate this, I found a lot of information on the Internet and found many errors.

Look at the schematic:

 

Baidu baibaibaike: 74HC573 digital tube 41074hc573 is a transparent latch with eight outputs. The output is a three-state gate. It is a high-performance silicon gate CMOS device. The SL74HC573 is the same as the LS/AL573 pin. The input of the device is compatible with the standard CMOS output, and they can be compatible with the LS/ALSTTL output. The ----------------------------------------------------------------------------------------------------------- dynamic display interface connects the eight display strokes "a, B, c, d, e, f, g, and dp" of all digital tubes with the same name, in addition, the bitwise control circuit is added for the public pole COM of each digital tube, and the bitwise control is controlled by the independent I/O Lines. When the single chip microcomputer outputs the font code, all digital tubes receive the same font code, but which digital tube will display the font type depends on the control of the matching circuit of the single-chip microcomputer through the COM terminal, therefore, we only need to select and control the digital tube to be displayed, and the bit will display the font shape, and the digital tube that has not been selected will not be bright. By controlling the COM end of each digital tube in turn in a time-sharing manner, various digital tubes are displayed in turn, which is a dynamic drive. During the rotating display process, the lighting time of each digital tube is 1 ~ 2 ms. Due to the temporary visual effect of people and the afterglow effect of light emitting diodes, although you don't actually light up your digital tubes at the same time, as long as the scanning speed is fast enough, the impression is that a set of stable display data does not flash. The dynamic display effect is the same as the static display, which can save a lot of I/O Ports, and lower power consumption. As you can see from the preceding figure, the bid and field code displayed by the digital tube are assigned values respectively (select allow control before assigning values to open, and select allow disable after assigning values, the value after the location code or field code assignment is completed is immediately locked, as long as the value is not re-assigned to the location code or field code, the value of the lock remains unchanged. (Note: The P0 port is assigned to the lock. The P0 value remains unchanged as long as the P0 port is not assigned again.) therefore:

Usually, it IS (1) clearing the bit code → (2) assigning the lock to the next field code to be displayed (in the font code), enabling segment selection, disabling segment selection → (3) assign the lock to the next bit (Location Code) to be displayed, enable the bit selection, and disable the bit selection.

1 P0 = 0xff; // remove the shadow. Disable all digits. Select 2 wela = 1; 3 wela = 0; 4 P0 = digitron_table [shi]. // call the eight-segment digital tube code table 5 dula = 1; 6 dula = 0; 7 P0 = 0xbf; 8 wela = 1; 9 wela = 0; 10 delay (1 ); 11 12 P0 = 0xff; // remove duplicate shadows 13 wela = 1; 14 wela = 0; 15 P0 = digitron_table [ge]; // call eight-segment digital code table 16 dula = 1; 17 dula = 0; 18 P0 = 0x7f; 19 wela = 1; 20 wela = 0; 21 delay (1 );
View Code

You can also (1) Clear the field code → (2) Assign the lock to the next bit code (Location Code) to be displayed, enable the bit selection, and disable the bit selection → (3) assign the lock to the next field code (font Code) to be displayed, enable segment selection, and disable segment selection.

1 P0 = 0x00; // remove the duplicate image. Select 2 dula = 1 for the closed segment; 3 dula = 0; 4 P0 = 0xbf; 5 wela = 1; 6 wela = 0; 7 P0 = digitron_table [shi]; // call eight-segment digital tube code table 8 dula = 1; 9 dula = 0; 10 delay (1); 11 12 P0 = 0x00; // remove shadow 13 dula = 1; 14 dula = 0; 15 P0 = 0x7f; 16 wela = 1; 17 wela = 0; 18 P0 = digitron_table [ge]; // call eight-segment digital tube code table 19 dula = 1; 20 dula = 0; 21 delay (1 );
View Code

 

In this way, no matter how fast the refresh frequency is.

Bytes --------------------------------------------------------------------------------------

Complete code:

1 // use the timer 1 to interrupt the right shift of 8 LEDs, with an interval of 500 ms. At the same time, use the timer 0 interrupt mode to display the first two digits of the digital tube with an interval of ms from 0 to 60, 2 // If an external interrupt occurs, stop the number of digital tubes (External Interrupt 0 low-level trigger mode) 3 4 # include <reg52.h> 5 # include <intrins. h> 6 7 // macro definition to facilitate writing 8 # define uchar unsigned char 9 # define uint unsigned int 10 11 sbit dula = P2 ^ 6; 12 sbit wela = P2 ^ 7; 13 uchar counter_s; 14 15 // sub-function declaration 16 void interrupt_timer_init (); 17 void display (uchar I); 18 void delay (uint z ); 19 20 // eight-segment digital tube code table 21 uchar code digitron_table [] = {// LED Unit dp g f e d c B a 22 0x3F, // "0" 0011 1111 23 0x06, // "1" 0000 24 0x5B, // "2" 0101 1011 ***** a ***** 25 0x4F, // "3" 0100 1111 ** 26 0x66, // "4" 0110 0110 ** 27 0x6D, // "5" 0110 1101 ** 28 0x7D, // "6" 0111 1101 f B 29 0x07, // "7" 0000 0111 ** 30 0x7F, // "8" 0111 1111 ** 31 0x6F, // "9" 0110 1111 ** 32 0x77, // "A" 0111 0111 ***** g ***** 33 0x7C, // "B" 0111 1100 ** 34 0x39, // "C" 0011 1001 ** 35 0x5E, // "D" 0101 1110 ** 36 0x79, // "E" 0111 1001 e c 37 0x71, // "F" 0111 0001 ** 38 0x76, // "H" 0111 0110 ** 39 0x38, // "L" 0011 1000 ** 40 0x37, // "n" 0011 0111 ***** d ***** dp ** 41 0x3E, // "u" 0011 1110 42 0x73, // "P" 0111 0011 43 0x5C, // "o" 0101 1100 44 0x40, // "-" 0100 0000 45 0x00, // extinguish 0000 0000 46 0x00 // custom 47}; 48 49 // main function part 50 void main () 51 {52 interrupt_timer_init (); 53 while (1) {54 display (counter_s ); 55} 56} 57 58 // register configuration and timer initialization for special functions of service interruption 59 void interrupt_timer_init () 60 {61 TMOD = 0x11; // scheduled mode: 0 and 1. The TMOD address of the working mode register is 0x89. It cannot be divisible by 8. It can only be used for byte operations, but cannot be used for 62 TH1 = 0x4c; // formula: timing time t = (2 ^ 16-T1 Initial Value) * oscillation period * 12 (oscillation period * 12 is the machine cycle) 63 TH0 = 0x4c; 64 TL1 = 0x00; // T1 = 2 ^ 16-t * 11059200/12 (this scheduled time is 50 ms, T1 = 19456 = 0x4c00) 65 TL0 = 0x00; 66 TR1 = 1; // The timer operation control position is 1. The TCON address is 0x88 and can be operated on 67 TR0 = 1; 68 ET1 = 1; // Timer/Counter T1 overflow interrupt permitted location 1, T1 interrupt allowed, interrupt allowed register IE (A8H) 69 ET0 = 1; 70 EX0 = 1; 71 IT0 = 0; 72 EA = 1; // The total control position of the interrupt is allowed. 1. The CPU is open and the interrupt allows the register IE (A8H) 73 P1 = 0x7f; 74} 75 76 // 77 void interrupt_program_INT0 () interrupt 0 // (1) the interrupt function has no return value, which will damage the stack (2) the parameter cannot be passed to ISR, will destroy stack (3) ISR should be as short as possible (4) interrupt function cannot be called, hardware Decision 78 {79 TR0 = 0; 80} 81 82 // T1 interrupt service program 83 void interrupt_program_T1 () interrupt 3 84 {85 uchar counter; 86 counter ++; 87 TH1 = 0x4c; 88 TL1 = 0x00; 89 if (counter = 10) {90 P1 = _ cror _ (P1, 1); 91 counter = 0; 92} 93} 94 95 // T0 interrupt service program 96 void interrupt_program_T0 () interrupt 1 97 {98 uchar counter_ms; 99 counter_ms ++; 100 TH1 = 0x4c; 101 TL1 = 0x00; 102 if (counter_ms = 20) {103 counter_ms = 0; 104 counter_s ++; 105 if (counter_s = 60) {106 counter_s = 0; 107} 108} 109 110 111 // latency function 112 void delay (uint z) 113 {114 uint x, y; 115 for (x = 0; x <z; x ++) 116 for (y = 0; y <114; y ++); 117} 118 119 // digital display function 120 void display (uchar I) 121 {122 uchar shi, ge; 123 shi = I/10; // modulus 124 ge = I % 10; // evaluate the remaining 125 // in the actual product, (1) turn off all bits → (2) output the next bits to be displayed → (3) Enable the next bits to be displayed, select 126 // actually, (1) turn off all field codes → (2) Enable the next field to be displayed select → (3) output the field code 127 P0 = 0x00 for the next field to be displayed; // eliminate duplicate shadows, select 128 dula = 1; 129 dula = 0; 130 P0 = 0xbf; 131 wela = 1; 132 wela = 0; 133 P0 = digitron_table [shi]; // call the eight-segment digital tube code Table 134 dula = 1; 135 dula = 0; 136 delay (1); 137 138 P0 = 0x00; // remove the shadow 139 dula = 1; 140 dula = 0; 141 P0 = 0x7f; 142 wela = 1; 143 wela = 0; 144 P0 = digitron_table [ge]; // call the eight-segment digital tube code Table 145 dula = 1; 146 dula = 0; 147 delay (1); 148 149/* 150 P0 = 0xff; // eliminate duplicate shadows, disable all digits to select 151 wela = 1; 152 wela = 0; 153 P0 = digitron_table [shi]; // call the eight-segment digital tube code table 154 dula = 1; 155 dula = 0; 156 P0 = 0xbf; 157 wela = 1; 158 wela = 0; 159 delay (1); 160 161 P0 = 0xff; // remove duplicate shadows 162 wela = 1; 163 wela = 0; 164 P0 = digitron_table [ge]; // call the eight-segment digital tube code table 165 dula = 1; 166 dula = 0; 167 P0 = 0x7f; 168 wela = 1; 169 wela = 0; 170 delay (1 ); 171 x/172}
View Code

 

 

In case of any errors, please point out that if there is any infringement, please inform us. If you need to reprint it, please indicate the source!

My blog: http://www.cnblogs.com/yllinux/

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.