mbed base board 2016 Check program check for SD card read&write (3 switches, 6 leds, I2C LCD, SD card)
Dependencies: SDFileSystem mbed
Fork of SDFileSystem_HelloWorld by
ACM1602NI.h@2:0ee1c0236a11, 2016-10-26 (annotated)
- Committer:
- tamaki
- Date:
- Wed Oct 26 08:13:51 2016 +0000
- Revision:
- 2:0ee1c0236a11
- Parent:
- 1:a41c274f95e2
mbed base board 2016 Check program check for SD card read&write (3 switches, 6 leds, I2C LCD, SD card)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tamaki | 1:a41c274f95e2 | 1 | /* An I2C text LCD library for Displaytronic ACM1602NI-FLW-FBW-M01 |
tamaki | 1:a41c274f95e2 | 2 | * Copyright 2013, Takuo WATANABE (wtakuo) |
tamaki | 1:a41c274f95e2 | 3 | * |
tamaki | 1:a41c274f95e2 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
tamaki | 1:a41c274f95e2 | 5 | * you may not use this file except in compliance with the License. |
tamaki | 1:a41c274f95e2 | 6 | * You may obtain a copy of the License at |
tamaki | 1:a41c274f95e2 | 7 | * |
tamaki | 1:a41c274f95e2 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
tamaki | 1:a41c274f95e2 | 9 | * |
tamaki | 1:a41c274f95e2 | 10 | * Unless required by applicable law or agreed to in writing, software |
tamaki | 1:a41c274f95e2 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
tamaki | 1:a41c274f95e2 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
tamaki | 1:a41c274f95e2 | 13 | * See the License for the specific language governing permissions and |
tamaki | 1:a41c274f95e2 | 14 | * limitations under the License. |
tamaki | 1:a41c274f95e2 | 15 | */ |
tamaki | 1:a41c274f95e2 | 16 | |
tamaki | 1:a41c274f95e2 | 17 | #ifndef ACM1602NI_H |
tamaki | 1:a41c274f95e2 | 18 | #define ACM1602NI_H |
tamaki | 1:a41c274f95e2 | 19 | |
tamaki | 1:a41c274f95e2 | 20 | #include "mbed.h" |
tamaki | 1:a41c274f95e2 | 21 | |
tamaki | 1:a41c274f95e2 | 22 | /** An I2C text LCD library for Displaytronic ACM1602NI-FLW-FBW-M01. |
tamaki | 1:a41c274f95e2 | 23 | * The device does not work with default I2C library due to its slow I2C responce. |
tamaki | 1:a41c274f95e2 | 24 | * This library adds some extra waits so that the device can answer to the I2C commands. |
tamaki | 1:a41c274f95e2 | 25 | * The interface is basically the same as TextLCD by Simon Ford. |
tamaki | 1:a41c274f95e2 | 26 | * |
tamaki | 1:a41c274f95e2 | 27 | * @code |
tamaki | 1:a41c274f95e2 | 28 | * #include "mbed.h" |
tamaki | 1:a41c274f95e2 | 29 | * #include "ACM1602NI.h" |
tamaki | 1:a41c274f95e2 | 30 | * |
tamaki | 1:a41c274f95e2 | 31 | * // p9: sda, p10: scl |
tamaki | 1:a41c274f95e2 | 32 | * ACM1602NI lcd(p9, p10); |
tamaki | 1:a41c274f95e2 | 33 | * |
tamaki | 1:a41c274f95e2 | 34 | * int main() { |
tamaki | 1:a41c274f95e2 | 35 | * lcd.printf("Hello, World!\n"); |
tamaki | 1:a41c274f95e2 | 36 | * lcd.printf("ACM1602NI\n"); |
tamaki | 1:a41c274f95e2 | 37 | * } |
tamaki | 1:a41c274f95e2 | 38 | * @endcode |
tamaki | 1:a41c274f95e2 | 39 | */ |
tamaki | 1:a41c274f95e2 | 40 | class ACM1602NI : public Stream |
tamaki | 1:a41c274f95e2 | 41 | { |
tamaki | 1:a41c274f95e2 | 42 | public: |
tamaki | 1:a41c274f95e2 | 43 | /** Create an ACM1602NI object connected to the specified I2C pins. |
tamaki | 1:a41c274f95e2 | 44 | * |
tamaki | 1:a41c274f95e2 | 45 | * @param sda The I2C data pin |
tamaki | 1:a41c274f95e2 | 46 | * @param scl The I2C clock pin |
tamaki | 1:a41c274f95e2 | 47 | */ |
tamaki | 1:a41c274f95e2 | 48 | ACM1602NI(PinName sda, PinName scl); |
tamaki | 1:a41c274f95e2 | 49 | |
tamaki | 1:a41c274f95e2 | 50 | /** Create an ACM1602NI object connected to the specified I2C port. |
tamaki | 1:a41c274f95e2 | 51 | * |
tamaki | 1:a41c274f95e2 | 52 | * @param i2c The I2C port to connect to |
tamaki | 1:a41c274f95e2 | 53 | */ |
tamaki | 1:a41c274f95e2 | 54 | ACM1602NI(I2C &i2c); |
tamaki | 1:a41c274f95e2 | 55 | |
tamaki | 1:a41c274f95e2 | 56 | /** Initialize the device and clear screen |
tamaki | 1:a41c274f95e2 | 57 | */ |
tamaki | 1:a41c274f95e2 | 58 | void init(); |
tamaki | 1:a41c274f95e2 | 59 | |
tamaki | 1:a41c274f95e2 | 60 | /** Locate to a screen column and row |
tamaki | 1:a41c274f95e2 | 61 | * |
tamaki | 1:a41c274f95e2 | 62 | * @param column The horizontal position from the left, indexed from 0 |
tamaki | 1:a41c274f95e2 | 63 | * @param row The vertical position from the top, indexed from 0 |
tamaki | 1:a41c274f95e2 | 64 | */ |
tamaki | 1:a41c274f95e2 | 65 | void locate(int column, int row); |
tamaki | 1:a41c274f95e2 | 66 | |
tamaki | 1:a41c274f95e2 | 67 | /** Clear the screen and locate to 0,0 */ |
tamaki | 1:a41c274f95e2 | 68 | void cls(); |
tamaki | 1:a41c274f95e2 | 69 | |
tamaki | 1:a41c274f95e2 | 70 | int rows(); |
tamaki | 1:a41c274f95e2 | 71 | int columns(); |
tamaki | 1:a41c274f95e2 | 72 | |
tamaki | 1:a41c274f95e2 | 73 | protected: |
tamaki | 1:a41c274f95e2 | 74 | virtual int _putc(int value); |
tamaki | 1:a41c274f95e2 | 75 | virtual int _getc(); |
tamaki | 1:a41c274f95e2 | 76 | |
tamaki | 1:a41c274f95e2 | 77 | int address(int column, int raw); |
tamaki | 1:a41c274f95e2 | 78 | void character(int column, int row, int c); |
tamaki | 1:a41c274f95e2 | 79 | int writeBytes(const char *data, int length, bool repeated = false); |
tamaki | 1:a41c274f95e2 | 80 | void writeCommand(int command); |
tamaki | 1:a41c274f95e2 | 81 | void writeData(int data); |
tamaki | 1:a41c274f95e2 | 82 | |
tamaki | 1:a41c274f95e2 | 83 | static const int i2c_addr = 0x50 << 1; |
tamaki | 1:a41c274f95e2 | 84 | static const int i2c_bit_wait_us = 20; |
tamaki | 1:a41c274f95e2 | 85 | static const int i2c_command_wait_ms = 4; |
tamaki | 1:a41c274f95e2 | 86 | |
tamaki | 1:a41c274f95e2 | 87 | static const int display_columns = 16; |
tamaki | 1:a41c274f95e2 | 88 | static const int display_rows = 2; |
tamaki | 1:a41c274f95e2 | 89 | |
tamaki | 1:a41c274f95e2 | 90 | I2C _i2c; |
tamaki | 1:a41c274f95e2 | 91 | int _column, _row; |
tamaki | 1:a41c274f95e2 | 92 | }; |
tamaki | 1:a41c274f95e2 | 93 | |
tamaki | 1:a41c274f95e2 | 94 | #endif |
tamaki | 1:a41c274f95e2 | 95 |