Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
main.cpp@1:23bf1845cc2f, 2017-12-27 (annotated)
- Committer:
- chills
- Date:
- Wed Dec 27 15:27:32 2017 +0000
- Revision:
- 1:23bf1845cc2f
- Parent:
- 0:87888ca85258
- Child:
- 2:ed06e716cca2
2017_12_27 15:24; Can print string but only slowly.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
chills | 0:87888ca85258 | 1 | #include "mbed.h" |
chills | 1:23bf1845cc2f | 2 | #include <string> |
chills | 0:87888ca85258 | 3 | |
chills | 0:87888ca85258 | 4 | DigitalOut myled(LED1); |
chills | 0:87888ca85258 | 5 | |
chills | 0:87888ca85258 | 6 | DigitalOut RS(D9); |
chills | 0:87888ca85258 | 7 | DigitalOut RW(D4); |
chills | 0:87888ca85258 | 8 | DigitalOut E(D8); |
chills | 0:87888ca85258 | 9 | BusInOut DB(A0, A1, A2, A3, D7, D6, D3, D1); //LSB First |
chills | 0:87888ca85258 | 10 | |
chills | 0:87888ca85258 | 11 | void clock_in(); |
chills | 0:87888ca85258 | 12 | void Function_Set(); |
chills | 0:87888ca85258 | 13 | void Display_Off(); |
chills | 0:87888ca85258 | 14 | void Display_Clear(); |
chills | 0:87888ca85258 | 15 | void Entry_Mode_Set(); |
chills | 0:87888ca85258 | 16 | void Display_On(); |
chills | 0:87888ca85258 | 17 | void DDRAM_Address(int Address); |
chills | 1:23bf1845cc2f | 18 | void Write_Data(string Letter); |
chills | 1:23bf1845cc2f | 19 | void Write_String(string Word); |
chills | 0:87888ca85258 | 20 | |
chills | 0:87888ca85258 | 21 | int main() { |
chills | 0:87888ca85258 | 22 | |
chills | 0:87888ca85258 | 23 | DB.output(); |
chills | 0:87888ca85258 | 24 | Function_Set(); |
chills | 0:87888ca85258 | 25 | wait(0.020); |
chills | 0:87888ca85258 | 26 | Display_Off(); |
chills | 0:87888ca85258 | 27 | wait(0.020); |
chills | 0:87888ca85258 | 28 | Display_Clear(); |
chills | 0:87888ca85258 | 29 | wait(0.020); |
chills | 0:87888ca85258 | 30 | Entry_Mode_Set(); |
chills | 0:87888ca85258 | 31 | wait(0.020); |
chills | 0:87888ca85258 | 32 | Display_On(); |
chills | 0:87888ca85258 | 33 | wait(0.020); |
chills | 0:87888ca85258 | 34 | DDRAM_Address(0); |
chills | 0:87888ca85258 | 35 | wait(0.020); |
chills | 1:23bf1845cc2f | 36 | Write_String("Greetings"); |
chills | 0:87888ca85258 | 37 | |
chills | 0:87888ca85258 | 38 | } |
chills | 0:87888ca85258 | 39 | |
chills | 0:87888ca85258 | 40 | void clock_in(){ |
chills | 0:87888ca85258 | 41 | E = 1; wait(0.01); E = 0; wait(0.01); E = 1; |
chills | 0:87888ca85258 | 42 | } |
chills | 0:87888ca85258 | 43 | |
chills | 0:87888ca85258 | 44 | void Function_Set(){ |
chills | 0:87888ca85258 | 45 | RS = 0; RW = 0; DB = 0x3C; clock_in(); |
chills | 0:87888ca85258 | 46 | } |
chills | 0:87888ca85258 | 47 | |
chills | 0:87888ca85258 | 48 | void Display_Off(){ |
chills | 0:87888ca85258 | 49 | RS = 0; RW = 0; DB = 0x08; clock_in(); |
chills | 0:87888ca85258 | 50 | } |
chills | 0:87888ca85258 | 51 | |
chills | 0:87888ca85258 | 52 | void Display_Clear(){ |
chills | 0:87888ca85258 | 53 | RS = 0; RW = 0; DB = 0x01; clock_in(); |
chills | 0:87888ca85258 | 54 | } |
chills | 0:87888ca85258 | 55 | |
chills | 0:87888ca85258 | 56 | void Entry_Mode_Set(){ |
chills | 0:87888ca85258 | 57 | RS = 0; RW = 0; DB = 0x06; clock_in(); |
chills | 0:87888ca85258 | 58 | } |
chills | 0:87888ca85258 | 59 | |
chills | 0:87888ca85258 | 60 | void Display_On(){ |
chills | 0:87888ca85258 | 61 | RS = 0; RW = 0; DB = 0x0E; clock_in(); |
chills | 0:87888ca85258 | 62 | } |
chills | 0:87888ca85258 | 63 | |
chills | 0:87888ca85258 | 64 | void DDRAM_Address(int Address){ |
chills | 0:87888ca85258 | 65 | RS = 0; RW = 0; DB = 0x80 + Address; clock_in(); |
chills | 0:87888ca85258 | 66 | } |
chills | 0:87888ca85258 | 67 | |
chills | 1:23bf1845cc2f | 68 | void Write_Data(string Letter){ |
chills | 1:23bf1845cc2f | 69 | |
chills | 1:23bf1845cc2f | 70 | int ASCII_Converted[32]; |
chills | 1:23bf1845cc2f | 71 | |
chills | 1:23bf1845cc2f | 72 | for (int i = 0; i < Letter.length(); i++) |
chills | 1:23bf1845cc2f | 73 | { |
chills | 1:23bf1845cc2f | 74 | ASCII_Converted[i] = Letter.at(i); |
chills | 1:23bf1845cc2f | 75 | |
chills | 1:23bf1845cc2f | 76 | } |
chills | 1:23bf1845cc2f | 77 | |
chills | 1:23bf1845cc2f | 78 | RS = 1; RW = 0; DB = ASCII_Converted[0]; clock_in(); |
chills | 1:23bf1845cc2f | 79 | |
chills | 0:87888ca85258 | 80 | } |
chills | 1:23bf1845cc2f | 81 | |
chills | 1:23bf1845cc2f | 82 | void Write_String(string Word){ |
chills | 1:23bf1845cc2f | 83 | |
chills | 1:23bf1845cc2f | 84 | int ASCII_Converted; |
chills | 1:23bf1845cc2f | 85 | for (int i = 0; i < Word.length(); i++) |
chills | 1:23bf1845cc2f | 86 | { |
chills | 1:23bf1845cc2f | 87 | ASCII_Converted = Word.at(i); |
chills | 1:23bf1845cc2f | 88 | DDRAM_Address(i); //wait(0.020); |
chills | 1:23bf1845cc2f | 89 | RS = 1; RW = 0; DB = ASCII_Converted; clock_in(); |
chills | 1:23bf1845cc2f | 90 | } |
chills | 1:23bf1845cc2f | 91 | |
chills | 1:23bf1845cc2f | 92 | |
chills | 1:23bf1845cc2f | 93 | |
chills | 1:23bf1845cc2f | 94 | } |