# 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

- Enter and run 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

- Save ASCIIName.bs2 as ASCIIRandom.bs2
- Pick 12 random numbers between 32 and 126.
- Replace the ASCII code numbers in the program with the numbers you chose.
- Run your modified program to see what you get!

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.

- Save ASCIIRandom.bs2 as YourASCIIName.bs2
- Open up the ASCII Chart.
- Using the chart as a reference, modify the program to spell your own name.
- Run the program to see if you spelled your name correctly.
- If you did, good job, and save your program!

Go to Welcome page

BASIC Stamp Help Version 2.5.4

Copyright © Parallax Inc.

8/8/2012