MCU program 3, digital tube displays 0-9 self-test

Publisher:爱笑的猫咪Latest update time:2015-11-18 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
The digital tube of this learning board uses P0 to display the strokes, and P2 to select each word.
#include
#include
 
unsigned char data dis_digit;
unsigned char code dis_code[11] = 
{0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8, 0x80, 0x90, 0xFF}; //Common anode digital tube
unsigned char data dis_buf[10];
unsigned char data dis_index;
unsigned char i = 0, j = 0;
 
void main(void)
{
unsigned char i;
 
P0 = 0xFF;
P2 = 0xFF;
TMOD = 1;
TH0   = 0xFC;
TL0   = 0x17;
IE   = 0x82;
 
for(i=0;i<=9;i++)
{
dis_buf[i] = dis_code[i];
}
dis_digit = 0xFE;
dis_index = 0;
 
TR0 = 1;
while(1);
}
 
void timer0() interrupt 1
//Timer 0 interrupt service routine, used for dynamic scanning of digital tubes
//dis_index--display index, used to identify the offset of the current digital tube and buffer
//dis_gigit--bit selection channel, transmitted to P2 port to select the current digital tube value, such as 0xFE to select the P2.0 port digital tube
//dis_buf--display buffer base address
{
TH0 = 0xFC;
TL0 = 0x17;
 
P2 = 0xFF; //Turn off all digital tubes first
P0 = dis_buf[dis_index];
P2 = dis_digit;
 
dis_digit = _crol_(dis_digit, 1); //Shift the bit selection channel to the left, and select the next digital tube at the next interrupt
i++;
       //The simplest way to change the display content after a delay
if (i==100)
{
j++;
i = 0;
if (j == 5)
{
dis_index++;
if (dis_index == 10)
{
dis_index = 0;
}
i = 0;
j = 0;
}
}
 
//dis_index &= 0x07; //All 8 digital tubes have been scanned, restart
}

Reference address:MCU program 3, digital tube displays 0-9 self-test

Previous article:51 single chip microcomputer pulse controller
Next article:MCU LED program 2, using timer PWM to realize LED gradual brightness

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号