Download presentation
Presentation is loading. Please wait.
Published byGriselda Thornton Modified over 9 years ago
1
Microcontroller I Seth Price Department of Chemical Engineering New Mexico Tech Rev. 9/22/14
2
Microcontrollers Miniature computer for a specific task Also called “embedded system” Examples: microwave, gas pump, alarm clock
3
BASIC Stamp 2 Microcontroller manufactured by Parallax, Inc. Programmed with a computer using PBASIC
4
PBASIC Program Format Microcontroller Information – Select “STAMP BS2” – Select “PBASIC Language 2.5 Declarations – Variables and constants Program END Subroutines
5
PBASIC Variables and Constants Variables must be declared – Variable Name, VAR, Size Variables have different sizes – Bit: a 1 or 0 – Nib: 4 bits – Byte: 8 bits – Word: 16 bits Constants must be declared – Constant Name, CON, Value
6
PBASIC Commands: DEBUG DEBUG: computer window will display info CR: “Carriage Return” Example Program DEBUG “Hello World!” DEBUG CR DEBUG “Welcome to PBASIC!” END
7
PBASIC Commands: DO Loop Executes code until a condition is met Format DO….LOOP UNTIL condition Example Program: DO DEBUG “Hello World Forever!” LOOP END
8
PBASIC Commands: FOR Loop Executes code a set number of times Format: FOR variable = start TO end STEP stepsize – End loop with NEXT Example Program: counter VAR word FOR counter = 1 TO 1000 DEBUG “Hello World!” DEBUG DEC counter NEXT END
9
PBASIC Variable Size Declaring variables sets aside memory Change “counter VAR word” to “counter VAR Byte” Run the program. What happened?
10
PBASIC Variable Size “WORD” is 16 bits – Has 2 16 states: 0000000000000000 to 1111111111111111 – Represent decimal numbers: 0 to (2 16 ) – 1 – This means: 0 to 65,535 “Byte” is 8 bits – Has 2 8 states: 00000000 to 11111111 – Represent decimal numbers: 0 to (2 8 ) – 1 – This means: 0 to 255 Counter “rolls over”, loop never reaches 1000
11
PBASIC Memory Press F8 to see the RAM Map There are 12 registers (16 bits), meaning: – 12 Words – 24 Bytes – 48 Nibs – 192 Bits
12
PBASIC Conditionals Can pick which piece of code is executed Format: IF THEN (action) ELSEIF (or ELSE) ENDIF
13
PBASIC IN and OUT We can pull digital data from the outside world – Format: IN – Example: IF (IN3 = 1) THEN We can push digital data to the outside world – Format: (HIGH or LOW) – Example: HIGH 14
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.