Guest User

Untitled

a guest
Aug 26th, 2011
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 11.82 KB | None | 0 0
  1. {{
  2. ┌────────────────────────────────────┐
  3. │ Parallax Serial Terminal Demo v1.0 │
  4. │ Author: Jeff Martin                â”‚                    
  5. │ Copyright (c) 2009 Parallax Inc.   │                    
  6. │ See end of file for terms of use.  â”‚                      
  7. └────────────────────────────────────┘
  8.  
  9. Demonstration of various handy features of the Parallax Serial Terminal (object and software).  The Parallax Serial
  10. Terminal software is included with the Propeller Tool installer (v1.2.6 or newer) and provides a simple serial-based
  11. interface to the Propeller chip.  Typically this is done over the programming connection but may use other I/O pins
  12. if desired.
  13.  
  14. How to use:
  15.  
  16.  o Run the Parallax Serial Terminal (included with the Propeller Tool) and set it to the connected Propeller
  17.    chip's COM Port with a baud rate of 115200.
  18. o In the Propeller Tool, press the F10 (or F11) key to compile and load the code.
  19. o Immediately click the Parallax Serial Terminal's Enable button.  Do not wait until the program is finished
  20.    downloading.
  21. }}
  22.  
  23. CON
  24.   _clkmode = xtal1 + pll16x
  25.   _xinfreq = 5_000_000
  26.  
  27. CON
  28.   ColPos = 8  
  29.  
  30. OBJ
  31.   pst   :       "Parallax Serial Terminal"
  32.  
  33. PUB Main | value, base, width, offset
  34.   pst.Start(57_600)                                                            'Set Parallax Serial Terminal to 115200 baud
  35.  
  36.  
  37.  '-------- Demo 1 --------
  38.   pst.Str(@DemoHeader)                                                          'Print header; uses string in DAT section.
  39.  pst.Chars("-", strsize(@DemoHeader))                                          'Use Chars method to output hyphens "-"
  40.   pst.Str(String(pst#NL, pst#NL, "*** Number Feedback Example ***"))
  41.   repeat
  42.     pst.Chars(pst#NL, 3)                                                        'Output multiple new lines
  43.     pst.Str(String("Enter a decimal value: "))  <----------HERE                                'Prompt user to enter a number; uses immediate string.
  44.    value := pst.DecIn                                                          'Get number (in decimal).
  45.     pst.Str(String(pst#NL, "Your value is..."))                                 'Announce output
  46.     pst.Str(String(pst#NL, " (Decimal):"))                                      'In decimal
  47.     pst.PositionX(16)                                                           'Move cursor to column 16
  48.    pst.Dec(value)
  49.    pst.Str(String(pst#NL, " (Hexadecimal):", pst#PX, 16))                      'In hexadecimal.  We used PX control code to
  50.     pst.Hex(value, 8)                                                           '  move cursor (alternative to PositionX method).
  51.    pst.Str(String(pst#NL, " (Binary):"))                                       'In binary.
  52.     pst.MoveRight(6)                                                            'Used MoveRight to move cursor (alternative
  53.    pst.Bin(value, 32)                                                          '  to features used above).
  54.     pst.Str(String(pst#NL, pst#NL, "Try again? (Y/N):"))                        'Prompt to repeat
  55.     value := pst.CharIn
  56.   while (value == "Y") or (value == "y")                                        'Loop back if desired
  57.  
  58.  
  59.  '-------- Demo 2 --------
  60.   repeat
  61.     pst.Clear                                                                   'Clear screen
  62.    pst.Str(@DemoHeader)                                                        'Print header.
  63.     pst.Chars("-", strsize(@DemoHeader))                                        'Use Chars method to output hyphens "-"
  64.    pst.Str(String(pst#NL, pst#NL, "*** Pseudo-Random Number Example ***"))    
  65.    pst.Chars(pst#NL, 2)                                                        'Output multiple new lines
  66.     pst.Str(String("Enter 'seed' value: "))                                     'Prompt for seed value
  67.    value := pst.DecIn                                                          
  68.    pst.Str(String(pst#NL, "Display decimal, hexadecimal, or binary? (D/H/B)")) 'Prompt for base size
  69.     base := pst.CharIn
  70.     pst.Str(@RandomHeader)                                                      'Output table header
  71.    pst.Dec(value)
  72.    base := lookdownz(base & %11011111: "B", "H", "D") <# 2                     'Convert base to number (B=0, H=1, else = 2)
  73.     offset := ColPos + 4 + width := lookupz(base: 32, 8, 11)                    'Calculate column offset and field width
  74.    pst.Chars(pst#NL, 2)                                                        'New lines
  75.     pst.PositionX(ColPos)                                                       'Position and display first column heading
  76.    pst.Str(@Forward)
  77.    pst.PositionX(offset)                                                       'Position and display second column heading
  78.     pst.Str(@Backward)
  79.     pst.NewLine                                                                 'Draw underlines
  80.    pst.PositionX(ColPos)
  81.    pst.Chars("-", width)
  82.    pst.PositionX(offset)
  83.    pst.Chars("-", width)
  84.    pst.NewLine
  85.    
  86.    'Pseudo-Random Number (Forward)
  87.     repeat 10                                                                  
  88.       waitcnt(clkfreq / 6 + cnt)                                                'Wait 1/6 second
  89.      pst.PositionX(ColPos)                                                     'Position to first column
  90.       ?value                                                                    'Generate random number forward
  91.      case base                                                                 'Output in binary, hexadecimal, or decimal
  92.         0: pst.Bin(value, width) {binary}                                      
  93.         1: pst.Hex(value, width) {hex}
  94.         2: pst.Dec(value)        {decimal}
  95.       pst.MoveDown(1)                                                           'Move to next line
  96.    
  97.    'Pseudo-Random Number (Backward)
  98.     repeat 10
  99.       waitcnt(clkfreq / 6 + cnt)                                                'Wait 1/6 second                          
  100.      pst.MoveUp(1)                                                             'Move to previous line                    
  101.       pst.PositionX(offset)                                                     'Position to second column                
  102.      case base                                                                 'Output in binary, hexadecimal, or decimal
  103.         0: pst.Bin(value, width) {binary}                                                                                
  104.         1: pst.Hex(value, width) {hex}                                                                                    
  105.         2: pst.Dec(value)        {decimal}                                                                                
  106.       value?                                                                    'Generate random number backward
  107.          
  108.    pst.Position(0, 23)                                                         'Position below table
  109.     pst.Str(String("Try again? (Y/N):"))                                        'Prompt to repeat
  110.    value := pst.CharIn
  111.  while (value == "Y") or (value == "y")                                        'Loop back if desired
  112.  
  113.   pst.Clear
  114.   pst.Str(String("Thanks for playing."))  
  115.  
  116. DAT
  117.  
  118. DemoHeader    byte "Parallax Serial Terminal Demonstration", pst#NL, 0
  119. RandomHeader  byte pst#NL, pst#NL, "Pseudo-Random Numbers Generated by Seed Value ", 0
  120. Forward       byte "Forward", 0
  121. Backward      byte "Backward", 0
  122.  
  123.  
  124. {{
  125. ┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
  126. │                                                   TERMS OF USE: MIT License                                                  â”‚                                                            
  127. ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
  128. │Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation    â”‚
  129. │files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,    â”‚
  130. │modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software│
  131. │is furnished to do so, subject to the following conditions:                                                                   │
  132. │                                                                                                                              â”‚
  133. │The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.│
  134. │                                                                                                                              â”‚
  135. │THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE          â”‚
  136. │WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR         │
  137. │COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,   │
  138. │ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                         │
  139. └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
  140. }}
Advertisement
Add Comment
Please, Sign In to add comment