串行通信PC×PIC 我试图在PC机和PIC16F83A之间进行通信,在PC机上使用VB.NET和C++中的P+通信。我用的是max232。我无法通过按下电脑上的按钮来点灯: 编辑:
我的照片是:串行通信PC×PIC 我试图在PC机和PIC16F83A之间进行通信,在PC机上使用VB.NET和C++中的P+通信。我用的是max232。我无法通过按下电脑上的按钮来点灯: 编辑:,c++,vb.net,pic,C++,Vb.net,Pic,我的照片是: #define LED1 PORTB.f0 unsigned char input; void main() { TRISB = 0x00; PORTB = 0b00001110; SPBRG=129; TXSTA=0b00100110; RCSTA=0b10010000; UART1_Init(9600); // initialize USART module delay_ms(100);
#define LED1 PORTB.f0
unsigned char input;
void main() {
TRISB = 0x00;
PORTB = 0b00001110;
SPBRG=129;
TXSTA=0b00100110;
RCSTA=0b10010000;
UART1_Init(9600); // initialize USART module
delay_ms(100); // (8 bit, 9600 baud rate, no parity bit...)
while (1) {
PORTB.F1 = 1;
if (Uart1_Data_Ready()) {
input=uart1_read();
if (input == 1)
LED1 = 1;
else
LED1 = 0;
}
}
}
我使用的是20MHz xtal。您确定
SerialPort1
对象使用正确的设置连接到正确的端口吗?你没有表现出来。你能使用终端应用在PC上运行吗?ups,对不起,我很确定它连接到了正确的端口。我使用COM3连接max 232,如果未连接,将显示错误消息。您是发送字符“1”还是发送值1?PIC代码需要一个ASCII值为1的单个字符,请尝试将PIC代码改为if(input='1')
。您需要初始化串行端口设置以匹配PIC中的设置(9600波特等)。您能给我们看一下原理图吗?
#define LED1 PORTB.f0
unsigned char input;
void main() {
TRISB = 0x00;
PORTB = 0b00001110;
SPBRG=129;
TXSTA=0b00100110;
RCSTA=0b10010000;
UART1_Init(9600); // initialize USART module
delay_ms(100); // (8 bit, 9600 baud rate, no parity bit...)
while (1) {
PORTB.F1 = 1;
if (Uart1_Data_Ready()) {
input=uart1_read();
if (input == 1)
LED1 = 1;
else
LED1 = 0;
}
}
}