You are here: Getting Started > Introducing ASCII Code

Introducing ASCII Code

In the First Program activity, you used the DEC formatter with the DEBUG command to display a decimal number in the Debug Terminal.  But what happens if you don’t use the DEC formatter with a number?  If you use the DEBUG command followed by a number with no formatter, the BASIC Stamp will read that number as an ASCII code.

Programming with ASCII Code

ASCII is short for American Standard Code for Information Interchange.  Most microcontrollers and PC computers use this code to assign a number to each keyboard function.  Some numbers correspond to keyboard actions, such as cursor up, cursor down, space, and delete.  Other numbers correspond to printed characters and symbols.  The numbers 32 through 126 correspond to those characters and symbols that the BASIC Stamp can display in the Debug Terminal. The following program will use ACSII code to display the words  “BASIC Stamp 2” in the Debug Terminal.

Example Program – ASCIIName.bs2

Tip:  Remember to use the toolbar icons to place Compiler Directives into your programs!
'{$STAMP BS2} - Use the diagonal green electronic chip icon.
'{$PBASIC 2.5} - Use the gear icon labeled 2.5.

' Stamps in Class - ASCIIName.bs2
' Use ASCII code in a DEBUG command to display the words BASIC Stamp 2.
 
'{$STAMP BS2}
'{$PBASIC 2.5} 

PAUSE 1000
DEBUG 66,65,83,73,67,32,83,116,97,109,112,32,50
 
END

How ASCIIName.bs2 Works

Each number in the DEBUG command corresponds to one ASCII code symbol that appeared in the Debug Terminal.

DEBUG 66,65,83,73,67,32,83,116,97,109,112,32,50

66 is the ASCII code for capital “B”, 65 is the code for capital “A” and so on.  32 is the code for a space between characters. Notice that each code number was separated with a comma.  The commas allow the one instance of DEBUG to transmit each symbol as a separate value.  This is much easier to type than 12 separate DEBUG commands. 

Your Turn – Exploring ASCII Code

 

This Help file has an ASCII Chart (located in PBASIC Language Reference > ASCII Chart) with the numbers and their corresponding symbols. You can look up the corresponding code numbers to spell your own name.

Go to Welcome page

BASIC Stamp Help Version 2.5.4

Copyright © Parallax Inc.

8/8/2012