本帖最后由 小白变大白 于 2013-9-11 11:28 编辑
是232转485的。485有个发送接收使能端,还是以是485的使能端了。谢谢各位#include <htc.h>
//#include <pic.h>
//#define _XTAL_FREQ 10000000 //4Mhz FRC internal osc
//__CONFIG(FOSC_HS & WDTE_OFF & PWRTE_OFF & MCLRE_ON & CP_OFF & CPD_OFF & BOREN_ON & IESO_ON & FCMEN_ON & LVP_OFF);
//__CONFIG(BOR4V_BOR40V & WRT_OFF);
__CONFIG(0x28e2); //外部时钟10M
__CONFIG(0x3eff);
void serial_init();
char data = 0;
void serial_init()
{
TRISB4=0; /* 使能485*/
RB4 = 1;
SPBRG = 64; /*波特率 */
SPEN = 1; /*使能EUART,自动配置RX为输入*/
RCIE = 1;
GIE = 1;
PEIE = 1;
CREN = 1; /*使能接收电路*/
SYNC = 0; /*异步操作*/
}
void interrupt ISR(void)
{
if(1 == PIR1bits.RCIF) /*----- rec interrupt ---*/
{
data = RCREG;
}
}
int main()
{
serial_init();
/*---------TEST LED-----------*/
TRISCbits.TRISC0 = 0;
PORTCbits.RC0 = 0;
while(1)
{
if(data == 0x55)
PORTCbits.RC0 = 1;
}
return 0;
}
|