Professional Documents
Culture Documents
68HC11 Microcontroller Activity Board With Interactive C Documentation
68HC11 Microcontroller Activity Board With Interactive C Documentation
68HC11 Microcontroller Activity Board With Interactive C Documentation
AX-11
68HC11 microcontroller
Activity board
with Interactive C
Documentation
INNOVATIVE EXPERIMENT
2lAX-11 : 68HC11 Microcontroller Activity board doumentation
The Handy Board is distributed under MIT’s free licensing policy, in which the design may
be licensed for for personal, educational, or commercial use with no charge.
Interactive C (IC) is provided free of charge as a service to educators and the general
public. IC7.08ax supports the Handy Board with Expansion Board and AX-11 board. IC is
property of KISS Institute for Practical Robotics, a 501(c)3 nonprofit organization.
Interactive C was written by Randy Sargent of the KISS Institute for Practical Robotics.
Randy was assisted by Mark Sherman. Portions of the code and the libraries are based on
the public distribution of Interactive C 2.8 written by Randy Sargent, Anne Wright and
Fred Martin.
AX-11 : 68HC11 Microcontroller Activity board doumentationl3
Contents
Chapter 1 : Hardware Introduction.........................................................5
1.1 AX-11 Activity board features
1.2 Interactive C software
1.3 Preparation the Interactive C with AX-11 Activity board
1.8 How to use AX-11 Activity board with USB to RS-232 serial port converter
3.2 Processes
3.3 Encoders
Chapter 1
Hardware introduction
The AX-11 is a modified version of the popular Handy board from MIT and the first
ever microcontroller board used for learning C language by Interactive C programming.
The AX-11 is a 6811-based microcontroller system that lets you build mobile robots for
educational, hobbyist, and industrial purposes. People use the AX-11 Board to run robot
design courses and competitions at the university and high school level, build robots for fun,
and control industrial devices.
POWER switch
) DC jack
68HC11E1
MCU.
Charging indicator (CHG.-Yellow LED)
RS-232 port jack
Serial interface indicator (SER-Green LED)
Power indicator (PWR-Green LED)
Analog input
AI-16 to AI-31
(16-ch.) Battery indicator (BATT-Red LED)
A
D0
D2
D4
D6
A8
A9
AS
A13
A15
E
The AX-11 activity board are designed to support the learning of microcontroller
with high language programming in C by Intreractive C. Besides you can use the AX-11
activity board to study about 68HC11 microcontroller architecture with Assembly langauge
programming or Basic or ANSI C.
With expansion ports, you can interface 68HC11 microcontroller with simple and
advance external devices such as Real-Time Clock IC, Ultrasonic ranger, 2-wires devices,
Digital compass and more.
AX-11 activity board interfaces with computer serial port for downloading the In-
teractive C firmware and code. User code will be stored in memory with back up circuit.
The code is saved although the power off about 250 hours continually. The LOW BATT red
indicator will shows if the battery low power. It need to change the battery if you use
alcaline type and charge with the external DC adaptor. AX-11 board has built-in low
current battery charger circuit. If use 1800mAH, need 16 hours charging time. User who
need to speed the battery charging, the external battery charger is required. We suggest
use the 1 or 2 cells battery fast chargere; V-6280 Vanson (show in the Figure 1-4).
+5V
OUT-0
+5V
0.1/50V
+V Servo OUT-1
16
15 1 D0 +5V
SERVO-0 Y0 A0 OUT-2
14 2 D1 74HC273
SERVO-1 Y1 A1 20
13 3 D2
SERVO-2 Y2 A2 13 12
12 6 D0 Q0
SERVO-3 Y3 CS2 8 9 OUT-3
11 4 D1 Q1
SERVO-4 Y4 LE 7 6
10 5 +5V D2 Q2
SERVO-5 Y5 CS1 14 15
9 0.1/50V D3 Q3
Y6 17 16 OUT-4
7 D4 Q4
Y7 20 4 5
D5 Q5
19 2 3 2
8 Q0 D0 D6 Q6
74HC237 18 3 18 19 OUT-5
Q1 D1 D7 Q7
17 4 11 150 x 8
+5V Q2 D2 CLK
16 5
Q3 D3 RST
15 6 OUT-6
10/16V Q4 D4 1 10
14 7
+5V Q5 D5
13 8
0.1/50V 0.1/50V Q6 D6
12 9 OUT-7
Q7 D7
16 +5V 11
AI-16 74HC574 CLK
13 11
Y0 A0 10k
AI-17 10
14 A1 OE
Y1 9
AI-18 A2 10 1 +5V +5V
15
Y2 1k 1k
AI-19 3 C9012 0.1/50V +Vm
12 COM
Y3 47 GRN RED GRN RED
AI-20 1 6 20 L293D 8 16
Y4 IN +5V
AI-21 7 13 12 10 11
5 VEE 11 D0 Q0 I3 OUT3 +
Y5 8 2 D0 8 9 13 12 15 14 MOTOR-1
AI-22 VSS VDD 15 12 D1 Q1 I4 OUT4 -
2 A D1 7 6 2 3
Y6 10k LCD 16x2 with Backlight LED 13 D2 Q2 I1 OUT1 +
LCD Contrast
3 VEE
D2 14 15 11 10 7 6 MOTOR-2
AI-23 4 16 15 D3 Q3 I2 OUT2 -
Y7 K
74HC4051 1 D3 17 16 9 0.1/50V
VSS E RS R/W D0 D1 D2 D3 D4 D5 D6 D7 16 D4 Q4 CS2
+5V +5V D4 4 5 1
6 4 5 17 D5 Q5 CS1
+5V +5V D5 3 2 74HC04
1000 18 D6 Q6
0.1/50V 1k 6V3 D6 18 19
19 D7 Q7 4 5 12 13
0.1/50V D7 11
0.1/50V CLK +5V
16 0.1/50V
AI-24 74HC573 RST 1k
13 11 52 26 30 20 1k
Y0 A0 1 10 +Vm
AI-25 10 VRH VDD OC4 9 2 19 10
14 A1 AD0 D0 Q0 A0 GRN RED GRN RED
Y1 9 10 3 18 9
A2 AD1 D1 Q1 A1 74HC04 L293D 8 16
AI-26 15 43 11 4 17 8
Y2 AN0 AD2 D2 Q2 A2 10 11
3 45 12 5 16 7 I3 OUT3 +
AI-27 12 COM AN1 AD3 D3 Q3 A3 9 8 15 14 MOTOR-3
Y3 13 6 15 6 I4 OUT4 -
+5V 2 3
AI-28 +5V AD4 D4 Q4 A4
1 6 14 7 14 5 0.1/50V I1 OUT1 +
Y4 IN AD5 D5 Q5 A5 1 2 7 6 MOTOR-4
7 15 8 13 4 I2 OUT2 -
AI-29 5 VEE 47 AD6 D6 Q6 A6 9
Y5 AI-2 AN2 14 CS2 0.1/50V
8 16 9 12 3 5 6 1
VSS AD7 D7 Q7 A7
AI-30 2 4 11 CS1
Y6 AS LE 7
AI-31 49 74HC04
4 AI-3 AN3 OE 4 5 12 13 +5V
Y7 74HC4051 SRAM
1 10 62256
44
AI-4 AN4 +5V DI-15
42 25
A8 A8
41 24 10k x 8
A9 A9
46 40 21
AI-5 AN5 A10 A10 DI-14
39 23 +5V
A11 A11
38 2
A12 A12 0.1/50V
48 37 26
AI-6 AN6 A13 A13 DI-13
0.1/50V 36 1
A14 A14 20
35 12 4
A15 11 6 18 2
13 O0 D0
5 9 17 3
E 7 5 8 20 O1 D1 DI-12
17 10 E 16 4
+5V RESET O2 D2
6 14 27 15 5
R/W WR O3 D3
1 28 14 6 DI-11
KNOB 10k 50 3 74HC00 VDD O4 D4
AN7 13 7
+5V 51 0.1/50V O5 D5
VRL 2 12 8
+5V G O6 D6
0.1/50V 1 RED 3mm. 11 9 +5V
VSS 3 14 22 DI-10
2 BAT. O7 D7
MODB MC68HC11E1 +Vmem 1 10k x3
10/16V +5V 1 OE1
+5V 19
0.1/50V 47k +V 4 OE2 DI-9
16 2
1k 16 PAI : Pulse Accumulator Interrupt
10
10/16V 1 4 10/16V 3 RESET KIA7042 1 9 74HC541
A0 Y6
ICL232 2 7 DI-8
SERIAL PORT 3 5 GND A1 Y7
47/16V 3 IC2 : Input Capture -2
47k 1k 2 A2
1k 4 13
14 11 21 CS2 Y2
1 TxD 5 DI-7
RxD CS3 STOP START IC3 : Input Capture -3
2 13 12 20 6 15
TxD RxD CS1 Y0
3
15 1k 74HC138
4 2k2 6 1k 8
GND
YEL 3mm. GRN 3mm. 3
MODA
SER 10/16V POWER 27 0.22R
PAI
33
IC2
+5V +5V+5V 34 KTA1046Y
IC3
29
OC3 470/16
47k 47k 10k 0.5R
+5V +5V x2 1 2
18 KIA278R06 +Vm
XIRQ XIRQ
19 +5V
IRQ IRQ
J3 3 4
RxD 1N5819 470/16
DC adaptor jack
0xFFFF
0xF000 0x8000-0xFFFF
32KB External RAM of AX-11 board.
Reserve for Interrupt vector 32 bytes.
0xE000 The usage memory space is 32,736 bytes.
0xD000
0xC000
0xBFC0-0xBFFF : Interrupt vector 32 bytes
0xB000
0xA000
0x9000
0x8000
0x7000-0x7FFF : Assigned to
0x7000 1. Read value from the digital sensors
2. Write data to control DC motor
0x6000
0x4000-0x6FFF
0x5000 Assigned for digital input/output port
0x4000
0x3000
0x2000
Figure 1-4 : The single cell fast battery charger. It charge from 1 to 8 cells
simultaneously.
l CD-ROM drive
l Free serial port RS-232 or USB to Serial port converter if computer available only
USB port (UCON-232S is recommended).
1.2.2 Installation
(1) Insert AX-11 CD-ROM to CD-ROM drive.
(2) Enter to Software folder and double-click on the IC708axSetup.exe. The setup
window will appear. Click on the Next button to begin the installation and click the OK or
Next button in every step until the installation complete.
AX-11 : 68HC11 Microcontroller Activity board doumentationl11
(2) Turn-on the POWER switch. If the batttery power level more enough, the green
PWR. LED will light.
(3) In first time using, at LCD screen of the AX-11 activity board will display :
IC 7.08 on AX-11
Activity Board
If no anything to show, may be from 2 reasons as follows.
(3.2) There is any code into AX-11 memory. User can download the new
code to run continue.
Normally, AX-11 board has the memory back-up system. It can save the data or
code about 250 hours (10 days approximation). Therefore the changing new battery af-
ter empty will not affect to the memory.
12lAX-11 : 68HC11 Microcontroller Activity board doumentation
AX-11
Turn-on POWER switch
68HC11 microcontroller IC1
Activity Board
CHARGE POWER
(IC3)
IN-7
OC2
SOUND
DC-INPUT
IN-8
(IC2)
MC68HC11E1
microcontroller
(PAI)
IN-9
DOWNLOAD
SER.
PWR.
,+=@=FJAH
12V 500mA
Figure 1-5 : Using the external DC adaptor with the AX-11 activity board
(2) Make sure the battery holder of the AX-11 board empty. Do not connect the
DC adaptor to AX-11 board if the alcaline batteries are in the holder except using the
rechargable batteries.
(3) Connect the DC adaptor to the DC in jack of AX-11 board, making sure the
power switch is off.
(4) Turn-on the POWER switch. The green PWR. LED will light following the Figure 1-5.
WARNING ! : If using the external DC adaptor, MUST REMOVE or DO NOT PUT ANY ALCALINE
BATTERIES INTO THE BATTERY HOLDER to protect the alcaline batteries burning.
AX-11 : 68HC11 Microcontroller Activity board doumentationl13
AX-11
68HC11 microcontroller IC1
Activity Board
CHARGE POWER
(IC3)
IN-7
OC2
SOUND
DC-INPUT
IN-8
(IC2)
MC68HC11E1
microcontroller
(PAI)
IN-9
DOWNLOAD
SER.
PWR.
BATT.
Figure 1-6 : Charging the battery with buit-in charger circuit of AX-11 activity
board
(2) Select the output voltage to +12V. Plug the DC adaptor to a wall outet.
(3) Connect the DC adaptor to the DC in jack of AX-11 board, making sure the
power switch is off. No need to turn-on POWER. The yellow CHG. LED will light to indicate
the charging operation. This indicator will dim when the battery voltage full.
(4) To faster charging, the 6 cells AA or more external battery charger is required.
14lAX-11 : 68HC11 Microcontroller Activity board doumentation
AX-11
68HC11 microcontroller IC1
Activity Board
CHARGE POWER
(IC3)
IN-7
OC2
Plug the CX-4 serial cable
SOUND to the RS-232 jack.
DC-INPUT The green SER. LED will
IN-8
(IC2)
IN-9
DOWNLOAD
SER.
PWR.
BATT.
AX-11
68HC11 microcontroller IC1
Activity Board
CHARGE POWER
(IC3)
IN-7
OC2
Plug the CX-4 serial cable
SOUND to the RS-232 jack.
DC-INPUT
IN-8
(IC2)
IN-9
DOWNLOAD
SER.
PWR.
BATT.
CX-4 serial
cable
Before using the USB to RS-232 serial port converter do not forget install its driver
and checking the USB Serial port address by clicking to the Control panel à System à
Hardware à Device manager à ports.
16lAX-11 : 68HC11 Microcontroller Activity board doumentation
(2) Take the AX-11 and connect it to the serial port of the computer . The green SER
LED will light, indicating that the connection of the AX-11 to the serial port of the com-
puter was successful, and is ready for use.
The Choose target window will apppear following. Select the AX-11R6. Click
on the OK button.
AX-11 : 68HC11 Microcontroller Activity board doumentationl17
(4) IC Port Selection window will appear. Click at the COM port address that con-
nect with AX-11 board and click on the OK button to next.
(5) If your AX-11 board does not install firmware or lost, the SerialConnectDialog will
appear. Click on the Download Firmware button.
18lAX-11 : 68HC11 Microcontroller Activity board doumentation
(6) Firmware Download will appear and shows the steps in downloading the firm-
ware to the AX-11 board
(6.1) Start by connecting the download cable to the serial port and to the
AX-11 board. The green SER. LED is lit.
(6.3) Press the STOP switch on the AX-11 board. While still holding it down,
turn on the power of the AX-11 board. Both LED at PWR. and BATT. must off. Now the AX-
11 board ready for firmware downloading.
If the PWR LED is lit, it means the board is unable to enter the down-
load mode of the program, and to check the download cable again before repeating
the steps for download.
If the BATT LED is lit, it means the voltage supply of the battery is low
and needs to be recharged for at least another 30 minutes before using it again if use
rechargable battery or chage the new batteries if use alcaline type.
(9) After downloading, the AX-11 board will beep a sound and the display will
show following message below.
IC 7.08 on AX-11
Activity Board
(10) The Interactive C program will then go to the Interaction window, which is
used for testing the program.
The AX-11 activity board is now ready for program coding and operation.
AX-11 : 68HC11 Microcontroller Activity board doumentationl21
(2) The monitor shows the results from the AX-11, displaying Hello world! on
the top sentence. The display of the Interaction window will display the message. This
means that the AX-11 board can now interact with the Interactive C program.
(3) Next we will create a simple Interactive C program to use with the AX-11 board.
(3.3) Click Download to download the program. A window will appear ask-
ing to save the file *.ic first. Here, the file is hello.ic. A window displaying the status of the
download will then appear.
The message Hello world! will appear on the top of the AX-11
display screen.
AX-11 : 68HC11 Microcontroller Activity board doumentationl23
If the Interactive C program is closed and reopened again while the AX-11 board
is still on, and the firmware still operating, the communication between the AX-11 and the
Interactive C program must be reestablished. Choose the serial port used to communi-
cate, and then click Connect Now. A window displaying the status of downloading the
Interactive C library to the AX-11 board will appear as seen in the picture.
Then we will go to the Interaction window, causing the program that was saved in
the memory previously to have disappeared; therefore it must be downloaded again.
This means that every time the Interactive C program is closed and opened again,
the user must always download the program he needs into the memory again. This is
because the Interactive C program is a program that needs to be connected to the
hardware in order to check its status continuously. Therefore, if the communication is lost
because it was turned off, the communication must always be reestablished at the be-
ginning by downloading the program’s library to the AX-11 board.
24lAX-11 : 68HC11 Microcontroller Activity board doumentation
If the AX-11 board is fully charged, it can be used continuously for 2-4 hours, de-
pending on the number of peripherals connected and the amount of voltage they use.
1.8.1 UCON-232S
This is a compact size RS232 Serial to USB Convertor. Its fully compatible with all our
robotic kits and microcontroller for Laptop or Desktop users whose computers do not have
a RS232 Serial Port.
The mainly function of this converter is making the Virtual COM port compatible
with true RS-232 serial port. The figure 1-8 shows the UCON-232S photo and features.
The UCON-232S is used FT232RL from FTDI. It is USB-UART converter chip. FTDI support
the driver for computer to know this device. You can see more information and down-
load the latest driver at www.ftdichip.co.uk or www.parallax.com.
#
RJ11-6P4C modular plug
" #
"
! !
conductor side
2 RxD 3 TxD 4 DTR 5 GND
(3) Plug the UCON-232S to USB port. Wait a moment. The blue LED of UCON-232S
lights ready to use.
(4) Check the COM port address by clicking Start à Control Panel à System à
Hardware à Device Manager
26lAX-11 : 68HC11 Microcontroller Activity board doumentation
(5) See the list of USB serial port and remember the COM port address to work with
AX-11 board. Normally UCON-232S will create COM3 or above.
AX-11 : 68HC11 Microcontroller Activity board doumentationl27
(2) Open Interactive C. Choose the hardware to AX-11R6 and click on the OK
button. The IC Port Selection window will appear.
(3) Select the USB serial port that you know. If the COM port is over COM12, click on the
Custom Port button
(4) The Serial Port Input dialog will appear. Put the message \\.\comX to choose
the COM port that created from UCON-232S. Thus, X is number of COM port. From ex-
ample below is COM15. Click on the OK button.
28lAX-11 : 68HC11 Microcontroller Activity board doumentation
(5) The IC Port Selection window will appear again and show only one COM port
selection. Click at the circle to choosing and click on the OK button.
(6) Interaction window of Interactive C will appear. Observe the title bar. It shows
the COM port that interface with Interactive C. For this example is COM15.
AX-11 : 68HC11 Microcontroller Activity board doumentationl29
INNOVATIVE EXPERIMENT
30lAX-11 : 68HC11 Microcontroller Activity board doumentation
AX-11 : 68HC11 Microcontroller Activity board doumentationl31
Chapter 2
Interactive C
Programming Reference
2.1 Introduction
Interactive C (IC for short) is a C language consisting of a compiler (with interactive
command-line compilation and debugging) and a run-time machine language module.
IC implements a subset of C including control structures (for, while, if, else), local and
global variables, arrays, pointers, structures, 16-bit and 32-bit integers, and 32-bit floating
point numbers.
IC works by compiling into pseudo-code for a custom stack machine, rather than
compiling directly into native code for a particular processor. This pseudo-code (or p-
code) is then interpreted by the run-time machine language program. This unusual ap-
proach to compiler design allows IC to offer the following design tradeoffs:
does array bounds checking at run-time to protect against some programming errors.
l Small object code. Stack machine code tends to be smaller than a native
code representation.
Since IC’s ultimate performance is limited by the fact that its output p-code is inter-
preted, these advantages are taken at the expense of raw execution speed.
32lAX-11 : 68HC11 Microcontroller Activity board doumentation
2.2 Using IC
When IC is running and has a connection to a compatible processor board such
as the Handy Board or RCX, C expressions, function calls, and IC commands may be
typed in the command entry portion of the interaction window.
2.3 IC Interface
Both new (unsaved) and saved files can be opened for editing in IC. A row of tabs
lists the files that have been opened. Clicking a file’s tab activates it for editing. The first
tab for the interface is always the interaction window.
The File menu has standard entries for New, Open, Close, Save, Save As, Print and
Exit. Under File - Save As, if no file name extension is supplied, IC automatically saves with
the “.ic” extension.
To download the active file, simply click the button. The active file will
also be saved, unless it is new, in which case the user is prompted for a “save as” file
name. Remark: a preprocessor command #use has been added to IC to specify any
other saved files (personal libraries) that need to be downloaded along with the active
file [Note: #use is quite different from the #include prepreocessor command of standard
C environments. #include is not implemented for reasons given later in the section de-
scribing the IC-preprocessor.]
If a downloaded program does not do what is intended, it may corrupt the p-code
interpreter, particularly if pointers are being employed. The interface provides an option
under the Settings button for downloading the firmware to reinitialize the board.
Create new
IC file
Interaction
window
Current code
window
Path of the
current file
Editor space
Status message
File Tools :
New (Ctrl+N) Create the new file Check parens Check parentheses
Open (Ctrl-O) Open the exist file Upload array Upload data from array
Close (Ctrl+W) Close the active file List functions Show the list of function
Save (Ctrl + S) Save the active file List global variables Show the list of global variable
Save As Save the active file to List loaded files Show the downloaded file
new name List # Define Show the list of defined
Print (Ctrl+P) Print out the active code variable
Exit Exit program View diagram Show AX-11 board layout
Edit Download firmware Download firmware to AX-11
Undo Undo the last edit action Download Libraries Download library of IC7.08ax
Redo Redo the last edit action
Setting
Cut Cut text to clipboard
Incerase Font size
Copy Copy text to clipboard
Decrease Font size
Paste Paste text from clipboard
Change controller type
Select all Select all text
Find Find words Change serial port
Find Next Find next words Disconnect serial port
Goto line Go to the target line Help
Indent Indent message Manual Interactive C HTML manual
Indent All Indent all file
About License of IC
34lAX-11 : 68HC11 Microcontroller Activity board doumentation
Interactive C function
1. Printing
printf Display message on the LCD screen of AX-11 board
3. Motor
alloff or a0 Off all motor driver
bk Backward driving
fd Forward driving
init_expbd_servos Enable servo motor driver
motor Choose motor driver power; value is -100 to 100
off Off the specific motor driver channel
4. Sound
beep Generate 500Hz signal in 0.3 second approximation
beeper_off Turn off sound
beeper_on Turn on sound with the latest frequency
set_beeper_pitch Set the sound frequency
Tone Generate the sound with the specific frequency of
set_beeper_pitch function and set the duration time in second.
5. Timing
mseconds Count time in millisecond unit
msleep Set delay time in millisecond unit
reset_system_time Reset time
seconds Count time in second unit
sleep Set delay time in second unit
AX-11 : 68HC11 Microcontroller Activity board doumentationl35
6. Sensor
analog Get value from the specific analog input
digital Get value from the specific digital input
disable_encoder Disable the encoder function
enable_encoder Enable the encoder function
knob Read value from potentiometer at KNOB position of AX-11
read_encoder Read data from the encoder function
reset_encoder Reset the encoder function
start_button Read START button value
start_press Loop for checking the STARTswitch is pressed
stop_button Read STOP button value
stop_press Loop for checking the STOP switch is pressed
7. Math
atan Calculate Arctangent (TAN-1). Result is in Radian unit
cos Calculate Cosine (COS). Result is in Radian unit
exp Calculate the power of natural exponential (en)
exp10 Calculate the power of 10 (10n)
log Calculate the natural logarithm
log10 Calculate the logarithm of 10
random Random number in range 2 to 32,767
sin Calculate Sine (SIN). Result is in Radian unit
sqrt Calculate the square-root of integer
tan Calculate Tangent (TAN). Result is in Radian unit
8. Multi-tasking
hog_processor Allocates an additional 256 milliseconds of execution to the
currently running process.
defer Makes a process swap out immediately after the function is
called.
kill_process Destroy processes
start_process Start a process, which then runs in parallel with other active
processes.
36lAX-11 : 68HC11 Microcontroller Activity board doumentation
Under the Tools menu, among other options, are ones for listing downloaded files,
global variables, and functions (including library functions).
The interface provides additional capabilities for program entry/edit, minor adjust-
ment to the display, and for setting up the serial interface to a board.
Note: to reset the Handy Board without running the main() function (for instance,
when hooking the board back to the computer), hold down the board’s Start button
while activating the board. The board will then reset without running main().
Many of these differences arise from the desire to have IC be “safer” than stan-
dard C. For instance, in IC, array bounds are checked at run time; for this reason, arrays
cannot be converted to pointers in IC. Also, in IC, pointer arithmetic is not allowed.
Other differences are due to the desire that the IC runtime be small and efficient.
For instance, the IC printf function does not understand many of the more exotic format-
ting options specified by ANSI C.
Yet other differences are due to the desire that IC be simpler than standard C. This
is the reason for the global scope of all declarations.
In the rest of this document, when we refer to “C”, the statement applies to both IC
and standard C. When we wish to specify one or the other, we will refer to either “IC” or
“standard C”. When no such qualifiers are present, you should assume that we are talking
about IC.
AX-11 : 68HC11 Microcontroller Activity board doumentationl37
All functions must have a return type. Since main does not return a value, it uses
void, the null type, as its return type. Other types include integers (int) and floating point
numbers (float). This function declaration information must precede each function defini-
tion.
Immediately following the function declaration is the function’s name (in this case,
main). Next, in parentheses, are any arguments (or inputs) to the function. main has none,
but an empty set of parentheses is still required.
After the function arguments is an open curly-brace {. This signifies the start of the
actual function code. Curly-braces signify program blocks, or chunks of code.
Let’s look at an another example to learn some more features of C. The following
code defines the function square, which returns the mathematical square of a number.
int square(int n)
{
return(n * n);
}
38lAX-11 : 68HC11 Microcontroller Activity board doumentation
The function is declared as type int, which means that it will return an integer value.
Next comes the function named square, followed by its argument list in parenthe-
ses. square has one argument, n, which is an integer. Notice how declaring the type of
the argument is done similarly to declaring the type of the function.
When a function has arguments declared, those argument variables are valid within
the “scope” of the function (i.e., they only have meaning within the function’s own code).
Other functions may use the same variable names independently.
The code for square is contained within the set of curly braces. In fact, it consists of
a single statement: the return statement. The return statement exits the function and re-
turns the value of the C expression that follows it (in this case “n * n”).
Let’s look at an example of a function that performs a function call to the square
program.
float hypotenuse(int a, int b)
{
float h;
h = sqrt((float)(square(a) + square(b)));
return(h);
}
This code demonstrates several more features of C. First, notice that the floating
point variable h is defined at the beginning of the hypotenuse function. In general, when-
ever a new program block (indicated by a set of curly braces) is begun, new local vari-
ables may be defined.
The value of h is set to the result of a call to the sqrt function. It turns out that sqrt is
a built-in IC function that takes a floating point number as its argument.
We want to use the square function we defined earlier, which returns its result as an
integer. But the sqrt function requires a floating point argument. We get around this type
incompatibility by coercing the integer sum (square(a) + square(b)) into a float by pre-
ceding it with the desired type, in parentheses. Thus, the integer sum is made into a float-
ing point number and passed along to sqrt.
2.6.1 Variables
Variable names are case-sensitive. The underscore character is allowed and is of-
ten used to enhance the readability of long variable names. C keywords like if, while, etc.
may not be used as variable names.
Functions and global variables may not have the same name. In addition, if a
local variable is named the same as a function or a global variable, the local use takes
precedence; ie., use of the function or global variable is prevented within the scope of
the local variable.
2.6.1.1 Declaration
In C, variables can be declared at the top level (outside of any curly braces) or at
the start of each block (a functional unit of code surrounded by curly braces). In general,
a variable declaration is of the form:
<type> <variable-name>; or
<type> <variable-name>=<initialization-data>;
In IC, <type> can be int, long, float, char, or struct <struct-name>, and determines
the primary type of the variable declared. This form changes somewhat when dealing
with pointer and array declarations, which are explained in a later section, but in general
this is the way you declare variables.
2.6.2 Constants
2.6.2.1 Integer Constants
Integers constants may be defined in decimal integer format (e.g., 4053 or -1),
hexadecimal format using the “0x” prefix (e.g., 0x1fff), and a non-standard but useful
binary format using the “0b” prefix (e.g., 0b1001001). Octal constants using the zero prefix
are not supported.
Character string constants are defined with quotation marks, e.g., “This is a char-
acter string.”.
2.6.2.5 NULL
The special constant NULL has the value of zero and can be assigned to and com-
pared to pointer or array variables (which will be described in later sections). In general,
you cannot convert other constants to be of a pointer type, so there are many times
when NULL can be useful.
For example, in order to check if a pointer has been initialized you could compare
its value to NULL and not try to access its contents if it was NULL. Also, if you had a defined
a linked list type consisting of a value and a pointer to the next element, you could look
for the end of the list by comparing the next pointer to NULL.
42lAX-11 : 68HC11 Microcontroller Activity board doumentation
2.6.3.5 Pointers
IC pointers are 16-bit numbers which represent locations in memory. Values in
memory can be manipulated by calculating, passing and dereferencing pointers repre-
senting the location where the information is stored.
2.6.3.6 Arrays
Arrays are used to store homogenous lists of data (meaning that all the elements of
an array have the same type). Every array has a length which is determined at the time
the array is declared. The data stored in the elements of an array can be set and re-
trieved in the same manner as for other variables.
2.6.3.7 Structures
Structures are used to store non-homogenous but related sets of data. Elements of a
structure are referenced by name instead of number and may be of any supported type.
Structures are useful for organizing related data into a coherent format, reducing
the number of arguments passed to functions, increasing the effective number of values
which can be returned by functions, and creating complex data representations such as
directed graphs and linked lists.
AX-11 : 68HC11 Microcontroller Activity board doumentationl43
2.6.4 Pointers
The address where a value is stored in memory is known as the pointer to that
value. It is often useful to deal with pointers to objects, but great care must be taken to
insure that the pointers used at any point in your code really do point to valid objects in
memory.
Attempts to refer to invalid memory locations could corrupt your memory. Most
computing environments that you are probably used to return helpful messages like ‘Seg-
mentation Violation’ or ‘Bus Error’ on attempts to access illegal memory. However, you
won’t have this safety net on the board you are connecting to. Invalid pointer
dereferencing is very likely to go undetected, and will likely render invalid your data, your
program, or even the pcode interpreter.
First, you should always check that the value of a pointer is not equal to NULL (a
special zero pointer) before you try to access it. Variables which are declared to be point-
ers are initialized to NULL, so many uninitialized values could be caught this way.
Second, you should never use a pointer to a local variable in a manner which
could cause it to be accessed after the function in which it was declared terminates.
When a function terminates the space where its values were being stored is recycled.
Therefore not only may dereferencing such pointers return incorrect values, but assigning
to those addresses could lead to serious data corruption. A good way to prevent this is to
never return the address of a local variable from the function which declares it and never
store those pointers in an object which will live longer than the function itself (a global
pointer, array, or struct). Global variables and variables local to main will not move once
declared and their pointers can be considered to be secure.
The type checking done by IC will help prevent many mishaps, but it will not catch
all errors, so be careful.
The value stored at the location the pointer refers to is accessed by using the *
operator before the expression which calculates the pointer. This process is known as
dereferencing.
44lAX-11 : 68HC11 Microcontroller Activity board doumentation
The address of a variable is calculated by using the & operator before that vari-
able, array element, or structure element reference.
There are two main differences between how you would use a variable of a given
type and a variable declared as a pointer to that type.
So, for example, consider what would happen if the first two statements after X
and Xptr were declared were the following:
X=50L; *Xptr=50L;
The first statement is valid : it sets the value of X to 50L. The second statement would
be valid if Xptr had been properly initialized, but in this case it has not. Therefore, this
statement would corrupt memory.
Here is a sequence of commands you could try which illustrate how pointers and
the * and & operators are used. It also shows that once a pointer has been set to point at
a place in memory, references to it actually share the same memory as the object it
points to:
X=50L; /* set the memory allocated for X to 50 */
Xptr=&X; /* set Xptr to point to memory address of X */
printf(“%d “,*Xptr); /* dereference Xptr; value at address is 50 */
X=100L; /* set X to the value 100 */
printf(“%d “,*Xptr); /* dereference again; value is now 100 */
*Xptr=200L; /* set value at address given by Xptr to 200 */
printf(“%d\n”,X); /* check that the value of X changed to 200 */
AX-11 : 68HC11 Microcontroller Activity board doumentationl45
The following example defines an average_sensor function which takes a port num-
ber and a pointer to an integer variable. The function will average the sensor and store
the result in the variable pointed at by result.
The pointer variable is used in the last line of the function. In this statement, the
answer sum/10 is stored at the location pointed at by result. Notice that the * is used to
assign a value to the location pointed by result.
2.6.5 Arrays
IC supports arrays of characters, integers, long integers, floating-point numbers, struc-
tures, pointers, and array pointers (multi-dimensional arrays). While unlike regular C arrays in a
number of respects, they can be used in a similar manner. The main reasons that arrays are
useful are that they allow you to allocate space for many instances of a given type, send an
arbitrary number of values to functions, and provide the means for iterating over a set of values.
Arrays in IC are different and incompatible with arrays in other versions of C. This
incompatibility is caused by the fact that references to IC arrays are checked to insure that
the reference is truly within the bounds of that array. In order to accomplish this checking in
the general case, it is necessary that the size of the array be stored with the contents of the
array. It is important to remember that an array of a given type and a pointer to the same
type are incompatible types in IC, whereas they are largely interchangeable in regular C.
Since _array_size is not a standard C feature, code written using this primitive will
only be able to be compiled with IC.
48lAX-11 : 68HC11 Microcontroller Activity board doumentation
The _array_size primitive returns the size of the array given to it regardless of the
dimension or type of the array. Here is an example of declarations and interaction with
the _array_size primitive:
int i[4]={10,20,30};
int j[3][2]={{1,2},{2,4},{15}};
int k[2][2][2];
_array_size(i); /* returns 4 */
_array_size(j); /* returns 3 */
_array_size(j[0]); /* returns 2 */
_array_size(k); /* returns 2 */
_array_size(k[0]); /* returns 2 */
The IC upload array capability is accessed using the tools tab. When upload array
is activated, it lists all globally declared arrays. When an array is selected, it is opened in a
(modal) view window. The array can be copied to the clipboard, or saved to a TXT or CSV
(comma separated values) file for import to analysis software.
2.6.6 Structures
Structures are used to store non-homogenous but related sets of data. Elements of
a structure are referenced by name instead of number and may be of any supported
type.
Structures are useful for organizing related data into a coherent format, reducing
the number of arguments passed to functions, increasing the effective number of values
which can be returned by functions, and creating complex data representations such as
directed graphs and linked lists.
Structures are used to store non-homogenous but related sets of data. Elements of
a structure are referenced by name instead of number and may be of any supported
type. Structures are useful for organizing related data into a coherent format, reducing
the number of arguments passed to functions, increasing the effective number of values
which can be returned by functions, and creating complex data representations such as
directed graphs and linked lists.
The following example shows how to define a structure, declare a variable of struc-
ture type, and access its elements.
AX-11 : 68HC11 Microcontroller Activity board doumentationl49
struct foo
{
int i;
int j;
};
struct foo f1;
void set_f1(int i,int j)
{
f1.i=i;
f1.j=j;
}
void get_f1(int *i,int *j)
{
*i=f1.i;
*j=f1.j;
}
The first part is the structure definition. It consists of the keyword struct, followed by
the name of the structure (which can be any valid identifier), followed by a list of named
elements in curly braces. This definition specifies the structure of the type struct foo. Once
there is a definition of this form, you can use the type struct foo just like any other type. The
line struct foo f1; is a global variable declaration which declares the variable f1 to be
of type struct foo.
The dot operator is used to access the elements of a variable of structure type. In
this case, f1.i and f1.j refer to the two elements of f1. You can treat the quantities f1.i and
f1.j just as you would treat any variables of type int (the type of the elements was defined
in the structure declaration at the top to be int).
Pointers to structure types can also be used, just like pointers to any other type.
However, with structures, there is a special short-cut for referring to the elements of the
structure pointed to.
struct foo *fptr;
void main()
{
fptr=&f1;
fptr->i=10;
fptr->j=20;
}
In this example, fptr is declared to be a pointer to type struct foo. In main, it is set to
point to the global f1 defined above. Then the elements of the structure pointed to by fptr
(in this case these are the same as the elements of f1), are set. The arrow operator is used
instead of the dot operator because fptr is a pointer to a variable of type struct foo. Note
that (*fptr).i would have worked just as well as fptr->i, but it would have been clumsier.
Note that only pointers to structures, not the structures themselves, can be passed
to or returned from functions.
50lAX-11 : 68HC11 Microcontroller Activity board doumentation
For initialized declarations of single dimensional arrays, the length can be left blank
and a suitable length based on the initialization data will be assigned to it. Multi-dimen-
sional arrays must have the size of all dimensions specified when the array is declared. If a
length is specified, the initialization data may not overflow that length in any dimension or
an error will result. However, the initialization data may be shorter than the specified size
and the remaining entries will be initialized to 0. Following is an example of legal global
and local variable initializations:
/* declare many globals of various types */
int i=50;
int *ptr=NULL;
float farr[3]={ 1.2, 3.6, 7.4 };
int tarr[2][4]={ { 1, 2, 3, 4 }, { 2, 4, 6, 8} };
char c[]=”Hi there how are you?”;
char carr[5][10]={“Hi”,”there”,”how”,”are”,”you”};
struct bar
{
int i;
int *p;
long j;
} b={5, NULL, 10L};
struct bar barr[2] = { { 1, NULL, 2L }, { 3 } };
/* declare locals of various types */
int foo()
{
int x; /* local variable x with initial value 0 */
int y= tarr[0][2]; /* local variable y with initial value 3 */
int *iptr=&i; /* local pointer to integer
which points to the global i */
int larr[2]={10,20}; /* local array larr
with elements 10 and 20 */
struct bar lb={5,NULL,10L};
/* local variable of type
struct bar with i=5 and j=10 */
char lc[]=carr[2]; /* local string lc with
initial value “how” */
...
}
AX-11 : 68HC11 Microcontroller Activity board doumentationl51
2.7.1 Operators
Each of the data types has its own set of operators that determine which opera-
tions may be performed on them.
2.7.1.4 Characters
Characters are only allowed in character arrays. When a cell of the array is refer-
enced, it is automatically coerced into a integer representation for manipulation by the
integer operations. When a value is stored into a character array, it is coerced from a
standard 16- bit integer into an 8-bit character (by truncating the upper eight bits).
*
A single * preceeding an expression which evaluates to a pointer returns the value
which is stored at that address. This process of accessing the value stored within a pointer
is known as dereferencing.
AX-11 : 68HC11 Microcontroller Activity board doumentationl53
[<expr>]
An expression in square braces following an expression which evaluates to an ar-
ray (an array variable, the result of a function which returns an array pointer, etc.) checks
that the value of the expression falls within the bounds of the array and references that
element.
.
A dot between a structure variable and the name of one of its fields returns the
value stored in that field.
->
An arrow between a pointer to a structure and the name of one of its fields in that
structure acts the same as a dot does, except it acts on the structure pointed at by its left
hand side. Where f is a structure of a type with i as an element name, the two expressions
f.i and (&f)->i are equivalent.
Operator Associativity
() [] left to right
! ~ ++ — - (<type>) right to left
*/% left to right
+- left to right
<< >> left to right
< <= > >= left to right
== != left to right
& left to right
^ left to right
| left to right
&& left to right
|| right to left
= += -= right to left
, left to right
54lAX-11 : 68HC11 Microcontroller Activity board doumentation
<expression> is evaluated; if it is not equal to zero (e.g., logic true), then <state-
ment-1> is executed.
The else clause is optional. If the if part of the statement did not execute, and the
else is present, then <statement-2> executes.
2.12.3 While
The syntax of a while loop is the following:
while (<expression>)
<statement>
while begins by evaluating <expression>. If it is false, then <statement> is skipped. If
it is true, then <statement> is evaluated. Then the expression is evaluated again, and the
same check is performed. The loop exits when <expression> becomes zero.
One can easily create an infinite loop in C using the while statement:
while (1)
<statement>
2.12.4 Do-While
The syntax of a do-while loop is the following:
do
<statement>
while (<expression>);
2.12.5 For
The syntax of a for loop is the following:
for (<expr-1>;<expr-2>;<expr-3>)
<statement>
2.12.6 Switch
The syntax of a switch block is as follows:
switch (int)
{
case const1:
<statement list1>
break;
case const2:
<statement list2>
break;
default:
<statement list3>
}
The switch construct takes an integer variable as input, and compares it to each
case listed. The first matching const is selected, and execution begins there. The break is
optional, and if no break is found then execution continues through each following state-
ment. Also note that each case has a list of single statements, as opposed to a block
enclosed in curly braces.
56lAX-11 : 68HC11 Microcontroller Activity board doumentation
2.12.5 Break
Use of the break statement provides an early exit from a while or a for loop.
l When using a two-line display, the printf() command treats the display as a single
longer line.
l Printing of long integers is not presently supported.
58lAX-11 : 68HC11 Microcontroller Activity board doumentation
2.14 Preprocessor
The preprocessor processes a file before it is sent to the compiler. The IC preproces-
sor allows definition of macros, and conditional compilation of sections of code. Using
preprocessor macros for constants and function macros can make IC code more effi-
cient as well as easier to read. Using #if to conditionally compile code can be very useful,
for instance, for debugging purposes.
The special preprocessor command #use has been included to allow programs to
cause a program to download to initiate the download of stored programs that are not in
the IC library. For example, suppose you have a set of stored programs in a file named
“mylib.ic”, some of which you need for your current program to work.
/* load my library */
#use “mylib.ic”
void main()
{
char s[32] = “text string wrapping badly\n”;
fix (s); /* apply my fix function to s and print it */
printf(s);
}
Each time a macro is invoked, it is replaced with its body. If the macro has argu-
ments, then each place the argument appears in the body is replaced with the actual
argument provided.
Invocations of macros without arguments look like global variable references. In-
vocations of macros with arguments look like calls to functions. To an extent, this is how
they act. However, macro replacement happens before compilation, whereas global
references and function calls happen at run time. Also, function calls evaluate their argu-
ments before they are called, whereas macros simply perform text replacement. For ex-
ample, if the actual argument given to a macro contains a function call, and the macro
instantiates its argument more than once in its body, then the function would be called
multiple times, whereas it would only be called once if it were being passed as a function
argument instead.
Appropriate use of macros can make IC programs and easier to read. It allows
constants to be given symbolic names without requiring storage and access time as a
global would. It also allows macros with arguments to be used in cases when a function
call is desirable for abstraction, without the performance penalty of calling a function.
The fact that #define directives contained within #if blocks are defined regardless
of whether the #if evaluates to be true or false is a side effect of making the preprocessor
macros have global scope.
INNOVATIVE EXPERIMENT
AX-11 : 68HC11 Microcontroller Activity board doumentationl61
Chapter 3
Interactive C Library
Library files provide standard C functions for interfacing with hardware on the ro-
bot controller board. These functions are written either in C or as assembly language
drivers. Library files provide functions to do things like control motors, make tones, and
input sensors values.
IC automatically loads the library file every time it is invoked. Depending on which
board is being used, a different library file will be required. IC may be configured to load
different library files as its default; IC will automatically load the correct library for the
board you’re using at the moment.
To understand better how the library functions work, study of the library file source
code is recommended; e.g., the main library file for the AX-11 is named lib_hb.ic same
the Handyboard.
stop_button();
Returns 1 if STOP button is pressed, otherwise 0.
digital();
Returns 0 if the switch attached to the port is open and returns 1 if the switch is
closed. Digital ports are numbered 7 to 15. Typically used for bumpers or limit switches.
analog();
Returns the analog value of the port (a value in the range 0 to 255). Analog ports
on the AX-11 board are numbered 2 to 6 and 16 to 31. Light sensors and range sensors are
examples of sensors you would use in analog ports.
knob();
Returns an int between 0 and 255 depending on knob position.
62lAX-11 : 68HC11 Microcontroller Activity board doumentation
sleep(<float_secs>);
Waits specified number of seconds.
beep();
Causes a beep sound.
tone(<float_frequency>, <float_secs>)
Plays at specified frequency for specified time (seconds).
%c prints a character
motor(<motor_#>, <speed>)
Controls the motors.
<speed> is an integer between -100 and 100 where 0 means the motor is off
and negative numbers run the motor in the reverse direction.
fd(<motor_#>);
Turns on the motor specified (direction is determined by plug orientation.
bk(<motor_#>);
Turns on the motor specified in the opposite direction from fd.
off(<motor_#>);
Turns off the motor specified.
ao();
Turns all motor ports off.
AX-11 : 68HC11 Microcontroller Activity board doumentationl63
3.2 Processes
Processes work in parallel. Each process, once it is started, will continue until it fin-
ishes or until it is killed by another process using the kill_process(<process_id)>); statement.
Each process that is active gets 50ms of processing time. Then the process is paused
temporarily and the next process gets its share of time. This continues until all the active
process have gotten a slice of time, then it all repeats again. From the user’s standpoint it
appears that all the active processes are running in parallel.
Processes can communicate with one another by reading and modifying global
variables. The globals can be used as semaphores so that one process can signal an-
other. Process IDs may also be stored in globals so that one process can kill another when
needed.
defer();
When placed in a function that is used as a process this will cause that process to
give up the remainder of its time slice whenever defer is called.
kill_process(<process_id>);
This will terminate the process specified by the <process_id>.
64lAX-11 : 68HC11 Microcontroller Activity board doumentation
3.3 Encoders
The enable_encoder() library function is used to start a process which updates the
transition count for the encoder specified. The encoder library functions are designed for
sensors connected to (digital) ports 7,8,12 and 13. The corresponding <encoder#> values
are 0,1,2 and 3. Every enabled encoder uses a lot of the AX-11’s processor — so don’t
enable an encoder unless you are going to use it, and never put an enable statement
inside of a loop.
enable_encoder(<encoder#>);
Turns on the specified encoder (either 0,1,2, or 3 which are plugged into digital
ports 7, 8, 12, 13 respectively). This should be done only once - never enable an already
enabled encoder. If an encoder is not enabled, read_encoder will always return 0.
disable_encoder(<encoder#>)
Turns off the specified encoder.
reset_encoder(<encoder#>)
Sets the specified encoder value to 0.
read_encoder(<encoder#>)
Returns an int that is the current value of the specified encoder.
AX-11 : 68HC11 Microcontroller Activity board doumentationl65
3.4.1.1 Procedure
(1) Connect the DC Motors to M-0 and M-1 channel on the AX-11 Board.
(2) Make sure the Interactive C Program is opened. Select a NEW Program or con-
tinue with your existing Program.
(3) The Following Sample Code, “DC-CODE” in Listing 3-1, shows how you can control
the DC Motors.
(4) After you have typed / inserted the code, click on the RUN MAIN button.
(5) Observe the Motor Indicator on the LCD Screen.
AI-2
KNOB
CHARGE
MC68HC11E1
Motor
SER.
PWR. 4.5V
BATT.
M-0 M-1 M-2 M-3
Motor
4.5V
DC MOTOR
5 4 3 2 1 0
MOTOR
SERVO
START STOP
66lAX-11 : 68HC11 Microcontroller Activity board doumentation
3.4.1.2 Results
Observe and you will see the following:
- GREEN LED Lights Up.
- Motor Turns in 1 direction for 2 Seconds
- RED LED Lights Up
- Motor Turns in faster by 30% in another direction for 2 Seconds
3.4.2.1 Procedure
(1) Connect the RC Servo motor to Channel 0 on the main board. BE CAREFUL OF
THE COLOR CODE.
- WHITE GOES TO S
- RED to +
- BLACK to -
(2) Make sure the Interactive C Program is opened. Select a NEW Program.
(3) The Following Sample Code, “SERVO-CODE” in Listing 3-2, shows how you can
control the Servo Motors.
(4) After you have typed / inserted the code, click on the “RUN MAIN” button.
(5) Observe the Servo Motor’s Operations.
KNOB
CHARGE
MC68HC11E1
SER.
PWR.
BATT.
M-0 M-1 M-2 M-3
AX-11 SER
M O VO
T
68HC11 Microcontroller 6Vd OR
c
Activity Board
DC MOTOR
4 3 2 1 0
MOTOR
SERVO
START STOP
S+-
68lAX-11 : 68HC11 Microcontroller Activity board doumentation
(1) Connect the Switch sensor to DI-15 ( Digital Input 15) on the Main Board.
(2) Make sure the Interactive C Program is opened. Select a NEW Program.
(4) After you have typed / inserted the code, click on the “RUN MAIN” button.
AI-2
KNOB
CHARGE
MC68HC11E1
SER.
DI-11 DI-12 DI-13 DI-14 DI-15
PWR.
HIGH LOW
SWITCH
BATT.
DC MOTOR
5 4 3 2 1 0
MOTOR
SERVO
START STOP
/* Hardware configuration
- Touch sensor connected to DI-11 */
void main()
{
int result; // Declare keep input from touch sensor
while(1) // Infinite loop
{
result = digital(11); // Keep value from DI-11 channel
if(result==1) // Check Touch sensor pressed
{
printf(“Your press!\n”); // Display message for pressed
beep(); // Sound beep
sleep(1.0); // Delay 1 second for display message
}
else
{
printf(“—————\n”); // Display when Touch sensor not pressed
sleep(0.1); // Delay 0.1 second for display message
}
}
}
3.4.4.1 Procedure
(1) Connect the Light Sensor to AI-2 (Analog Input 2)
(2) Make sure the Interactive C Program is opened. Select a NEW Program.
(3) The Following Sample Code, “LIGHT-CODE”
(4) After you have typed / inserted the code, click on the “RUN MAIN” button.
(5) Try these in LIGHT and DARK surroundings.
(6) Observe the LCD Screen on the Main Board.
Light
AI-2
KNOB
CHARGE
MC68HC11E1
SER.
PWR.
BATT.
M-0 M-1 M-2 M-3
Light = 50
DC MOTOR
5 4 3 2 1 0
MOTOR
SERVO
START STOP
/* GP2D120 test*/
/*
Hardware configuration*/
#define base -19
float dis_table[118]=
{ /*distance value*//*ADC value*/
32.0,/*19*/ 30.1,/*20*/ 29.5,/*21*/ 28.6,/*22*/ 27.5,/*23*/
26.1,/*24*/ 25.3,/*25*/ 24.5,/*26*/ 23.7,/*27*/ 23.2,/*28*/
22.3,/*29*/ 22.0,/*30*/ 21.1,/*31*/ 20.5,/*32*/ 20.0,/*33*/
19.3,/*34*/ 19.1,/*35*/ 18.4,/*36*/ 17.9,/*37*/ 17.5,/*38*/
17.1,/*39*/ 16.5,/*40*/ 16.2,/*41*/ 15.8,/*42*/ 15.6,/*43*/
15.5,/*44*/ 15.3,/*45*/ 14.8,/*46*/ 14.2,/*47*/ 13.8,/*48*/
13.6,/*49*/ 13.3,/*50*/ 13.1,/*51*/ 12.8,/*52*/ 12.6,/*53*/
12.4,/*54*/ 12.2,/*55*/ 12.0,/*56*/ 11.8,/*57*/ 11.7,/*58*/
11.6,/*59*/ 11.6,/*60*/ 11.5,/*61*/ 11.4,/*62*/ 11.3,/*63*/
10.85,/*64*/ 10.6,/*65*/ 10.3,/*66*/ 10.2,/*67*/ 10.0,/*68*/
9.8,/*69*/ 9.7,/*70*/ 9.5,/*71*/ 9.3,/*72*/ 9.2,/*73*/
9.0,/*74*/ 8.9,/*75*/ 8.8,/*76*/ 8.6,/*77*/ 8.4,/*78*/
8.3,/*79*/ 8.2,/*80*/ 8.0,/*81*/ 7.85,/*82*/ 7.7,/*83*/
7.6,/*84*/ 7.5,/*85*/ 7.3,/*86*/ 7.2,/*87*/ 7.15,/*88*/
7.1,/*89*/ 7.0,/*90*/ 6.9,/*91*/ 6.8,/*92*/ 6.7,/*93*/
6.6,/*94*/ 6.5,/*95*/ 6.4,/*96*/ 6.35,/*97*/ 6.3,/*98*/
6.2,/*99*/ 6.15,/*100*/ 6.1,/*101*/ 6.0,/*102*/ 5.9,/*103*/
5.85,/*104*/ 5.8,/*105*/ 5.7,/*106*/ 5.65,/*107*/ 5.6,/*108*/
5.55,/*109*/ 5.45,/*110*/ 5.4,/*111*/ 5.4,/*112*/ 5.3,/*113*/
5.2,/*114*/ 5.1,/*115*/ 5.0,/*116*/ 5.0,/*117*/ 4.9,/*118*/
4.9,/*119*/ 4.8,/*120*/ 4.8,/*121*/ 4.7,/*122*/ 4.7,/*123*/
4.6,/*124*/ 4.6,/*125*/ 4.5,/*126*/ 4.5,/*127*/ 4.4,/*128*/
4.4,/*129*/ 4.3,/*130*/ 4.3,/*131*/ 4.2,/*132*/ 4.2,/*133*/
4.1,/*134*/ 4.1,/*135*/ 4.0/*136*/
};
void main()
{
int an; // Keep analog value from sensor
while(1) // Infinite loop
{
an = analog(6); // Read analog value from sensor
if(an>=19 && an<=136 ) // Distance interval 10-80 cm
{
printf(“dis %f cm adc=%d \n”,dis_table[an+base],an);
// Show distance value
}
else
{
printf(“ Out of Range adc = %d\n”,an); // Show mesage out of Range
}
sleep(1.0); // Delay before read new cycle
}
}
3.4.5.1 Procedure
(1) Connect the GP2D120 Sensor to AI-6.
(2) Make sure the Interactive C Program is opened. Select a NEW Program or con-
tinue with your existing Program.
(4) After you have typed / inserted the code, click on the “RUN MAIN” button.
(7) Move the object nearer and further from the sensor and observe the LCD Screen
again.
KNOB
SER. CHARGE
GND
Vout MC68HC11E1
DI-10 DI-11 DI-12 DI-13 DI-14 DI-15
PWR.
/2 , BATT.
DC MOTOR
5 4 3 2 1 0
MOTOR
SERVO
START STOP
INNOVATIVE EXPERIMENT
AX-11 : 68HC11 Microcontroller Activity board doumentationl73
74lAX-11 : 68HC11 Microcontroller Activity board doumentation
COPYRIGHTS
INEX grants the user a conditional right to download, duplicate, and distribute this
text without INEXs permission. This right is based on the following conditions: the
text, or any portion thereof, may not be duplicated for commercial use; it may be
duplicated only for educational purposes when used solely in conjunction with INEX
products, and the user may recover from the student only the cost of duplication.
All text and figure is subject to publishers approval. We are not responsible for mis-
takes, misprints, or typographical errors. Innovative Experiment Co., Ltd. (INEX) as-
sumes no responsibility for the availability.
Special thanks for KISS institue (www.kipr.org) about the Interactive C software and
Fred G. Martin for the original Handyboard firmware.