MCU Lesson 4th: timer for dynamic display of common cathode digital tube

Source: Internet
Author: User


The above is a circuit diagram. j16 is connected to j15, and J6 321 corresponds to P2 ^ 0--p2 ^ 2, which is conducive to saving MCU resources. Among them, P1 ^ 0 and Le are connected, segment selection (determines what the digital display is), and bit selection (which one of the digital tubes is bright) is determined by the 138 decoder. Let's write the program first:

# Include <reg51.h> # define uint unsigned int # define uchar unsigned char // Add code to store this in ROM; otherwise, it is stored in Ram.
// The ram bucket is small. Only 128 byteuchar code table_smg [8] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07}; uchar temp; uchar flag = 0; void inittimer0 (); void main () {int I; inittimer0 (); P1 = 0x01; temp = 0x00; while (1) {for (I = 0; I <8; I ++) {While (flag! = 1); If (flag = 1) {flag = 0; If (temp = 0x08) {temp = 0x00;} P2 = temp; p0 = table_smg [I]; temp = temp + 0x01 ;}}} void inittimer0 () {tmod = 0x01; th0 = (65536-5000)/256; tl0 = (65536-5000) % 256; et0 = 1; EA = 1; tr0 = 1;} void timer0 () interrupt 1 {th0 = (65536-5000)/256; tl0 = (65536-5000) % 256; flag ++ ;}
Pay attention to the use of latches and 138 decoders, as well as the timer interruption.




MCU Lesson 4th: timer for dynamic display of common cathode digital tube

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.