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 and ILI grant DUE MIPPET has 4 switches, 4 LED's, a High Current Output, an A/D converter and two communication ports
User Code to control MIPPET MIPPET Class MIPPET
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
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
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
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 = 0x04 But we cannot just write 0x04 ( ) to the port as this will clear all other bits.
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 = OR
Talking to devices is basically a matter of reading/writing to ports Abstraction is a wonderful thing! * Hiding * Device changes, client does not notice
QUESTIONS?