/** Clear the screen * * Clear the entire display. * */ void lcdClear() { // Set the position lcdCommand(0x80); lcdCommand(0x40); uint16_t index; for(index = 0; index < (LCD_COL * LCD_ROW); index++) { lcdData(CLEAR_BYTE); } }
/*!\brief Print to the LCD on both lines. * *\details Clears the LCD, then prints the two C strings given. Each string * should be equal or less than 16 characters to fit on the LCD. We print * str_top on the first line of the LCD, and str_bottom on the second line. * * @param str_top C string, 16 characters or less, to print on the first line * of the LCD. * @param str_bottom C string, 16 characters or less, to print on the bottom * line of the LCD. */ void printLCD (char *str_top, char *str_bottom) { lcdCommand(CLEAR_LCD); // Start by clearing the LCD. lcdCommand(FIRST_LINE); // Go to the first line. // Print out the string for the top: usart_fprint(LCD_ADDRESS, (uint8_t *) str_top); lcdCommand(SECOND_LINE); // Go to the second line. // Print out the string for the bottom: usart_fprint(LCD_ADDRESS, (uint8_t *) str_bottom); }
void lcdBlitPortrait(uint8_t *img, unsigned char rows, unsigned char cols, unsigned char x, unsigned char y) { int j; lcdCommand(LCD_PAGE_SET(x/8)); lcdCommand(LCD_COLUMN_SET_HI(4 + y)); lcdCommand(LCD_COLUMN_SET_LO(4 + y)); for(j=0;j<8;j++) { lcdData(img[j]); } }
/*!\brief Initialize the LCD for communication, called before any printing * can be done. * *\details This function must be called once before trying to print on the LCD, * or else the LCD will not receive commands sent to it. In technical detail, * to be able to communicate with and print on the LCD, we have to set the * Data Register DDRD, and then set PortD pin 3 as output compare, since the * LCD is connected to pin 3 on Chico™. * */ void initLCD (void) { // Open the USART port for writing. usartOpen(LCD_ADDRESS, 9600, portSERIAL_BUFFER_TX, portSERIAL_BUFFER_RX); // Set the data register for the LCD. DDRD |= _BV(DDD3); // Point at pin 3, where the LCD is connected. PORTD |= _BV(PORTD3); // Turn on the display. lcdCommand(TURN_ON_DISPLAY); // Clear the LCD, in case it has any previous content. lcdCommand(CLEAR_LCD); }
//****************************************************************************** void lcd_reset(void) { LCD_DDR = 0xFF; //LCD port is output LCD_PRT &= ~(1<<LCD_EN); //LCD_EN = 0 delay_us(20000); //wait for stable power (more than 15 ms) lcdCommand(0x03); //$30 for reset delay_us(10000); //wait for more than (4.1 ms) lcdCommand(0x03); //$30 for reset delay_us(1000); //wait (for more than (100 us) lcdCommand(0x03); //$30 for reset delay_us(1000); //wait (for more than 100 us) lcdCommand(0x02); //$20 for reset delay_us(1000); //wait (for more than 100 us) }
void lcdPrintPortrait(char *msg, char line) { int i, j; for(i=0;i<8;i++) { if(msg[i] == 0) { break; } lcdCommand(LCD_PAGE_SET(i)); lcdCommand(LCD_COLUMN_SET_HI(4 + line * 8)); lcdCommand(LCD_COLUMN_SET_LO(4 + line * 8)); for(j=0;j<8;j++) { lcdData(font[msg[i]][j]); } } }
void lcdInit() { int i; // hardware layout specific optimisations here // if you change the pinout these need to be changed rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN | RCC_APB2ENR_AFIOEN); rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN); // timer 2 for backlight dimming rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_TIM2EN); gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_10_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, LCD_RST_PIN | LCD_E_PIN | LCD_RW_PIN | LCD_CS_PIN); gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_10_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, LCD_DC_PIN); gpio_set_mode(LCD_BL_PORT, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, LCD_BL_PIN); gpio_clear(LCD_RST_PORT, LCD_RST_PIN); gpio_set(LCD_CS_PORT, LCD_CS_PIN); gpio_set(LCD_DC_PORT, LCD_DC_PIN); gpio_clear(LCD_RW_PORT, LCD_RW_PIN); gpio_clear(LCD_E_PORT, LCD_E_PIN); /* === Setup PWM peripherals for brightness === */ /* global settings for timer 1 */ TIM2_CR1 = TIM_CR1_CKD_CK_INT | TIM_CR1_CMS_EDGE; TIM2_ARR = 65535; TIM2_PSC = 0; TIM2_EGR = TIM_EGR_UG; /* timer 1 channel 2 (screen brightness) */ TIM2_CCMR2 |= TIM_CCMR2_OC3M_PWM1 | TIM_CCMR2_OC3PE; TIM2_CCER |= TIM_CCER_CC3E; TIM2_CCR3 = 0; TIM2_CR1 |= TIM_CR1_ARPE; TIM2_CR1 |= TIM_CR1_CEN; // TIM2_BDTR |= TIM_BDTR_MOE; for(i=0;i<10000;i++) {__asm__("nop\n\t");} gpio_set(LCD_RST_PORT, LCD_RST_PIN); for(i=0;i<10000;i++) {__asm__("nop\n\t");} lcdCommand(LCD_BIAS_SEVENTH); lcdCommand(LCD_DIRECTION_FWD); lcdCommand(LCD_COMMON_FWD); lcdCommand(LCD_VREG_SET); lcdCommand(LCD_CONTRAST_HI); lcdCommand(LCD_CONTRAST_LO(32)); lcdCommand(LCD_POWER_SETUP); lcdCommand(LCD_DISPLAY_ON); }
void FTPClient::executeCommand(std::string command, std::string param) { if ( command == "LLIST" ) llistCommand(); else if ( command == "LCD" ) lcdCommand(param); }
//Writes byte to selected page void lcdWrite(uint8_t page, uint8_t column) { // make sure column and page are within bounds page %= 9; column %= 128; // set column MSB lcdCommand(0x10 | ((127 - column) >> 4)); // set column LSB lcdCommand(0x0F & (127 - column)); // set page lcdCommand(0xB0 |(0x0F & (7-page))); //Data write PMPSetAddress(1); PMPMasterWrite( display[page][column] ); //Reverse Vertical Axis }
void lcd_generate(unsigned char location, unsigned char *ptr) { unsigned char i; if(location<8) { lcdCommand(0x40+(location*8)); for(i=0;i<8;i++) { lcdData(ptr[i]); } } }
/** Initialise the LCD * * Sets up the pins required to communicate with the LCD screen and then does * the actual chipset initialisation. The pin numbers to use are defined in * @ref hardware.h. */ void lcdInit() { LCD_SCK_SET_OUTPUT(); LCD_MOSI_SET_OUTPUT(); LCD_CD_SET_OUTPUT(); LCD_SCK_LOW(); LCD_MOSI_LOW(); LCD_CD_LOW(); #if defined(LCD_USE_PROGRAM_RESET) LCD_RESET_SET_OUTPUT(); LCD_RESET_LOW(); // Do a hard reset on the LCD waitReset(); //PORTB |= (1 << LCD_RESET); LCD_RESET_HIGH(); #endif // Initialise the LCD lcdCommand(0x21); // LCD Extended Commands. lcdCommand(0x80|LCD_CONTRAST_VALUE); // Set LCD Vop (Contrast). lcdCommand(0x04); // Set Temp coefficent. lcdCommand(0x14); // LCD bias mode 1:48. lcdCommand(0x20); // LCD Normal commands lcdCommand(0x08 | 0x04); // Normal display, horizontal addressing }
//****************************************************************************** void lcd_init(void) { //lcd_reset(); LCD_DDR = 0xFF; delay_us(2000); /* Function set */ lcdCommand(0x33); //$28 for 4-bit mode delay_us(100); //wait /* Display ON/OFF Control */ lcdCommand(0x32); //display on, cursor on, blinking delay_us(100); //wait lcdCommand(LCD_FUNCTION_4BIT_2LINES); delay_us(100); //clear LCD lcdCommand(LCD_DISP_ON); delay_us(100); lcdCommand(CLEAR_DISPLAY); delay_us(2000); //wait /* Entry mode set */ lcdCommand(LCD_ENTRY_INC_); //shift && cursor right delay_us(100); //wait }
/** Write a single character * * Display a single ASCII character at the position described by the row and * column parameters. Note that the row indicates an 8 pixel high character * row while the column represents individual pixels. This code uses a built * in character set where each character is 5 pixels wide and adds a single * column of pixels as spacing giving a total width of 6 pixels. * * @param row the row number (0 to 5) to display the character. * @param col the column position (0 to 83) for the start of the left side of * the character. * @param ch the character to display. If the character is out of range it * will be replaced with the '?' character. */ void lcdPrintChar(uint8_t row, uint8_t acol, char ch, uint8_t size) { // Make sure it is on the screen if((row>=LCD_ROW)||(acol>=LCD_COL)) { return; } // If the character is invalid replace it with the '?' if((ch<0x20)||(ch>0x7f)) { ch = '?'; } uint8_t i; for(i = 0; i < size; i++) { uint8_t col = acol; // Set the starting address lcdCommand(0x80 | col); lcdCommand(0x40 | ((row + i) % LCD_ROW)); // And send the column data const uint8_t *chdata = SMALL_FONT + ((ch - 0x20) * 5); uint8_t pixels; for(pixels = 0; (pixels < DATA_WIDTH) && (col < LCD_COL); pixels++, col++, chdata++) { uint8_t data = pgm_read_byte_near(chdata); if(size != 2) { lcdData(data); continue; } data = bitScale(data, i * 4); lcdData(data); lcdData(data); } // Add the padding byte if(col < LCD_COL) { lcdData(CLEAR_BYTE); } } }
void initLCD() { //No commands for 40ms OpenTimer2( T2_PS_1_256 | T2_ON, delay( 40 ) ); //Start Reset mPORTAClearBits( 1 << 3 ); mPORTASetPinsDigitalOut( 1 << 3 ); //Prep mPMPOpen( PMP_ON | PMP_TTL | PMP_READ_WRITE_EN | PMP_WRITE_POL_LO | PMP_READ_POL_LO, PMP_MODE_MASTER1 | PMP_WAIT_BEG_4 | PMP_WAIT_MID_15 | PMP_WAIT_END_4, PMP_PEN_0, PMP_INT_OFF ); //Wake Up! while( !mT2GetIntFlag() ); CloseTimer2(); mT2ClearIntFlag(); //End Reset mPORTASetBits( 1 << 3 ); //No Commands for 39us OpenTimer2( T2_PS_1_256 | T2_ON, delay( 40 ) ); //Wake Up! while( !mT2GetIntFlag() ); CloseTimer2(); mT2ClearIntFlag(); lcdCommand(LCD_ON); //Best boot 5-1-05 lcdCommand(0xA3); //LCD Bias (A2 A3) - First Choice lcdCommand(0x2F); //Turn on internal power control lcdCommand(0x26); //Pseudo-Contrast 7 = dark 6 = OK - First Choice lcdCommand(0x81); //Set contrast lcdCommand(40);//The Contrast (30 to 54 - Recommeneded) lcdCommand(0xC8); //Flip screen on the horizontal to match with the vertical software invertion lcdClear(); }
void lcdClear() { int i, j; for(i=0;i<8;i++) { lcdCommand(LCD_PAGE_SET(i)); lcdCommand(LCD_COLUMN_SET_HI(4)); lcdCommand(LCD_COLUMN_SET_LO(4)); for(j=0;j<128;j++) { lcdData(0x00); } } lcdCommand(LCD_PAGE_SET(0)); lcdCommand(LCD_COLUMN_SET_HI(4)); lcdCommand(LCD_COLUMN_SET_LO(4)); }
//******************************************************************************* void lcd_cursor_off(void) { lcdCommand(LCD_DISP_ON); delay_us(100); }
//******************************************************************************* void lcd_move_cursor_right(void) { lcdCommand(LCD_MOVE_CURSOR_RIGHT); delay_us(100); }
//******************************************************************************* void lcd_clear(void) { lcdCommand(CLEAR_DISPLAY); delay_us(2000); lcd_gotoxy(1,1); }
/* * the parameter is the position of the cursor according to the HD44780 specs * for the lcd display our board has the top row's position range is 01 to */ void lcdGoTo(char pos) { // add 0x80 to be able to use HD44780 position convention lcdCommand(0x80 + pos); }
void lcdContrast(unsigned char contrast) { contrast = contrast & 0x3F; lcdCommand(LCD_CONTRAST_HI); lcdCommand(LCD_CONTRAST_LO(contrast)); }
void main(void) { char packet[] = {'T', 'e', 's', 't'}; unsigned char i = 0; unsigned char packet_size = sizeof (packet) / sizeof (packet[0]); unsigned char cArray[10] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'}; // temporary local array unsigned char writtenArray[10]; // local variables for all test cases and their initialisation unsigned char chData; unsigned char *pReadArray; unsigned char *pWriteArray; unsigned char j = 0; unsigned char i = 0; pReadArray = pWriteArray = writtenArray; /* Configure the oscillator for the device */ ConfigureOscillator(); /* Initialize I/O and Peripherals for application */ InitApp(); // LCD test TRISAbits.RA2 = 0; // our chip select pin needs to be an output so that we can toggle it CS = 1; // set CS pin to high, meaning we are sending any information to the MCP23S17 chip // configure SPI: the MCP23S17 chip's max frequency is 10MHz, let's use 10MHz/64 (Note FOSC=10Mhz, our external oscillator) OpenSPI1(SPI_FOSC_64, MODE_10, SMPEND); // frequency, master-slave mode, sampling type // set LCD pins DB0-DB7 as outputs setIODIR(IODIRB_ADDRESS, 0x00); // set RS and E LCD pins as outputs setIODIR(IODIRA_ADDRESS, 0x00); // RS=0, E=0 setGPIO(IODIRA_ADDRESS, 0x00); // Function set: 8 bit, 2 lines, 5x8 lcdCommand(0b00111111); // Cursor or Display Shift lcdCommand(0b00001111); // clear display lcdCommand(0b00000001); // entry mode lcdCommand(0b00000110); // send characters lcdWriteString((unsigned char *) "Waiting..."); // using the string function lcdGoTo(0x40); // go to line two /*lcdChar('S'); // using the single character function lcdChar('P'); lcdChar('I'); lcdChar(' '); lcdChar('L'); lcdChar('i'); lcdChar('b'); lcdChar('r'); lcdChar('a'); lcdChar('r'); lcdChar('y'); */ /////////////////////////////////////////////////// /* TODO <INSERT USER APPLICATION CODE HERE> */ /* while(1) { i = 0; do { UARTIntPutChar(packet[i++]); } while (i < packet_size); while (!vUARTIntStatus.UARTIntTxBufferEmpty); Delay10KTCYx(1000); } */ TRISD = 0; PORTD = 0; while (1) { /* for (j = 0; j < 100; j++) { i = 0; do { if (vUARTIntStatus.UARTIntTxBufferEmpty) UARTIntPutChar(cArray[i++]); } while (i < 10); } */ if (!(vUARTIntStatus.UARTIntRxError) && !(vUARTIntStatus.UARTIntRxOverFlow) && !(vUARTIntStatus.UARTIntRxBufferEmpty)) { if (UARTIntGetChar(&chData)) { PORTD = chData; lcdChar(chData); } } } }
//******************************************************************************* void lcd_cursor_on(void) { lcdCommand(LCD_DISP_ON_CURSOR_BLINK); delay_us(100); }
//****************************************************************************** void lcd_gotoxy(unsigned char x, unsigned char y) { unsigned char firstcharAdr[] = {0x80, 0xC0, 0x94, 0xD4}; lcdCommand(firstcharAdr[y-1] + x - 1); delay_us(100); }
//******************************************************************************* void lcd_move_cursor_left(void) { lcdCommand(LCD_MOVE_CURSOR_LEFT); delay_us(100); }