智能车制作

标题: 关于上拉电阻 [打印本页]

作者: chenrunshe_007    时间: 2009-4-19 15:46
标题: 关于上拉电阻
请问一下上拉电阻有什么用?
//如下程序,要设置PUCR_PUPBE=1才行
//通过A口的2个按键来控制B口的2个灯,没有PUCR_PUPBE=1就不行。
#include <hidef.h>      /* common defines and macros */
#include <mc9s12dg128.h>     /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12dg128b"
#include <hidef.h>      /* common defines and macros */
void delay(int cnt)
{
int i,j;
for(i=0;i<cnt;i++)
{j=1300;
  while(j--);
}
}
void delay00(void)
{
  
unsigned  int m,n,s;
for(m=20;m>0;m--)
  for(n=20;n>0;n--)
   for(s=3000;s>0;s--);
}
void main()
{

  
  EnableInterrupts;
  DDRB=0xFF;
  DDRA=0x00;
  PORTB=0xFF;
  PUCR_PUPBE=1;

while(1)
  {
  if((PORTA&0xff)==0xfe)
   {
  delay(20);
  if((PORTA&0xff)==0xfe)
   {
   
  PORTB=0xFE;
  delay00();
  PORTB=0xFF;
   }
   }        
  if((PORTA&0xff)==0xfd)
   {
  delay(20);
  if((PORTA&0xff)==0xfd)
   {
  PORTB=0xFd;
  delay00();
  PORTB=0xFF;
   }
   }
  }
}
作者: gxuyang    时间: 2009-4-19 15:46
强悍。。。
作者: chenrunshe_007    时间: 2009-4-19 16:35
顺便加多一句:如果没有上拉这句(PUCR_PUPBE=1;)的话,我单步运行时
EnableInterrupts;
  DDRB=0xFF;
  DDRA=0x00;
  PORTB=0xFF;
它运行到到DDRA=0x00这句就跳过PORTB=0xFF,直接到while(1)这里了。
作者: chenrunshe_007    时间: 2009-4-20 13:31
3# gxuyang
差多了,老杨,你又不是知道我的水平,看哪位高手能帮我们解决一下啊
作者: yangzan66    时间: 2010-4-6 10:26
hehe
作者: wushshsha    时间: 2012-4-23 20:38





欢迎光临 智能车制作 (http://111.231.132.190/) Powered by Discuz! X3.2