Eight-digit digital tube dynamic display program

Publisher:mancozcLatest update time:2012-10-27 Source: 21ic Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

This is a program from the 51hei development board area. The comments are very detailed and there is no problem running it. The original address is: http://www.51hei.com/bbs/dispbbs.asp?boardid=10&id=4140

/*The design idea of ​​dynamic digital display is that we first need to know how to make which bit light up and what the displayed segment is. The next
step is the interruption time. The design steps are as follows. If we want the eight digital tubes to display 1 to 8 statically, we can modify the interruption time, such as changing 50000 to 100 or lower*/

#include
#include
#define uint unsigned int
#define uchar unsigned char
sbit duan=P2^6;
sbit wei=P2^7;

uchar a,numw,numd;
uchar code tabled[]={
0x3f,0x06,0x5b,0x4f,0x66
, 0x6d,0x7d,0x07,0x7f,0x6f}; /*The second step is to create a code table for the segment display values ​​0~9. If you want to display values ​​1~8, it is best to add the two digits 0 and 9 before and after,
because when the ++ is shifted later, it can light up in our regular order. As for how to display the corresponding values, please see the digital display circuit diagram first*/
uchar code tablew[]={
0xfe,0xfd,0xfb,0xf7,
0xef,0xdf,0xbf,0x7f}; //The second step is to create a bit display, that is, the display position. This code table is relatively simple. It is represented by binary 11111110~01111111, and 0 is the position of the eight-digit display tube.
void main()
{
a=0; //Define a time function
numl=0; //The initial value of the attached bit display is 0
numd=0; //The initial value of the attached segment display is 0

TMOD=0X01; //The fourth step, attach the initial value of the interrupt register
TH0=(65535-50000)/256; //Attach the initial value of the interrupt request time, the high 8 bits
TL0=(65536-50000)%256; //Attach the initial value of the interrupt request time, the low 8 bits
EA=1; //Turn on the total interrupt
ET0=1; //Turn on the timer interrupt
TR0=1; //Start the timer interrupt
while(1)
{
if(a==10) //The third step, execution speed, if 20 is almost 1 second, then execute the next step, which is equivalent to the time when the unit value is on
{
a=0; //Re-attach the initial value 0
numd++; //Segment display value++
if(numd==9) //If the segment value is in the 9th position of the matching code table, then execute the next step
numd=1; /*Re-append the first bit of the segment display value to the corresponding code table. Because of ++, the 0th bit is not displayed in the digital tube.
If it is to be displayed, it will be displayed in the second round because of ++*/
duan=1; //Open the segment display terminal
P0=tabled[numd];//Append the segment display P0 value to the segment display value code table
duan=0; //Latch
wei=1; //Open the bit display terminal
P0=tablew[numw];//Append the bit display P0 value to the bit display value code table
wei=0; //Latch
numw++; //Equivalent to bit display shift
if(numw==8) //If the bit display value reaches the eighth bit of the corresponding bit display code table, then execute
numw=0; //Re-append the bit display value to the corresponding code table from the 0th bit
/*

The following is a simple single digital tube display example in the first step. After modification, in the third step
#include "reg52.h"
#include "intrins.h"

sbit duan=P2^6; //segment display port
sbit wei=P2^7; //bit display port

void main()
{
//P0=0xff; The digital tube does not display any signal. By default, it does not display when powered on, so
duan=1 is not required; //Open the segment display port
P0=0x06; //The value of the valued segment display is 1. You can refer to the code table corresponding to the display in the digital tube circuit diagram
duan=0; //Latch, keep the previous segment display state, please refer to the 74HC573 function for hardware description
wei=1; //Open the bit display port
P0=0xfe; //The valued bit display position, 01111111, the first bit on the left, is displayed as 0
wei=0; //Latch, keep the previous bit display state, please refer to the 74HC573 function for hardware description
}
*/

}
}
}

void timer0() interrupt 1 /*The fourth step, the interrupt time function is equivalent to the speed of shifting
the digital display. If the speed is fast enough, the human eye will have an afterglow effect, and it feels that the 8-digit display is always on, which is equivalent to the film being played*/

{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
a++;
}

/*

If there is anything that needs to be improved, please let me know.

*/

Reference address:Eight-digit digital tube dynamic display program

Previous article:Smart timing socket program
Next article:Learning infrared remote control assembly language program

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号