Digital tube buttons plus or minus one

Publisher:平稳心绪Latest update time:2024-08-15 Source: cnblogs Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

//Button plus or minus one

#include

#include

int duan[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F}; //Hexadecimal of the common cathode digital tube 0 to 9

sbit K1 = P1^0;

sbit K2 = P1^7;

char num = 0;

//Delay function with parameters

void delay(unsigned int i){

while(i--);

}

//Main function

void main(void)

{

while(1){

if(K1 == 0){

delay(5000); //key press delay

if(K1 == 0){

num++;

}

}

if(K2 == 0){

delay(5000);

if(K2 == 0){

num --;

}

}

//cycle

if(num > 99){

num = 0;

}

if(num < 0){

num = 99;

}

//Knowledge point: The unit digit of any two-digit number divided by 10 is the tens digit

P3=0x08; //unit display

P0 = ~duan[num%10]; //Only multiples of ten modulo 10 equal 0, so other non-multiples of ten equal themselves plus their units digit

delay(5000);

P3=0x04; //ten digit display

P0= ~duan[num/10%10]; //Any number in the MCU divided by 10 equals its tens digit

delay(6000);

}

}

a2f039a563fc33e8eeaa5a602aa78d2d_1047760-20170516160256682-417201096.png


Reference address:Digital tube buttons plus or minus one

Previous article:External interrupt 0/1
Next article:Digital tube application digital_pile

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号