1 / 15

Handy Board

Handy Board. Lecture 26. Hands-on Lab #6 - The Traffic Light. Hands-On Lab #6 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.

Télécharger la présentation

Handy Board

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Handy Board Lecture 26 Winter Quarter

  2. Hands-on Lab #6 - The Traffic Light • Hands-On Lab #6 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. Winter Quarter

  3. Programming 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> Winter Quarter

  4. Programming in Real Time - Time of Day • From the time 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. Winter Quarter

  5. Programming 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) ; Winter Quarter

  6. A sleep function void sleep (float n) { long start, now ; now=time(NULL) ; start=now ; while(now - start < n) now = time(NULL) ; } Winter Quarter

  7. Programming 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). Winter Quarter

  8. Programming 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); Winter Quarter

  9. The 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. Winter Quarter

  10. Interactive 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. Winter Quarter

  11. Interactive 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 not Winter Quarter

  12. Interactive 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 construct Winter Quarter

  13. Traffic Light States Winter Quarter

  14. Traffic Light States Winter Quarter

  15. Skeleton Program for Traffic Light void change( /*parameters*/ ) { /* motor function calls (or display light status) */ } voidmain( ) { /* declarations */ /* set initial light conditions */ /* while loop with timing and function calls */ } Winter Quarter

More Related