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

[复制链接]
3206|3
 楼主| elife 发表于 2009-3-27 08:05 | 显示全部楼层 |阅读模式
我用的板子接入电脑,能识别为REALTEK&nbsp;ISP设备,也能用CYCONSOLE来download编译后的C51程序.可是为什么不能让接在PA6,PA7的LED灯闪烁呢?程序如下,欢迎指导.谢过.<br />#include&nbsp;&quot;reg52.h&quot;<br /><br />unsigned&nbsp;int&nbsp;count,count1,count2,count3;<br />&nbsp;xdata&nbsp;volatile&nbsp;unsigned&nbsp;char&nbsp;IFCONFIG&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_at_&nbsp;0xE601;&nbsp;&nbsp;//&nbsp;Interface&nbsp;Configuration<br />&nbsp;xdata&nbsp;volatile&nbsp;unsigned&nbsp;char&nbsp;PORTACFG&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_at_&nbsp;0xE670;&nbsp;&nbsp;//&nbsp;I/O&nbsp;PORTA&nbsp;Alternate&nbsp;Configuration<br />&nbsp;sfr&nbsp;OEA=0xb2;<br />main()<br />{<br />&nbsp;void&nbsp;LedLight();<br />&nbsp;void&nbsp;LedOff();<br /><br />&nbsp;IFCONFIG=0x80;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;PORTACFG=0;<br />&nbsp;OEA=0xc0;&nbsp;<br /><br />&nbsp;<br /><br />&nbsp;while(1)<br />&nbsp;{<br />&nbsp;&nbsp;LedOff();<br />&nbsp;&nbsp;LedLight();<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;LedOff();<br />&nbsp;&nbsp;LedLight();<br /><br />&nbsp;&nbsp;LedOff();<br />&nbsp;&nbsp;LedLight();<br />&nbsp;}&nbsp;<br /><br />}<br /><br />void&nbsp;LedLight()<br />{<br />&nbsp;&nbsp;P0=0x3f;<br />&nbsp;&nbsp;for(count=0;count++;count&lt64000)<br />&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for(count1=0;count1++;count1&lt60000)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<br />&nbsp;&nbsp;}&nbsp;<br />}<br /><br />void&nbsp;LedOff()<br />{<br />&nbsp;&nbsp;P0=0xff;<br />&nbsp;&nbsp;for(count=0;count++;count&lt64000)<br />&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;for(count1=0;count1++;count1&lt60000)<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<br />&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;}<br />}<br />
 楼主| elife 发表于 2009-4-1 11:31 | 显示全部楼层

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

  
computer00 发表于 2009-4-10 01:40 | 显示全部楼层

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

改成这样试试看:<br /><br />#include&nbsp;&quot;reg52.h&quot;<br /><br />unsigned&nbsp;int&nbsp;count,count1,count2,count3;<br />xdata&nbsp;volatile&nbsp;unsigned&nbsp;char&nbsp;IFCONFIG&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_at_&nbsp;0xE601;&nbsp;&nbsp;//&nbsp;Interface&nbsp;Configuration<br />xdata&nbsp;volatile&nbsp;unsigned&nbsp;char&nbsp;PORTACFG&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_at_&nbsp;0xE670;&nbsp;&nbsp;//&nbsp;I/O&nbsp;PORTA&nbsp;Alternate&nbsp;Configuration<br />sfr&nbsp;OEA=0xb2;<br />main()<br />{<br />void&nbsp;LedLight();<br />void&nbsp;LedOff();<br /><br />IFCONFIG=0x80;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />PORTACFG=0;<br />OEA=0xc0;&nbsp;<br /><br /><br /><br />while(1)<br />{<br />&nbsp;&nbsp;LedOff();<br />&nbsp;&nbsp;LedLight();<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;LedOff();<br />&nbsp;&nbsp;LedLight();<br /><br />&nbsp;&nbsp;LedOff();<br />&nbsp;&nbsp;LedLight();<br />}&nbsp;<br /><br />}<br /><br />void&nbsp;LedLight()<br />{<br />&nbsp;&nbsp;P0=0x3f;<br />&nbsp;&nbsp;for(count=0;count&lt3;count++)<br />&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for(count1=0;count1&lt60000;count1++)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<br />&nbsp;&nbsp;}&nbsp;<br />}<br /><br />void&nbsp;LedOff()<br />{<br />&nbsp;&nbsp;P0=0xff;<br />&nbsp;&nbsp;for(count=0;count&lt3;count++)<br />&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;for(count1=0;count1&lt60000;count1++)<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<br />&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;}<br />}<br />
 楼主| elife 发表于 2009-4-13 08:05 | 显示全部楼层

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

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

本版积分规则

35

主题

408

帖子

4

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