#51 MCU#Interrupt and digital tube application

Publisher:andyliow1980Latest update time:2021-10-27 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Application of interrupts and digital tubes - "9999" countdown table


#include


unsigned char code LedChar[10]={//Numbers displayed by the digital tube 0~9

0XC0,0XF9,0XA4,0XB0,0X99,0X92,0X82,0XF8,0X80,0X90};


unsigned char LedBuff[4]={//The buffer area displayed by the digital tube

0XFF,0XFF,0XFF,0XFF};


sbit Tube1 = P1^0;

sbit Tube2 = P1^1;

sbit Tube3 = P1^2;

sbit Tube4 = P1^3;


unsigned char i = 0;

unsigned int cnt = 0; //interrupt times

unsigned long sec = 0; //Record the number of seconds that have passed


void main()

{

// Enable T0 interrupt

EA = 1;

ET0 = 1;


//Set T0

TMOD = 0X01;

TH0 = 0XFFED;

TL0 = 0XFFFF;

TR0 = 1;


while(1)

{

if(cnt>500)

{

cnt = 0;

sec++;

}

LedBuff[0] = LedChar[9-sec%10];

LedBuff[1] = LedChar[9-sec/10%10];

LedBuff[2] = LedChar[9-sec/100%10];

LedBuff[3] = LedChar[9-sec/1000%10];

}

}


//Timer 0 interrupt service

void InterruptTimer() interrupt 1

{

TH0 = 0XFFED;

TL0 = 0XFFFF;

cnt++;


switch(i)

{

case 0:

P0 = LedBuff[0];Tube1=0;Tube2=1;Tube3=1;Tube4=1;i++;break;

case 1:

P0 = LedBuff[1];Tube1=1;Tube2=0;Tube3=1;Tube4=1;i++;break;

case 2:

P0 = LedBuff[2];Tube1=1;Tube2=1;Tube3=0;Tube4=1;i++;break;

case 3:

P0 = LedBuff[3];Tube1=1;Tube2=1;Tube3=1;Tube4=0;i=0;break;

default:break;

}

}

Reference address:#51 MCU#Interrupt and digital tube application

Previous article:#51 MCU#button
Next article:#51 single chip microcomputer#Static and dynamic display of digital tube

Latest Microcontroller Articles
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号