• 大小: 109KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-24
  • 语言: 其他
  • 标签:

资源简介

51单片机跑马灯完整程序与电路仿真图,适合对单片机开发感兴趣的爱好者。

资源截图

代码片段和文件信息

#include 

unsigned char RunMode;
//**********************************System Fuction*************************************************
void Delay1ms(unsigned int count)
{
unsigned int ij;
for(i=0;i for(j=0;j<120;j++);
}

unsigned char code LEDDisplayCode[] = { 0xC00xF90xA40xB00x990x920x820xF8 //0~7
                           0x800x900x880x830xC60xA10x860x8E0xFF};

void Display(unsigned char Value)
{
P3 = LEDDisplayCode[Value];
}

void LEDFlash(unsigned char Count)
{
unsigned char i;
bit Flag;
for(i = 0; i {
Flag = !Flag;
if(Flag)
Display(RunMode);
else
Display(0x10);
Delay1ms(100);
}
Display(RunMode);
}

unsigned char GetKey(void)
{
unsigned char KeyTempCheckValueKey = 0x00;
CheckValue = P2&0x32;
if(CheckValue==0x32)
return 0x00;

Delay1ms(10);
KeyTemp = P2&0x32;
if(KeyTemp==CheckValue)
return 0x00;

if(!(CheckValue&0x02))
Key|=0x01;
if(!(CheckValue&0x10))
Key|=0x02;
if(!(CheckValue&0x20))
Key|=0x04;
return Key;
}

unsigned int TimerCountSystemSpeedSystemSpeedIndex;
void InitialTimer2(void)
{
T2CON  = 0x00; //16 Bit Auto-Reload Mode
  TH2 = RCAP2H = 0xFC;   //重装值初始值 TL2 = RCAP2L = 0x18;
ET2=1; //定时器 2 中断允许
TR2 = 1; //定时器 2 启动
EA=1;
}

unsigned int code SpeedCode[]={   1   2   3   5   8  10  14  17  20  30
     40  50  60  70  80  90 100 120 140 160
180 200 300 400 500 600 700 800 9001000};//30
void SetSpeed(unsigned char Speed)
{
SystemSpeed =SpeedCode[Speed];
}

void LEDShow(unsigned int LEDStatus)
{
P1 = ~(LEDStatus&0x00FF);
P0 = ~((LEDStatus>>8)&0x00FF);
}

void InitialCPU(void)
{
RunMode = 0x00;
TimerCount = 0;
SystemSpeedIndex = 10;

P1 = 0x00;
P0 = 0x00;
P2 = 0xFF;
P3 = 0x00;
Delay1ms(500);
P1 = 0xFF;
P0 = 0xFF;
P2 = 0xFF;
P3 = 0xFF;
SetSpeed(SystemSpeedIndex);
Display(RunMode);
}

//Mode 0
unsigned int LEDIndex = 0;
bit LEDDirection = 1LEDFlag = 1;
void Mode_0(void)
{
LEDShow(0x0001< LEDIndex = (LEDIndex+1)%16;
}
//Mode 1
void Mode_1(void)
{
LEDShow(0x8000>>LEDIndex);
LEDIndex = (LEDIndex+1)%16;
}
//Mode 2
void Mode_2(void)
{
if(LEDDirection)
LEDShow(0x0001< else
LEDShow(0x8000>>LEDIndex);
if(LEDIndex==15)
LEDDirection = !LEDDirection;
   LEDIndex = (LEDIndex+1)%16;
}
//Mode 3
void Mode_3(void)
{
if(LEDDirection)
LEDShow(~(0x0001< else
LEDShow(~(0x8000>>LEDIndex));
if(LEDIndex==15)
LEDDirection = !LEDDirection;
   LEDIndex = (LEDIndex+1)%16;
}

//Mode 4
void Mode_4(void)
{
if(LEDDirection)
{
if(LEDFlag)
LEDShow(0xFFFE<     else
LEDShow(~(0x7FFF>>LEDIndex));
}
else
{
if(LEDFlag)
LEDShow(0x7FFF>>LEDIndex);
else
LEDShow(~(0xFFFE< }
if(LEDIndex==15)
{
LEDDirection = !LEDDirection;
if(LEDDirection) LEDFlag = !LE

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2009-04-23 17:01  走马灯\
     文件     2801078  2005-09-17 04:19  走马灯\hurricanelamp.bmp
     文件      165791  2006-01-19 02:55  走马灯\HurricaneLamp.DSN
     文件         626  2006-01-21 01:29  走马灯\HurricaneLamp.PWI
     目录           0  2009-04-23 17:00  走马灯\Keil\
     文件       12246  2005-09-17 01:24  走马灯\Keil\HurricaneLamp
     文件        5134  2005-09-17 01:21  走马灯\Keil\HurricaneLamp.c
     文件        3965  2005-09-17 01:24  走马灯\Keil\HurricaneLamp.hex
     文件          58  2005-09-17 01:24  走马灯\Keil\HurricaneLamp.lnp
     文件       12987  2005-09-17 01:24  走马灯\Keil\HurricaneLamp.LST
     文件       21437  2005-09-17 01:24  走马灯\Keil\HurricaneLamp.M51
     文件       15453  2005-09-17 01:24  走马灯\Keil\HurricaneLamp.OBJ
     文件        1465  2005-09-17 02:54  走马灯\Keil\HurricaneLamp.Opt
     文件         197  2005-09-17 02:54  走马灯\Keil\HurricaneLamp.plg
     文件        2019  2005-09-17 01:24  走马灯\Keil\HurricaneLamp.Uv2
     文件        1464  2005-09-17 01:24  走马灯\Keil\HurricaneLamp_Opt.Bak
     文件        2001  2005-09-17 01:12  走马灯\Keil\HurricaneLamp_Uv2.Bak
     文件        5115  2002-04-16 15:32  走马灯\Keil\STARTUP.A51
     文件      165722  2005-09-17 17:28  走马灯\Last Loaded HurricaneLamp.DBK
     文件         184  2009-04-20 17:16  走马灯\proteus仿真论坛.txt
     文件         205  2009-04-20 17:14  走马灯\proteus仿真论坛.url
     文件         184  2009-04-20 17:17  走马灯\重要说明.txt

评论

共有 条评论

相关资源