PIC12F1840串口调试程序成功
扫描二维码
随时随地手机看文章
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
问题一直出现在APFCON=0x88;改成APFCON=0x8c;1 = RA4 上具有TX/CK 功能,要仔细阅读资料哦!!!
#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;//内部晶振定义4M
CLKRCON=0B00010000;
C1ON=0;
OPTION_REG=0X87;
BAUDCON=0; //波特率控制
RCSTA=0X90;
SPBRGL=0X19;
SPBRGH=0X0;
TXSTA=0X24;
//APFCON=0x88; //王改 这里才是问题所在
//APFCON=0x8c;
APFCON=0x8c; //这样是正确的,不仔细读资料导致的错误。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发送一个16进制数0x12
}
}
}
void interrupt usart(void)
{
if(RCIE&&RCIF)
// aaa=RCREG;
//RCIF=0;
TXREG=RCREG;
}