51 MCU Programming Section 4: Digital Tube Driver

Publisher:Yuexin888Latest update time:2016-10-22 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Section 4: Digital tube driver

Display "12345678"
P1 port connects to the segment pole of 8-link common cathode digital tube SLED8: P1.7 connects to segment h, ..., P1.0 connects to segment a
P2 port connects to the segment pole of 8-link common cathode digital tube SLED8: P2.7 connects to the common cathode on the left, ..., P2.0 connects to the common cathode on the right
Solution description: Crystal oscillator frequency fosc = 12MHz, digital tube uses dynamic refresh mode to display, implemented in 1ms timer service program

Code

1. #include    

2. unsigned char DisBuf[8]; //Global display buffer, DisBuf[0] corresponds to the right SLED, DisBuf[7] corresponds to the left SLED,   

3. void DisplayBrush(void)   

4. { code unsigned char cathode[8]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f}; // cathode control code   

5. Code unsigned char Seg7Code[16]= //Use hexadecimal as the array subscript to directly obtain the corresponding seven-segment code bytes   

6. {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};   

7. static unsigned char i=0; // (0≤i≤7) Refresh the display in a loop. Since it is a static variable, this assignment is only done once.   

8. P2 = 0xff; //Display blanking to prevent the next code value from being displayed on the previous SLED   

9. P1 = Seg7Code[ DisBuf[i] ]; //Get the original data from the display buffer, convert it into seven-segment code after looking up the table, and then send it to the display   

10. P2 = cathode[ i ]; //Set the corresponding cathode to low and display   

11. if( ++i >= 8 ) i=0; //point to the next digital tube and corresponding data   

12. }   

13. void Timer0IntRoute( void ) interrupt 1   

14. {   

15. TL0 = -1000; //Since TL0 has only 8 bits, assign the lower 8 bits of (-1000) to TL0   

16. TH0 = (-1000)>>8; // Take the high 8 bits of (-1000) and assign them to TH0, re-timing 1ms   

17. DisplayBrush();   

18. }   

19. void Timer0Init( void )   

20. { TMOD=(TMOD & 0xf0) | 0x01; // Initialization, timer T0, working mode 1   

21. TL0 = -1000; // Timing 1ms   

22. TH0 = (-1000)>>8;   

23. TR0 = 1; //Allow T0 to start counting   

24. ET0 = 1; //Allow T0 to generate an interrupt request when the count overflows   

25. }   

26. void Display( unsigned char index, unsigned char dataValue ){ DisBuf[ index ] = dataValue; }   

27. void main( void )   

28. {   

29. unsigned char i;   

30. for( i=0; i<8; i++ ){ Display(i, 8-i); } //DisBuf[0] is right, DisBuf[7] is left   

31. Timer0Init();   

32. EA = 1; // Allow CPU to respond to interrupt requests   

33. While(1);   

34. }  


Reference address:51 MCU Programming Section 4: Digital Tube Driver

Previous article:51 MCU Programming Section 5: Keyboard Driver
Next article:51MCU PWM

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号