Re-pick the second day of the MCU Digital tube use (press the button, the value increases until the maximum value, press the minus button, the value decreases, until the minimum value)

Source: Internet
Author: User

1.

1         /*--------------www.szjcdz.cn--------------------2 Name: 2-button plus minus operation3 written by: Szjcdz4 Date: 2010.95 content: Press the Add button, the value increases until the maximum value, press the minus button, the value decreases until the minimum value6 ------------------------------------------------*/7#include <reg52.h>8 #defineUchar8 unsigned char9 #defineuint16 unsigned intTenSbit key_add=p3^3; OneSbit key_dec=p3^4; ASbit latch1=p2^6; -Sbit latch2=p2^7; - voiddisplay (); the  -UCHAR8 Code duanma[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};//Show segment code value 0~F -UCHAR8 Code weima[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};//corresponding to the corresponding digital tube lit, the accession code -  +Uchar8 Template;//Global variables that store display values -  + //Delay Function A voiddelayms (uint16 val) at { - uint16 i,j; -         for(i=0; i<val;i++) -             for(j=0;j<113; j + +); -  - }     in  -  to //******************************* main function *******************************// + voidMainvoid) - { the uchar8 num; *     $Key_add=1;Panax NotoginsengKey_dec=1; -  the    while(1) +   { A        if(!Key_add) the        { +Delayms (Ten); -           if(!Key_add) $           { $                while(! Key_add);//if pressed, key_add=0, then true, then wait -            -                 { the                  if(num< the) -num++;Wuyi                          the               } -           } Wu      -        } About      $         if(!Key_dec) -        { -Delayms (Ten); -           if(!Key_dec) A           { +                while(! KEY_DEC);//If the press is not released, Key_add=0, then true, then wait the            -                 { $                  if(num>0) thenum--; the                          the               } the           } -      in        } the  the     //The above realizes the function of a number num equals several About  the  theTemplate=duanma[num];//global variable segment code to determine what number to display the  + display (); Show -  the    }Bayi      the  the } -  -/***************************************************************/

the voidDisplayvoid ) the { thep0=0; -latch1=1; thelatch1=0; the theP0=weima[2]; That is, choosing a third digital tube .94Latch2=1; LATCH2 WEI p2^7 theLatch2=0; the thep0=Template; Because the segment code is a global variable, so p0=template=duanma[num];98latch1=1; LATCH1 DUAN p2^6 Aboutlatch1=0; - 101Delayms (2);102 104}

Experimental phenomena:

We choose the 3rd one here is weima[2], press the Independent button INT1 is +1, press the Independent button T0 is-1, can be from 0 to F

Dynamic Scan Digital tube:

UCHAR8 Code duanma[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};//Displays the segment code value 0~ F

1 voidDisplayvoid )2 {3          inti;4 5p0=0;6latch1=1;7latch1=0;8 9p0=weima[2];TenLatch2=1;  OneLatch2=0; A  -        for(i=0;i< -; i++) -       { the  -P0=duanma[i];//     //dynamic scanning, or very simple, so that the control -latch1=1;  -latch1=0; +  -Delayms ( $); +  A       } at}

Re-pick the second day of the MCU Digital tube use (press the button, the value increases until the maximum value, press the minus button, the value decreases, until the minimum value)

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.