+ Reply to Thread
Results 1 to 2 of 2

Thread: Changing variables through serial port

  1. #1
    pingouin Newbie
    Join Date
    Aug 2003
    Posts
    3

    Default Changing variables through serial port

    I would like to slap my Psion 3a ( :shock: ) running a VT100 terminal emulator to a 16F872 (ok, I would be using a Max232 with the PIC to do the serial stuff). What I have in mind is to be able to check and change variables in my program from the Psion. To do so, I thought on creating a kind of parser in the code in the PIC to handle the commands: for instance, if I typed "get A" and pressed return, the output would be something like

    A = 42
    OK>

    AFAIK, one way (conceptually speaking since I do not know if it would fly in PIC/BASIC) to achieve that is to create a buffer to hold X characters and read the last X characters comming off the serial port up to a carriage return (or whatever is put out when you hit the enter key) and then start looking for the right patterns). Is that the best way to do this in this PIC? Would it be a better way to do so? Has any of you done something similar and could show me some pointers?

    Also, I was planning on doing that in PIC/BASIC as opposite to assembly because the last time I used assembly was in a ZX80. ops: Would it be a bad idea to use BASIC?


  2. #2
    ivancho Newbie
    Join Date
    Aug 2003
    Location
    Kansas
    Posts
    333

    Default

    I have not really used a VT100 terminal for my serial comunications. I normally just do a VB program that controls the Serial Port and shows me what is happening.

    I am going to suppose then that a VT100 terminal emulator sends everything you type serially when a enter is pressed.

    PICBASIC PRO doesn't have the ability to handle strings. So to type "get A" is not the best idea....... a good idea is to create your own protocol..... can you send ESC (ASCII 27d)? You could make ESC + 1 be the "GET" comand so that whatever comes after ESC + 1 is the letter to get. (By the way the letter "A" is ASCII 65d or 41 hex, was that what you meant?)

    So the program in the PIC would be something along the lines
    Code:
    SERIAL-IN Pin, baudrate, WAIT for ESC, VAR1, VAR2
    IF VAR1=1 the  GET ASCII value for VAR2
    
    in PICBASIC would be along the terms of:

    Code:
    COMMAND var byte
    Letter va Byte
    
    Loop:
    Serin Pin#,BaudRate, [27], COMMAND,Letter  'Waits for ESC (ASCII 27)
    Select Case COMMAND
    
    Case "1"
      Serout Pin#, BaudRate, [Letter, "=", #Letter, "d" 10, 13]
    Case else
      Serout Pin#, BaudRate, ["Unknown Command", 10, 13]
    end select
    
    goto Loop
    
    So if you were to send serially a ESC + 1 + A (ASCII 27d, 49d, 65d) you will receive serially...

    A= 65d

    Since A is ASCII 65 decimal

    i hope it gives you some ideas

    Ivancho

+ Reply to Thread

Tags for this Thread