Presentation is loading. Please wait.

Presentation is loading. Please wait.

Many students find it difficult understanding the concept of Object Oriented Programming (OOP) Lack of exciting labs leads to a loss of interest Created.

Similar presentations


Presentation on theme: "Many students find it difficult understanding the concept of Object Oriented Programming (OOP) Lack of exciting labs leads to a loss of interest Created."— Presentation transcript:

1

2 Many students find it difficult understanding the concept of Object Oriented Programming (OOP) Lack of exciting labs leads to a loss of interest Created with partial support from the National Science Foundation’s Division of Undergraduate Education through CCD grant DUE 97-52626 and ILI grant DUE 98-50983. MIPPET has 4 switches, 4 LED's, a High Current Output, an A/D converter and two communication ports

3 User Code to control MIPPET MIPPET Class MIPPET

4 Object Class provides a high level coding structure for the user Mippet (int port); // Precondition: Mippet must be connected to parallel port at // address "port" (can be 0x378, 0x278 or 0x3BC) // Postcondition: Mippet is initialized to all items off // (status port bits 0-3 low, 4-7 high) void ReadSwitches (bool & switch0, bool & switch1, bool & switch2, bool & switch3); // Precondition: None // Postcondition: Sets the switch parameters to 0 or 1 depending on // whether the switch is pressed or not at the instant // the function call is made (0 = not pressed, // 1 = pressed) // Returns: None

5 MIPPET connects to the parallel port of a computer All inputs and outputs are through pins on the parallel port To use a port, we need to know its base address and the semantics of its usage provided by the data sheet

6 MS C/C++ provides two functions to write/read from the port: inp & outp e.g. The parallel port has a base address of 0x378. To read the Status Port (located at the base address+1): int x; x = inp(0x379); To set or clear a bit, need to create a mask

7

8

9 Say we want to set Logical Output 3 high. We know that Logical Output 3 is connected to pin 4, which is bit 2 on the status port Since we want to modify bit 2, our mask will be 0000 0100 = 0x04 But we cannot just write 0x04 (0000 0100) to the port as this will clear all other bits.

10 Must read in the existing value of the data port e.g. x = inp(0x378) We take this value and “OR” it with our mask (0x04) “OR”ing this mask with the value read from the status port sets bit 2 and keeps all other values unchanged. e.g. x = 11000101100110 OR 00001000000100 ----------- ----------- 1100110 1100110

11 Talking to devices is basically a matter of reading/writing to ports Abstraction is a wonderful thing! * Hiding * Device changes, client does not notice

12 QUESTIONS?


Download ppt "Many students find it difficult understanding the concept of Object Oriented Programming (OOP) Lack of exciting labs leads to a loss of interest Created."

Similar presentations


Ads by Google