Я пытаюсь установить связь между моим ПК и PIC16f873a, используя vb.net на ПК и C ++ в PIC. Я использую max232. Я не могу зажечь свет нажатием кнопки на ПК:
РЕДАКТИРОВАТЬ:
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Close()
End Sub
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
Try
SerialPort1.Open()
Button7.Enabled = True
Button6.Enabled = False
GroupBox1.Enabled = True
GroupBox2.Enabled = True
GroupBox4.Enabled = True
ToolStripStatusLabel1.Text = "Connect to COM3"
Catch ex As Exception
Console.WriteLine(ex.Message)
MsgBox("COM. Port Not Found", MsgBoxStyle.Exclamation)
End Try
End Sub
Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
SerialPort1.Close()
Button7.Enabled = False
Button6.Enabled = True
GroupBox1.Enabled = False
GroupBox2.Enabled = False
GroupBox4.Enabled = False
ToolStripStatusLabel1.Text = "No Connection"End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
SerialPort1.Write(CStr(Int(1)))
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
SerialPort1.Write(Chr(2))
End Sub
Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
SerialPort1.Write(Chr(CInt(TextBox1.Text)))
End Sub
End Class
И мой ПИК это:
#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;
}
}
}
Я использую 20 МГц XTAL.
Задача ещё не решена.
Других решений пока нет …