I
Programming Examples
I
I
Writing the Control Register
1
Basic 110 Operations
Reading BCD Data
Bit Operations
The examples presented below use the BASIC programming language to
illustrate some of common programming tasks. Line numbers in these
examples were arbitrarily selected; these examples will work with any
valid line numbering scheme.
The following code specifies 300h as the base address of the P10-12, then
configures all of the ports as outputs:
10 B A D D R = & H 3 0 0
20 O U T B A D D R + 3 , & H 8 0
The following code performs some basic I/O operations:
30 O U T B A D D R , & H 2 2
40 O U T BADDR + 1 , 9 9
50 P R I N T I N P ( B A D D R + 1 ) ' R e a d s a n d d i s p l a y s
60 P R I N T H E X $ ( I N P ( B A D D R ) ) ' R e a d s a n d d i s p l a y s
The following code reads 2-digit BCD (Binary Coded Decimal) data:
30 B C D % = I N P ( B A D D R )
40 B C D % = ( B C D % A N D & H F 0 ) * 1 0 / 1 6 + ( B C D % A N D & H O F )
Bit operations can use the Boolean operators OR, AND, XOR, EQV, IMP,
and NOT
' S p e c i f i e s
' P I O - 1 2 b a s e I / O a d d r e s s .
' S e t s
a l l p o r t s t o o u t p u t s .
' S e n d s
2 2 H e x t o P o r t A .
' S e n d s
9 9 t o P o r t B .
' P o r t B d a t a i n d e c i m a l .
' P o r t A d a t a i n H e x .
' R e a d
d a t a .
' C o n v e r t t o d e c i m a l .
3 0 0 h a s t h e
4-5