Proteus simulation 51 single chip basketball scorer

Publisher:数字思维Latest update time:2016-03-23 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

#include   源码下载
#include
#define uchar unsigned char
#define uint unsigned int
uchar secs = 0;
uchar minutes = 1;
uchar LED,num1,num2,num = 4;
uchar  flag1 = 1,flag2 = 0;
uchar m_secs = 24;
uchar key_value = 0;
uchar table[13] = {1,2,3,4,5,6,7,8,9,0,1,2,3};
uchar code LedNum[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar scan_kay(void);
void delay(uchar z);
void INT0_Initial(void)
{
    EX0 = 1;
    IT0 = 1;
    EA = 1;
    P1 = 0xF0;
}

void INT0_Interrupt(void) interrupt 0
{
    uchar temp;
    temp = scan_kay();
    if(temp!=0x7f)
    {
        key_value = temp;
    }
    P1 = 0xF0;
}

void Time0_Initial(void)
{
    TMOD = 0x01;
    TH0 = (65536-50000)/256;
    TL0 = (65536-50000)%256;
    ET0 = 1;
    TR0 = 1;
    EA = 1;
    PT0 = 1;
    PX0 = 0;
}

volatile uchar cnt = 0;
void Time0_Interrupt(void) interrupt 1
{
    TH0 = (65536-50000)/256;
    TL0 = (65536-50000)%256;
    cnt ++;
 minutes=11;
    if(cnt==15)
    {
        cnt = 0;
        secs --;
        m_secs --;
        if(flag2==1)
        {
            LED = !LED;
        }
        if(flag2==0)
        {
            LED = 0;
        }
    }
    if(secs>60)
    {
        secs = 59;
        minutes --;
    }
    if(m_secs>24)
    {
        m_secs = 23;
        if(flag1==1)
        {
            flag2 = 1;
        }
        if(flag1==0)
        {
            flag2 = 0;
       
    }
    if(minutes>60)
    {
        minutes = 11;
        m_secs = 24;
        num ++;
    }
    if(num==4)
    {
        num = 1;
    }
}
void HEXTOBCD(void)
{
    table[0] = LedNum[num];
    table[1] = LedNum[m_secs/10];
    table[2] = LedNum[m_secs%10];
    table[3] = LedNum[minutes/10];
    table[4] = LedNum[minutes%10];
    table[5] = LedNum[secs/10];
    table[6] = LedNum[secs%10];
    table[7] = LedNum[num1/100];
    table[8] = LedNum[num1%100/10];
    table[9] = LedNum[num1%10];
    table[10] = LedNum[num2/100];
    table[11] = LedNum[num2%100/10];
    table[12] = LedNum[num2%10];
}

void Display(uchar *str)
{
    uchar i,temp = 0;
    for(i=0;i<13;i++)
    {
        P0 = 0x00;
        _nop_();
        P2 = temp+i;
        P0 = str[i];
        delay(2);
    }
}
uchar i,j;
void delay(uchar z)
{
 for(i=1;i   for(j=1;j<110;j++);
}

void main()
{
    INT0_Initial();
    Time0_Initial();
    delay(10);
    LED = 0;
    while(1)
    {
        switch(key_value)
     {
            case 12:
      {
                num1 ++;key_value = 0;
                flag1 = 0;
                if(num1>255)
          {
                 num1 = 0;
          }
             break;
      }
            case 13:
      {
                num1 --;key_value = 0;
                flag1 = 0;
                if(num1>255)
          {
                 num1 = 255;
          }
             break;
      }
            case 14:
      {
                num2 ++;key_value = 0;
                flag1 = 0;
                if(num2>255)
          {
                 num2 = 0;
          }
             break;
      }
            case 15:
      {
                num2 --;key_value = 0;
                flag1 = 0;
                if(num2>255)
          {
                 num2 = 255;
          }
             break;
      }
            case 1:
      {
             TR0 = 1;
                key_value = 0;
             break;
      }
            case 2:
      {
                num1 = 0;num2 = 0;
             num = 4;
                secs = 0;minutes = 12;
                m_secs = 24;
                key_value = 0;
             TR0 = 1;
             break;
      }
            case 3:
      {
             TR0 = 0;
                key_value = 0;
             break;
      }
            default:
      {
             break;
      }
     
        HEXTOBCD();
        delay(5);
        Display(table);
        delay(10);
    }
}
uchar scan_key(void)
{
    uchar i,key_value;
    P1 = 0xFF;
    for(i=0;i<4;i++)
    {
        P1 = ~(1<         key_value = P1&0xF0;
        if(key_value!=0xF0)
        {
            delay(20);
            key_value = P1&0xF0;
            if(key_value!=0xF0)
         {
                key_value &= 0xF0;
                switch(key_value)
             {
                    case 0x70: key_value = 15-(3-i)*4;break;
                    case 0xb0: key_value = 14-(3-i)*4;break;
                    case 0xd0: key_value = 13-(3-i)*4;break;
                    case 0xe0: key_value = 12-(3-i)*4;break;
                    default: key_value = 0x7f;
             }
                return key_value;
         }
        }
        P1 = 0xFF;
    }
    return 0x7f;
}

uchar scan_kay(void)
{
    uchar key_va1,key_va2;
    key_va1 = scan_key();
    if(key_va1==0x7f)
    {
        return 0x7f;
    }
    do
    {
        key_va2 = scan_key();
    }while(key_va1==key_va2);
    return key_va1;
}

Reference address:Proteus simulation 51 single chip basketball scorer

Previous article:Full-duplex serial communication between 51 single-chip microcomputer and computer
Next article:MCU 12864LCD scrolling display

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号