PIC-RB7是否有价值? [英] PIC - is there a value for RB7?

查看:108
本文介绍了PIC-RB7是否有价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读取了端口RB7,并检查了值.如果RB7上有输出,我希望芯片上的LED点亮(LED D1),但是即使没有任何连接到RB7,它也会一直点亮.我做错了什么?那就是PIC 18F4550,它是用mplab v8.63和C18编译器编写的.

I read the port RB7, and in the if a check the value. if there is output on RB7 I want that the led on my chip light up (led D1), but it burns all the time even when there is nothing connected to RB7. What i'm doing wrong? That's the PIC 18F4550 It's written in mplab v8.63 and the C18 compiler.

void main (void) 
{  
 TRISD = 0x00;            // PORTD  als uitgang 
 TRISB = 0b00110000;      // RB4 en RB5 als ingang 

 RCONbits.IPEN = 0;    // prioriteit uit 
 INTCONbits.GIE = 1;   // enable interrupt 
 INTCONbits.RBIE = 1;  // interrupt portB aan 

 TRISBbits.TRISB7 = 0; 
 TRISBbits.TRISB6 = 0; 
 TRISBbits.TRISB3 = 0; 

 while(1) 
 {  
  _asm sleep _endasm  
 } 
} 
#pragma interrupt ISR 
void ISR (void) 
{ 
 if (INTCONbits.RBIF==1) 
 {   
  if(LATBbits.LATB7 == 1)    // value on RB7 ? 
  { 
   LATDbits.LATD1 ^= 1;    // D2 togglen 
  } 
 }  
 INTCONbits.RBIF = 0; 
}

推荐答案

三件事:

  1. 无论您是否连接了任何输入,输入始终为高电平或低电平.您有适当的上拉或下拉电路吗?
  2. 您可能需要对输入进行去抖动,以防止单个输入触发多个状态更改.
  3. 看起来好像您在启动时都没有设置输出D1.我不认为它默认为任何特定状态.

这篇关于PIC-RB7是否有价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆