PC to Pic data transfer of control values - best way ?

Status
Not open for further replies.

Wp100

Well-Known Member
Hi,

There is a lot of info on various ways to convert pic hex values to ascii for transmission to the PC.

However I'm looking at sending multiple control values from the PC to the Pic for Timers and Temp control such as 19:21, 14.2c and function controls with Y or N.

The basic way I can see to do it is, if its not a Y or N character then store the next 1 ,2 or 3 bytes in registers until CR is sent, then use an ascii to hex converter.

While it works, it does seem a long hard way of doing things, so wondered what kind of methods other members use and if there are some easier ways of doing this type of data transfer.



A handy snippet of working code I found
Code:
ASCSum2Hex   ; Local sub for RX handler, turn ASCII pseudo-sum into actual sum in checksum MSB
      ; FSR0 must be pointed at pseudo-sum MSB on entry
   MOVLW      0x30
   SUBWF      INDF0,F,A      ; Sub 30H from MSB of pseudo-sum
   MOVLW      .9
   CPFSGT   INDF0,A      ; Skip if result > 9 (letter A-F)
   BRA      ASHa         ; MS good to go, swap it
   MOVLW      0x7
   SUBWF      INDF0,F,A      ; Sub another 7 to get A-F
ASHa   SWAPF      POSTINC0,F,A   ; Swap result to MS nibble and bump pointer to LS sum
   MOVLW      0x30
   SUBWF      INDF0,F,A      ; Sub 30H from LSB of pseudo-sum
   MOVLW      .9
   CPFSGT   INDF0,A      ; Skip if result > 9 (letter A-F)
   BRA      ASHb         ; MS good to go, swap it
   MOVLW      0x7
   SUBWF      INDF0,F,A      ; Sub another 7 to get A-F
ASHb   MOVF      POSTDEC0,W,A   ; Fetch LS result and bump pointer back to MS
   IORWF      INDF0,F,A      ; OR into LSnibble of result
   RETURN            ; Done, exit
 
There are several ways to do this.

On the low tech side you could always send the info in a given order starting with some know sequence like START. Or you can send values preceded by an identification which you will have to parse on the PC unless you are just logging values.

If you have a program other then a terminal emulator on the PC side you can devise a packet protocol with error checking. You have the option of making the packet human readable or not. If not you can send entire values in one or two bytes as in hiByte and loByte.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…