我买了个JET51仿真器+SH79F166板,用C写了个很简单程序,用P0.0为输出,驱动一个LED,P0.1口为按键输入,设置了P0CR和P0PCR两个寄存器。奇怪的是,P0.1-P0.7的脚会有一个约3ms的低电平出了,系统复位。请指教。谢谢!
/*4MHZ¾§Õñ*/
#include<SH79F166.h>
#define uchar unsigned char
#define uint unsigned int
sbit key=P0^1; //°´¼ü¶¨Òå
sbit led=P0^0; //ledÊä³ö¿Ú¶¨Òå
uchar b; //¶¨ÒåÒ»¸ö״̬±êÖ¾
void delay(uint ms)//ÑÓʱº¯Êý
{
uint i,j;
for(i=ms;i>0;i--)
for(j=21;j>0;j--);
}
void ledflash()//ledÏÔʾº¯Êý
{
if(b==1) //0.5ÃëÉÁÁÁ
{
led=~led;
delay(500);
}
if(b==2) //50mSÉÁÁÁ
{
led=~led;
delay(50);
}
if(b==3) //5mSÉÁÁÁ
{
led=~led;
delay(5);
}
if(b==0) //¹Ø±Õled
{
led=1;
}
if(b>3) //»Øµ½ledÃð״̬
{
b=0;
}
}
void main()
{
P0CR=0x01; //0000 0001 ÉèP0.0ΪÊä³ö£¬P0.1ΪÊäÈë
P0PCR=0xFE; //1111 1110 ÉèP0.1-0.7ÉÏÀµç×è
led=1; //¹ØLED
b=0;
while(1)
{
if(key==0)
{
delay(1);
if(key==0)
{
b++;
while(key==0);
}
}
ledflash(); //ledÏÔʾº¯Êý
}
} |