找回密码
 立即注册

QQ登录

只需一步,快速开始

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

请问请问这段代码中的变量TCount是什么意思?该程序中是怎么实现加速减速的?谢谢...

[复制链接]
跳转到指定楼层
楼主
ID:214531 发表于 2017-6-25 20:55 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
//可调控的跑马灯
#include<reg52.h>
#define uchar unsigned char       
#define uint unsigned int
uchar ModeNo;//模式
uint Speed;
uchar TCount=0;////////////?????????????
uchar Idx;
uchar mb_Count=0;
bit Dirtect=1;                                       
uchar code DSY_CODE[]={0xC0,0XF9, 0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
uint code sTable[]={0,1,3,5,7,9,15,100,200,230,300,350};

void Delay(uint x)               
{
uchar i;
while(x--) for(i=0;i<120;i++);
}               

uchar GetKey()//获取按键信息
{
uchar K;
if(P2==0xFF) return 0;
Delay(10);
switch(P2)
{                         case 0xFE: K=1;break;                         case 0xFD: K=2;break;                         case 0xFB: K=3;break;                         default:   K=0;
}                         while (P2!=0xFF);                         return K;
}

void Led_Demo(uint Led16)
{
P1=(uchar)(Led16&0x00FF);
P0=(uchar)(Led16>>8);
}

void T0_INT() interrupt 1//模式内容
{
if(++TCount<Speed) return;/////////////////////?????????
TCount=0;
switch(ModeNo)
{
case 0:Led_Demo(0x0001<<mb_Count);break;
case 1:Led_Demo(0x8000>>mb_Count);break;
case 2:if(Dirtect)Led_Demo(0x000F<<mb_Count);
Else
Led_Demo(0xF000>>mb_Count);
if(mb_Count==15) Dirtect=!Dirtect;break;
case 3:if(Dirtect)Led_Demo(~(0x000F<<mb_Count));
else                          Led_Demo(~(0xF000>>mb_Count));
if(mb_Count==15) Dirtect=!Dirtect;
break;
case 4:if(Dirtect)Led_Demo(0x003F<<mb_Count);
else                          Led_Demo(0xFC00>>mb_Count);
if(mb_Count==15) Dirtect=!Dirtect;break;
case 5:if(Dirtect)Led_Demo(0x0001<<mb_Count);
else                   Led_Demo(0x8000>>mb_Count);
if(mb_Count==15) Dirtect=!Dirtect;
break;
case 6:if(Dirtect)Led_Demo(~(0x0001<<mb_Count));
else                   Led_Demo(~(0x8000>>mb_Count));
if(mb_Count==15) Dirtect=!Dirtect;break;
case 7:if(Dirtect)Led_Demo(0xFFFE<<mb_Count);
else                   Led_Demo(0x7FFF>>mb_Count);
if(mb_Count==15) Dirtect=!Dirtect;break;
default:break;
}
mb_Count=(mb_Count+1)%16;
}

void KeyProcess(uchar Key)//按键处理选择模式
{
switch(Key)
{                         case 1:
Dirtect=1;mb_Count=0;
ModeNo=(ModeNo+1)%8;
P3=DSY_CODE[ModeNo];break;                         case 2:
if(Idx>1) Speed=sTable[--Idx];break;                         case 3:
if(Idx<15) Speed=sTable[++Idx];
}
}

void main()
{
uchar Key;
P0=P1=P2=P3=0xFF;
ModeNo=0;Idx=4;
P3=DSY_CODE[ModeNo];
IE=0x82;
TMOD=0x00;
TR0=1;
while(1)
{
Key=GetKey();
if(Key!=0) KeyProcess(Key);
}
}
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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