void execute_command(struct gpioID enabled_gpio[], int data_to_write) { char msb = (data_to_write >> 4) & 0x0f; char lsb = (data_to_write) & 0x0f; #if CONFIG_DEBUG_LCD printf("data_to_write: 0x%.2x\n" "MSB: 0x%x , LSB: 0x%x\n" ,data_to_write, msb, lsb); #endif turn_ON_OFF_pins( enabled_gpio, msb, 6); pulsePin( enabled_gpio, msb, 6, 5, 0.05); sleep(0.1); turn_ON_OFF_pins( enabled_gpio, lsb, 6); pulsePin( enabled_gpio, lsb, 6, 5, 0.05); sleep(0.1); /* ALTERNATIVE: read the busy flag */ /* requires control over R/W pin */ //D7 = 1; //Make D7th bit of LCD as i/p //en = 1; //Make port pin as o/p //rs = 0; //Selected command register //rw = 1; //We are reading //while(LCD_D7) // pulsePin(enabled_gpio, data_to_write, 6, 5, CMD_DELAY); }
/** * @brief Puts a single character onto the screen. * @param characterToWrite The character we want to write. * @param selected_GPIOs[] initialized array of gpioID. **/ void charToScreen(char characterToWrite, struct gpioID enabled_gpio[]) { unsigned int data_to_write=0; data_to_write=write_character (characterToWrite,0); turn_ON_OFF_pins(enabled_gpio, data_to_write, 6); pulsePin(enabled_gpio, data_to_write, 6, 5, 0.05); data_to_write=write_character (characterToWrite,1); turn_ON_OFF_pins(enabled_gpio, data_to_write, 6); pulsePin(enabled_gpio, data_to_write, 6, 5, 0.05); }
/** * @brief Puts a single character onto the screen. * @param characterToWrite The character we want to write. * @param enabled_gpio[] initialized array of gpioID. **/ void charToScreen(char characterToWrite, struct gpioID enabled_gpio[]) { int delay=0; unsigned int data_to_write=0; data_to_write=write_character (characterToWrite,0); digitalWrite_multiple(enabled_gpio,6,data_to_write); pulsePin(enabled_gpio,data_to_write,6,5,delay); data_to_write=write_character (characterToWrite,1); digitalWrite_multiple(enabled_gpio,6,data_to_write); pulsePin(enabled_gpio,data_to_write,6,5,delay); }
/** * @brief Clears the LCD from anything thats in there. * @param enabled_gpio[] initialized array of gpioID. **/ void clear_Screen(struct gpioID enabled_gpio[]) { unsigned int data_to_write; //E RS DB4 DB5 DB6 DB7 = 000000 (2) = 0 (10) data_to_write=0; digitalWrite_multiple(enabled_gpio,6,data_to_write); pulsePin(enabled_gpio,data_to_write,6,5,0); //E RS DB4 DB5 DB6 DB7 = 001000 (2) = 8 (10) data_to_write=8; digitalWrite_multiple(enabled_gpio,6,data_to_write); pulsePin(enabled_gpio,data_to_write,6,5,0); }
/** * @brief This function is still not working correctly. Technically the * function should set the cursor to a well defined position in the LCD, but * it is not doing so for the second line. I think my LCD is broken. Until, I * fix this function (or at least test it with different LCDs) do not use it. * @param line Line number; where 0 is the top line and 1 is the bottom line. * @param position Position; where the initial position is 0. * @param enabled_gpio[] Initialized array of gpioID. **/ void goto_ScreenLocation(int line, int position,struct gpioID enabled_gpio[]) { unsigned int data_to_write; if (line==1) position=position+64; data_to_write=return_address_in_bitform(position,0); data_to_write=bitWrite(data_to_write,1,0); digitalWrite_multiple(enabled_gpio,6,data_to_write); pulsePin(enabled_gpio,data_to_write,6,5,0); data_to_write=return_address_in_bitform(position,1); digitalWrite_multiple(enabled_gpio,6,data_to_write); pulsePin(enabled_gpio,data_to_write,6,5,0); }
/** * @brief Puts a single character onto the screen. * @param characterToWrite The character we want to write. * @param selected_GPIOs[] initialized array of gpioID. **/ void charToScreen(char characterToWrite, struct gpioID enabled_gpio[]) { unsigned int data_to_write=0; const char *pinDescription[] = {"","","","","",""}; data_to_write=write_character (characterToWrite,0); turn_ON_OFF_pins(enabled_gpio,data_to_write,6,0.10,pinDescription); pulsePin(enabled_gpio,data_to_write,6,0, pinDescription, 5, 0.10); sleep(0.10); data_to_write=write_character (characterToWrite,1); turn_ON_OFF_pins(enabled_gpio,data_to_write,6,0.10,pinDescription); pulsePin(enabled_gpio,data_to_write,6,0, pinDescription, 5, 0.10); sleep(0.10); }
/** * @brief Disables the blinking cursor with an underline. * @param enabled_gpio[] initialized array of gpioID. **/ void disableBlinkingCursor(struct gpioID enabled_gpio[]) { int delay=0; unsigned int data_to_write; //enable cursor part 1 //E RS DB4 DB5 DB6 DB7 = 000000 (2) = 0 (10) data_to_write=0; digitalWrite_multiple(enabled_gpio,6,data_to_write); pulsePin(enabled_gpio,data_to_write,6,5,delay); //enable display part 2 - Display ON/OFF & Cursor //E RS DB4 DB5 DB6 DB7 = 000011 (2) = 3 (10) data_to_write=3; digitalWrite_multiple(enabled_gpio,6,data_to_write); pulsePin(enabled_gpio,data_to_write,6,5,delay); }
/** * @brief Clears the LCD from anything thats in there. * @param selected_GPIOs[] initialized array of gpioID. **/ void clear_Screen(struct gpioID enabled_gpio[]) { int nbr_selectedPins=6; unsigned int data_to_write; //E RS DB4 DB5 DB6 DB7 = 000000 (2) == 0 (10) data_to_write=0; turn_ON_OFF_pins(enabled_gpio,data_to_write,nbr_selectedPins); pulsePin(enabled_gpio,data_to_write,nbr_selectedPins, 5, CMD_DELAY); usleep(CMD_DELAY); //E RS DB4 DB5 DB6 DB7 = 001000 (2) == 8 (10) data_to_write=8; turn_ON_OFF_pins(enabled_gpio,data_to_write,nbr_selectedPins); pulsePin(enabled_gpio,data_to_write,nbr_selectedPins, 5, CMD_DELAY); usleep(CMD_DELAY); }
/** * @brief Clears the LCD from anything thats in there. * @param selected_GPIOs[] initialized array of gpioID. **/ void clear_Screen(struct gpioID enabled_gpio[]) { int nbr_selectedPins=6; const char *pinDescription[] = {"","","","","",""}; unsigned int data_to_write; //E RS DB4 DB5 DB6 DB7 = 000000 (2) == 0 (10) data_to_write=0; turn_ON_OFF_pins(enabled_gpio,data_to_write,nbr_selectedPins,MAX_DELAY,pinDescription); pulsePin(enabled_gpio,data_to_write,nbr_selectedPins,DISPLAY_DATA_ON_SCREEN, pinDescription, 5, MAX_DELAY); sleep(MAX_DELAY); //E RS DB4 DB5 DB6 DB7 = 001000 (2) == 8 (10) data_to_write=8; turn_ON_OFF_pins(enabled_gpio,data_to_write,nbr_selectedPins,MAX_DELAY,pinDescription); pulsePin(enabled_gpio,data_to_write,nbr_selectedPins,DISPLAY_DATA_ON_SCREEN, pinDescription, 5, MAX_DELAY); sleep(MAX_DELAY); }
void TPIC6B595::write(byte bits) { #if USE_HARD_SPI SPI.transfer(bits); #else shiftOut(_dataPin, _clockPin, LSBFIRST, bits); #endif pulsePin(_latchPin, HIGH); }
/** * @brief Disables the blinking cursor with an underline. * @param selected_GPIOs[] initialized array of gpioID. **/ void disableBlinkingCursor(struct gpioID enabled_gpio[]) { int nbr_selectedPins=6; unsigned int data_to_write; //enable cursor part 1 //E RS DB4 DB5 DB6 DB7 = 000000 (2) == 0 (10) data_to_write=0; turn_ON_OFF_pins(enabled_gpio,data_to_write,nbr_selectedPins); pulsePin(enabled_gpio,data_to_write,nbr_selectedPins, 5, CMD_DELAY); usleep(CMD_DELAY); //enable display part 2 - Display ON/OFF & Cursor //E RS DB4 DB5 DB6 DB7 = 000011 (2) == 3 (10) data_to_write=3; turn_ON_OFF_pins(enabled_gpio,data_to_write,nbr_selectedPins); pulsePin(enabled_gpio,data_to_write,nbr_selectedPins, 5, CMD_DELAY); usleep(CMD_DELAY); }
/** * @brief Disables the blinking cursor with an underline. * @param selected_GPIOs[] initialized array of gpioID. **/ void disableBlinkingCursor(struct gpioID enabled_gpio[]) { int nbr_selectedPins=6; const char *pinDescription[] = {"","","","","",""}; unsigned int data_to_write; //enable cursor part 1 //E RS DB4 DB5 DB6 DB7 = 000000 (2) == 0 (10) data_to_write=0; turn_ON_OFF_pins(enabled_gpio,data_to_write,nbr_selectedPins,MAX_DELAY,pinDescription); pulsePin(enabled_gpio,data_to_write,nbr_selectedPins,DISPLAY_DATA_ON_SCREEN, pinDescription, 5, MAX_DELAY); sleep(MAX_DELAY); //enable display part 2 - Display ON/OFF & Cursor //E RS DB4 DB5 DB6 DB7 = 000011 (2) == 3 (10) data_to_write=3; turn_ON_OFF_pins(enabled_gpio,data_to_write,nbr_selectedPins,MAX_DELAY,pinDescription); pulsePin(enabled_gpio,data_to_write,nbr_selectedPins,DISPLAY_DATA_ON_SCREEN, pinDescription, 5, MAX_DELAY); sleep(MAX_DELAY); }
/** * @brief After you are done using the LCD you should terminate it properly. * Failure to do so will guarantee that next time you use LCD it will be on 8 bit * mode... and you will must turn ON/OFF the screen. * @param enabled_gpio[] initialized array of gpioID. * @param selectedPins[] list of the pins that we are using **/ void terminate_Screen(struct gpioID enabled_gpio[],int selectedPins[]) { int nbr_selectedPins=6; unsigned int data_to_write; //put the display back in 8 bit mode to allow to re-run program //E RS DB4 DB5 DB6 DB7 = 001100 (2) = 12 (10) data_to_write=12; digitalWrite_multiple(enabled_gpio,6,data_to_write); pulsePin(enabled_gpio,data_to_write,6,5,0); //we should now tell the OS that we are done with the GPIOs cleanup_multiple(enabled_gpio,nbr_selectedPins); }
/** * @brief This function is still not working correctly. Technically the * function should set the cursor to a well defined position in the LCD, but * it is not doing so for the second line. I think my LCD is broken. Until, I * fix this function (or at least test it with different LCDs) do not use it. * @param line Line number; where 0 is the top line and 1 is the bottom line. * @param position Position; where the initial position is 0. * @param selected_GPIOs[] Initialized array of gpioID. **/ void goto_ScreenLocation(int line, int position,struct gpioID enabled_gpio[]) { int nbr_selectedPins=6; unsigned int data_to_write; //printf("position: %d\n",position); //printf("line: %d\n\n",line); if (line==1) position=position+40; data_to_write=return_address_in_bitform(position,0); //printf("data_to_write: %d\n",data_to_write); data_to_write=bitWrite(data_to_write,1,0); //printf("<%d>\n",data_to_write); turn_ON_OFF_pins(enabled_gpio,data_to_write,nbr_selectedPins); pulsePin(enabled_gpio,data_to_write,nbr_selectedPins, 5, CMD_DELAY); usleep(CMD_DELAY); data_to_write=return_address_in_bitform(position,1); //printf("data_to_write: %d\n",data_to_write); turn_ON_OFF_pins(enabled_gpio,data_to_write,nbr_selectedPins); pulsePin(enabled_gpio,data_to_write,nbr_selectedPins, 5, CMD_DELAY); usleep(CMD_DELAY); }
/** * @brief After you are done using the LCD you should terminate it properly. * Failure to do so will guarantee that next time you use LCD it will be on 8 bit * mode... and you will must turn ON/OFF the screen. * @param selected_GPIOs[] initialized array of gpioID. **/ void terminate_Screen(struct gpioID enabled_gpio[],int selectedPins[]) { int nbr_selectedPins=6; unsigned int data_to_write; //put the display back in 8 bit mode to allow to re-run program //E RS DB4 DB5 DB6 DB7 = 001100 (2) == 12 (10) data_to_write=12; turn_ON_OFF_pins(enabled_gpio,data_to_write,nbr_selectedPins); pulsePin(enabled_gpio,data_to_write,nbr_selectedPins, 5, CMD_DELAY); usleep(CMD_DELAY); //we should now tell the OS that we are done with the GPIOs cleanup_GPIO(enabled_gpio,selectedPins,nbr_selectedPins); }
/** * @brief This function is still not working correctly. Technically the * function should set the cursor to a well defined position in the LCD, but * it is not doing so for the second line. I think my LCD is broken. Until, I * fix this function (or at least test it with different LCDs) do not use it. * @param line Line number; where 0 is the top line and 1 is the bottom line. * @param position Position; where the initial position is 0. * @param selected_GPIOs[] Initialized array of gpioID. **/ void goto_ScreenLocation(int line, int position,struct gpioID enabled_gpio[]) { int nbr_selectedPins=6; const char *pinDescription[] = {"","","","","",""}; unsigned int data_to_write; //printf("position: %d\n",position); //printf("line: %d\n\n",line); if (line==1) position=position+40; data_to_write=return_address_in_bitform(position,0); //printf("data_to_write: %d\n",data_to_write); data_to_write=bitWrite(data_to_write,1,0); //printf("<%d>\n",data_to_write); turn_ON_OFF_pins(enabled_gpio,data_to_write,nbr_selectedPins,MAX_DELAY,pinDescription); pulsePin(enabled_gpio,data_to_write,nbr_selectedPins,DISPLAY_DATA_ON_SCREEN, pinDescription, 5, MAX_DELAY); sleep(MAX_DELAY); data_to_write=return_address_in_bitform(position,1); //printf("data_to_write: %d\n",data_to_write); turn_ON_OFF_pins(enabled_gpio,data_to_write,nbr_selectedPins,MAX_DELAY,pinDescription); pulsePin(enabled_gpio,data_to_write,nbr_selectedPins,DISPLAY_DATA_ON_SCREEN, pinDescription, 5, MAX_DELAY); sleep(MAX_DELAY); }
/** * @brief After you are done using the LCD you should terminate it properly. * Failure to do so will guarantee that next time you use LCD it will be on 8 bit * mode... and you will must turn ON/OFF the screen. * @param selected_GPIOs[] initialized array of gpioID. **/ void terminate_Screen(struct gpioID enabled_gpio[],int selectedPins[]) { int nbr_selectedPins=6; const char *pinDescription[] = {"","","","","",""}; unsigned int data_to_write; //put the display back in 8 bit mode to allow to re-run program //E RS DB4 DB5 DB6 DB7 = 001100 (2) == 12 (10) data_to_write=12; turn_ON_OFF_pins(enabled_gpio,data_to_write,nbr_selectedPins,MAX_DELAY,pinDescription); pulsePin(enabled_gpio,data_to_write,nbr_selectedPins,DISPLAY_DATA_ON_SCREEN, pinDescription, 5, MAX_DELAY); sleep(MAX_DELAY); //we should now tell the OS that we are done with the GPIOs cleanup_GPIO(enabled_gpio,selectedPins,nbr_selectedPins); }
/** * @brief Initializes the screen so we can use it. * @param selected_GPIOs[] An initialized array of gpioID. * @param selectedPins[] The user defined pins. **/ void initialize_Screen(struct gpioID enabled_gpio[],int selectedPins[]) { int nbr_selectedPins=6; const char *pinDescription[] = {"","","","","",""}; unsigned int data_to_write; initialize_each_enabled_gpio(enabled_gpio,selectedPins,nbr_selectedPins); if (DISPLAY_DATA_ON_SCREEN) display_each_enabled_gpio(enabled_gpio,nbr_selectedPins,pinDescription); //E RS DB4 DB5 DB6 DB7 //0 0 1 1 0 0 (base 2) which equals 12 (base 10) data_to_write=12; turn_ON_OFF_pins(enabled_gpio,data_to_write,nbr_selectedPins,MAX_DELAY,pinDescription); pulsePin(enabled_gpio,data_to_write,nbr_selectedPins,DISPLAY_DATA_ON_SCREEN, pinDescription, 5, MAX_DELAY); sleep(MAX_DELAY); //E RS DB4 DB5 DB6 DB7 //0 0 0 1 0 0 (base 2) which equals 4 (base 10) : 4 bit mode data_to_write=4; turn_ON_OFF_pins(enabled_gpio,data_to_write,nbr_selectedPins,MAX_DELAY,pinDescription); pulsePin(enabled_gpio,data_to_write,nbr_selectedPins,DISPLAY_DATA_ON_SCREEN, pinDescription, 5, MAX_DELAY); sleep(MAX_DELAY); //enable display part 1 - Display ON/OFF & Cursor //E RS DB4 DB5 DB6 DB7 = 000000 (2) == 0 (10) data_to_write=0; turn_ON_OFF_pins(enabled_gpio,data_to_write,nbr_selectedPins,MAX_DELAY,pinDescription); pulsePin(enabled_gpio,data_to_write,nbr_selectedPins,DISPLAY_DATA_ON_SCREEN, pinDescription, 5, MAX_DELAY); sleep(MAX_DELAY); //enable display part 2 - Display ON/OFF & Cursor //E RS DB4 DB5 DB6 DB7 = 000011 (2) == 3 (10) data_to_write=3; turn_ON_OFF_pins(enabled_gpio,data_to_write,nbr_selectedPins,MAX_DELAY,pinDescription); pulsePin(enabled_gpio,data_to_write,nbr_selectedPins,DISPLAY_DATA_ON_SCREEN, pinDescription, 5, MAX_DELAY); sleep(MAX_DELAY); //two line mode 5x7 part 1 //E RS DB4 DB5 DB6 DB7 = 000100 (2) == 4 (10) data_to_write=4; turn_ON_OFF_pins(enabled_gpio,data_to_write,nbr_selectedPins,MAX_DELAY,pinDescription); pulsePin(enabled_gpio,data_to_write,nbr_selectedPins,DISPLAY_DATA_ON_SCREEN, pinDescription, 5, MAX_DELAY); sleep(MAX_DELAY); //two line mode 5x7 part 2 (the 0 next to the 1 specifies the 5x7) //E RS DB4 DB5 DB6 DB7 = 000001 (2) == 1 (10) data_to_write=1; turn_ON_OFF_pins(enabled_gpio,data_to_write,nbr_selectedPins,MAX_DELAY,pinDescription); pulsePin(enabled_gpio,data_to_write,nbr_selectedPins,DISPLAY_DATA_ON_SCREEN, pinDescription, 5, MAX_DELAY); sleep(MAX_DELAY); }
/** * @brief Initializes the screen so we can use it. * @param selected_GPIOs[] An initialized array of gpioID. * @param selectedPins[] The user defined pins. **/ void initialize_Screen(struct gpioID enabled_gpio[],int selectedPins[]) { int nbr_selectedPins=6; unsigned int data_to_write; initialize_each_enabled_gpio(enabled_gpio,selectedPins,nbr_selectedPins); #if CONFIG_DEBUG_LCD display_each_enabled_gpio(enabled_gpio,nbr_selectedPins); #endif /* INIT (cf wiki) */ usleep (20000); // 15000 execute_command(enabled_gpio, 0x30); usleep (10000); // 4100 execute_command(enabled_gpio, 0x30); usleep (1000); // 100 execute_command(enabled_gpio, 0x30); usleep ( 1000); // 4-bit //execute_command(enabled_gpio, 0x20); turn_ON_OFF_pins( enabled_gpio, 0x2, 6); pulsePin( enabled_gpio, 0x2, 6, 5, 0.05); usleep ( 1000); /* FUNCTION SET : 4-bit, 2-line, 5x7, */ execute_command(enabled_gpio, 0x28); /* DISPLAY ON/OFF CONTROL : display ON, cursor OFF, blink OFF */ execute_command(enabled_gpio, 0x0c); /* CLEAR DISPLAY : clear display and return to home position */ execute_command(enabled_gpio, 0x01); /* ENTRY MODE SET : set direction to increment */ execute_command(enabled_gpio, 0x06); /* RETURN HOME : return to home position */ // execute_command(enabled_gpio, 0x02); /* CURSOR & DISPLAY SHIFT : cursor move, right direction */ // execute_command(enabled_gpio, 0x14); }
/** * @brief Initializes the screen so we can use it. * @param enabled_gpio[] An initialized array of gpioID. * @param selectedPins[] The user defined pins. **/ void initialize_Screen(struct gpioID enabled_gpio[],int selectedPins[]) { int delay=0; int nbr_selectedPins=6; unsigned int data_to_write; pinMode_multiple(enabled_gpio,selectedPins,nbr_selectedPins,"out"); //E RS DB4 DB5 DB6 DB7 = 001100 (2) = 12 (10) data_to_write=12; digitalWrite_multiple(enabled_gpio,6,data_to_write); pulsePin(enabled_gpio,data_to_write,6,5,delay); delayms(delay); //E RS DB4 DB5 DB6 DB7 = 000100 (2) = 4 (10) : 4 bit mode data_to_write=4; digitalWrite_multiple(enabled_gpio,6,data_to_write); pulsePin(enabled_gpio,data_to_write,6,5,delay); delayms(delay); //enable display part 1 - Display ON/OFF & Cursor //E RS DB4 DB5 DB6 DB7 = 000000 (2) = 0 (10) data_to_write=0; digitalWrite_multiple(enabled_gpio,6,data_to_write); pulsePin(enabled_gpio,data_to_write,6,5,delay); delayms(delay); //enable display part 2 - Display ON/OFF & Cursor //E RS DB4 DB5 DB6 DB7 = 000011 (2) = 3 (10) data_to_write=3; digitalWrite_multiple(enabled_gpio,6,data_to_write); pulsePin(enabled_gpio,data_to_write,6,5,delay); delayms(delay); //two line mode 5x7 part 1 //E RS DB4 DB5 DB6 DB7 = 000100 (2) = 4 (10) data_to_write=4; digitalWrite_multiple(enabled_gpio,6,data_to_write); pulsePin(enabled_gpio,data_to_write,6,5,delay); delayms(delay); //two line mode 5x7 part 2 (the 0 next to the 1 specifies the 5x7) //E RS DB4 DB5 DB6 DB7 = 000001 (2) = 1 (10) data_to_write=1; digitalWrite_multiple(enabled_gpio,6,data_to_write); pulsePin(enabled_gpio,data_to_write,6,5,delay); delayms(delay); }
void TPIC6B595::clear() { pulsePin(_clearPin, LOW); pulsePin(_latchPin, HIGH); }