main.c

来自「AVR单片机中的DI数字量输入处理程序 已成成功使用 欢迎大家下载叫交流」· C语言 代码 · 共 40 行

C
40
字号
#include <iom64.h>        
unsigned int result=0;  
unsigned int DI_result=0;

void delay()
  {
     unsigned int i;
     for(i=0;i<50;i++);     
  }

unsigned int switpressed(void)
{
  unsigned int swit;
  swit=PINB; 
  swit=(swit>>4);
  if(swit==0x00)
    return 0;
  else
    return 1;
}  

unsigned int switscan(void)
{
   delay(); 
    if(switpressed()==1)
      result=(PINB&0xF0);
    else  
      result=0;
    return result; 
}
void main(void)
{
   DDRB|=0x0F;     //定义PB0、PB1、PB2为输出,PB4、PB5、PB6、PB7为输入 
   while(1)
   { 
       if(switpressed()==1)
       DI_result=switscan(); 
   };
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?