void LCD_clearPixel( unsigned char x, unsigned char y ) { unsigned char value; unsigned char row; row = y / 8; value = lcd_buffer[row][x]; value &= ~(1 << (y % 8)); lcd_buffer[row][x] = value; //LCD_update(); LCD_gotoXY (x,row); LCD_writeData(value); }
/*-------------------------------------------------------------------------------------------------- Name : LCD_clear_row Description : Clears the display row Argument(s) : row, 1-6, the row to be cleared Return value : None. --------------------------------------------------------------------------------------------------*/ void LCD_clear_row (uint8_t row) { int j; LCD_gotoXY (0,row); //start with (0,row) position for(j=0; j<84; j++) { LCD_writeData( 0x00 ); if ((row < 6) && (j < 84)) lcd_buffer[row][j] = 0x00; } LCD_gotoXY (0,0); //bring the XY position back to (0,0) }
void LCD_update( void ) { int i,j; LCD_gotoXY (0,0); //start with (0,0) position for(i=0; i<7; i++) { LCD_gotoXY (0,i); for(j=0; j<84; j++) { LCD_writeData(lcd_buffer[i][j]); } } LCD_gotoXY (0,0); //bring the XY position back to (0,0) }
/*-------------------------------------------------------------------------------------------------- Name : LCD_clear Description : Clears the display Argument(s) : None. Return value : None. --------------------------------------------------------------------------------------------------*/ void LCD_clear ( void ) { int i,j; LCD_gotoXY (0,0); //start with (0,0) position for(i=0; i<8; i++) { for(j=0; j<90; j++) { LCD_writeData( 0x00 ); if ((i < 6) && (j < 84)) lcd_buffer[i][j] = 0x00; } } LCD_gotoXY (0,0); //bring the XY position back to (0,0) }
void printImage(uint8_t * image) { int column; int row; int imageWidth = image[0]; int imageHeight = image[1]; for(row = 0; row < imageHeight; row++) { setColumn(0); setPage(row); uint8_t imageRow[imageWidth]; for(column = 0; column < imageWidth; column++) { imageRow[column] = image[2 + imageWidth*row + column]; } LCD_writeData(imageRow,imageWidth); } }
int main(void) { UART_init(); spi_init(); delay_ms(100); LCD_init (); delay_ms(100); LCD_clear (); // send the init frame //UART_transmit(0xFB); UART_transmit(0xFB); UART_transmit(0x0A); UART_transmit(0x0A); UART_transmit(0x0A); UART_transmit(0x0D); // upload the pixel array done = 0; while (done == 0) { // receive data frame df_data = UART_receive(); df_seq_msb = UART_receive(); df_seq_lsb = UART_receive(); df_end = UART_receive(); df_cr = UART_receive(); // store into byte pixel array if (df_seq_msb == 0x01) { byte_pixel[256 + df_seq_lsb] = df_data; } else { byte_pixel[df_seq_lsb] = df_data; } // send the ack UART_transmit(0xFA); UART_transmit(df_seq_msb); UART_transmit(df_seq_lsb); UART_transmit(0x0A); UART_transmit(0x0D); // break when the last byte (503) is received if ((df_seq_msb == 0x01) && (df_seq_lsb == 247)) { done = 1; } } // set the cursor LCD_gotoXY(0,0); // write byte_pixel by byte_pixel for (index = 0; index < 504; index++) { LCD_writeData(byte_pixel[index]); } /* //LCD_drawBorder ( ); LCD_gotoXY (4,2); //LCD_writeChar (0x41); //LCD_writeString_F("Thermometer"); //LCD_writeString_F("0123"); LCD_writeChar (0x20); LCD_writeChar (0x20); LCD_writeChar (0x68); LCD_writeChar (0x6f); LCD_writeChar (0x77); LCD_writeChar (0x64); LCD_writeChar (0x79); LCD_gotoXY (4,3); //LCD_writeChar (0x43); //LCD_writeString_F("by DHARMANI"); //LCD_writeString_F("6789"); LCD_writeChar (0x44); LCD_writeChar (0x61); LCD_writeChar (0x6D); LCD_writeChar (0x6D); LCD_writeChar (0x69); LCD_writeChar (0x74); LCD_writeChar (0x21); */ }
void LCD_putc(char character, uint8_t type) { // Code below borrowed and modified from: http://www.instructables.com/id/Connecting-Nokia-3310-LCD-to-USB-using-AVR/step4/Programming-the-ATmega/ // if we've been forced to a new line and it requires handling, go to a new line since we went back up if ((type & LCD_TYP_CKNL) && lcd_wasnl == 1) { LCD_goto(0, ++cursor_row); lcd_wasnl = 0; if (character == ' ') return; // if space is next, just ignore it if (character == '\n') return; // if the next in line is NEWLINE, ignore it also since we just created a newline here } // Newline \n = 0x0A in hex, if the char we want to draw is this, // we call LCD_goto and increase Y by 1 if (character == '\n') { LCD_goto(0, ++cursor_row); return; // We don't have anything more to do, return } // Sometimes the character we want to draw is too close to the edge of the screen // to be drawn normally. To prevent the character from being partly drawn over 2 lines // we check if we have enough room to draw the character, and if we don't we simply // draw it on the next line instead // If there are less than 5 pixels left of this, // Count how many pixels this character needs if (LCD_WIDTH - cursor_col < 5) { uint8_t width = 0; for (uint8_t j = 0; j < 5; j++) { // Count if this is not a skip if (font[(character-32)*5 + j] != 0b10000000) { width++; } } // If the width of this character is over the amount of pixels left on the X axis if (width > LCD_WIDTH - cursor_col) { LCD_goto(0, ++cursor_row); // Goto next line } } // For 5 pixels (Our font maximum width) for (uint8_t j = 0; j < 5; j++) { // The first draw-able character we have is space (32 in decimal) // Our font do not use the first 32 ASCII characters, so we remove 32 from the character // we want to draw, and we get the same character as in out font! // As some of the characters don't use all 5 pixels, we can make it look nicer by not // drawing the empty space. 0b10000000 (0x80) is the value for not drawing anything in our font, aka "skip" // so, we don't print the 0x80 columns, we ignore them if (font[(character-32)*5 + j] != 0b10000000) { // Remove 32 from the character we want to draw, and then draw it. uint8_t tmp = font[(character-32)*5 + j]; // inverted? if (type & LCD_TYP_INV) { tmp = 255 - tmp; // invert } // shift character up for (uint8_t t = 0; t < (type & 0b00000011); t++) { tmp = tmp >> 1; // shift up "type & 0b00000011" many times (0-3) } // underlined with BLACK pixel? if (type & LCD_TYP_ULI) { tmp = tmp | 0b10000000; // set bottom pixel } // underlined with WHITE pixel? if (type & LCD_TYP_ULIW) { tmp = tmp & 0b01111111; // clear bottom pixel } // write to LCD LCD_writeData(tmp); } }
/** * Funkcja aktualizująca stan interfejsu użytkownika na podstawie wciśnieta klawisza * @param key wciśnięty przycisk */ void UI_update(Key key) { switch(currentState) { case UI_Welcome: { _UI_setState(UI_LoadCfg); break; } case UI_LoadCfg: { if(key==KEY_DOWN) { _UI_setState(UI_LoadCfg_EnterNo); boolCharEntered = 0; } else if(key==KEY_RIGHT || key==KEY_LEFT) _UI_setState(UI_LoadSeq); break; } case UI_LoadCfg_EnterNo: { if(key==KEY_UP) _UI_setState(UI_LoadCfg); else if(_isNumber(key)) { boolCharEntered = 1; enteredChar = key; LCD_goto(2,1); LCD_writeData(key); } else if(key==KEY_DOWN && boolCharEntered) { uint8_t name[12]="0.cfg"; name[0] = enteredChar; FAT32_readFile(READ,name,0,currentString); _UI_setState(UI_EditCfg); Ledmatrix_parse_and_write(currentString); Ledmatrix_update_display(); } break; } case UI_EditCfg: { if(key==KEY_UP) _UI_setState(UI_LoadCfg); else if (key==KEY_LEFT || key==KEY_RIGHT) _UI_setState(UI_SaveCfg); else if(key==KEY_DOWN) { uint8_t i; for(i=0;i<15;++i){ newString[i]=currentString[i]; if(!currentString[i]) break; } newLength = i; _UI_setState(UI_EditCfg_EnterNewConfig); } break; } case UI_EditCfg_EnterNewConfig: { if(key==KEY_UP) _UI_setState(UI_EditCfg); else if( ((key>=KEY_1 && key<=KEY_8) || key==KEY_PLUS) && newLength<14) { newString[newLength++] = key; LCD_goto(newLength+1,1); LCD_writeData(key); } else if(key==KEY_LEFT && newLength>0) { LCD_goto(newLength+1,1); newString[--newLength] = 0x00; LCD_writeData(' '); } else if(key==KEY_DOWN) { uint8_t i; for(i=0;i<newLength;++i) currentString[i] = newString[i]; currentString[i]=0x00; // terminate with 0x00 Ledmatrix_parse_and_write(currentString); Ledmatrix_update_display(); _UI_setState(UI_EditCfg); } break; } case UI_SaveCfg: { if (key==KEY_DOWN) _UI_setState(UI_SaveCfg_Confirm); else if (key==KEY_UP) _UI_setState(UI_LoadCfg); else if (key==KEY_LEFT || key==KEY_RIGHT) _UI_setState(UI_EditCfg); break; } case UI_SaveCfg_Confirm: { if (key==KEY_UP) _UI_setState(UI_SaveCfg); else if (key==KEY_DOWN) { uint8_t name[12]="0.cfg"; name[0] = enteredChar; FAT32_convertFileName(name); FAT32_findFiles(DELETE,name); //FAT32_writeFile(name,1,currentString); FAT32_writeFile(name,1,"123\0"); _UI_setState(UI_SaveCfg); } break; } case UI_LoadSeq: { if(key==KEY_RIGHT || key==KEY_LEFT) _UI_setState(UI_LoadCfg); else if(key==KEY_DOWN) _UI_setState(UI_LoadSeq_EnterNo); break; } case UI_LoadSeq_EnterNo: { if(key==KEY_UP) _UI_setState(UI_LoadSeq); else if(_isNumber(key)) { boolCharEntered = 1; enteredChar = key; LCD_goto(2,1); LCD_writeData(key); } else if(key==KEY_DOWN && boolCharEntered) { uint8_t name[12]="0.seq"; name[0] = enteredChar; FAT32_readFile(READ,name,0,currentString); _UI_setState(UI_EditSeq); } break; } case UI_EditSeq: { if(key==KEY_UP) _UI_setState(UI_LoadSeq); else if(key==KEY_DOWN) { uint8_t i; for(i=0;i<15;++i){ newString[i]=currentString[i]; if(!currentString[i]) break; } newLength = i; _UI_setState(UI_EditSeq_EnterNewSeq); } else if(key==KEY_LEFT || key==KEY_RIGHT) _UI_setState(UI_SaveSeq); break; } case UI_EditSeq_EnterNewSeq: { if(key==KEY_UP) _UI_setState(UI_EditSeq); else if(key>=KEY_1 && key<=KEY_8 && newLength<14) { newString[newLength++] = key; LCD_goto(newLength+1,1); LCD_writeData(key); } else if(key==KEY_LEFT && newLength>0) { LCD_goto(newLength+1,1); newString[--newLength] = 0x00; LCD_writeData(' '); } else if(key==KEY_DOWN && newLength>0) { uint8_t i; for(i=0;i<newLength;++i) currentString[i] = newString[i]; currentString[i]=0x00; // terminate with 0x00 _UI_setState(UI_EditSeq); } break; } case UI_SaveSeq: { if(key==KEY_UP) _UI_setState(UI_LoadSeq); else if(key==KEY_DOWN) _UI_setState(UI_SaveSeq_Confirm); else if((key==KEY_LEFT) || (key==KEY_RIGHT)) _UI_setState(UI_EditSeq); break; } case UI_SaveSeq_Confirm: { if (key==KEY_UP) _UI_setState(UI_SaveSeq); else if (key==KEY_DOWN) { uint8_t name[12]="0.seq"; name[0] = enteredChar; FAT32_convertFileName(name); FAT32_findFiles(DELETE,name); FAT32_writeFile(name,1,currentString); _UI_setState(UI_SaveSeq); } break; } case UI_LoadBtData: { if (key==KEY_UP) _UI_setState(prevState); // else if (key==KEY_DOWN) // { // // name[0] = incomingData[0]; // if(incomingData[1]=='c') // { // name[1] = '.'; // name[2] = 'c'; // name[3] = 'f'; // name[4] = 'g'; // name[5] = 0; // } // else if(incomingData[1]=='s') // { // name[1] = '.'; // name[2] = 's'; // name[3] = 'e'; // name[4] = 'q'; // name[5] = 0; // } // // FAT32_convertFileName(name); // FAT32_findFiles(DELETE,name); // // FAT32_writeFile(name,1,incomingData+2); // _UI_setState(prevState); // } break; } default: break; } }
/** * Funkcja wyświetlająca na LCD menu aktualnego stanu interfejsu użytkownika */ void UI_printMenu() { LCD_clear(); switch(currentState) { case UI_Welcome: { LCD_goto(0,0); LCD_writeText("HubzinatorPro(R)"); LCD_goto(0,1); LCD_writeText("Press any key"); break; } case UI_LoadCfg: { LCD_goto(0,0); LCD_writeText("< Load conf. >"); break; } case UI_LoadCfg_EnterNo: { LCD_goto(0,0); LCD_writeText("Conf. No.:"); LCD_goto(0,1); LCD_writeText("> "); break; } case UI_EditCfg: { LCD_goto(0,0); LCD_writeText("< Edit conf. "); LCD_writeData(enteredChar); LCD_writeText(" >"); break; } case UI_EditCfg_EnterNewConfig: { LCD_goto(0,0); LCD_writeText("Enter new conf."); LCD_goto(0,1); LCD_writeText("> "); LCD_goto(2,1); LCD_writeText(newString); break; } case UI_SaveCfg: { LCD_goto(0,0); LCD_writeText("< Save conf. "); LCD_writeData(enteredChar); LCD_writeText(" >"); break; } case UI_SaveCfg_Confirm: case UI_SaveSeq_Confirm: { LCD_goto(0,0); LCD_writeText("Overwrite?"); break; } case UI_LoadSeq: { LCD_goto(0,0); LCD_writeText("< Load seq. >"); break; } case UI_LoadSeq_EnterNo: { LCD_goto(0,0); LCD_writeText("Sequence No.:"); LCD_goto(0,1); LCD_writeText("> "); break; } case UI_EditSeq: { LCD_goto(0,0); LCD_writeText("< Edit seq. "); LCD_writeData(enteredChar); LCD_writeText(" >"); break; } case UI_EditSeq_EnterNewSeq: { LCD_goto(0,0); LCD_writeText("Enter new seq."); LCD_goto(0,1); LCD_writeText("> "); LCD_goto(2,1); LCD_writeText(newString); break; } case UI_SaveSeq: { LCD_goto(0,0); LCD_writeText("< Save seq. "); LCD_writeData(enteredChar); LCD_writeText(" >"); break; } case UI_LoadBtData: { LCD_goto(0,0); LCD_writeText("File incoming"); LCD_goto(0,1); LCD_writeText("Accept?"); break; } default: break; } }
/// Funkcja wyświetlenia napisu na wyswietlaczu. void LCD_writeText(char * text) { while(*text) LCD_writeData(*text++); }
// Writes 8 bits to the TFT controller. void LCD_write8(uint8_t value){ LCD_assertWr(); // Assert the WR line. LCD_writeData(value); // Copy the data out to the MIO pins. LCD_negateWr(); // Negate WR. }