The decimal point of the digital tube is controlled by a single one. This is the magical place of the physical world and the digital world. There are 7 led segments used by the digital tube to display numbers and letters, plus 8 decimal points, which corresponds to one byte. The number of bits, so that a single port of the microcontroller can be used for all operations, such as display 2. Just change the 1st digit of the binary number corresponding to the number 2 to 1. In practice, we will have the number displayed with dots and 0x80. Phase or can be, the principle is as follows:
Common cathode (1 bright 0 off): DP GFEDCBA
0 1 0 1 1 0 1 1 = 0x5B
1 0 0 0 0 0 0 0 = 0x80
After two sets of binary numbers are ORed, the result is:
1 1 0 1 1 0 1 1 = 0xDB
It can be found that after the OR operation, the part (green code) that originally displayed the number 2 does not change, but the part (red) where the original control point is displayed is 1, which just achieves the effect of not affecting the number and lighting the point. The following code achieves a 10-fold reduction in display 0-999.
#include
Sbit LATCH1=P2^2; // segment lock
Sbit LATCH2=P2^3; // bit latch
Unsigned char code DuanMa[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};// Display segment code value 0~9
Unsigned char code WeiMa[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};// corresponding to the corresponding digital tube lighting, that is, bit code
Unsigned char TempData[8]; //Store global variables that display values
Void Delay(unsigned int t); //Function declaration
Void Display(unsigned char FirstBit, unsigned char Num);
Main()
{
Unsigned int num;
Unsigned int j;
While(1)
{
j++;
If(j==200) //Detect the current value after a short period of time, the value to be displayed is increased by 1 to achieve the change of the data display.
{
j=0;
Num++;
If(num==1000)// is used to display 0~999
Num=0;
}
TempData[0]=DuanMa[num/100];//Disassembly display information 123/100=1
TempData[1]=DuanMa[(num%100)/10]|0x80; //23/10=2. Add the second digit of the countdown to reduce the number by 10 times.
TempData[2]=DuanMa[(num%100)%10]; //23%10=3
Display(2,3);
}
}
Void Delay(unsigned int t)
{
While(--t);
}
/*------------------------------------------------
Display function for dynamic scanning of digital tubes
The input parameter FirstBit indicates the first digit to be displayed. For example, the assignment 2 indicates that the display starts from the third digital tube.
If you enter 0, it means to display from the first one.
Num indicates the number of digits to be displayed. If you need to display 99 two digits, the value is entered as 2
------------------------------------------------*/
Void Display(unsigned char FirstBit, unsigned char Num)
{
Unsigned char i;
For(i=0;i{
P1=0; //Clear the data to prevent alternate ghosting
LATCH1=1; //segment latch
LATCH1=0;
P1=WeiMa[i+FirstBit]; //Get the bit code
LATCH2=1; //bit latch
LATCH2=0;
P1=TempData[i]; //Get display data, segment code
LATCH1=1; //segment latch
LATCH1=0;
Delay(200); // Scan gap delay, the time will be too long to flash, too short will cause ghosting
}
}
Color Tft,Tft Lcd Module,Tft Color Display,Tft Color Lcd
Huangshan Kaichi Technology Co.,Ltd , https://www.kaichitech.com