程序如下:
#include<pic.h>
__CONFIG(INTIO&WDTDIS&PWRTDIS&MCLREN&BOREN&PROTECT&CPD);
unsigned char count1;
unsigned char count2;
#define ClrWdt() {__asm__ volatile ("clrwdt");}
#define TX GPIO5
#define RX GPIO4
#define TEst GPIO2
#define T0_10ms 100
void delay()
{
unsigned char i,j;
for(i=255;i>0;i--)
for(j=200;j>0;j--);
}
void init(void)
{
OPTION=0b11000101; //DISEN PULL_UP, TMR0:1:64,
INTCON=0x00; //DISENABLE ALL INTER
CMCON=0X07; //DIS CMCON
TRISIO=0X05; //0x1f 0001 1111 GP0-GP2 IS INPUT,OTHERS OUTPUT
ANSEL=0X05; //0x07 GP0-GP2 IS ADIN
}
void TMR0_init(void)
{
GIE=1; //开总中断
T0IE=1; //开TMR0中断
TMR0=T0_10ms;
T0IF=0;
}
void led(void)
{
TEst=~TEst;
}
void main()
{
init();
TX=0;
RX=0;
TEst=1;
TMR0_init();
//T0IF=0;
//GIE=1; //开总中断
//T0IE=1; //开TMR0中断
//TMR0=T0_10ms;
while(1)
{
led();
delay();
}
}
void interrupt service(void)
{
if(T0IF==1)
{
count1++;
count2++;
if(count1==2)
{
TX=~TX;
count1=0;
}
if(count2==4)
{
RX=~RX;
count2=0;
}
TMR0=T0_10ms;
T0IF=0;
}
//T0IE=0;
}
仿真时进不了while()循环中,也就是说死在中断中了,各位大侠这个怎么回事,急啊,在线等 |