I2C-LC-Diaplsay mit PCF8574

Dependents:   120_robot_H_Bridge8835_UserButton_DIR_PWM_I2C_LCD 140_robot_H_Bridge8835_DIR_PWM_US_LCD xxx_Uhr_I2C_LCD_Delay_Bua xxx_Uhr_I2C_LCD_Delay_BuaV ... more

Committer:
itbusch
Date:
Wed Feb 23 18:52:50 2022 +0000
Revision:
1:68d6c4c092fb
Parent:
0:43e25c35d0c1
140_robot_H_Bridge8835_DIR_PWM_US_LCD

Who changed what in which revision?

UserRevisionLine numberNew contents of line
itbusch 0:43e25c35d0c1 1 #include "LCD.h"
itbusch 0:43e25c35d0c1 2
itbusch 0:43e25c35d0c1 3 lcd::lcd(void)
itbusch 0:43e25c35d0c1 4 {
itbusch 0:43e25c35d0c1 5 i2c=new SoftwareI2C(PB_9, PB_8); //PA_12,PA_11
itbusch 0:43e25c35d0c1 6 //po=new PortOut(PortC,0xFF);
itbusch 0:43e25c35d0c1 7 //t=new DigitalIn(PA_1,PullDown);
itbusch 0:43e25c35d0c1 8 init();
itbusch 0:43e25c35d0c1 9
itbusch 0:43e25c35d0c1 10 };
itbusch 0:43e25c35d0c1 11
itbusch 0:43e25c35d0c1 12 void lcd::clear(void)
itbusch 0:43e25c35d0c1 13 {
itbusch 0:43e25c35d0c1 14
itbusch 0:43e25c35d0c1 15 sendeByte(0x01,0,0);
itbusch 0:43e25c35d0c1 16 cursorpos(0);
itbusch 0:43e25c35d0c1 17 //sleep_for(20);
itbusch 0:43e25c35d0c1 18
itbusch 0:43e25c35d0c1 19 };
itbusch 0:43e25c35d0c1 20
itbusch 0:43e25c35d0c1 21 void lcd::warte(void)
itbusch 0:43e25c35d0c1 22 {/*
itbusch 0:43e25c35d0c1 23 *po=wert;
itbusch 0:43e25c35d0c1 24 while(*t==0);
itbusch 0:43e25c35d0c1 25 wait_ms(20);
itbusch 0:43e25c35d0c1 26 while(*t==1);
itbusch 0:43e25c35d0c1 27 wait_ms(20);*/
itbusch 0:43e25c35d0c1 28 };
itbusch 0:43e25c35d0c1 29 void lcd::sendeByte(char b,uint8_t rw, uint8_t rs )
itbusch 0:43e25c35d0c1 30 {
itbusch 0:43e25c35d0c1 31
itbusch 0:43e25c35d0c1 32 wert=(b&0xF0)+0x08+((rw&0x01)<<1)+(rs&0x01);
itbusch 0:43e25c35d0c1 33 i2c->write(Adresse,wert);
itbusch 0:43e25c35d0c1 34 warte();
itbusch 0:43e25c35d0c1 35 wert=(b&0xF0)+0xC+((rw&0x01)<<1)+(rs&0x01);
itbusch 0:43e25c35d0c1 36 i2c->write(Adresse,wert);
itbusch 0:43e25c35d0c1 37 warte();
itbusch 0:43e25c35d0c1 38 wert=(b&0xF0)+0x8+((rw&0x01)<<1)+(rs&0x01);
itbusch 0:43e25c35d0c1 39 i2c->write(Adresse,wert);
itbusch 0:43e25c35d0c1 40 warte();
itbusch 0:43e25c35d0c1 41 wert=((b&0xF)<<4)+0x8+((rw&0x01)<<1)+(rs&0x01);
itbusch 0:43e25c35d0c1 42 i2c->write(Adresse,wert);
itbusch 0:43e25c35d0c1 43 warte();
itbusch 0:43e25c35d0c1 44 wert=((b&0xF)<<4)+0xC+((rw&0x01)<<1)+(rs&0x01);
itbusch 0:43e25c35d0c1 45 i2c->write(Adresse,wert);
itbusch 0:43e25c35d0c1 46 warte();
itbusch 0:43e25c35d0c1 47 wert=((b&0xF)<<4)+0x8+((rw&0x01)<<1)+(rs&0x01);
itbusch 0:43e25c35d0c1 48 i2c->write(Adresse,wert);
itbusch 0:43e25c35d0c1 49 warte();
itbusch 0:43e25c35d0c1 50 }
itbusch 0:43e25c35d0c1 51
itbusch 0:43e25c35d0c1 52 void lcd::sendeNippel(char b,uint8_t rw, uint8_t rs )
itbusch 0:43e25c35d0c1 53 {
itbusch 0:43e25c35d0c1 54 wert=((b&0xF)<<4)+0x0+((rw&0x01)<<1)+(rs&0x01);
itbusch 0:43e25c35d0c1 55 i2c->write(Adresse,wert);
itbusch 0:43e25c35d0c1 56 warte();
itbusch 0:43e25c35d0c1 57 wert=((b&0xF)<<4)+0x4+((rw&0x01)<<1)+(rs&0x01);
itbusch 0:43e25c35d0c1 58 i2c->write(Adresse,wert);
itbusch 0:43e25c35d0c1 59 warte();
itbusch 0:43e25c35d0c1 60 wert=((b&0xF)<<4)+0x0+((rw&0x01)<<1)+(rs&0x01);
itbusch 0:43e25c35d0c1 61 i2c->write(Adresse,wert);
itbusch 0:43e25c35d0c1 62 warte();
itbusch 0:43e25c35d0c1 63 }
itbusch 0:43e25c35d0c1 64 void lcd::cursorpos(uint8_t pos)
itbusch 0:43e25c35d0c1 65 {
itbusch 0:43e25c35d0c1 66 sendeByte(0x80+pos,0,0);
itbusch 0:43e25c35d0c1 67 }
itbusch 0:43e25c35d0c1 68 void lcd::init(void)
itbusch 0:43e25c35d0c1 69 {
itbusch 0:43e25c35d0c1 70 //Adresse=pAdresse<<1;
itbusch 0:43e25c35d0c1 71 uint8_t data[1];
itbusch 0:43e25c35d0c1 72 for (Adresse=0;Adresse<255&&data[0]!=0x55;Adresse++)
itbusch 0:43e25c35d0c1 73 {
itbusch 0:43e25c35d0c1 74 i2c->write(Adresse,0x55);
itbusch 0:43e25c35d0c1 75 i2c->read(Adresse,data,1);
itbusch 0:43e25c35d0c1 76 }
itbusch 0:43e25c35d0c1 77
itbusch 0:43e25c35d0c1 78 wait_us(20000);
itbusch 0:43e25c35d0c1 79 sendeNippel(0b0011,0,0);
itbusch 0:43e25c35d0c1 80 wait_us(5000);
itbusch 0:43e25c35d0c1 81 sendeNippel(0b0011,0,0);
itbusch 0:43e25c35d0c1 82 wait_us(1000);
itbusch 0:43e25c35d0c1 83 sendeNippel(0b0011,0,0);
itbusch 0:43e25c35d0c1 84
itbusch 0:43e25c35d0c1 85 sendeNippel(0b0010,0,0);
itbusch 0:43e25c35d0c1 86
itbusch 0:43e25c35d0c1 87 sendeByte(0b00101000,0,0); //4Bit 2 Zeilen
itbusch 0:43e25c35d0c1 88
itbusch 0:43e25c35d0c1 89
itbusch 0:43e25c35d0c1 90 sendeByte(0b00000001,0,0); //display clear
itbusch 0:43e25c35d0c1 91
itbusch 0:43e25c35d0c1 92 sendeByte(0b00000110,0,0); //Increment Cursor*/
itbusch 0:43e25c35d0c1 93
itbusch 0:43e25c35d0c1 94 sendeByte(0b10000000,0,0); //Home
itbusch 0:43e25c35d0c1 95
itbusch 0:43e25c35d0c1 96 sendeByte(0b00001110,0,0); //Display On
itbusch 0:43e25c35d0c1 97
itbusch 0:43e25c35d0c1 98
itbusch 0:43e25c35d0c1 99 cursorpos(0x0);
itbusch 0:43e25c35d0c1 100
itbusch 0:43e25c35d0c1 101 printf("GSOE V%0.1f",1.1);
itbusch 0:43e25c35d0c1 102
itbusch 0:43e25c35d0c1 103
itbusch 0:43e25c35d0c1 104
itbusch 0:43e25c35d0c1 105 }
itbusch 0:43e25c35d0c1 106 int lcd::printf(const char *format, ...)
itbusch 0:43e25c35d0c1 107 {
itbusch 0:43e25c35d0c1 108 char buf[20];
itbusch 0:43e25c35d0c1 109 va_list args;
itbusch 0:43e25c35d0c1 110 va_start(args, format);
itbusch 0:43e25c35d0c1 111 vsprintf(buf,format,args);
itbusch 0:43e25c35d0c1 112 va_end(args);
itbusch 0:43e25c35d0c1 113 //LCD_i2c_textaus(buf);
itbusch 0:43e25c35d0c1 114 for (int i=0;i<16 && buf[i]!=0;i++)
itbusch 0:43e25c35d0c1 115 sendeByte(buf[i],0,1);
itbusch 0:43e25c35d0c1 116 return 0;
itbusch 0:43e25c35d0c1 117 }