Let's Make Robots!

PIC28X2 VB Simple High Low Serial Interface

Hey all i'm new here so i would gladly aprechiate any help on this topic
I've got my picaxe chip plugged in and i have logicator to write programs to the chip
In the BASIC part of flowsheet programming i don't understand how to receive the commands from visual basic

BASIC CODE

main:    //MAIN LOOP FOR CHIP
serin 1,T9600, b1 //Check for serial command and store into variable b1
if b1 = 0 then p0high //Go to p0high if variable b1 = 0
if b1 = 1 then p0low //Go to p0low if variable b1 = 1
goto main

p0high:
high b.0 //Turns light on output pin b0
goto main

p0low:
low b.0 //Turns light off output pin b0
goto main


Can anyone help me find this solution?
I'm sending a serial command to the chip as chr(&h48) as asci 0 and chr(&h49) as asci 1
The light flickers when ever i send the commands but ultimately stays on?

VB CODE

 


Public Class Form1

//FORM LOADS UP
    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        SerialPort1.PortName = "COM1" //SET SERIAL PORT 1 COM PORT NAME
        SerialPort1.BaudRate = "9600" //SET PORT BAUD RATE
        SerialPort1.StopBits = IO.Ports.StopBits.One //SET STOP BITS TO 1
        SerialPort1.Parity = IO.Ports.Parity.None //SET ZERO PARITY
        SerialPort1.DataBits = 8 //SET DATABITS TO 8
        Try //TRY TO OPEN THE COM PORT
            SerialPort1.Open()
        Catch ex As Exception //IF THE COMPORT IS ALREADY OPEN CLOSE IT THEN OPEN IT
            SerialPort1.Close()
            SerialPort1.Open()
        End Try
    End Sub

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        SerialPort1.Write(Chr(&H48)) 'Turn light off //SEND 0 TO CHIP
    End Sub

    Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
        SerialPort1.Write(Chr(&H49)) 'Turn light on //SEND 1 TO CHIP
    End Sub

//FORM IS CLOSED OT EXITED
    Private Sub Form1_FormClosed(sender As Object, e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        SerialPort1.Close() //CLOSE THE SERIAL PORT
    End Sub
End Class

 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

This is what I think should work. Others can correct at will :D

main:    'MAIN LOOP FOR CHIP
serrxd #b1 'Check for serial command and store into variable b1
if b1 = 0 then p0high 'Go to p0high if variable b1 = 0
if b1 = 1 then p0low 'Go to p0low if variable b1 = 1
goto main

p0high:
high b.0 'Turns light on output pin b0
goto main

p0low:
low b.0 'Turns light off output pin b0
goto main

 

Just tested your code, it dont work?

As you can see 0 or "0" turns b.1 on

BUT i also have 1 or "1" which turns b.0 OFF

Yes this is weird because it turns on and off b.1 no matter if i send 1 or 0 to the chip.... Wth is this kinda behavour??

main:
serin 1,T9600, b1
if b1 = 0 or b1 = "0" then p0high
if b1 = 1 or b1 = "1" then p0low
goto main

p0high:
high b.1
goto main

p0low:
low b.0
goto main

Asuming the light is not flashing because it is somehow connected to the serial input pin...

Also: the last posted code shows actions on two diffent pins B.0 and B.1 but that might be a typo.

The serin command stores the binary data in the variable unless you use the # sign (serin 1, T9600, #b1) which stores the ascII value. You can check the actual value by using the debug command.

To make sure, change the VB code to send binary 0 and 1  / Chr(0) and Chr(1)

Another thing you might try to make sure the right data is collected is to use a marker.

serin 1, T9600, (0), b1

that statement will wait to fill the variable b1 until a binary zero has been successfully recieved. Of course you can choose to make the marker anything you want like the string "ABC" serin 1, T9600, ("ABC"), b1

finaly: make sure you use the right baud rate T9600_8 for 8mhz (default on the 28X2)

Going to try that now thanks mint :)

Thank you!, it was my vb code! chr(0) & chr(1) was the problem, i'm now using a numeric box to print these values. Thanks mint you are a star!


BASIC CODE

main:       serrxd b1
               if b1 = 1 then high b.0
               else low b.0
               endif
               if b1 = 2 then high b.1
               else low b.1
               endif
               goto main:
       
'reduce download time
#no_table
#no_data

VB CODE

Public Class Form1
    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        SerialPort1.PortName = "COM1"
        SerialPort1.BaudRate = "9600"
        SerialPort1.StopBits = IO.Ports.StopBits.One
        SerialPort1.Parity = IO.Ports.Parity.None
        SerialPort1.DataBits = 8
    End Sub

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        SerialPort1.Open()
        SerialPort1.Write(Chr(NumericUpDown1.Value))
        SerialPort1.Close()
    End Sub
End Class