PIC12F1840串口調(diào)試程序成功
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
問題一直出現(xiàn)在APFCON=0x88;改成APFCON=0x8c;1 = RA4 上具有TX/CK 功能,要仔細(xì)閱讀資料哦?。?!
#include "PIC.h
__CONFIG (FOSC_INTOSC & PWRTE_OFF & MCLRE_OFF &CP_ON & CPD_OFF & BOREN_ON&WDTE_OFF );
__CONFIG (WRT_OFF );
unsigned int aaa,cnt_32ms;
void delay(unsigned int x)
{
unsigned int a,b;
for(a=x;a>0;a--)
for(b=110;b>0;b--);
}
void main()
{
//TRISA=0xf0;
INTCON=0;
//TRISA=0x2F; //王改
TRISA=0x3F; //這不是問題所在
ANSELA=0;
OSCCON = 0X6A;//內(nèi)部晶振定義4M
CLKRCON=0B00010000;
C1ON=0;
OPTION_REG=0X87;
BAUDCON=0; //波特率控制
RCSTA=0X90;
SPBRGL=0X19;
SPBRGH=0X0;
TXSTA=0X24;
//APFCON=0x88; //王改 這里才是問題所在
//APFCON=0x8c;
APFCON=0x8c; //這樣是正確的,不仔細(xì)讀資料導(dǎo)致的錯(cuò)誤。1 = RA4 上具有TX/CK 功能
GIE=1; //開放全局中斷6666666666666666666666666666666666666666
PEIE=1;
RCIE=1;
BRGH=1;
CREN=1;
SPEN=1;
SYNC=0;
//TXIE=1;
TMR0=0;
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
while(1)
{
if(TMR0>=125)
{
TMR0=0;
cnt_32ms++;
}
if(cnt_32ms>=32)
{
cnt_32ms=0;
TXREG=0x12; //每隔1s發(fā)送一個(gè)16進(jìn)制數(shù)0x12
}
}
}
void interrupt usart(void)
{
if(RCIE&&RCIF)
// aaa=RCREG;
//RCIF=0;
TXREG=RCREG;
}