32
Introduction to Interfacing Projects Nareen Khan

Introduction to Interfacing Projects

  • Upload
    kane

  • View
    36

  • Download
    0

Embed Size (px)

DESCRIPTION

Introduction to Interfacing Projects. Nareen Khan. Using Turing. Command to send data to parallel port parallelput (x : int) The command sends 1 byte of data to the parallel port at a time. Using 1 byte (8 bits) we can represent 2 8 =256 different states. - PowerPoint PPT Presentation

Citation preview

Page 1: Introduction to Interfacing Projects

Introduction to Interfacing Projects

Nareen Khan

Page 2: Introduction to Interfacing Projects

Using Turing

Command to send data to parallel port

parallelput (x : int) The command sends 1 byte of data to the

parallel port at a time. Using 1 byte (8 bits) we can represent

28=256 different states. The 8 bits are sent along the Data pins on the

parallel port (Pins 2-9, D0-D7)

Page 3: Introduction to Interfacing Projects

19 8 67 5 4 3 213 12 11 10

22 21 1920 18 17 16 1525 24 23 14

Understanding the Parallel Port

D7 D6 D4D5 D3 D2 D1 D0

Data Lines (D) used for output.

Grounds

Status Lines (S) used for input.

Control Lines (C) may be used for input / output

Page 4: Introduction to Interfacing Projects

Binary on the Parallel Port

parallelput(0) parallelput(1) parallelput(37) parallelput(255)

0 0 00 0 0 0 00 0 00 0 0 0 10 0 01 0 1 0 11 1 11 1 1 1 1

The integer parameter is translated into binary and each bit corresponds to one of the data pins on the parallel port.

Unsure of your conversions? Try this utility.

Page 5: Introduction to Interfacing Projects

What does the circuit look like?

parallelput(0)

Switch is open, no path, LED off

parallelput(1)

Switch is closed, path exists, LED on

Voltage from

parallel port

220Ω

Pin 2

Pin 18

Page 6: Introduction to Interfacing Projects

Breadboard Basics

Connected vertically in blocks of 5

Connected horizontally

Page 7: Introduction to Interfacing Projects

Light Emitting Diodes

LED’s will only work if they are installed in the right direction.

Here are three ways to tell which is the negative (-’ve) lead.

1) –’ve lead is shorter

Page 8: Introduction to Interfacing Projects

Light Emitting Diodes

LED’s will only work if they are installed in the right direction.

Here are three ways to tell which is the negative (-’ve) lead.

2) Internal segment is

larger

Page 9: Introduction to Interfacing Projects

Light Emitting Diodes

LED’s will only work if they are installed in the right direction.

Here are three ways to tell which is the negative (-’ve) lead.

3) Flat side on lip

Top View

Page 10: Introduction to Interfacing Projects

Wiring an LED

+’ve, Long Lead

Page 11: Introduction to Interfacing Projects

Project Samples

Traffic Intersection

Page 12: Introduction to Interfacing Projects

Traffic Intersection

Page 13: Introduction to Interfacing Projects

Traffic Intersection

Page 14: Introduction to Interfacing Projects

Student GUIs

Page 15: Introduction to Interfacing Projects

Student GUI’s

Page 16: Introduction to Interfacing Projects

The Traffic Intersection Project

Steps:

1) Wire six LED / resistor pairs on breadboard

2) Attach the wires to your model

3) Write your program

4) Enjoy hours of staring at the lights change

Page 17: Introduction to Interfacing Projects

Step 1 – Wiring the lights

+’ve, Long Lead

-’ve, Short Lead

Page 18: Introduction to Interfacing Projects

Step 2 – The D-Sub Connector

1)Attach your wires to the crimp pins.

2)Be sure to press the clamps down tight on the wire.

3)Push the crimped pin into the D-Sub Connector (it’s a tight fit).

4)Repeat for the other 7 wires.

Page 19: Introduction to Interfacing Projects

Step 1 – Wiring the lights

Page 20: Introduction to Interfacing Projects

Step 1 – Wiring the lights

Page 21: Introduction to Interfacing Projects

Test your interface

Once you’ve got the wires connected to the parallelport, you can test the interface.

Try :

parallelput(255)

This should turn on all your lights.

Page 22: Introduction to Interfacing Projects

Sample Program #1

Page 23: Introduction to Interfacing Projects

Sample Program #Step 1 – Wire Wrapping

Page 24: Introduction to Interfacing Projects

Make Use of the Tri-State Buffer – See the Handout

Page 25: Introduction to Interfacing Projects

Making The Turing Program 1

Make a Program Header%

% The "trafficIntersection" program

% Course Code: ICS 3M1

% Instructor: Your Teacher

% Date: April 25, 2007

% Initial Release

%

% This Program simulates a traffic intersection in graphics. It can also properly drive the actual

% intersection by use of a parallel port and binary outputs.

Page 26: Introduction to Interfacing Projects

Making The Turing Program 2

Create a User Defined Data Typetype trafficState: % data type trafficState will store various components of traffic

states.

record

timeWait : int % var for the time in that state

binState : int % binary value of that state (more details see pin output state table

NSPic : string % var for the state of the NS light

EWPic : string % var for the state of the EW light

end record

Page 27: Introduction to Interfacing Projects

Making The Turing Program 3

Create a User Defined Data Typedrawfillbox(0, 0, maxx, maxy, 54) % code for background colour% The 6 states are declared as an array of trafficState data typevar trafficPattern : array 1 .. 6 of trafficState

% Below contains the value of each of the states% timeWait: Green light - 5 sec.% Yellow light - 2 sec.% Both red light - 1.25 sec.% binaryStates in decimal: NS green - 1 % NS yellow - 2% NS red - 4% EW green - 8% EW yellow - 16% EW red - 32

Page 28: Introduction to Interfacing Projects

Making The Turing Program 4

Note the binary States listed belowdrawfillbox(0, 0, maxx, maxy, 54) % code for background colour% The 6 states are declared as an array of trafficState data typevar trafficPattern : array 1 .. 6 of trafficState

% Below contains the value of each of the states% timeWait: Green light - 5 sec.% Yellow light - 2 sec.% Both red light - 1.25 sec.% binaryStates in decimal: NS green - 1 % NS yellow - 2% NS red - 4% EW green - 8% EW yellow - 16% EW red - 32

Page 29: Introduction to Interfacing Projects

Making The Turing Program 5

Then Define Each Traffic Pattern in this manner…

%NS Green EW Red

trafficPattern(1).timeWait := 5000

trafficPattern(1).binState := 1 + 32

trafficPattern(1).NSPic := "trafficgreen.bmp"

trafficPattern(1).EWPic := "trafficred.bmp“

%NS Yellow EW Red

trafficPattern(2).timeWait := 2000

trafficPattern(2).binState := 2 + 32

trafficPattern(2).NSPic := "trafficyellow.bmp"

trafficPattern(2).EWPic := "trafficred.bmp“ etc…

Page 30: Introduction to Interfacing Projects

Making The Turing Program 6

Create a Procedure% procedure for loading the pictures in the different states

procedure drawIntersection (NSFile : string, EWFile : string)

Pic.ScreenLoad (NSFile, 250, 250, 0)

Pic.ScreenLoad (EWFile, 100, 150, 2)

Pic.ScreenLoad (NSFile, 250, 50, 0)

Pic.ScreenLoad (EWFile, 400, 150, 2)

end drawIntersection

Page 31: Introduction to Interfacing Projects

Making The Turing Program 7

Finally, cycle through the lights…% Loop to make the cycle continuous

for i : 1 .. 4

% Loop for each of the traffic states and giving drawIntersection the images to change

for j : 1 .. 6

drawIntersection (trafficPattern(j).NSPic , trafficPattern(j).EWPic)

parallelput (trafficPattern(j).binState) % send info to parallel port

delay (trafficPattern(j).timeWait) % delay the amount of milliseconds indicated in traffic state

end for

end for

Page 32: Introduction to Interfacing Projects

Making The Turing Program 8

Make Sure You Have These Graphics Files