找回密码
 立即注册

QQ登录

只需一步,快速开始

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

2019年电赛F题纸张计数显示装置源程序

[复制链接]
跳转到指定楼层
楼主
ID:129825 发表于 2020-3-12 17:26 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
2019年电赛F题

单片机源程序如下:
  1. //////////////////////////////////////////////////////////////////////////////////         
  2. //本程序只供学习使用,未经作者许可,不得用于其它任何用途
  3. //
  4. //  文 件 名   : main.c
  5. //  版 本 号   : v2.0
  6. //  作    者   : HuangKai
  7. //  生成日期   : 2014-0101
  8. //  最近修改   :
  9. //  功能描述   : OLED 4接口演示例程(51系列)
  10. //              说明:
  11. //              ----------------------------------------------------------------
  12. //              GND    电源地
  13. //              VCC  接5V或3.3v电源
  14. //              D0   P1^0(SCL)
  15. //              D1   P1^1(SDA)
  16. //              RES  接P12
  17. //              DC   接P13
  18. //              CS   接P14               
  19. //              ----------------------------------------------------------------
  20. // 修改历史   :
  21. // 日    期   :
  22. // 作    者   : HuangKai
  23. // 修改内容   : 创建文件
  24. //版权所有,盗版必究。
  25. //Copyright(C) 中景园电子2014/3/16
  26. //All rights reserved
  27. //******************************************************************************/
  28. #include "reg51.h"
  29. #include "oled.h"
  30. sbit buzz=P3^6;
  31. sbit LED=P2^0;
  32. sbit s1=P2^4;
  33. int t,S;
  34. bit flag = 0;
  35. char i;
  36. u8 count = 0;
  37. u8 time = 0;
  38. u8 temp;
  39. void init()
  40. {       
  41.         EA = 1;
  42.     ET0 = 1;
  43.     ET1 = 1;
  44.     TMOD = 0x16;
  45.     TH0 = 0x00;
  46.     TL0 = 0x00;
  47.     TR0 = 1;
  48.     TH1 = (65536 - 50000) / 256;
  49.     TL1 = (65536 - 50000) % 256;
  50.     TR1 = 1;
  51. }
  52. void delay(u8 z)
  53. {
  54.         u8 x,y;
  55.         for(x=z;x>0;x--)
  56.                 for(y=110;y>0;y--);
  57. }
  58. int main(void)
  59. {                                
  60.                 OLED_Clear();                                
  61.                 OLED_Init();        //初始化OLED         
  62.                 init();
  63.             OLED_Clear();
  64.                 OLED_ShowCHinese(36,0,0);//欢
  65.                 OLED_ShowCHinese(54,0,1);//迎
  66.                 OLED_ShowCHinese(72,0,2);//使
  67.                 OLED_ShowCHinese(90,0,3);//用
  68.                 OLED_ShowCHinese(10,2,4);//纸
  69.                 OLED_ShowCHinese(28,2,5);//张
  70.                 OLED_ShowCHinese(46,2,6);//计
  71.                 OLED_ShowCHinese(64,2,7);//数
  72.                 OLED_ShowCHinese(82,2,8);//装
  73.                 OLED_ShowCHinese(100,2,9);//置
  74.                 OLED_ShowCHinese(0,4,10);//纸
  75.                 OLED_ShowCHinese(18,4,11);//张
  76.                 OLED_ShowCHinese(36,4,12);//数
  77.                 OLED_ShowString(52,5,":",2);
  78.                 OLED_ShowCHinese(108,4,11);//张
  79.                 OLED_ShowCHinese(0,6,13);//时
  80.                 OLED_ShowCHinese(18,6,14);//间
  81.                 OLED_ShowString(32,7,":",2);
  82.                 OLED_ShowString(50,7,"MS",2);
  83.                 delay_ms(50);
  84.         while(1)
  85.         {
  86.                                           
  87.                         if (flag == 1)
  88.                     {       
  89.                                           temp=count;
  90.                                           temp=temp*1.113*0.5712;
  91.                                           if(temp<16)  {t=0;        buzz=0;        delay_ms(300);        buzz=1; }         
  92.                                           else if((temp>16)&&(temp<23))        t=1;
  93.                                           else if((temp>23)&&(temp<29))        t=2;
  94.                                           else if((temp>29)&&(temp<34))        t=3;
  95.                                           else if((temp>34)&&(temp<39))        t=4;
  96.                                           else if((temp>39)&&(temp<44))        t=5;
  97.                                           else if((temp>44)&&(temp<48))        t=6;
  98.                                           else if((temp>48)&&(temp<52))        t=7;
  99.                                           else if((temp>52)&&(temp<56))        t=8;
  100.                                           else if((temp>56)&&(temp<59))        t=9;
  101.                                           else if((temp>59)&&(temp<64))        t=10;
  102.                                           else if((temp>64)&&(temp<67))        t=11;
  103.                                           else if((temp>67)&&(temp<70))        t=12;
  104.                                           else if((temp>70)&&(temp<73))        t=13;
  105.                                           else if((temp>73)&&(temp<75))        t=14;
  106.                                           else if((temp>75)&&(temp<78))        t=15;
  107.                                           else if((temp>78)&&(temp<79))        t=16;
  108.                                           else if((temp>79)&&(temp<82))        t=17;
  109.                                           else if((temp>82)&&(temp<84))        t=18;
  110.                                           else if((temp>84)&&(temp<86))        t=19;
  111.                                           else if((temp>86)&&(temp<88))        t=20;
  112.                                           else if((temp>88)&&(temp<90)) t=21;
  113.                                           else if((temp>90)&&(temp<92)) t=22;
  114.                                           else if((temp>92)&&(temp<95)) t=23;                  
  115.                                           else if((temp>95)&&(temp<97)) t=24;
  116.                                           else if((temp>97)&&(temp<99)) t=25;
  117.                                           else if((temp>99)&&(temp<100)) t=26;
  118.                                           else if((temp>100)&&(temp<101)) t=27;
  119.                                           else if((temp>101)&&(temp<103)) t=28;
  120.                       else if((temp>103)&&(temp<105)) t=29;
  121.                                           else if((temp>105)&&(temp<106)) t=30;
  122.                                           else if((temp>106)&&(temp<107)) t=31;
  123.                                           else if((temp>107)&&(temp<108)) t=32;
  124.                                           else if((temp>108)&&(temp<109)) t=33;
  125.                                           else if((temp>109)&&(temp<110)) t=34;
  126.                                           else if((temp>110)&&(temp<113)) t=35;
  127.                                           else if((temp>113)&&(temp<115)) t=36;
  128.                                           else if((temp>115)&&(temp<117)) t=37;
  129.                                           else if((temp>117)&&(temp<119)) t=38;
  130.                                           else if((temp>119)&&(temp<121)) t=39;
  131.                                           else if((temp>121)&&(temp<124)) t=40;
  132.                                           else if((temp>124)&&(temp<127)) t=41;
  133.                                           else if((temp>127)&&(temp<130)) t=42;
  134.                                           else if((temp>130)&&(temp<133)) t=43;
  135.                                           else if((temp>133)&&(temp<135)) t=44;
  136.                                           else if((temp>135)&&(temp<139)) t=45;
  137.                                           else if((temp>139)&&(temp<142)) t=46;
  138.                                           else if((temp>142)&&(temp<144)) t=47;
  139.                                           else if((temp>144)&&(temp<147)) t=48;
  140.                                           else if((temp>147)&&(temp<149)) t=49;
  141.                                           else if((temp>149)&&(temp<151)) t=50;
  142.                                
  143.                                           OLED_ShowNum(40,7,S,2);
  144.                                           OLED_ShowNum(70,5,t/10,2);
  145.                                           OLED_ShowNum(80,5,t%10,2);
  146.                                           delay_ms(100) ;          
  147.                               if(s1==0)
  148.                                   {
  149.                                           delay(10);
  150.                                         if(s1==0)
  151.                                         {
  152.                                                 EA=1;
  153.                                                 count=0;
  154.                                                 flag=0;
  155.                                                 delay(20);
  156.                                         }
  157.                                   }                                         
  158.                         }
  159.         }
  160.                                          
  161. }
  162.        


  163. void Count0()interrupt 1
  164. {       
  165.        
  166.     ++count;
  167.         ++S;
  168. }
  169. void Time1()interrupt 3
  170. {
  171.     if(flag==0)
  172.         {
  173.         TH1 = (65536 - 50000) / 256;
  174.     TL1 = (65536 - 50000) % 256;
  175.     ++time;
  176.     if (time == 20)
  177.     {
  178.                 time=0;
  179.         EA = 0;
  180.                 TH0 = 0x00;
  181.             TL0 = 0x00;
  182.         flag = 1;
  183.                 buzz=0;
  184.                 LED=1;
  185.                 delay_ms(300);
  186.                 buzz=1;
  187.                 LED=0;
  188.            flag=1;

  189.             }
  190.         }
  191. }
复制代码

所有资料51hei提供下载:
F题纸张计数显示装置.zip (103.2 KB, 下载次数: 107)


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

使用道具 举报

沙发
ID:1 发表于 2020-3-13 00:04 | 只看该作者
本帖需要重新编辑补全电路原理图,源码,详细说明与图片即可获得100+黑币(帖子下方有编辑按钮)
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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