搜索

求基于单片机的八路抢答器设计,要用到74LS47N和共阳led,求电路图和程序(最好是C),加急!!

发布网友 发布时间:2022-04-24 01:11

我来回答

4个回答

热心网友 时间:2023-10-17 13:51

#include<reg52.h>

#define uchar unsigned char

#define uint unsigned int

sbit kai=P2^2;

sbit ting=P2^3;

sbit hao1=P1^0;

sbit hao2=P1^1;

sbit hao3=P1^2;

sbit hao4=P1^3;

sbit hao5=P1^4;

sbit hao6=P1^5;

sbit hao7=P1^6;

sbit hao8=P1^7;

sbit wela=P2^1;

sbit dela=P2^0;

sbit P2_6=P2^6;

sbit P2_7=P2^7;

uchar code table[]=

{0x3f,0x06,0x5b,0x4f,

0x66,0x6d,0x7d,0x07,

0x7f,0x6f,0x40};

uchar a,a1,num,shi,ge,hao,

aa,num1,flag1,flag2,flag3,flag4,

flag5,flag6,flag7,flag8,flag9,flag10;

void display(uchar hao,uchar aa,uchar shi,uchar ge);

void init();

void delay(uint z);

void keyscan();

void main()

{

    init();

    while(1)

    {

        keyscan();

        if(flag1==1)

     {

            display(hao,10,shi,ge);

     }

        else

     {

            display(hao,10,0,0);

     }

    }

}

void delay(uint z)

{

    uint x,y;

    for(x=z;x>0;x--)

      for(y=110;y>0;y--);

}

void keyscan()

{

    if(kai==0)

    {

        delay(5);

        if(kai==0)

     {

            while(!kai);

             hao=0;

             num=30;

             shi=3;

             ge=0;

             TR0=1;

             flag1=1;

             P2_7=0;

             P2_6=1;

     }

    }

    if(ting==0)

    {

        delay(5);

        if(ting==0)

     {

            while(!ting)

      {

          a=0;

             num=30;

             num1=0;

             hao=0;

             shi=3;

             ge=0;

             TR0=0;

             TR1=0;

                flag1=0;

                P2_6=0;

             P2_7=1;

             P3=0xff;

      }

     }

    }

    if(flag1==1)

    { 

        if(hao==0&&hao1==0)

     {

            delay(5);

            if(hao1==0)

      {

                while(!hao1);

              P2_6=1;

              P2_7=1;

                 P3=0xfe;

                  flag2=1;

              shi=0;

              ge=0;

              hao=1;

              TR1=1;

                 TR0=0;

      }

     }

        if(hao==0&&hao2==0)

     {

            delay(5);

            if(hao2==0)

      {

             flag3=1;

                while(!hao2);

                P2_6=1;

             P2_7=1;

             P3=0xfd;

             shi=0;

             ge=0;

             hao=2;

             TR0=0;

             TR1=1;

      }

     }

        if(hao==0&&hao3==0)

     {

            delay(5);

            if(hao3==0)

      {

             flag4=1;

                while(!hao3);

                P2_6=1;

             P2_7=1;

             P3=0xfb;

             shi=0;

             ge=0;

             TR0=0;

             TR1=1;

             hao=3;

      }

     }

    

        if(hao==0&&hao4==0)

     {

            delay(5);

            if(hao4==0)

      {

             flag5=1;

                while(!hao4);

                P2_6=1;

             P2_7=1;

             P3=0xf7;

             shi=0;

             ge=0;

             TR0=0;

                TR1=1;

             hao=4;

      }

     }

    

        if(hao==0&&hao5==0)

     {

            delay(5);

            if(hao5==0)

      {

             flag6=1;

                while(!hao5);

                P2_6=1;

             P2_7=1;

             P3=0xef;

             shi=0;

             ge=0;

             TR0=0;

             TR1=1;

             hao=5;

      }

     }

    

        if(hao==0&&hao6==0)

     {

            delay(5);

            if(hao6==0)

      {

             flag7=1;

                while(!hao6);

                P2_6=1;

             P2_7=1;

             P3=0xdf;

             shi=0;

                ge=0;

               hao=6;

             TR0=0;

             TR1=1;

      }

     }

    

        if(hao==0&&hao7==0)

     {

            delay(5);

            if(hao7==0)

      {

             flag8=1;

                while(!hao7);

                P2_6=1;

             P2_7=1;

             P3=0xbf;

             shi=0;

             ge=0;

                hao=7;

             TR0=0;

             TR1=1;

      }

     }

    

        if(hao==0&&hao8==0)

     {

            delay(5);

            if(hao8==0)

      {

                flag9=1; 

                while(!hao8);

                P2_6=1;

             P2_7=1;

             P3=0x7f;

             shi=0;

             ge=0;

             hao=8;

             TR0=0;

             TR1=1;

      }

     }

        if(!hao==0)

     {

            if(flag2==1)

      {

                if(hao1==0)

          {

                 delay(5);

                 if(hao1==0)

           {

               TR1=0;

              }   

          }

      }

            if(flag3==1)

      {

                if(hao2==0)

          {

                 delay(5);

                 if(hao2==0)

           {

               TR1=0;

              }   

          }

      }

            if(flag4==1)

      {

                if(hao3==0)

          {

                 delay(5);

                 if(hao3==0)

           {

               TR1=0;

              }   

          }

      }

            if(flag5==1)

      {

                if(hao4==0)

          {

                 delay(5);

                 if(hao4==0)

           {

               TR1=0;

              }   

          }

      }

            if(flag6==1)

      {

                if(hao5==0)

          {

                 delay(5);

                 if(hao5==0)

           {

               TR1=0;

              }   

          }

      }

            if(flag7==1)

      {

                if(hao6==0)

          {

                 delay(5);

                 if(hao6==0)

           {

               TR1=0;

              }   

          }

      }

            if(flag8==1)

      {

                if(hao7==0)

          {

                 delay(5);

                 if(hao7==0)

           {

               TR1=0;

              }   

          }

      }

            if(flag9==1)

      {

                if(hao8==0)

          {

                 delay(5);

                 if(hao8==0)

           {

               TR1=0;

              }   

          }

      }

     

     } 

    }

}

void display(uchar hao,uchar aa,uchar shi,uchar ge)

{

    P0=0xff;

    wela=1;

    P0=0xfe;

    wela=0;

    P0=0;

    dela=1;

    P0=table[hao];

    dela=0;

    delay(5);

    P0=0xff;

    wela=1;

    P0=0xfd;

    wela=0;

    P0=0;

    dela=1;

    P0=table[aa];

    dela=0;

    delay(5);

    P0=0xff;

    wela=1;

    P0=0xfb;

    wela=0;

    P0=0;

    dela=1;

    P0=table[shi];

    dela=0;

    delay(5);

    P0=0xff;

    wela=1;

    P0=0xf7;

    wela=0;

    P0=0;

    dela=1;

    P0=table[ge];

    dela=0;

    delay(5);

}

void init()

{

    TMOD=0X11;

    TH0=(65536-50000)/256;

    TL0=(65536-50000)%256;

    EA=1;

    ET0=1;

    TH1=(65536-50000)/256;

    TL1=(65536-50000)%256;

    ET1=1;

    num=30;

    num1=0;

    a1=0;

    a=0;

    shi=3;

    ge=0;

    flag1=0;

    P2_6=0;

}

void timer0() interrupt 1

{

    TH0=(65536-50000)/256;

    TL0=(65536-50000)%256;

    a++;

    if(a==18)

    {

        a=0;

        num--;

        if(num==0)

     {

            num=0;

            TR0=0;

     }

        shi=num/10;

        ge=num%10;

     }

}

void timer1() interrupt 3

{

    TH1=(65536-50000)/256;

    TL1=(65536-50000)%256;

    a1++;

    if(a1==18)

    {

        a1=0;

        num1++;

        if(num1==60)

     {

        P3=0xff;

        P2_6=0;

        P2_7=1;

        TR1=0;

     }

        shi=num1/10;

        ge=num1%10;

     }

}

热心网友 时间:2023-10-17 13:51

估计不会有人来“领赏”,因为:
1.任何熟悉单片机的人不会再使用其它芯片了,用单片机最小系统,CPU的数据口直接可以驱动LED。
2.或许用逻辑芯片搭接此抢答器的费用是单片机方案的一小半,多数人会觉得你不是真的这样要做这个抢答器。
3.单片机只能识别汇编语言经“汇编”的机器码,目前尚没有将高级语言汇编成单片机的机器码。
提请你注意:一个成功的单片机硬件系统凝结了设计者的大量心血,或许他愿意拿出来与人共享这个成果,但他一定不会很情愿地把它用在过于简单的,不能发挥作用的地方。

热心网友 时间:2023-10-17 13:52

抢答器这个东西其实是比较简单的,
我只能给你个思路,
程序我是不会帮你写的,
数码管用1个就可以显示1-8路数,占用1个io口,比如P0;
识别按键1-8,也用1个io口,
再用1个io口,驱动1-8路指示灯,
程序就是一直扫描按键判断是否有键按下,
只要有一个按下,就不再识别其他的按键
然后将键值送出(1-8)显示,
同时点亮指示灯。
延时一段时间后自动熄灭,或者在设个按键用来清除。

热心网友 时间:2023-10-17 13:52

这是DP801单片机做的8路抢答器电路图,如果需要程序你可给我邮箱,我给你发过去。

声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。
E-MAIL:11247931@qq.com

热门图文

Top