LCD Baseshield GSOE GSOF
Dependents: WebserverGSOE_Schnaiter HC05__TI4_RP5_Schnaiter
LCD.cpp@2:96140687b227, 2020-03-10 (annotated)
- Committer:
- jack1930
- Date:
- Tue Mar 10 15:10:47 2020 +0000
- Revision:
- 2:96140687b227
- Parent:
- 1:d6c8b9840a53
- Child:
- 7:c3d157395c16
Printf Fehler 16 Zeichen beseitigt
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 | 0:0eebf803661c | 14 | sendeByte(0x01,0,0); |
jack1930 | 0:0eebf803661c | 15 | cursorpos(0); |
jack1930 | 0:0eebf803661c | 16 | //sleep_for(20); |
jack1930 | 0:0eebf803661c | 17 | }; |
jack1930 | 0:0eebf803661c | 18 | |
jack1930 | 0:0eebf803661c | 19 | void lcd::warte(void) |
jack1930 | 0:0eebf803661c | 20 | {/* |
jack1930 | 0:0eebf803661c | 21 | *po=wert; |
jack1930 | 0:0eebf803661c | 22 | while(*t==0); |
jack1930 | 0:0eebf803661c | 23 | wait_ms(20); |
jack1930 | 0:0eebf803661c | 24 | while(*t==1); |
jack1930 | 0:0eebf803661c | 25 | wait_ms(20);*/ |
jack1930 | 0:0eebf803661c | 26 | }; |
jack1930 | 0:0eebf803661c | 27 | void lcd::sendeByte(char b,uint8_t rw, uint8_t rs ) |
jack1930 | 0:0eebf803661c | 28 | { |
jack1930 | 0:0eebf803661c | 29 | |
jack1930 | 0:0eebf803661c | 30 | wert=(b&0xF0)+0x08+((rw&0x01)<<1)+(rs&0x01); |
jack1930 | 0:0eebf803661c | 31 | i2c->write(Adresse,wert); |
jack1930 | 0:0eebf803661c | 32 | warte(); |
jack1930 | 0:0eebf803661c | 33 | wert=(b&0xF0)+0xC+((rw&0x01)<<1)+(rs&0x01); |
jack1930 | 0:0eebf803661c | 34 | i2c->write(Adresse,wert); |
jack1930 | 0:0eebf803661c | 35 | warte(); |
jack1930 | 0:0eebf803661c | 36 | wert=(b&0xF0)+0x8+((rw&0x01)<<1)+(rs&0x01); |
jack1930 | 0:0eebf803661c | 37 | i2c->write(Adresse,wert); |
jack1930 | 0:0eebf803661c | 38 | warte(); |
jack1930 | 0:0eebf803661c | 39 | wert=((b&0xF)<<4)+0x8+((rw&0x01)<<1)+(rs&0x01); |
jack1930 | 0:0eebf803661c | 40 | i2c->write(Adresse,wert); |
jack1930 | 0:0eebf803661c | 41 | warte(); |
jack1930 | 0:0eebf803661c | 42 | wert=((b&0xF)<<4)+0xC+((rw&0x01)<<1)+(rs&0x01); |
jack1930 | 0:0eebf803661c | 43 | i2c->write(Adresse,wert); |
jack1930 | 0:0eebf803661c | 44 | warte(); |
jack1930 | 0:0eebf803661c | 45 | wert=((b&0xF)<<4)+0x8+((rw&0x01)<<1)+(rs&0x01); |
jack1930 | 0:0eebf803661c | 46 | i2c->write(Adresse,wert); |
jack1930 | 0:0eebf803661c | 47 | warte(); |
jack1930 | 0:0eebf803661c | 48 | } |
jack1930 | 0:0eebf803661c | 49 | |
jack1930 | 0:0eebf803661c | 50 | void lcd::sendeNippel(char b,uint8_t rw, uint8_t rs ) |
jack1930 | 0:0eebf803661c | 51 | { |
jack1930 | 0:0eebf803661c | 52 | wert=((b&0xF)<<4)+0x0+((rw&0x01)<<1)+(rs&0x01); |
jack1930 | 0:0eebf803661c | 53 | i2c->write(Adresse,wert); |
jack1930 | 0:0eebf803661c | 54 | warte(); |
jack1930 | 0:0eebf803661c | 55 | wert=((b&0xF)<<4)+0x4+((rw&0x01)<<1)+(rs&0x01); |
jack1930 | 0:0eebf803661c | 56 | i2c->write(Adresse,wert); |
jack1930 | 0:0eebf803661c | 57 | warte(); |
jack1930 | 0:0eebf803661c | 58 | wert=((b&0xF)<<4)+0x0+((rw&0x01)<<1)+(rs&0x01); |
jack1930 | 0:0eebf803661c | 59 | i2c->write(Adresse,wert); |
jack1930 | 0:0eebf803661c | 60 | warte(); |
jack1930 | 0:0eebf803661c | 61 | } |
jack1930 | 0:0eebf803661c | 62 | void lcd::cursorpos(uint8_t pos) |
jack1930 | 0:0eebf803661c | 63 | { |
jack1930 | 0:0eebf803661c | 64 | sendeByte(0x80+pos,0,0); |
jack1930 | 0:0eebf803661c | 65 | } |
jack1930 | 0:0eebf803661c | 66 | void lcd::init(void) |
jack1930 | 0:0eebf803661c | 67 | { |
jack1930 | 0:0eebf803661c | 68 | //Adresse=pAdresse<<1; |
jack1930 | 0:0eebf803661c | 69 | uint8_t data[1]; |
jack1930 | 1:d6c8b9840a53 | 70 | for (Adresse=0;Adresse<255&&data[0]!=0x55;Adresse++) |
jack1930 | 0:0eebf803661c | 71 | { |
jack1930 | 0:0eebf803661c | 72 | i2c->write(Adresse,0x55); |
jack1930 | 0:0eebf803661c | 73 | i2c->read(Adresse,data,1); |
jack1930 | 0:0eebf803661c | 74 | } |
jack1930 | 0:0eebf803661c | 75 | |
jack1930 | 1:d6c8b9840a53 | 76 | wait_us(20000); |
jack1930 | 0:0eebf803661c | 77 | sendeNippel(0b0011,0,0); |
jack1930 | 1:d6c8b9840a53 | 78 | wait_us(5000); |
jack1930 | 0:0eebf803661c | 79 | sendeNippel(0b0011,0,0); |
jack1930 | 1:d6c8b9840a53 | 80 | wait_us(1000); |
jack1930 | 0:0eebf803661c | 81 | sendeNippel(0b0011,0,0); |
jack1930 | 0:0eebf803661c | 82 | |
jack1930 | 0:0eebf803661c | 83 | sendeNippel(0b0010,0,0); |
jack1930 | 0:0eebf803661c | 84 | |
jack1930 | 0:0eebf803661c | 85 | sendeByte(0b00101000,0,0); //4Bit 2 Zeilen |
jack1930 | 0:0eebf803661c | 86 | |
jack1930 | 0:0eebf803661c | 87 | |
jack1930 | 0:0eebf803661c | 88 | sendeByte(0b00000001,0,0); //display clear |
jack1930 | 0:0eebf803661c | 89 | |
jack1930 | 0:0eebf803661c | 90 | sendeByte(0b00000110,0,0); //Increment Cursor*/ |
jack1930 | 0:0eebf803661c | 91 | |
jack1930 | 0:0eebf803661c | 92 | sendeByte(0b10000000,0,0); //Home |
jack1930 | 0:0eebf803661c | 93 | |
jack1930 | 0:0eebf803661c | 94 | sendeByte(0b00001110,0,0); //Display On |
jack1930 | 0:0eebf803661c | 95 | |
jack1930 | 0:0eebf803661c | 96 | |
jack1930 | 0:0eebf803661c | 97 | cursorpos(0x0); |
jack1930 | 0:0eebf803661c | 98 | |
jack1930 | 0:0eebf803661c | 99 | printf("GSOE V%0.1f",1.1); |
jack1930 | 0:0eebf803661c | 100 | |
jack1930 | 0:0eebf803661c | 101 | |
jack1930 | 0:0eebf803661c | 102 | |
jack1930 | 0:0eebf803661c | 103 | } |
jack1930 | 0:0eebf803661c | 104 | int lcd::printf(const char *format, ...) |
jack1930 | 0:0eebf803661c | 105 | { |
jack1930 | 2:96140687b227 | 106 | char buf[20]; |
jack1930 | 0:0eebf803661c | 107 | va_list args; |
jack1930 | 0:0eebf803661c | 108 | va_start(args, format); |
jack1930 | 0:0eebf803661c | 109 | vsprintf(buf,format,args); |
jack1930 | 0:0eebf803661c | 110 | va_end(args); |
jack1930 | 0:0eebf803661c | 111 | //LCD_i2c_textaus(buf); |
jack1930 | 0:0eebf803661c | 112 | for (int i=0;i<16 && buf[i]!=0;i++) |
jack1930 | 0:0eebf803661c | 113 | sendeByte(buf[i],0,1); |
jack1930 | 0:0eebf803661c | 114 | return 0; |
jack1930 | 0:0eebf803661c | 115 | } |