LCD Baseshield GSOE
Dependents: DigitaleingabeBluetooth_TI4 Temperatursever_TI4 BelueftungMitDS1820 ZustandCodeschloss ... more
LCD.cpp@13:1d86cdba3ff5, 2022-03-03 (annotated)
- Committer:
- jack1930
- Date:
- Thu Mar 03 13:42:31 2022 +0000
- Revision:
- 13:1d86cdba3ff5
- Parent:
- 7:c3d157395c16
- Child:
- 14:2d570187d0ca
cls locate putc
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jack1930 | 0:0eebf803661c | 1 | #include "LCD.h" |
jack1930 | 0:0eebf803661c | 2 | |
jack1930 | 0:0eebf803661c | 3 | lcd::lcd(void) |
jack1930 | 0:0eebf803661c | 4 | { |
jack1930 | 0:0eebf803661c | 5 | i2c=new SoftwareI2C(PA_12,PA_11); |
jack1930 | 0:0eebf803661c | 6 | //po=new PortOut(PortC,0xFF); |
jack1930 | 0:0eebf803661c | 7 | //t=new DigitalIn(PA_1,PullDown); |
jack1930 | 0:0eebf803661c | 8 | init(); |
jack1930 | 0:0eebf803661c | 9 | |
jack1930 | 0:0eebf803661c | 10 | }; |
jack1930 | 0:0eebf803661c | 11 | |
jack1930 | 0:0eebf803661c | 12 | void lcd::clear(void) |
jack1930 | 0:0eebf803661c | 13 | { |
jack1930 | 7:c3d157395c16 | 14 | |
jack1930 | 0:0eebf803661c | 15 | sendeByte(0x01,0,0); |
jack1930 | 0:0eebf803661c | 16 | cursorpos(0); |
jack1930 | 0:0eebf803661c | 17 | //sleep_for(20); |
jack1930 | 7:c3d157395c16 | 18 | |
jack1930 | 0:0eebf803661c | 19 | }; |
jack1930 | 0:0eebf803661c | 20 | |
jack1930 | 13:1d86cdba3ff5 | 21 | void lcd::locate(int column, int row) |
jack1930 | 13:1d86cdba3ff5 | 22 | { |
jack1930 | 13:1d86cdba3ff5 | 23 | cursorpos(column+row*0x40); |
jack1930 | 13:1d86cdba3ff5 | 24 | } |
jack1930 | 13:1d86cdba3ff5 | 25 | |
jack1930 | 13:1d86cdba3ff5 | 26 | void lcd::putc(int c) |
jack1930 | 13:1d86cdba3ff5 | 27 | { |
jack1930 | 13:1d86cdba3ff5 | 28 | sendeByte(c,0,1); |
jack1930 | 13:1d86cdba3ff5 | 29 | } |
jack1930 | 13:1d86cdba3ff5 | 30 | |
jack1930 | 13:1d86cdba3ff5 | 31 | void lcd::cls() |
jack1930 | 13:1d86cdba3ff5 | 32 | { |
jack1930 | 13:1d86cdba3ff5 | 33 | clear(); |
jack1930 | 13:1d86cdba3ff5 | 34 | } |
jack1930 | 13:1d86cdba3ff5 | 35 | |
jack1930 | 13:1d86cdba3ff5 | 36 | |
jack1930 | 0:0eebf803661c | 37 | void lcd::warte(void) |
jack1930 | 0:0eebf803661c | 38 | {/* |
jack1930 | 0:0eebf803661c | 39 | *po=wert; |
jack1930 | 0:0eebf803661c | 40 | while(*t==0); |
jack1930 | 0:0eebf803661c | 41 | wait_ms(20); |
jack1930 | 0:0eebf803661c | 42 | while(*t==1); |
jack1930 | 0:0eebf803661c | 43 | wait_ms(20);*/ |
jack1930 | 0:0eebf803661c | 44 | }; |
jack1930 | 0:0eebf803661c | 45 | void lcd::sendeByte(char b,uint8_t rw, uint8_t rs ) |
jack1930 | 0:0eebf803661c | 46 | { |
jack1930 | 0:0eebf803661c | 47 | |
jack1930 | 0:0eebf803661c | 48 | wert=(b&0xF0)+0x08+((rw&0x01)<<1)+(rs&0x01); |
jack1930 | 0:0eebf803661c | 49 | i2c->write(Adresse,wert); |
jack1930 | 0:0eebf803661c | 50 | warte(); |
jack1930 | 0:0eebf803661c | 51 | wert=(b&0xF0)+0xC+((rw&0x01)<<1)+(rs&0x01); |
jack1930 | 0:0eebf803661c | 52 | i2c->write(Adresse,wert); |
jack1930 | 0:0eebf803661c | 53 | warte(); |
jack1930 | 0:0eebf803661c | 54 | wert=(b&0xF0)+0x8+((rw&0x01)<<1)+(rs&0x01); |
jack1930 | 0:0eebf803661c | 55 | i2c->write(Adresse,wert); |
jack1930 | 0:0eebf803661c | 56 | warte(); |
jack1930 | 0:0eebf803661c | 57 | wert=((b&0xF)<<4)+0x8+((rw&0x01)<<1)+(rs&0x01); |
jack1930 | 0:0eebf803661c | 58 | i2c->write(Adresse,wert); |
jack1930 | 0:0eebf803661c | 59 | warte(); |
jack1930 | 0:0eebf803661c | 60 | wert=((b&0xF)<<4)+0xC+((rw&0x01)<<1)+(rs&0x01); |
jack1930 | 0:0eebf803661c | 61 | i2c->write(Adresse,wert); |
jack1930 | 0:0eebf803661c | 62 | warte(); |
jack1930 | 0:0eebf803661c | 63 | wert=((b&0xF)<<4)+0x8+((rw&0x01)<<1)+(rs&0x01); |
jack1930 | 0:0eebf803661c | 64 | i2c->write(Adresse,wert); |
jack1930 | 0:0eebf803661c | 65 | warte(); |
jack1930 | 0:0eebf803661c | 66 | } |
jack1930 | 0:0eebf803661c | 67 | |
jack1930 | 0:0eebf803661c | 68 | void lcd::sendeNippel(char b,uint8_t rw, uint8_t rs ) |
jack1930 | 0:0eebf803661c | 69 | { |
jack1930 | 0:0eebf803661c | 70 | wert=((b&0xF)<<4)+0x0+((rw&0x01)<<1)+(rs&0x01); |
jack1930 | 0:0eebf803661c | 71 | i2c->write(Adresse,wert); |
jack1930 | 0:0eebf803661c | 72 | warte(); |
jack1930 | 0:0eebf803661c | 73 | wert=((b&0xF)<<4)+0x4+((rw&0x01)<<1)+(rs&0x01); |
jack1930 | 0:0eebf803661c | 74 | i2c->write(Adresse,wert); |
jack1930 | 0:0eebf803661c | 75 | warte(); |
jack1930 | 0:0eebf803661c | 76 | wert=((b&0xF)<<4)+0x0+((rw&0x01)<<1)+(rs&0x01); |
jack1930 | 0:0eebf803661c | 77 | i2c->write(Adresse,wert); |
jack1930 | 0:0eebf803661c | 78 | warte(); |
jack1930 | 0:0eebf803661c | 79 | } |
jack1930 | 0:0eebf803661c | 80 | void lcd::cursorpos(uint8_t pos) |
jack1930 | 0:0eebf803661c | 81 | { |
jack1930 | 0:0eebf803661c | 82 | sendeByte(0x80+pos,0,0); |
jack1930 | 0:0eebf803661c | 83 | } |
jack1930 | 0:0eebf803661c | 84 | void lcd::init(void) |
jack1930 | 0:0eebf803661c | 85 | { |
jack1930 | 0:0eebf803661c | 86 | //Adresse=pAdresse<<1; |
jack1930 | 0:0eebf803661c | 87 | uint8_t data[1]; |
jack1930 | 1:d6c8b9840a53 | 88 | for (Adresse=0;Adresse<255&&data[0]!=0x55;Adresse++) |
jack1930 | 0:0eebf803661c | 89 | { |
jack1930 | 0:0eebf803661c | 90 | i2c->write(Adresse,0x55); |
jack1930 | 0:0eebf803661c | 91 | i2c->read(Adresse,data,1); |
jack1930 | 0:0eebf803661c | 92 | } |
jack1930 | 0:0eebf803661c | 93 | |
jack1930 | 1:d6c8b9840a53 | 94 | wait_us(20000); |
jack1930 | 0:0eebf803661c | 95 | sendeNippel(0b0011,0,0); |
jack1930 | 1:d6c8b9840a53 | 96 | wait_us(5000); |
jack1930 | 0:0eebf803661c | 97 | sendeNippel(0b0011,0,0); |
jack1930 | 1:d6c8b9840a53 | 98 | wait_us(1000); |
jack1930 | 0:0eebf803661c | 99 | sendeNippel(0b0011,0,0); |
jack1930 | 0:0eebf803661c | 100 | |
jack1930 | 0:0eebf803661c | 101 | sendeNippel(0b0010,0,0); |
jack1930 | 0:0eebf803661c | 102 | |
jack1930 | 0:0eebf803661c | 103 | sendeByte(0b00101000,0,0); //4Bit 2 Zeilen |
jack1930 | 0:0eebf803661c | 104 | |
jack1930 | 0:0eebf803661c | 105 | |
jack1930 | 0:0eebf803661c | 106 | sendeByte(0b00000001,0,0); //display clear |
jack1930 | 0:0eebf803661c | 107 | |
jack1930 | 0:0eebf803661c | 108 | sendeByte(0b00000110,0,0); //Increment Cursor*/ |
jack1930 | 0:0eebf803661c | 109 | |
jack1930 | 0:0eebf803661c | 110 | sendeByte(0b10000000,0,0); //Home |
jack1930 | 0:0eebf803661c | 111 | |
jack1930 | 0:0eebf803661c | 112 | sendeByte(0b00001110,0,0); //Display On |
jack1930 | 0:0eebf803661c | 113 | |
jack1930 | 0:0eebf803661c | 114 | |
jack1930 | 0:0eebf803661c | 115 | cursorpos(0x0); |
jack1930 | 0:0eebf803661c | 116 | |
jack1930 | 0:0eebf803661c | 117 | printf("GSOE V%0.1f",1.1); |
jack1930 | 0:0eebf803661c | 118 | |
jack1930 | 0:0eebf803661c | 119 | |
jack1930 | 0:0eebf803661c | 120 | |
jack1930 | 0:0eebf803661c | 121 | } |
jack1930 | 0:0eebf803661c | 122 | int lcd::printf(const char *format, ...) |
jack1930 | 0:0eebf803661c | 123 | { |
jack1930 | 2:96140687b227 | 124 | char buf[20]; |
jack1930 | 0:0eebf803661c | 125 | va_list args; |
jack1930 | 0:0eebf803661c | 126 | va_start(args, format); |
jack1930 | 0:0eebf803661c | 127 | vsprintf(buf,format,args); |
jack1930 | 0:0eebf803661c | 128 | va_end(args); |
jack1930 | 0:0eebf803661c | 129 | //LCD_i2c_textaus(buf); |
jack1930 | 0:0eebf803661c | 130 | for (int i=0;i<16 && buf[i]!=0;i++) |
jack1930 | 0:0eebf803661c | 131 | sendeByte(buf[i],0,1); |
jack1930 | 0:0eebf803661c | 132 | return 0; |
jack1930 | 0:0eebf803661c | 133 | } |