打印

请教一个68013的一个很菜的问题,控制输出口LED灯.

[复制链接]
2350|3
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
elife|  楼主 | 2009-3-27 08:05 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
我用的板子接入电脑,能识别为REALTEK ISP设备,也能用CYCONSOLE来download编译后的C51程序.可是为什么不能让接在PA6,PA7的LED灯闪烁呢?程序如下,欢迎指导.谢过.
#include "reg52.h"

unsigned int count,count1,count2,count3;
 xdata volatile unsigned char IFCONFIG          _at_ 0xE601;  // Interface Configuration
 xdata volatile unsigned char PORTACFG          _at_ 0xE670;  // I/O PORTA Alternate Configuration
 sfr OEA=0xb2;
main()
{
 void LedLight();
 void LedOff();

 IFCONFIG=0x80;       
 PORTACFG=0;
 OEA=0xc0; 

 

 while(1)
 {
  LedOff();
  LedLight();
  
  LedOff();
  LedLight();

  LedOff();
  LedLight();
 } 

}

void LedLight()
{
  P0=0x3f;
  for(count=0;count++;count<64000)
  {
      for(count1=0;count1++;count1<60000)
     {
 
     } 
  } 
}

void LedOff()
{
  P0=0xff;
  for(count=0;count++;count<64000)
  {
    for(count1=0;count1++;count1<60000)
    {
 
    } 
   
  }
}

相关帖子

沙发
elife|  楼主 | 2009-4-1 11:31 | 只看该作者

大虾们都很忙啊!顶一下.

使用特权

评论回复
板凳
computer00| | 2009-4-10 01:40 | 只看该作者

你的for循环写错了,条件放中间的。这样闪烁太快,看不出

改成这样试试看:

#include "reg52.h"

unsigned int count,count1,count2,count3;
xdata volatile unsigned char IFCONFIG          _at_ 0xE601;  // Interface Configuration
xdata volatile unsigned char PORTACFG          _at_ 0xE670;  // I/O PORTA Alternate Configuration
sfr OEA=0xb2;
main()
{
void LedLight();
void LedOff();

IFCONFIG=0x80;       
PORTACFG=0;
OEA=0xc0; 



while(1)
{
  LedOff();
  LedLight();
  
  LedOff();
  LedLight();

  LedOff();
  LedLight();


}

void LedLight()
{
  P0=0x3f;
  for(count=0;count<3;count++)
  {
      for(count1=0;count1<60000;count1++)
     {

     } 
  } 
}

void LedOff()
{
  P0=0xff;
  for(count=0;count<3;count++)
  {
    for(count1=0;count1<60000;count1++)
    {

    } 
   
  }
}

使用特权

评论回复
地板
elife|  楼主 | 2009-4-13 08:05 | 只看该作者

多谢00回复,确实是我写错了.

改后再试,发现一个奇怪现象.就是当延时程序放在主程序时,并且变量改为unsigned char 时,能够控制口闪烁,当放在子函数中用unsigned char时,也不行.当改为unsigned int时,无论放在主函数或子函数中时都不行.看了几遍编译后的ASM好象都没问题,很是奇怪.好象程序能执行一遍,灯变化一次后就不动了.请大家再帮想想.会不会板子做的不好,会有这种现象啊?

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

35

主题

392

帖子

4

粉丝