找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 4644|回复: 5
打印 上一主题 下一主题
收起左侧

单片机篮球计时计分系统代码+Proteus仿真

[复制链接]
跳转到指定楼层
楼主
所有资料都在文件里,有需要的下载就行了

仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)


单片机源程序如下:
  1. #include <reg52.h>
  2. #include <intrins.h>
  3. #include<string.h>
  4. #define uchar unsigned char
  5. #define uint unsigned int
  6. #include "LCD1602_drv.h"

  7. #include "stdio.h"  

  8. uchar  ocassioncount = 1;  //场次
  9. uint16 score1=0;//甲队分数
  10. uint16 score2=0;//乙队分数
  11. uint16 deadline24=24;//24秒倒计时
  12. uint16 deadline12=720;//12分钟秒倒计时
  13. uchar  scorestr[3];  //
  14. //uchar  scorestr2[3];  //
  15. uchar  dead24str[2];  //
  16. uchar  dead12str[5];  //
  17. uchar  ocassionstr[3];  //

  18.   /*延时函数*/
  19. void delay(unsigned char x)
  20. {
  21.     unsigned char i,j;
  22.         for(i = x;i > 0;i--)
  23.                 for(j = 100;j > 0;j--);
  24. }

  25. //数字转化为字符串        三位整数
  26. void numtostr(uint16 num)
  27. {       
  28.          uchar i=0,numsize=0;
  29.          scorestr[0]=num/100+0x30;         //bai位
  30.          scorestr[2]=num%10+0x30;         //个位
  31.          if(num>100)
  32.          {
  33.            scorestr[1]=(num/10)%10+0x30;         //bai位
  34.           }       
  35.           else
  36.           {
  37.                    scorestr[1]=num/10+0x30;         //bai位
  38.           
  39.           }
  40.    }
  41.          //数字转化为字符串        三位整数
  42. // void numtostr2(uint16 num)
  43. //{       
  44. //          uchar i=0,numsize=0;
  45. //         scorestr2[0]=num/100+0x30;         //bai位
  46. //         scorestr2[2]=num%10+0x30;         //个位
  47. //         if(num>100)
  48. //         {
  49. //           scorestr2[1]=(num/10)%10+0x30;         //bai位
  50. //          }       
  51. //          else
  52. //          {
  53. //                   scorestr2[1]=num/10+0x30;         //bai位
  54. //          
  55. //          }
  56. //   }

  57. //24s数字转为字符串
  58. void num24tostr(uint16 num)
  59. {
  60.            dead24str[0]=num/10+0x30;         //bai位
  61.         dead24str[1]=num%10+0x30;         //ge位                                                 
  62. }

  63. //12min数字转为字符串
  64. void num12tostr(uint16 num)
  65. {

  66.           uint16 temp;
  67.           temp=        num;

  68.            dead12str[0]=num/600+0x30;         //bai位
  69.           temp=num/60;

  70.          dead12str[1]=temp%10+0x30;         //ge位       

  71.            StringDisplay(11, 1, dead12str,2,1);
  72.           StringDisplay(13, 1,":",1,1);
  73.         dead12str[0]=(num%60)/10+0x30;         //bai位
  74.         dead12str[1]=(num%60)%10+0x30;         //ge位               
  75.          StringDisplay(14, 1, dead12str,2,1);
  76.                                          
  77. }
  78.                                          
  79. //12min数字转为字符串
  80. void ocassionchange(uchar charch)
  81. {
  82.    ocassionstr[0]=charch+0x30;
  83.          switch(charch)
  84.          {
  85.            case 1:
  86.                 ocassionstr[1]='s';
  87.                     ocassionstr[2]='t';
  88.                          break;
  89.             case 2:
  90.                          ocassionstr[1]='n';
  91.                      ocassionstr[2]='d';
  92.                          break;
  93.             case 3:
  94.                          ocassionstr[1]='r';
  95.                      ocassionstr[2]='d';
  96.                          break;
  97.             case 4:
  98.                          ocassionstr[1]='t';
  99.                     ocassionstr[2]='h';
  100.                          break;
  101.                          
  102.          }
  103. }
  104.    
  105. uchar P10last=0;
  106. uchar P11last=0;
  107. uchar P12last=0;
  108. uchar P13last=0;
  109. uchar P14last=0;
  110. uchar P15last=0;
  111. uchar P16last=0;
  112. uchar P17last=0;
  113. uchar P23last=0;
  114.          uint16 bifenchange1=0;
  115. //                  uint16 bifenchange2=0;
  116. void  keyslove1(void)
  117. {

  118.         if(!P10)
  119.         {
  120.         P10last=1;}
  121.         if(P10&P10last)
  122.         {        score1++;
  123.             numtostr(score1);
  124.        StringDisplay(0, 0, scorestr,3,1);
  125.            P10last=0;  
  126.         }  

  127.         if(!P11)
  128.         {
  129.         P11last=1;}
  130.         if(P11&P11last)
  131.         {         if(score1==0)
  132.              {score1=0; }
  133.                 else
  134.                 {
  135.                  score1--;
  136.                
  137.                 }
  138.             numtostr(score1);
  139.        StringDisplay(0, 0, scorestr,3,1);
  140.            P11last=0;  
  141.         }  

  142.            if(!P12)
  143.         {
  144.         P12last=1;}
  145.         if(P10&P12last)
  146.         { TR0 = ~TR0 ;          //启动定时器
  147.           
  148.            P12last=0;            
  149.         }  

  150.         if(!P13)
  151.         {
  152.         P13last=1;}
  153.         if(P13&P13last)
  154.         {        score2++;
  155.             numtostr(score2);
  156.        StringDisplay(4, 0, scorestr,3,1);
  157.            P13last=0;  
  158.         }  
  159.                  if(!P14)
  160.         {
  161.         P14last=1;}
  162.         if(P14&P14last)
  163.         { if(score2==0)
  164.              {score2=0; }
  165.                 else
  166.                 {
  167.                  score2--;
  168.                
  169.                 }
  170.             numtostr(score2);
  171.        StringDisplay(4, 0, scorestr,3,1);
  172.            P14last=0;  
  173.         }  


  174.                 if(!P15)
  175.         {
  176.         P15last=1;}
  177.         if(P15&P15last)
  178.         {       
  179.            deadline24=24;
  180.            num24tostr(deadline24);       
  181.        StringDisplay(14, 0, dead24str,3,10);
  182.            P15last=0;  
  183.         }  

  184.            if(!P16)
  185.         {
  186.         P16last=1;}
  187.         if(P16&P16last)
  188.         {       
  189.             bifenchange1=score1;
  190.         score1=score2;       
  191.                 score2=         bifenchange1;
  192. //                   numtostr(bifenchange1);
  193. //       StringDisplay(0, 0, scorestr,3,1);
  194. //          
  195. //                      numtostr2(bifenchange2);
  196. //       StringDisplay(0, 4, scorestr2,3,1);
  197. //
  198. //
  199. //           score1=bifenchange2;
  200. //           score2= bifenchange1;

  201.           
  202.            P16last=0;  
  203.         }  

  204.                 if(!P17)
  205.         {
  206.         P17last=1;}
  207.         if(P17&P17last)
  208.         {        ocassioncount++;
  209.             if(ocassioncount==5)
  210.            {
  211.                          ocassioncount=1;
  212.            }
  213.          
  214.            ocassionchange(ocassioncount);
  215.                  StringDisplay(0, 1, ocassionstr,3,1);
  216.            P17last=0;  
  217.         }  

  218.                   if(!P23)
  219.         {
  220.         P23last=1;}

  221.         if(P23&P23last)
  222.         {(*((void(code*)(void))0x0000))();
  223.            P23last=0;  
  224.         }  



  225. }


  226. uchar flagbuzz=0;
  227. void main(void)
  228. {
  229.        
  230.           P1=0xFF;
  231.           P23=1;
  232.      LCD1602Init();
  233.      TMOD = 0x01; //初始化TMOD,定时器0,方式1
  234.      TH0 = (65536 - 50000) / 256; //装填计数
  235.      TL0 = (65536 - 50000) % 256;
  236.      EA = 1; //开放所有中断
  237.      ET0 = 1; //开放定时器0中断控制位
  238.    
  239.          
  240.            numtostr(score1);
  241.        StringDisplay(0, 0, scorestr,3,1);
  242.            StringDisplay(3, 0,":",1,1);
  243.            numtostr(score2);
  244.        StringDisplay(4, 0, scorestr,3,1);
  245.            num24tostr(deadline24);       
  246.        StringDisplay(14, 0, dead24str,3,10);
  247.            ocassionchange(ocassioncount);
  248.            StringDisplay(0, 1, ocassionstr,3,1);
  249.            num12tostr(deadline12) ;

  250.                 
  251.     while (1)
  252.         {

  253.                   keyslove1();
  254.                   numtostr(score1);
  255.           StringDisplay(0, 0, scorestr,3,1);
  256.           
  257.            StringDisplay(3, 0,":",1,1);
  258. //              delay(50);
  259.            numtostr(score2);
  260.        StringDisplay(4, 0, scorestr,3,1);
  261. //              delay(50);

  262.                  num24tostr(deadline24);       
  263.        StringDisplay(14, 0, dead24str,3,10);
  264.        
  265.            StringDisplay(0, 1, ocassionstr,3,1);
  266.            num12tostr(deadline12) ;

  267.                 if(flagbuzz)
  268.                 {
  269.                           P37=~P37;
  270.                      delay(10);
  271.                 }

  272.                 }

  273.         }
  274.       


  275.          
  276.         uchar second1=0;
  277.                 int buzztime=0;
  278.    void Interrupt() interrupt 1
  279.   {
  280.       TH0 = (65536 - 50000) / 256; //触发中断时重新装填计时
  281.       TL0 = (65536 - 50000) % 256;
  282.            second1++;
  283.            if(second1==20)
  284.            {
  285.                           
  286.                     second1=0;
  287.                          if(deadline24==0)
  288.                    {   deadline24=0;
  289.                
  290.                    }

  291.                         else{  
  292.                         deadline24--;
  293.                         }
  294.                                 if(deadline12==0)
  295.                                 {
  296.                                         deadline12=0;
  297.                                    flagbuzz=1;

  298.                                 }
  299.                                 else{
  300.                                                   deadline12--;
  301.                                 }

  302.                   if(flagbuzz)
  303.                          {
  304.                             if(buzztime==5)       
  305.                                 {  flagbuzz=0;
  306.                                 }
  307.                                 else
  308.                                 {buzztime++        ;
  309.                                 }
  310.                          
  311.                          }




  312.            }


  313.           
  314.    
  315. }
复制代码

所有资料51hei提供下载:
20190511篮球计分器.zip (109.85 KB, 下载次数: 83)


评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏3 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:247623 发表于 2019-8-12 09:58 | 只看该作者
开始键P12按下有时会不灵,需要按2-3下,但其他按钮没出现这种情况,程序里好像没有按键消抖程序
回复

使用道具 举报

板凳
ID:733732 发表于 2020-4-20 18:49 | 只看该作者
按照上面的画了原理图但是LCD1602会亮不会显示是什么原因
回复

使用道具 举报

地板
ID:733732 发表于 2020-4-20 18:54 | 只看该作者
按照上面的原理图和代码操作后,LCD1602会亮但无法显示,是什么原因
回复

使用道具 举报

5#
ID:733732 发表于 2020-4-20 19:05 | 只看该作者
LCD1602会亮但是无法显示,这是为什么
回复

使用道具 举报

6#
ID:950257 发表于 2021-7-22 11:08 | 只看该作者
single0110 发表于 2020-4-20 18:49
按照上面的画了原理图但是LCD1602会亮不会显示是什么原因

上面电路图10K变阻器都接错了,你的lcd肯定不亮
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表