void Init_LCD(void ) /* This is called once to initialise the display */ { LCD_RS=0; delay_ms(30); LCDWriteNibble(0b0010); delay_ms(4); LCDWriteNibble(0b0010); LCDWriteNibble(0b1000); delay_100uS(); LCDWriteNibble(0b0010); LCDWriteNibble(0b1000); delay_100uS(); LCDWriteNibble(0b0000); /* set 4 bits */ LCDWriteNibble(0b1100); /* set 4 bits */ delay_100uS(); LCDWriteNibble(0b0000); /* set 4 bits */ LCDWriteNibble(0b0001); /* set 4 bits */ delay_100uS(); delay_ms(8); LCDWriteNibble(0b0000); /* set 4 bits */ LCDWriteNibble(0b0010); /* set 4 bits */ delay_100uS(); delay_ms(14); LCDWrite(0x4E); delay_100uS(); LCDWrite(0x80); }
//This function takes in a character, looks it up in the font table/array //And writes it to the screen //Each character is 8 bits tall and 5 bits wide. We pad one blank column of //pixels on each side of the character for readability. void LCDCharacter(char character) { LCDWrite(LCD_DATA, 0x00); //Blank vertical line padding for (int index = 0 ; index < 5 ; index++) LCDWrite(LCD_DATA, ASCII[character - 0x20][index]); //0x20 is the ASCII character for Space (' '). The font table starts with this character LCDWrite(LCD_DATA, 0x00); //Blank vertical line padding }
//This takes a large array of bits and sends them to the LCD void LCDBitmap(char my_array[]){ int index; for (index = 0 ; index < (LCD_X * LCD_Y / 8) ; index++) { LCDWrite(LCD_DATA, my_array[index]); } }
/** * Called when a track is changed (instrument id, muted status...) */ void TranzportClient::trackChanged(const Composition *c, Track* track) { RG_DEBUG << "TranzportClient, CompostionObserver::trackChanged"; if (device_online) { const Track* track2 = c->getTrackById(c->getSelectedTrack()); // If the changed track is the selected track if (track == track2) { RG_DEBUG << "TranzportClient, CompostionObserver::trackChanged updateing"; if (track->isArmed()) { LightOn(LightTrackrec); } else { LightOff(LightTrackrec); } if (track->isMuted()) { LightOn(LightTrackmute); } else { LightOff(LightTrackmute); } LCDWrite(track->getLabel(), Bottom); } } }
/** * Called when solo status changes (solo on/off, and selected track) */ void TranzportClient::soloChanged(const Composition * c, bool solo, TrackId selectedTrack ) { RG_DEBUG << "TranzportClient, CompostionObserver::soloChanged"; if (device_online) { if (solo) { LightOn(LightAnysolo); } else { LightOff(LightAnysolo); } Track* track = c->getTrackById(selectedTrack); if (track->isArmed()) { LightOn(LightTrackrec); } else { LightOff(LightTrackrec); } if (track->isMuted()) { LightOn(LightTrackmute); } else { LightOff(LightTrackmute); } LCDWrite(track->getLabel(), Bottom); } }
//Clears the LCD by writing zeros to the entire screen void LCDClear(void) { for (u16 index = 0 ; index < (LCD_X * LCD_Y / 8) ; index++) LCDWrite(LCD_DATA, 0x00); gotoXY(0, 0); //After we clear the display, return to the home position }
void LCDCat() { int index; for (index = 0 ; index < (LCD_X * LCD_Y / 8) ; index++) { LCDWrite(LCD_DATA, cat[index]); } }
/****************************************************************************** * Function: void LCDUpdate(void) * * PreCondition: LCDInit() must have been called once * * Input: LCDText[] * * Output: None * * Side Effects: None * * Overview: Copies the contents of the local LCDText[] array into the * LCD's internal display buffer. Null terminators in * LCDText[] terminate the current line, so strings may be * printed directly to LCDText[]. * * Note: None *****************************************************************************/ void LCDUpdate(void) { BYTE i, j; // Go home LCDWrite(0, 0x02); DelayMs(2); // Output first line for(i = 0; i < 16u; i++) { // Erase the rest of the line if a null char is // encountered (good for printing strings directly) if(LCDText[0][i] == 0u) { for(j=i; j < 16u; j++) { LCDText[0][j] = ' '; } } LCDWrite(1, LCDText[0][i]); Delay10us(5); } // Set the address to the second line LCDWrite(0, 0xC0); Delay10us(5); // Output second line // for(i = 16; i < 32u; i++) for(i = 0; i < 16u; i++) { // Erase the rest of the line if a null char is // encountered (good for printing strings directly) if(LCDText[1][i] == 0u) { //for(j=i; j < 32u; j++) for(j=i; j < 16u; j++) { LCDText[1][j] = ' '; } } LCDWrite(1, LCDText[1][i]); Delay10us(5); } }
//This sends the magical commands to the PCD8544 void LCDInit(void) { //Configure control pins as output TRISAbits.TRISA3 = 0; //SCE TRISAbits.TRISA4 = 0; //Reset TRISAbits.TRISA5 = 0; //DC Delay10TCYx(255); //Reset the LCD to a known state _LCDReset = 0; Delay10TCYx(255); _LCDReset = 1; LCDWrite(LCD_COMMAND, 0x21); //Tell LCD that extended commands follow LCDWrite(LCD_COMMAND, 0x90); //0xa5 0x95 //Set LCD Vop (Contrast): Try 0xB1(good @ 3.3V) or 0xBF if your display is too dark //You'll probably need to play around with the contrast value above on your screen to make it look good. Mine vary depending on the room temperature LCDWrite(LCD_COMMAND, 0x03); //Set Temp coefficent LCDWrite(LCD_COMMAND, 0x14); //LCD bias mode 1:48: Try 0x13 or 0x14 LCDWrite(LCD_COMMAND, 0x0C); //Set display control, normal mode. 0x0D for inverse (0x0C for normal) LCDWrite(LCD_COMMAND, 0x20); //We must send 0x20 before modifying the display control mode LCDWrite(LCD_COMMAND, 0x0C); //Set display control, normal mode. 0x0D for inverse (0x0C for normal) }
void LCDCharacter(char character, char invertMode) { int index; LCDWrite(LCD_DATA, 0x00); //Blank vertical line padding for (index = 0 ; index < 5 ; index++) { if (invertMode == 1){ LCDWrite(LCD_DATA, ~ASCII[character - 0x20][index]); } else { LCDWrite(LCD_DATA, ASCII[character - 0x20][index]); } //0x20 is the ASCII character for Space (' '). The font table starts with this character } if (invertMode == 1){ LCDWrite(LCD_DATA, 0xff); //Blank vertical line padding } else { LCDWrite(LCD_DATA, 0x00); //Blank vertical line padding } }
//Clears the LCD by writing zeros to the entire screen void LCDClear(void) { int index; gotoXY(0, 0); //Make sure that we start at the home position since the LCD seems to pick up where it left off. for (index = 0 ; index < 504 ; index++) //(LCD_X * LCD_Y / 8) = 504 //Doesn't seem to work with the defined macros, but does if I hard-code the number of pixels/8 { LCDWrite(LCD_DATA, 0x00); } gotoXY(0, 0); //After we clear the display, return to the home position }
/****************************************************************************** * Function: void LCDErase(void) * * PreCondition: LCDInit() must have been called once * * Input: None * * Output: None * * Side Effects: None * * Overview: Clears LCDText[] and the LCD's internal display buffer * * Note: None *****************************************************************************/ void LCDErase(void) { // Clear display LCDWrite(0, 0x01); DelayMs(2); // Clear local copy memset(LCDText, ' ', 32); }
void TranzportClient::stateUpdate() { if (device_online) { LCDWrite("Rosegarden"); if (m_composition->isSolo()) { LightOn(LightAnysolo); } else { LightOff(LightAnysolo); } if (m_composition->isLooping()) { LightOn(LightLoop); } else { LightOff(LightLoop); } TrackId trackID = m_composition->getSelectedTrack(); Track* track = m_composition->getTrackById(trackID); if (track->isArmed()) { LightOn(LightTrackrec); } else { LightOff(LightTrackrec); } if (track->isMuted()) { LightOn(LightTrackmute); } else { LightOff(LightTrackmute); } LCDWrite(track->getLabel().substr(0,9), Bottom); int bar, beat, fraction, remainder; m_composition->getMusicalTimeForAbsoluteTime( m_composition->getPosition(), bar, beat, fraction, remainder); std::stringstream ss; ss << bar+1 << ":" << beat; LCDWrite(ss.str(), Bottom, 10); } }
/* * Function implementations */ void show_screen(void) { // Reset our position in the LCD RAM LCDPosition(0,0); // Iterate through our buffer and write each byte to the LCD. unsigned int i; for(i = 0; i < LCD_BUFFER_SIZE; i++){ LCDWrite(LCD_D, screenBuffer[i]); } }
void LCD_build(unsigned char location, unsigned char *ptr){ unsigned char i; if(location<8){ LCDCommand(0x40+(location*8)); for(i=0;i<8;i++) LCDWrite(ptr[ i ] ); LCDCommand(0x80); } }
void LCDWriteChar(uint8_t data) { /* if (data=='\n') { if (g_nCurrentLine >= LCD_LINES - 1) lcd_setline(0); else lcd_setline(g_nCurrentLine+1); } else */ LCDWrite(data,1); Cpu_Delay100US(20); }
void lcdTest() { LCDConfiguration(); TMRConfiguration(); LCDInitialization(); LCDWrite(0x53); //S LCDWrite(0x75); //u LCDWrite(0x63); //c LCDWrite(0x6B); //k LCDWrite(0x20); //' ' LCDWrite(0x69); //i LCDWrite(0x74); //t LCDWrite(0x21); //! }
void TranzportClient::pointerPositionChanged(timeT time) { RG_DEBUG << "TranzportClient, pointerPositionChanged" << endl; if (device_online) { static int prevbeat = 0; int bar, beat, fraction, remainder; m_composition->getMusicalTimeForAbsoluteTime(time,bar,beat,fraction,remainder); if (prevbeat != beat) { std::stringstream ss; ss << bar+1 << ":" << beat; LCDWrite(ss.str(), Bottom, 10); prevbeat = beat; } } }
void LCDWScrollText(char* inputText,unsigned char row, unsigned char col) { unsigned char address_d = 0; // address of the data in the screen. switch(row) { case 0: address_d = 0x80 + col; // at zeroth row break; case 1: address_d = 0xC0 + col; // at first row break; case 2: address_d = 0x94 + col; // at second row break; case 3: address_d = 0xD4 + col; // at third row break; default: address_d = 0x80 + col; // returns to first row if invalid row number is detected break; } LCDCommand(address_d); while(*inputText) // Place a string, letter by letter. LCDWrite(*inputText++); }
//This sends the magical commands to the PCD8544 void LCDInit(void) { //Configure control pins LCD_DDR |= (1 << PIN_SCE) | (1 << PIN_RESET) | (1 << PIN_DC) | (1 << PIN_SDIN) | (1 << PIN_SCLK); //Reset the LCD to a known state LCD_PORT &= ~(1 << PIN_RESET); LCD_PORT |= (1 << PIN_RESET); LCDWrite(LCD_COMMAND, 0x21); //Tell LCD that extended commands follow LCDWrite(LCD_COMMAND, 0xB0); //Set LCD Vop (Contrast): Try 0xB1(good @ 3.3V) or 0xBF if your display is too dark LCDWrite(LCD_COMMAND, 0x04); //Set Temp coefficent LCDWrite(LCD_COMMAND, 0x14); //LCD bias mode 1:48: Try 0x13 or 0x14 LCDWrite(LCD_COMMAND, 0x20); //We must send 0x20 before modifying the display control mode LCDWrite(LCD_COMMAND, 0x0C); //Set display control, normal mode. 0x0D for inverse }
//This sends the magical commands to the PCD8544 void LCDInit(void) { //Configure control pins pinMode(PIN_SCE, OUTPUT); pinMode(PIN_RESET, OUTPUT); pinMode(PIN_DC, OUTPUT); pinMode(PIN_SDIN, OUTPUT); pinMode(PIN_SCLK, OUTPUT); //Reset the LCD to a known state digitalWrite(PIN_RESET, LOW); digitalWrite(PIN_RESET, HIGH); LCDWrite(LCD_COMMAND, 0x21); //Tell LCD that extended commands follow LCDWrite(LCD_COMMAND, 0xC0); //Set LCD Vop (Contrast): Try 0xB1(good @ 3.3V) or 0xBF if your display is too dark LCDWrite(LCD_COMMAND, 0x04); //Set Temp coefficent LCDWrite(LCD_COMMAND, 0x15); //LCD bias mode 1:48: Try 0x13 or 0x14 LCDWrite(LCD_COMMAND, 0x20); //We must send 0x20 before modifying the display control mode LCDWrite(LCD_COMMAND, 0x0C); //Set display control, normal mode. 0x0D for inverse }
void LCDHome() { LCDWrite(1, 0); Cpu_Delay100US(5); }
void LCDClear() { LCDWrite(0, 0); Cpu_Delay100US(5); }
void LCDCommand(uint8_t command) { LCDWrite(command, 0); }
/****************************************************************************** * Function: void LCDInit(void) * * PreCondition: None * * Input: None * * Output: None * * Side Effects: None * * Overview: LCDText[] is blanked, port I/O pin TRIS registers are * configured, and the LCD is placed in the default state * * Note: None *****************************************************************************/ void LCDInit(void) { BYTE i; memset(LCDText, ' ', sizeof(LCDText)-1); LCDText[sizeof(LCDText)-1] = 0; // Setup the I/O pins LCD_E_IO = 0; LCD_RD_WR_IO = 0; #if defined(LCD_DATA_TRIS) LCD_DATA_TRIS = 0x00; #else LCD_DATA0_TRIS = 0; LCD_DATA1_TRIS = 0; LCD_DATA2_TRIS = 0; LCD_DATA3_TRIS = 0; #if !defined(FOUR_BIT_MODE) LCD_DATA4_TRIS = 0; LCD_DATA5_TRIS = 0; LCD_DATA6_TRIS = 0; LCD_DATA7_TRIS = 0; #endif #endif LCD_RD_WR_TRIS = 0; LCD_RS_TRIS = 0; LCD_E_TRIS = 0; // Wait the required time for the LCD to reset DelayMs(40); // Set the default function // Go to 8-bit mode first to reset the instruction state machine // This is done in a loop 3 times to absolutely ensure that we get // to 8-bit mode in case if the device was previously booted into // 4-bit mode and our PIC got reset in the middle of the LCD // receiving half (4-bits) of an 8-bit instruction LCD_RS_IO = 0; #if defined(LCD_DATA_IO) LCD_DATA_IO = 0x03; #else LCD_DATA0_IO = 1; LCD_DATA1_IO = 1; LCD_DATA2_IO = 0; LCD_DATA3_IO = 0; #if !defined(FOUR_BIT_MODE) LCD_DATA4_IO = 0; LCD_DATA5_IO = 0; LCD_DATA6_IO = 0; LCD_DATA7_IO = 0; #endif #endif Nop(); // Wait Data setup time (min 40ns) Nop(); for(i = 0; i < 3u; i++) { LCD_E_IO = 1; Delay10us(1); // Wait E Pulse width time (min 230ns) LCD_E_IO = 0; DelayMs(2); } #if defined(FOUR_BIT_MODE) #if defined(SAMSUNG_S6A0032) // Enter 4-bit mode (requires only 4-bits on the S6A0032) #if defined(LCD_DATA_IO) LCD_DATA_IO = 0x02; #else LCD_DATA0_IO = 0; LCD_DATA1_IO = 1; LCD_DATA2_IO = 0; LCD_DATA3_IO = 0; #endif Nop(); // Wait Data setup time (min 40ns) Nop(); LCD_E_IO = 1; Delay10us(1); // Wait E Pulse width time (min 230ns) LCD_E_IO = 0; #else // Enter 4-bit mode with two lines (requires 8-bits on most LCD controllers) LCDWrite(0, 0x28); #endif #else // Use 8-bit mode with two lines LCDWrite(0, 0x38); #endif Delay10us(5); // Set the entry mode LCDWrite(0, 0x06); // Increment after each write, do not shift Delay10us(5); // Set the display control LCDWrite(0, 0x0C); // Turn display on, no cusor, no cursor blink Delay10us(5); // Clear the display LCDWrite(0, 0x01); DelayMs(2); }
void gotoXY(int x, int y) { LCDWrite(0, 0x80 | x); // Column x - range: 0 to 84 LCDWrite(0, 0x40 | y); // Row y - range: 0 to 5 }
void i_write(unsigned char v) { LCD_RS=0; LCDWrite(v); }
void gotoXY(int x, int y) { LCDWrite(0, 0x80 | x); // Column in Pixels LCDWrite(0, 0x40 | y); // Row in char_rows }
void Pos_xy_LCD(int x,int y) /* Sets the position for the next character write */ { LCD_RS=0; if (!y) LCDWrite(0x80+x); else LCDWrite(0xc0+x); }
void Put_LCD(char v) /* Writes the character v to the display */ { LCD_RS=1; LCDWrite(v); }