Menu

Using Hserprint ok, but need to send special bytes

Help
Paul Haug
2017-04-20
2017-04-20
  • Paul Haug

    Paul Haug - 2017-04-20

    I am using Hserprint to send a series of ASCII numbers from 0 to 0xff as decimal ASCII.
    The program works but I need to send special chars such as 0x0C which will clear the screen.
    I tried sersend but doesn't work with Hserprint, some sort of conflict ?
    Here is the code.
    At the bottem you will see initser & serprint commented out..
    So how can I send special ASII values to the terminal ?. (I am using putty as terminal emulator, works great for my testing)
    '
    This code partt will be used in a data logger (temperature from thermistors) to an sd card, but has to be in ASII. (using openlog device)

    'This program will send a byte using PORTB.7, the value of which
    'will sent out ASCII decimal format
    ; Compiler V0.97.01
    
        #Option Explicit
          #chip 18F14K22, 8
          #config Osc = Int
    
          #define USART_BAUD_RATE 9600
          #define USART_BLOCKING
          #define USART_TX_BLOCKING
          #define RS232Out PORTB.7
          #define RS232In  PORTB.5
      Dir RS232Out Out
     ; Dir RS232In In
      Dim newbyte as Byte ' Pattern to be displayed
      Dim ctrtstb as byte
    
      Do
    
        for ctrtstb =0x00 to 0xFF  ;test from 0 to 255
    
         Hserprint "  "  ;put a space between numbers
         '''HSerPrint hex(ctrtstb) ;print in hex for test
         Hserprint ctrtstb  ;prints out dec value in ascii
         Wait 10 ms   ;for test only
        next ctrtstb
    
       wait 2 s  ;for test only
       newbyte = 0x0C      ;form feed clrs screen
       Hserprint newbyte   ;how do i send a hex value of above ????
    
          ;initser 1 , r9600, 1+waitforstart,8,1,none,normal
         ;sersend 1,0x0c  ;top of form
    
     Loop
    

    EDIT: Added Code Format Tags

     

    Last edit: Chris Roper 2017-04-20
  • William Roth

    William Roth - 2017-04-20

    When using HSER, the USART takes exclusive control of the I/O pins used for RX/TX. To use sersend on the same pins, the USART will need to be disabled while sersend is active and then re-enabled. But this is not necessary.

    Use Hsersend instead of Hserprint when sending Terminal Codes (ASCII)

    There is no such thing as sending serial data as HEX or as sending serial data as Decimal. There is no diffference in what is sent out the serial pin between Hsersend 85, Hsersend 0x55, or Hsersend 0b01010101. All serial data is sent as binary ( 1's and 0's).

    When using Hsersend, the numerical value of the databyte is unchanged and sent as a series of 1's & 0's. This might be called raw data format.

    With Hserprint, we are using "characters" instead numerical values. Hserprint (0xC) sees a byte value of 10 dec. So it assumes you want to display "10" on the terminal. So it converts the 1 to 49 and 0 to 48 and send out these two bytes

    When sending ASCII control codes, use HSERSEND.

    Hsersend (8) will send a backspace code
    Hsersend (0x08) will also send a backspace
    Hsersend (0b00001000) will also send a backspace

    Hsersend (10) will send a Line Feed
    Hsersend (0x0A) will also send a Line Leed
    Hsersend (0b00001010) will also send a Line Feed

    SERPRINT (0x0C) will NOT send a form feed. It will instead send two bytes...one for the ASCII character "1" and another for the ASCII character "2". (DEC 12)

    To send a "Form Feed" use HSERSEND (0x0C) Or HSERSEND (12)

    This is where #define or macros can be helpful

    #define LineFeed 10
    #define FormFeed 12
    #define CarriageReturn 13
    #define ESC 27
    #define Backspace 8
    
    
    Macro CRLF
       Hsersend (13) : HSersend(10)
    End Macro
    
    Macro ClearTerminal
        Hersend (12)  '// Same as Hsersend (0x0C)
    End Macro
    

    *** Edit to correct codes for FormFeed and Line Feed

     

    Last edit: William Roth 2017-04-20
  • Paul Haug

    Paul Haug - 2017-04-20

    Many thanks William, I am pasting your entire reply into my notes on QCB for future refrence. Excellent explananation.

     
  • Marc in the Dark

    @William Roth

    Thanks for taking the time to type all that out and explaining in so much detail.
    You helped me as well.
    Very informative!

     
  • CDRIVE

    CDRIVE - 2017-04-21

    I saved William's exceptional explanation in a text file as well. Book marked this topic too!

    Chris

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.