Unformatted text preview:

Handy BoardHands-on Lab #7 – The Traffic LightProgramming in Real Time – Time of DaySlide 4Slide 5A sleep functionProgramming in Real Time – WaitingSlide 8Slide 9The Handy BoardInteractive CSlide 12Slide 13Traffic Light StatesSlide 15Skeleton Program for Traffic LightLect 26 P. 1 Engineering H192 - Computer Programming Winter QuarterThe Ohio State UniversityGateway Engineering Education CoalitionHandy BoardLecture 26Lect 26 P. 2 Engineering H192 - Computer Programming Winter QuarterThe Ohio State UniversityGateway Engineering Education CoalitionHands-on Lab #7 – The Traffic Light•Hands-On Lab #7 will use the MIT Handy Board controller.•First part of exercise is to write a C (not C++) program which performs functions to simulate the operation of a traffic light.•Second part of exercise will be to convert program to run on Interactive C, the compiler for the Handy Board.•Hand-outs will be provided for Handy Board basics, description of required C program, and laboratory exercise.Lect 26 P. 3 Engineering H192 - Computer Programming Winter QuarterThe Ohio State UniversityGateway Engineering Education CoalitionProgramming in Real Time – Time of Day•Programs which run in real time make frequent use of system timing functions and system clock.•On the Unix system there are some useful timing routines in <time.h> and <unistd.h>•We will need to use at least:–time defined in <time.h>–sleep defined in <unistd.h>Lect 26 P. 4 Engineering H192 - Computer Programming Winter QuarterThe Ohio State UniversityGateway Engineering Education CoalitionProgramming in Real Time – Time of Day•From the t i me routine in <time.h> we can look up the current time of day:•NAME time - get time•SYNOPSIS #include <sys/types.h> /* Not usually required */ #include <time.h>time_t time (time_t *tloc) ;•DESCRIPTION time returns the value of time in seconds since 00:00:00 UTC, January 1,1970. If tloc is non-zero, the return value is also stored in the location to which tloc points.Lect 26 P. 5 Engineering H192 - Computer Programming Winter QuarterThe Ohio State UniversityGateway Engineering Education CoalitionProgramming in Real Time – Time of Day•To get the elapsed time from some starting point:#include <time.h>int time_start, time_now, delta_t ;…time_start = time (NULL) ;…time_now = time (NULL) ;delta_t = time_now - time_start ;•More rigorously, one would probably use the difftime function:delta_t = difftime ( time_now, time_start) ;Lect 26 P. 6 Engineering H192 - Computer Programming Winter QuarterThe Ohio State UniversityGateway Engineering Education CoalitionA sleep functionvoid sleep (float n){ long start, now ; now=time (NULL) ; start=now ; while (now - start < n) now = time (NULL) ;}Lect 26 P. 7 Engineering H192 - Computer Programming Winter QuarterThe Ohio State UniversityGateway Engineering Education CoalitionProgramming in Real Time – Waiting•From the sleep routine in <unistd.h> we can wait for time to elapse (i.e., "take a nap"):•NAME sleep - suspend execution for interval•SYNOPSIS #include <unistd.h> unsigned sleep (unsigned seconds);•DESCRIPTION The current thread is suspended from execution for the number of seconds specified by the argument. The suspension time may be longer than requested by an arbitrary amount due to the scheduling of other activity in the system. See "man sleep" for more details on SLEEP(3C).Lect 26 P. 8 Engineering H192 - Computer Programming Winter QuarterThe Ohio State UniversityGateway Engineering Education CoalitionProgramming in Real Time – Waiting•To wait a specified amount of time between two statements in a program:#include <unistd.h>int color1, color2, direction1, direction2;change_lites (color1, direction1) ;sleep (6) ;change_lites (color2, direction2) ;Lect 26 P. 9 Engineering H192 - Computer Programming Winter QuarterThe Ohio State UniversityGateway Engineering Education CoalitionThe Handy BoardLect 26 P. 10 Engineering H192 - Computer Programming Winter QuarterThe Ohio State UniversityGateway Engineering Education CoalitionThe Handy Board•The Handy Board features:•52–pin Motorola 6811 microprocessor with system clock at 2 MHz.•32K of battery-backed CMOS static RAM.•Two L293D chips capable of driving four DC motors.•16 x 2 character LCD screen.•Two user-programmable buttons, one knob, and piezo beeper.•Powered header inputs for 7 analog sensors and 9 digital sensors.•Internal 9.6v nicad battery with built-in recharging circuit.•Hardware 38 kHz oscillator and drive transistor for IR output and on-board 38 kHz IR receiver.•Board size of 4.25 x 3.15 inches, designed for a commercial, high grade plastic enclosure which holds battery pack beneath the board.Lect 26 P. 11 Engineering H192 - Computer Programming Winter QuarterThe Ohio State UniversityGateway Engineering Education CoalitionInteractive C•Loosely based on ANSI C•Two versions available:–IC version 3.2 - installed in lab, available for $35 per educational user from Newton Labs. This is the most up-to-date version with some local (OSU) enhancements.–IC Version 2.8x - available for free as a download from the Handy Board web site. Does not support the use of structs, #define, multi-dimensional arrays, and some other improvements found only in Version 3.2.–Newer versions are available but are not yet stable.Lect 26 P. 12 Engineering H192 - Computer Programming Winter QuarterThe Ohio State UniversityGateway Engineering Education CoalitionInteractive C•Things that are different in IC (compared to ANSI C):–No function prototypes –No pointer arithmetic –Limited formats possible in printf–Array bounds checked at run time–Arrays can not be converted to pointers–No #include statements–Smaller set of allowable data types (only int, long, float, char, and struct (v3.2 only)–Character strings are supported, but simple char variables are notLect 26 P. 13 Engineering H192 - Computer Programming Winter QuarterThe Ohio State UniversityGateway Engineering Education CoalitionInteractive C•More things that are different in IC (compared to ANSI C):–No switch/case construct–Can only do +, -, and * on long int–All source files must be compiled together–No extern statement–#define has global scope–User functions come first in source file–No do/while constructLect 26 P. 14 Engineering H192 - Computer Programming Winter QuarterThe Ohio State UniversityGateway Engineering


View Full Document

OSU ENGR H192 - Handy Board

Documents in this Course
Strings

Strings

22 pages

Load more
Download Handy Board
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Handy Board and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Handy Board 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?