#include <pic.h> #define uint unsigned int #define uchar unsigned char __CONFIG(0x3B31); void delay_ms(uint); void init(); void scan(); void main() { init(); while(1) { scan(); } } void delay_ms(uint x) { uint a,b; for(a=x;a>0;x--) for(b=110;b>0;b--); } void scan() { if(RB0==0)//独立键盘KEY0 { delay_ms(10); if(RB0==0) { while(!RB0);//判断是否松开 PORTD=0x01;//LED灯第一个亮 } } if(RB1==0) { delay_ms(10); if(RB1==0) { while(!RB1); PORTD=0x02; } } if(RB2==0) { delay_ms(10); if(RB2==0) { while(!RB2); PORTD=0x04; } } if(RB3==0) { delay_ms(10); if(RB3==0) { while(!RB3); PORTD=0x08; } } } void init() { TRISB=0xff; //独立键盘引脚配置 TRISD=0; //LED灯引脚配置 PORTD=0; //由于刚上电LED会无次序亮,所以先置低电平熄灭 } 请问各位大神,我这个视频是看郭天祥视频里写的,为什么实现不了按一个独立按键LED灯就随着亮呢,按键按下灯没反应,请问这是怎么回事,我用的是天祥电子开发板。 |
在路上1324 发表于 2015-10-8 09:13
延时函数写错了,无符号整形永远大于0,进延时出不来,没细看
在路上1324 发表于 2015-10-8 09:16
还有延时函数都写错了,都对传x进行操作了,不知道你在干啥,a值一直没变
路人甲111 发表于 2015-10-8 11:09
void delay(uint z)
{
uint i,j;
欢迎光临 (http://www.51hei.com/bbs/) | Powered by Discuz! X3.1 |