用的是PIC24FJ16GA004单片机
PORTA端口配置如下
FUN PIN NO. I/O 1/0
PORTA
RA0 19 VREF 1 1
RA1 20 模拟 IN 1
RA2 30 OSCO 0 0
RA3 31 OSCI 1 1
RA4 34 未用 0
RA7 13 数字 IN 1
RA8 32 未用 0
RA9 35 未用 0
RA10 12 数字 IN 1
初始化程序如下:
_CONFIG1(JTAGEN_OFF & GCP_OFF & GWRP_OFF &BKBUG_OFF & COE_OFF & ICS_PGx3 & FWDTEN_OFF )// &WINDIS_OFF & FWPSA_PR128 & WDTPS_PS32768);
_CONFIG2(IESO_OFF & FNOSC_PRI & FCKSM_CSDCMD & OSCIOFNC_ON & POSCMOD_HS & IOL1WAY_OFF );
void init_mcu(void)
{
CLKDIV = 0x0000;
// set ADC
AD1CON1 = 0x00E4;
AD1CON2 = 0x003A;
AD1CON3 = 0x0101;
AD1PCFGbits.PCFG1 = 0; // AN1 as Analog Input
AD1PCFGbits.PCFG2 = 0; // AN2 as Analog Input
AD1PCFGbits.PCFG3 = 0; // AN3 as Analog Input
AD1PCFGbits.PCFG4 = 0; // AN4 as Analog Input
AD1PCFGbits.PCFG5 = 0; // AN5 as Analog Input
AD1PCFGbits.PCFG6 = 0; // AN6 as Analog Input
AD1PCFGbits.PCFG7 = 0; // AN7 as Analog Input
AD1PCFGbits.PCFG8 = 0; // AN8 as Analog Input
AD1PCFGbits.PCFG9 = 1; // AN9 as Digital Input
AD1PCFGbits.PCFG10 = 1; // AN10 as Digital Input
AD1CSSL = 0x0000;
// Set UART:串口使能:选择异步高速方式传输9位数据
RPINR18bits.U1RXR = 10; // Make Pin RP10 U1RX
RPOR5bits.RP11R = 3; // Make Pin RP11 U1TX
U1BRG = BRGVAL; // BAUD Rate Setting for 9600
U1MODE = 0x8000; // Reset UART to 8-n-1, alt pins, and enable
U1STA = 0x0440; // Reset status register and enable TX & RX
PMCONbits.PMPEN = 0; // Disable parallel port
PMAEN = 0;
_U1RXIF=0; // Clear UART RX Interrupt Flag
// Set up I/O ports
TRISA = 0x048B;
PORTA = 0x0000;
LATA = 0x0000;
}
PORTA是读端口,用ICD2仿真时
RA10接一个上拉电阻,奇怪,上电后为低电平,我想要的是它作为I/O口,读数用的,结果莫名其妙的给我将电平降低了?
RA7也是接一个上拉电阻,上电后为高电平。
但是PORTA的读数一直是0x0080,调试时没有反应 |