我这个程序问题在哪里

[复制链接]
2792|11
 楼主| zxser09 发表于 2009-12-23 19:53 | 显示全部楼层 |阅读模式
#include<reg51.h>
#include <intrins.h>
#define unc unsigned char
#define unt unsigned int
/*unc code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,
       0x7d,0x07,0x7f,0x6f};
sbit duan=P1^0;
sbit wei=P1^1;*/
sbit liu=P0;
void delay(unt);
void init();
void main()
{
init();
while(1)
{
liu=_crol_(liu,1);
P0=liu;
delay(1000);
}
}
void delay(unt e)
{
  unt x,y;
  for(x=e;x>0;x--)
   {
   for(y=110;y>0;y--);
   }
}
void init()
{
liu=0xfe;
}

为什么我这个程序流水灯不会流呢?望解答,谢谢!
NE5532 发表于 2009-12-23 20:29 | 显示全部楼层
告诫所有新入门的单片机初学者:程序不要写上一大堆再来调,你认为你是在“奋笔疾书”,我认为你是在“粪”笔疾书。

解决方案参考:《脱离仿真器玩单片机》
 楼主| zxser09 发表于 2009-12-23 20:48 | 显示全部楼层
:(,我有开发版的··但是我想先通过仿真器先玩玩先,这样程序和硬件可以都得到提高撒!1
NE5532 发表于 2009-12-23 20:50 | 显示全部楼层
你就是用仿真,也得一步一步写了来仿真。光写不调,不要说对初学者,对我都是灾难!我最怕就是写上2、300行都没有调试过的程序!
Dai_Weis 发表于 2009-12-23 21:38 | 显示全部楼层
从基本功能开始写,开始调,一点一点完成,别一口气把程序抄完,那样就没有意义了
 楼主| zxser09 发表于 2009-12-23 22:10 | 显示全部楼层
我是想用用 延时 和初始化功能``哪知道不行。
chfirst 发表于 2009-12-23 22:36 | 显示全部楼层
sbit liu=P0;
sbit不是定义位的嘛,这不对吧。
 楼主| zxser09 发表于 2009-12-23 22:59 | 显示全部楼层
也就是说 sbit liu=P1^0;  
要这样具体到某个引脚吗?
norman33 发表于 2009-12-24 10:28 | 显示全部楼层
sbit是定义单个的位变量,P0口有P0.0~P0.7 8个端口也就有8位,如果要操作P0口就要定义成unsigned char型,对于单个的P0.0或者P0.1等就用sbit定义 例如P0.0端口的话sbit liu=P0^0,其余的可以依葫芦画瓢
杜专 发表于 2009-12-24 12:01 | 显示全部楼层
反质子 发表于 2009-12-24 16:10 | 显示全部楼层
恩 sbit liu=P0 错
直接P0左移啊
yangjiang1989 发表于 2009-12-30 23:58 | 显示全部楼层
#include<reg51.h>
#include <intrins.h>
#define unt unsigned int
#define uchar unsigned char
uchar liu;
void delay(unt);
void init();
void main()
{
init();
while(1)
{
P0=liu;
liu=_crol_(liu,1);
delay(1000);
}
}
void delay(unt e)
{
unt x,y;
for(x=e;x>0;x--)
{
for(y=110;y>0;y--);
}
}
void init()
{
liu=0xfe;
}
您需要登录后才可以回帖 登录 | 注册

本版积分规则

81

主题

208

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部