void HD44780_74HC595::begin() { pinMode(_SRDataPin, OUTPUT); pinMode(_SRNextValuePin, OUTPUT); pinMode(_SRValidatePin, OUTPUT); pinMode(_SRResetPin, OUTPUT); pinMode(_LCDRegisterSelectPin, OUTPUT); pinMode(_LCDValidatePin, OUTPUT); // Init all outputs digitalWrite(_SRDataPin, LOW); digitalWrite(_SRNextValuePin, LOW); digitalWrite(_SRValidatePin, LOW); digitalWrite(_SRResetPin, LOW); digitalWrite(_LCDRegisterSelectPin, LOW); digitalWrite(_LCDValidatePin, LOW); delayMicroseconds(10); // Init 74HC595 SRreset(); // Wait 50ms delay(15); // Init LCD LCDcommand(_LCDSize); LCDcommand(LCD_CLEARDISPLAY); LCDcommand(LCD_ENTRYMODELEFT); LCDcommand(_LCDDisplayMode); }
void HD44780_74HC595::LCDonoff(bool value){ if (value == true) { LCDcommand(_LCDDisplayMode); LCDOn = true; } else { LCDcommand(LCD_DISPLAYOFF); LCDOn = false; } }
void LCDsetContrast(uint8_t val) { if (val > 0x7f) { val = 0x7f; } LCDcommand(PCD8544_FUNCTIONSET | PCD8544_EXTENDEDINSTRUCTION ); LCDcommand( PCD8544_SETVOP | val); LCDcommand(PCD8544_FUNCTIONSET); }
void LCDdisplay(void) { uint8_t col, maxcol, p; for(p = 0; p < 6; p++) { #ifdef enablePartialUpdate /* check if this page is part of update*/ if ( yUpdateMin >= ((p+1)*8) ) { continue; /* nope, skip it! */ } if (yUpdateMax < p*8) { break; } #endif LCDcommand(PCD8544_SETYADDR | p); #ifdef enablePartialUpdate col = xUpdateMin; maxcol = xUpdateMax; #else /* start at the beginning of the row */ col = 0; maxcol = LCDWIDTH-1; #endif LCDcommand(PCD8544_SETXADDR | col); for(; col <= maxcol; col++) { /*uart_putw_dec(col); */ /*uart_putchar(' '); */ LCDdata(pcd8544_buffer[(LCDWIDTH*p)+col]); } } LCDcommand(PCD8544_SETYADDR ); /* no idea why this is necessary but it is to finish the last byte? */ #ifdef enablePartialUpdate xUpdateMin = LCDWIDTH - 1; xUpdateMax = 0; yUpdateMin = LCDHEIGHT-1; yUpdateMax = 0; #endif }
void LCDInit(uint8_t SCLK, uint8_t DIN, uint8_t DC, uint8_t CS, uint8_t RST, uint8_t contrast) { _din = DIN; _sclk = SCLK; _dc = DC; _rst = RST; _cs = CS; cursor_x = cursor_y = 0; textsize = 1; textcolor = BLACK; /* set pin directions */ pinMode(_din, OUTPUT); pinMode(_sclk, OUTPUT); pinMode(_dc, OUTPUT); pinMode(_rst, OUTPUT); pinMode(_cs, OUTPUT); /* toggle RST low to reset; CS low so it'll listen to us */ if (_cs > 0) digitalWrite(_cs, LOW); digitalWrite(_rst, LOW); _delay_ms(500); digitalWrite(_rst, HIGH); /* get into the EXTENDED mode! */ LCDcommand(PCD8544_FUNCTIONSET | PCD8544_EXTENDEDINSTRUCTION ); /* LCD bias select (4 is optimal?) */ LCDcommand(PCD8544_SETBIAS | 0x4); /* set VOP */ if (contrast > 0x7f) contrast = 0x7f; LCDcommand( PCD8544_SETVOP | contrast); /* Experimentally determined */ /* normal mode */ LCDcommand(PCD8544_FUNCTIONSET); /* Set display to Normal */ LCDcommand(PCD8544_DISPLAYCONTROL | PCD8544_DISPLAYNORMAL); /* set up a bounding box for screen updates */ updateBoundingBox(0, 0, LCDWIDTH-1, LCDHEIGHT-1); }
int main (void) { // print infos printf("Raspberry Pi PCD8544 test\n"); printf("========================================\n"); printf("CLK on Port %i \n", _sclk); printf("DIN on Port %i \n", _din); printf("DC on Port %i \n", _dc); printf("CS on Port %i \n", _cs); printf("RST on Port %i \n", _rst); printf("========================================\n"); // check wiringPi setup if (wiringPiSetup() == -1) { printf("wiringPi-Error\n"); exit(1); } // init and clear lcd LCDInit(_sclk, _din, _dc, _cs, _rst, contrast); LCDclear(); // turn all the pixels on (a handy test) printf("Test: All pixels on.\n"); LCDcommand(PCD8544_DISPLAYCONTROL | PCD8544_DISPLAYALLON); delay(1000); // back to normal printf("Test: All pixels off.\n"); LCDcommand(PCD8544_DISPLAYCONTROL | PCD8544_DISPLAYNORMAL); LCDclear(); // display logo printf("Test: Display logo.\n"); LCDshowLogo(); delay(2000); LCDclear(); // draw a single pixel printf("Test: Display single pixel.\n"); LCDsetPixel(10, 10, BLACK); LCDdisplay(); delay(2000); LCDclear(); // draw many lines printf("Test: Draw many lines.\n"); int i; for (i=0; i<84; i+=4) { LCDdrawline(0, 0, i, 47, BLACK); } for (i=0; i<48; i+=4) { LCDdrawline(0, 0, 83, i, BLACK); } LCDdisplay(); delay(2000); LCDclear(); // draw rectangles printf("Test: Draw rectangles.\n"); for (i=0; i<48; i+=2) { LCDdrawrect(i, i, 96-i, 48-i, BLACK); } LCDdisplay(); delay(2000); LCDclear(); // draw multiple rectangles printf("Test: Draw multiple rectangles.\n"); for (i=0; i<48; i++) { // alternate colors for moire effect LCDfillrect(i, i, 84-i, 48-i, i%2); } LCDdisplay(); delay(2000); LCDclear(); // draw mulitple circles printf("Test: Draw multiple circles.\n"); for (i=0; i<48; i+=2) { LCDdrawcircle(41, 23, i, BLACK); } LCDdisplay(); delay(2000); LCDclear(); // draw the first ~120 characters in the font printf("Test: Draw the first ~120 chars.\n"); for (i=0; i < 64; i++) { LCDdrawchar((i % 14) * 6, (i/14) * 8, i); } LCDdisplay(); delay(2000); for (i=0; i < 64; i++) { LCDdrawchar((i % 14) * 6, (i/14) * 8, i + 64); } LCDdisplay(); delay(2000); LCDclear(); return 0; }