本帖最后由 lzc860105 于 2013-6-24 11:36 编辑
高手帮忙 pic30f5013单片机 在线调试全部正常,程序下进去后RB口不能采集到数据,下载后程序能够运行。
#include <p30F5013.h>
#include <P30FXXXX.H>
#include <xc.h>
// FOSC
#pragma config FPR = ECIO_PLL8 // Primary Oscillator Mode (ECIO w/ PLL 8x)
#pragma config FOS = PRI // Oscillator Source (Primary Oscillator)
#pragma config FCKSMEN = CSW_FSCM_OFF // Clock Switching and Monitor (Sw Disabled, Mon Disabled)
// FWDT
#pragma config FWPSB = WDTPSB_16 // WDT Prescaler B (1:16)
#pragma config FWPSA = WDTPSA_512 // WDT Prescaler A (1:512)
#pragma config WDT = WDT_OFF // Watchdog Timer (Disabled)
// FBORPOR
#pragma config FPWRT = PWRT_64 // POR Timer Value (64ms)
#pragma config BODENV = NONE // Brown Out Voltage (Reserved)
#pragma config BOREN = PBOR_ON // PBOR Enable (Disabled)
#pragma config MCLRE = MCLR_EN // Master Clear Enable (Enabled)
// FBS
#pragma config BWRP = WR_PROTECT_BOOT_OFF// Boot Segment Program Memory Write Protect (Boot Segment Program Memory may be written)
#pragma config BSS = NO_BOOT_CODE // Boot Segment Program Flash Memory Code Protection (No Boot Segment)
#pragma config EBS = NO_BOOT_EEPROM // Boot Segment Data EEPROM Protection (No Boot EEPROM)
#pragma config RBS = NO_BOOT_RAM // Boot Segment Data RAM Protection (No Boot RAM)
// FSS
#pragma config SWRP = WR_PROT_SEC_OFF // Secure Segment Program Write Protect (Disabled)
#pragma config SSS = NO_SEC_CODE // Secure Segment Program Flash Memory Code Protection (No Secure Segment)
#pragma config ESS = NO_SEC_EEPROM // Secure Segment Data EEPROM Protection (No Segment Data EEPROM)
#pragma config RSS = NO_SEC_RAM // Secure Segment Data RAM Protection (No Secure RAM)
// FGS
#pragma config GWRP = GWRP_OFF // General Code Segment Write Protect (Disabled)
#pragma config GCP = GSS_OFF // General Segment Code Protection (Disabled)
// FICD
#pragma config ICS = ICS_PGD // Comm Channel Select (Use PGC/EMUC and PGD/EMUD)
#define CAN1TX LATFbits.LATF2
#define CAN1RD LATFbits.LATF3
#define MCU_LED LATFbits.LATF5
#define CAN2TX LATFbits.LATF6
#define CAN2RD LATFbits.LATF7
#define ZINPUT1 PORTBbits.RB5
#define ZINPUT8 PORTBbits.RB9
#define ZINPUT9 PORTDbits.RD0
void initPORT(void)
{ //配置端口B所使用的属性
TRISBbits.TRISB5 = 1; //ZINPUT1
TRISBbits.TRISB9 = 1; //ZINPUT8
//配置端口D所使用的属性
TRISDbits.TRISD0 = 1; //ZINPUT9
//配置端口G所使用的属性
TRISGbits.TRISG0 = 1; //CAN2 TXD
TRISGbits.TRISG1 = 0; //CAN2 RXD
//配置端口F所使用的属性
TRISFbits.TRISF0 = 1; //CAN1 TXD
TRISFbits.TRISF1 = 0; //CAN1 RXD
TRISFbits.TRISF2 = 0; //DISPLAY2
TRISFbits.TRISF3 = 0; //DISPLAY3
TRISFbits.TRISF5 = 0; //DISPLAY1
TRISFbits.TRISF6 = 0; //DISPLAY5
TRISFbits.TRISF7 = 0; //DISPLAY4
}
/*******************************************主函数*****************************************/
int main(void)
{
OSCCONbits.POST = 1; //后分频 1/4
initPORT(); //定义端口属性
CAN1TX=1;
CAN1RD=1;
CAN2TX=1;
CAN2RD=1;
while(1)
{if (ZINPUT8==1)
{ CAN1TX=0;
}
else
{ CAN1TX=1;
}
}
}
|