tim008 tim008
/
pripremaLV8Z03
Sumejja Porca
main.cpp@0:6e6e952bc572, 2014-05-08 (annotated)
- Committer:
- tim008
- Date:
- Thu May 08 13:57:40 2014 +0000
- Revision:
- 0:6e6e952bc572
pripremaZ03
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tim008 | 0:6e6e952bc572 | 1 | #include "mbed.h" |
tim008 | 0:6e6e952bc572 | 2 | #include "N5110.h" |
tim008 | 0:6e6e952bc572 | 3 | |
tim008 | 0:6e6e952bc572 | 4 | Serial pc (USBTX, USBRX); |
tim008 | 0:6e6e952bc572 | 5 | //Deklaracija LCD objekta |
tim008 | 0:6e6e952bc572 | 6 | //N5110 lcd(VCC,SCE,RST,D/C,MOSI,SCLK,LED) |
tim008 | 0:6e6e952bc572 | 7 | N5110 lcd(dp4,dp24,dp23,dp25,dp2,dp6,dp18); |
tim008 | 0:6e6e952bc572 | 8 | |
tim008 | 0:6e6e952bc572 | 9 | int x(0), y(0); |
tim008 | 0:6e6e952bc572 | 10 | |
tim008 | 0:6e6e952bc572 | 11 | void deleteAll() |
tim008 | 0:6e6e952bc572 | 12 | { |
tim008 | 0:6e6e952bc572 | 13 | lcd.clear(); |
tim008 | 0:6e6e952bc572 | 14 | lcd.refresh(); |
tim008 | 0:6e6e952bc572 | 15 | x = y = 0; |
tim008 | 0:6e6e952bc572 | 16 | } |
tim008 | 0:6e6e952bc572 | 17 | |
tim008 | 0:6e6e952bc572 | 18 | void deleteLetter() |
tim008 | 0:6e6e952bc572 | 19 | { |
tim008 | 0:6e6e952bc572 | 20 | if(x == 0 && y == 0) |
tim008 | 0:6e6e952bc572 | 21 | { |
tim008 | 0:6e6e952bc572 | 22 | x = 84; |
tim008 | 0:6e6e952bc572 | 23 | y = 47; |
tim008 | 0:6e6e952bc572 | 24 | return; |
tim008 | 0:6e6e952bc572 | 25 | } |
tim008 | 0:6e6e952bc572 | 26 | |
tim008 | 0:6e6e952bc572 | 27 | if(x == 0) |
tim008 | 0:6e6e952bc572 | 28 | { |
tim008 | 0:6e6e952bc572 | 29 | y = y - 1; |
tim008 | 0:6e6e952bc572 | 30 | x = 84; |
tim008 | 0:6e6e952bc572 | 31 | return; |
tim008 | 0:6e6e952bc572 | 32 | } |
tim008 | 0:6e6e952bc572 | 33 | |
tim008 | 0:6e6e952bc572 | 34 | for(int i = x - 1; i >= x - 6; i--) |
tim008 | 0:6e6e952bc572 | 35 | { |
tim008 | 0:6e6e952bc572 | 36 | lcd.clearPixel(i,y); |
tim008 | 0:6e6e952bc572 | 37 | } |
tim008 | 0:6e6e952bc572 | 38 | |
tim008 | 0:6e6e952bc572 | 39 | lcd.refresh(); |
tim008 | 0:6e6e952bc572 | 40 | x = x - 6; |
tim008 | 0:6e6e952bc572 | 41 | } |
tim008 | 0:6e6e952bc572 | 42 | |
tim008 | 0:6e6e952bc572 | 43 | void newLine() |
tim008 | 0:6e6e952bc572 | 44 | { |
tim008 | 0:6e6e952bc572 | 45 | if(y == 47) y = 0; |
tim008 | 0:6e6e952bc572 | 46 | else y = y + 1; |
tim008 | 0:6e6e952bc572 | 47 | |
tim008 | 0:6e6e952bc572 | 48 | x = 0; |
tim008 | 0:6e6e952bc572 | 49 | } |
tim008 | 0:6e6e952bc572 | 50 | |
tim008 | 0:6e6e952bc572 | 51 | void getChar() |
tim008 | 0:6e6e952bc572 | 52 | { |
tim008 | 0:6e6e952bc572 | 53 | if(pc.readable()) |
tim008 | 0:6e6e952bc572 | 54 | { |
tim008 | 0:6e6e952bc572 | 55 | char c = pc.getc(); |
tim008 | 0:6e6e952bc572 | 56 | // if (c == backspace) |
tim008 | 0:6e6e952bc572 | 57 | deleteLetter(); |
tim008 | 0:6e6e952bc572 | 58 | // else if (c == del) |
tim008 | 0:6e6e952bc572 | 59 | deleteAll(); |
tim008 | 0:6e6e952bc572 | 60 | // else if (c == enter) |
tim008 | 0:6e6e952bc572 | 61 | newLine(); |
tim008 | 0:6e6e952bc572 | 62 | // else |
tim008 | 0:6e6e952bc572 | 63 | { |
tim008 | 0:6e6e952bc572 | 64 | lcd.printChar(c); |
tim008 | 0:6e6e952bc572 | 65 | |
tim008 | 0:6e6e952bc572 | 66 | x += 6; |
tim008 | 0:6e6e952bc572 | 67 | |
tim008 | 0:6e6e952bc572 | 68 | if(x == 84 && y != 5) |
tim008 | 0:6e6e952bc572 | 69 | { |
tim008 | 0:6e6e952bc572 | 70 | x = 0; |
tim008 | 0:6e6e952bc572 | 71 | y++; |
tim008 | 0:6e6e952bc572 | 72 | } |
tim008 | 0:6e6e952bc572 | 73 | } |
tim008 | 0:6e6e952bc572 | 74 | lcd.setXYAddress(x,y); |
tim008 | 0:6e6e952bc572 | 75 | } |
tim008 | 0:6e6e952bc572 | 76 | } |
tim008 | 0:6e6e952bc572 | 77 | |
tim008 | 0:6e6e952bc572 | 78 | int main() { |
tim008 | 0:6e6e952bc572 | 79 | // initialise display |
tim008 | 0:6e6e952bc572 | 80 | lcd.init(); |
tim008 | 0:6e6e952bc572 | 81 | lcd.normalMode(); |
tim008 | 0:6e6e952bc572 | 82 | |
tim008 | 0:6e6e952bc572 | 83 | lcd.setXYAddress(0,0); |
tim008 | 0:6e6e952bc572 | 84 | pc.attach(&getChar); |
tim008 | 0:6e6e952bc572 | 85 | while(1); |
tim008 | 0:6e6e952bc572 | 86 | |
tim008 | 0:6e6e952bc572 | 87 | } |