此程序用pic16f877的芯片,管脚改用PORTB和PORTD能够正常实现,不知道为啥886上不行了
#include<pic.h>
#define uchar unsigned char
#define uint unsigned int
void delay(uint x);
void init();
void scan();
void main()
{
init(); //初始化
while(1)
{
scan(); //扫描按键
}
}
void delay(uint x)
{
uint a,b;
for(a=x;a>0;a--)
for(b=110;b>0;b--);
}
void init()
{
TRISB=0X0F;
TRISA=0;
PORTA=0;
}
void scan()
{
if(RB0==0)
{
delay(10);
if(RB0==0)
{
while(!RB0);
PORTA=0x01;
}
}
if(RB1==0)
{
delay(10);
if(RB1==0)
{
while(!RB1);
PORTA=0x02;
}
}
if(RB2==0)
{
delay(10);
if(RB2==0)
{
while(!RB2);
PORTA=0x04;
}
}
if(RB3==0)
{
delay(10);
if(RB3==0)
{
while(!RB3);
PORTA=0x08;
}
}
} |