Digital Tube Keypad Decimal count

Source: Internet
Author: User
Tags xms

Digital display 00~59 Button 1 each time you press the display value plus one, button 2 each press the display value minus one, button 3 function zero, button 4 start or stop timer 0


#include <reg52.h>
#define UCHAR unsigned char
#define UINT unsigned int
Sbit key1=p3^4;
Sbit key2=p3^5;
Sbit key3=p3^6;
Sbit key4=p3^7;
Sbit dula=p2^6;
Sbit wela=p2^7;
Uchar Code table[]={
0X3F,0X06,0X5B,0X4F,
0X66,0X6D,0X7D,0X07,
0X7F,0X6F,0X77,0X7C,
0x39,0x5e,0x79,0x71
};
void delayms (UINT);
Uchar Numt0,num;
void display (Uchar Numdis)
{
Uchar Shi,ge;
SHI=NUMDIS/10;
ge=numdis%10;

Dula=1;
P0=table[shi];
dula=0;
P0=0xff;
Wela=1;
P0=0xfe;
wela=0;
Delayms (5);

Dula=1;
P0=table[ge];
dula=0;
P0=0xff;
Wela=1;
P0=0XFD;
wela=0;
Delayms (5);
}


void delayms (UINT XMS)
{
UINT I,j;
for (i=xms;i>0;i--)
for (j=110;j>0;j--);
}
void Init ()
{
tmod=0x01;
th0= (65535-45872)/256;
tl0= (65536-45872)%256;
Ea=1;
Et0=1;
}


void Keyscan ()
{
if (key1==0)
{
Delayms (10);
if (key1==0)
{
num++;
if (num==60)
num=0;
while (!key1);
}
}
if (key2==0)
{
Delayms (10);
if (key2==0)
{
if (num==0)
num=60;
num--;
while (!key2);
}
}
if (key3==0)
{
Delayms (10);
if (key3==0)
{
num=0;
while (!key3);
}
}
if (key4==0)
{
Delayms (10);
if (key4==0)
{
while (!KEY4);
TR0=~TR0;
}
}
}


void Main ()
{
Init ();
while (1)
{
Keyscan ();
Display (num);
}
}
void T0_timer () Interrupt 1
{
th0= (65536-45872)/256;
Re-install initial value
tl0= (65536-45872)%256;
numt0++;
if (numt0==20)
{
numt0=0;
num++;
if (num==60)
num=0;
}
}

Copyright notice: This article Bo Master original article. Blog, not reproduced without consent.

Digital Tube Keypad Decimal count

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.