Use external interruption and time interruption to count 0-999 and display it on the digital tube

Publisher:gamma13Latest update time:2017-01-20 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Requirements: The digital tube starts displaying from 0. Press a key once (and the internal interrupt, it will naturally enter an interrupt once every second). When an interrupt is entered, the number on the digital tube increases by 1 until it reaches 999, and then starts from 0 again.

Connection: P10 to L7, potentiometer to DC motor, pulse output to P32, CS1 to digital tube CS

#include

typedef unsigned char uchar;

xdata uchar LED_CS _at_ 0x9000;

xdata uchar LED_OUTSEG _at_ 0x9004;

xdata uchar LED_OUTBIT _at_ 0x9002;

sbit P10=P1^0;

fly n=0;

unsigned int Count=0;


code unsigned char LEDMAP[]={

//Eight-segment tube display code

0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07,

0x7f, 0x6f, 0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71

};


code unsigned char LEDWED[]= {0x20,0x10,0x08,0x04,0x02,0x01};


//Display buffer

uchar led_buf[]={0,0,0};


void delay(unsigned char ms)

{

unsigned char i;

while(ms--)

{

for(i = 0; i < 50; i++);

}

}


void ADcal()

{

led_buf[0]=Count/100;//hundreds place

led_buf[1]=Count/10%10;//ten digit

led_buf[2]=Count%10;

}

//Open time interrupt

void initTime(){

IE=0x83;

TR0=1;

}

//Open external interrupt

void initOut(){

IE=0x83;

IT0=1;

}


void timer0() interrupt 1

{

TH0=(65535-50000)/256;

TL0=(65535-50000)%256;


n++;

if(n==2)

{


P10=1;

delay(20);

P10=0;

delay(20);

Count++;

if(Count>=999)

{

Count=0;

}

}

}


void out0() interrupt 0

{

Count++;

if(Count>=999)

{

Count=0;

}

}


void main()

{

unsigned int i=0;

initOut(); //Open external interrupt'

initTime();

TH0=(65535-50000)/256;

TL0=(65535-50000)%256;


delay(10);

while(1)

{

ADcal();

LED_CS=0;

if(i==0)

{

LED_OUTSEG=LEDMAP[led_buf[i]];

}

if(i==1)

{

LED_OUTSEG=LEDMAP[led_buf[i]];

}

if(i==2)

{

LED_OUTSEG=LEDMAP[led_buf[i]];

}

LED_OUTBIT=LEDWED[i];

i++;

i=i%3;

delay(10);


}

}


Reference address:Use external interruption and time interruption to count 0-999 and display it on the digital tube

Previous article:Password lock system based on 51 single chip microcomputer, serial communication and ASP.NET
Next article:Generates several different waveforms

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号