这是代码:
#include<pic.h>
__CONFIG( FCMEN_OFF & IESO_OFF & CLKOUTEN_OFF & BOREN_OFF & CPD_OFF & CP_OFF & MCLRE_ON & PWRTE_OFF & WDTE_ON & FOSC_INTOSC);
//__CONFIG( FCMEN_OFF & IESO_OFF & CLKOUTEN_OFF & BOREN_ON & CPD_OFF & CP_OFF & MCLRE_OFF & PWRTE_OFF & WDTE_OFF & FOSC_INTOSC);
//__CONFIG(PLLEN_OFF & LVP_OFF & STVREN_OFF & WRT_OFF & BORV_19 ); // 8.63用配置
__CONFIG(PLLEN_OFF & LVP_OFF & STVREN_OFF & WRT_OFF & BORV_LO ); // 8.83用配置
unsigned char state;
unsigned char Receive(void)
{ if(RCIF==0)
{
state=RCREG;
return(state);
}
}
void send(unsigned char state)
{
TXREG=state;
while(TRMT==1);
}
void USART_init(void)
{
SYNC=0;
BRGH=1;
TXEN=1;
TX9 =0;
//BRG16=0;
SPBRG=0X19;
SPEN=1;
CREN=1;
RX9 =0;
OERR=0;
INTCON = 0XC0;
RCIE = 1;//允许USART接收中断
//RCIF = 0; // 清串口中断
//RCIE = 1; // 串口接收中断使能
INTEDG = 1;
}
void Port_init(void)
{
OSCCONbits.IRCF3 = 1; //1
OSCCONbits.IRCF2 = 1; //1
OSCCONbits.IRCF1 = 0; //1
OSCCONbits.IRCF0 = 1; //0 //使用了内部晶振4MHZ,所以不用额外设置
TRISB2=0;
TRISB1=1;
}
void main(void)
{
Port_init();
USART_init();
while(1)
{
Receive();
send(state);
}
}
此帖出自
小平头技术问答
http://bbs.big-bit.com/forum.php ... &fromuid=100824
一周热门 更多>