找回密码
 注册

QQ登录

只需一步,快速开始

搜索

基于51单片机的跑马灯Proteus仿真和程序源码

[复制链接]
eng 发表于 2021-6-28 00:55:39 | 显示全部楼层 |阅读模式
1.gif
部分源码如下:完整源码见附件
程序.rar (275.77 KB, 售价: 1 E币)
仿真.zip (27.74 KB, 售价: 1 E币)
  1. #include <REG52.H>
  2. #include "SoundPlay.h"

  3. unsigned char RunMode;

  4. //**********************************System Fuction*************************************************
  5. void Delay1ms(unsigned int count)
  6. {
  7.         unsigned int i,j;
  8.         for(i=0;i<count;i++)
  9.         for(j=0;j<120;j++);
  10. }

  11. unsigned char code LEDDisplayCode[] = { 0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,        //0~7
  12.                                                           0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E,0xFF};

  13. void Display(unsigned char Value)
  14. {
  15.         P3 = LEDDisplayCode[Value];
  16. }

  17. void LEDFlash(unsigned char Count)
  18. {
  19.         unsigned char i;
  20.         bit Flag;
  21.         for(i = 0; i<Count;i++)
  22.         {
  23.                 Flag = !Flag;
  24.                 if(Flag)
  25.                         Display(RunMode);
  26.                 else
  27.                         Display(0x10);
  28.                 Delay1ms(100);
  29.         }
  30.         Display(RunMode);
  31. }

  32. unsigned char GetKey(void)
  33. {
  34.         unsigned char KeyTemp,CheckValue,Key = 0x00;
  35.         CheckValue = P2&0x32;
  36.         if(CheckValue==0x32)
  37.                 return 0x00;
  38.         
  39.         Delay1ms(10);
  40.         KeyTemp = P2&0x32;
  41.         if(KeyTemp==CheckValue)
  42.                 return 0x00;

  43.         if(!(CheckValue&0x02))
  44.                 Key|=0x01;
  45.         if(!(CheckValue&0x10))
  46.                 Key|=0x02;
  47.         if(!(CheckValue&0x20))
  48.                 Key|=0x04;
  49.         return Key;
  50. }

  51. unsigned int Timer0Count,SystemSpeed,SystemSpeedIndex;
  52. void InitialTimer2(void)
  53. {
  54.         T2CON  = 0x00;                        //16 Bit Auto-Reload Mode
  55.          TH2 = RCAP2H = 0xFC;          //重装值,初始值        TL2 = RCAP2L = 0x18;
  56.         ET2=1;                                        //定时器 2 中断允许
  57.         TR2 = 1;                                //定时器 2 启动
  58.         EA=1;
  59. }

  60. unsigned int code SpeedCode[]={   1,   2,   3,   5,   8,  10,  14,  17,  20,  30,
  61.                                                              40,  50,  60,  70,  80,  90, 100, 120, 140, 160,
  62.                            
复制代码


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

本版积分规则

QQ|手机版|小黑屋|ELEOK |网站地图

GMT+8, 2024-3-29 22:10

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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