请教,我使用ATMEGA128单片机,PF4-PF7做按键扫描脚,JTAG也使用了PF4-PF7脚,熔丝位的JTAGEN使能,OCDEN 禁止,然后程序开始运行时置位JTD,关闭JTAG,但是JTD不能置1,PF4-PF7不能用做IO口,程序如下
void JTAG_Disable(void)
{
unsigned char temp = 0;
temp = MCUCSR | (1 << JTD);
MCUCSR = temp;
MCUCSR = temp;
}
//-------------------------------------------
void SysInit()
{
JTAG_Disable();
DDRA = 0xff;//PA3,PA4,PA6,PA7设置为输出
PORTA = 0xff;
DDRB = (1 << RS) | (1 << RW) | (1 << EN) | (1 << LCDRESET);
PORTB= 0xff;
DDRD = (1 << LCDCS1) | (1 << LCDCS2) | (1 << SDAT) | (1 << SCLT);
DDRD &=~( (1 << KEY2) | (1 << KEY9));
PORTD = 0xff;
DDRG = (1 << LCDLED) | (1 << BEEP)| (1 << FLASHALE)| (1 << FLASHWE) | (1 << FLASHOE);
PORTG = 0xff;
DDRE = (1 << FLASH_CS) | (1 << KEY7);
DDRE &=~( (1 << KEY6) | (1 << KEY8));
PORTE = 0xff;
DDRF = (1 << A16) | (1 << A17)| (1 << A18) | (1 << KEY1) | (1 << KEY3)| (1 << KEY5);
DDRF &= ~(1 << KEY4);
PORTF = 0xff;
UCSR0B = 0x00; //disable while setting baud rate //UART0 INIT
UCSR0A = 0x00;
UCSR0C =(1<<UCSZ01)|(1<<UCSZ00);//8bit+1bit stop
UBRR0L=71;
UBRR0H=0;
UCSR0B =(1 << RXCIE) |(1<<RXEN0)|(1<<TXEN0);//RXCEN TXCEN 接收中断使能
UCSR1B = 0x00; //disable while setting baud rate //UART1 INIT
UCSR1A = 0x00;
UCSR1C = (1<<UCSZ11)|(1<<UCSZ10);//8bit+1bit stop
UBRR1L=71;
UBRR1H=0;
UCSR1B =(1 << RXCIE1) | (1<<RXEN1)|(1<<TXEN1);//RXCEN TXCEN 接收中断使能
CLR_FLASHALE;
SET_FLASHWE;
SET_FLASHOE;
TCCR0=0x07; //普通模式,OC0不输出,1024分频
TCNT0=147; //初值,定时为10ms
TIFR=0x01; //清中断标志位
TIMSK=0x01; //使能定时器0溢出中断
EICRB = 0x80;//INT7下降沿中断
EIMSK = 0x80;//打开外部中断7
cli();
wdt_disable();//调用WDT.H的函数才可以初始化看门狗,直接写WDTCR,不能分频
wdt_enable(WDTO_2S);
sei();
}
JTD到底应该怎么关闭,哪位能指点下 |