Lab 1 Program C

Dependents:   Lab1C

Fork of mbed by -deleted-

Committer:
mattsims12
Date:
Tue Sep 29 03:04:58 2015 +0000
Revision:
44:1c5f591fce58
Parent:
43:aff670d0d510
Lab 1 Program C

Who changed what in which revision?

UserRevisionLine numberNew contents of line
simon.ford@mbed.co.uk 18:b3c9f16cbb96 1 /* mbed Microcontroller Library - PortInOut
emilmont 27:7110ebee3484 2 * Copyright (c) 2006-2011 ARM Limited. All rights reserved.
simon.ford@mbed.co.uk 18:b3c9f16cbb96 3 */
simon.ford@mbed.co.uk 18:b3c9f16cbb96 4
simon.ford@mbed.co.uk 18:b3c9f16cbb96 5 #ifndef MBED_PORTIN_H
simon.ford@mbed.co.uk 18:b3c9f16cbb96 6 #define MBED_PORTIN_H
simon.ford@mbed.co.uk 18:b3c9f16cbb96 7
emilmont 27:7110ebee3484 8 #include "device.h"
emilmont 27:7110ebee3484 9
emilmont 27:7110ebee3484 10 #if DEVICE_PORTIN
emilmont 27:7110ebee3484 11
simon.ford@mbed.co.uk 18:b3c9f16cbb96 12 #include "PortNames.h"
simon.ford@mbed.co.uk 18:b3c9f16cbb96 13 #include "PinNames.h"
simon.ford@mbed.co.uk 18:b3c9f16cbb96 14
simon.ford@mbed.co.uk 18:b3c9f16cbb96 15 namespace mbed {
simon.ford@mbed.co.uk 18:b3c9f16cbb96 16
screamer 43:aff670d0d510 17 /** A multiple pin digital input
screamer 43:aff670d0d510 18 *
screamer 43:aff670d0d510 19 * Example:
screamer 43:aff670d0d510 20 * @code
screamer 43:aff670d0d510 21 * // Switch on an LED if any of mbed pins 21-26 is high
screamer 43:aff670d0d510 22 *
screamer 43:aff670d0d510 23 * #include "mbed.h"
screamer 43:aff670d0d510 24 *
screamer 43:aff670d0d510 25 * PortIn p(Port2, 0x0000003F); // p21-p26
screamer 43:aff670d0d510 26 * DigitalOut ind(LED4);
simon.ford@mbed.co.uk 18:b3c9f16cbb96 27 *
screamer 43:aff670d0d510 28 * int main() {
screamer 43:aff670d0d510 29 * while(1) {
screamer 43:aff670d0d510 30 * int pins = p.read();
screamer 43:aff670d0d510 31 * if(pins) {
screamer 43:aff670d0d510 32 * ind = 1;
screamer 43:aff670d0d510 33 * } else {
screamer 43:aff670d0d510 34 * ind = 0;
screamer 43:aff670d0d510 35 * }
screamer 43:aff670d0d510 36 * }
screamer 43:aff670d0d510 37 * }
screamer 43:aff670d0d510 38 * @endcode
simon.ford@mbed.co.uk 18:b3c9f16cbb96 39 */
simon.ford@mbed.co.uk 18:b3c9f16cbb96 40 class PortIn {
simon.ford@mbed.co.uk 18:b3c9f16cbb96 41 public:
simon.ford@mbed.co.uk 18:b3c9f16cbb96 42
screamer 43:aff670d0d510 43 /** Create an PortIn, connected to the specified port
simon.ford@mbed.co.uk 18:b3c9f16cbb96 44 *
screamer 43:aff670d0d510 45 * @param port Port to connect to (Port0-Port5)
screamer 43:aff670d0d510 46 * @param mask A bitmask to identify which bits in the port should be included (0 - ignore)
screamer 43:aff670d0d510 47 */
simon.ford@mbed.co.uk 18:b3c9f16cbb96 48 PortIn(PortName port, int mask = 0xFFFFFFFF);
simon.ford@mbed.co.uk 18:b3c9f16cbb96 49
screamer 43:aff670d0d510 50 /** Read the value currently output on the port
simon.ford@mbed.co.uk 18:b3c9f16cbb96 51 *
screamer 43:aff670d0d510 52 * @returns
screamer 43:aff670d0d510 53 * An integer with each bit corresponding to associated port pin setting
simon.ford@mbed.co.uk 18:b3c9f16cbb96 54 */
emilmont 28:667d61c9177b 55 int read();
simon.ford@mbed.co.uk 18:b3c9f16cbb96 56
screamer 43:aff670d0d510 57 /** Set the input pin mode
simon.ford@mbed.co.uk 18:b3c9f16cbb96 58 *
screamer 43:aff670d0d510 59 * @param mode PullUp, PullDown, PullNone, OpenDrain
simon.ford@mbed.co.uk 18:b3c9f16cbb96 60 */
simon.ford@mbed.co.uk 18:b3c9f16cbb96 61 void mode(PinMode mode);
simon.ford@mbed.co.uk 18:b3c9f16cbb96 62
screamer 43:aff670d0d510 63 /** A shorthand for read()
simon.ford@mbed.co.uk 18:b3c9f16cbb96 64 */
simon.ford@mbed.co.uk 18:b3c9f16cbb96 65 operator int() {
screamer 43:aff670d0d510 66 return read();
simon.ford@mbed.co.uk 18:b3c9f16cbb96 67 }
simon.ford@mbed.co.uk 18:b3c9f16cbb96 68
simon.ford@mbed.co.uk 18:b3c9f16cbb96 69 private:
emilmont 28:667d61c9177b 70 #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368)
simon.ford@mbed.co.uk 18:b3c9f16cbb96 71 LPC_GPIO_TypeDef *_gpio;
emilmont 28:667d61c9177b 72 #endif
simon.ford@mbed.co.uk 18:b3c9f16cbb96 73 PortName _port;
emilmont 28:667d61c9177b 74 uint32_t _mask;
simon.ford@mbed.co.uk 18:b3c9f16cbb96 75 };
simon.ford@mbed.co.uk 18:b3c9f16cbb96 76
simon.ford@mbed.co.uk 18:b3c9f16cbb96 77 } // namespace mbed
simon.ford@mbed.co.uk 18:b3c9f16cbb96 78
simon.ford@mbed.co.uk 18:b3c9f16cbb96 79 #endif
emilmont 27:7110ebee3484 80
emilmont 27:7110ebee3484 81 #endif