Example #1
0
/* ����������������������������������������������������������������������� */
 void LcdLowLevelInit()
{
    u_char i;

    NutDelay(140);                               // wait for more than 140 ms after Vdd rises to 2.7 V

    for (i=0; i<3; ++i)
    {
        LcdWriteNibble(WRITE_COMMAND, 0x33);      // function set: 8-bit mode; necessary to guarantee that
        NutDelay(4);                              // SIR starts up always in 5x10 dot mode
    }

    LcdWriteNibble(WRITE_COMMAND, 0x22);        // function set: 4-bit mode; necessary because KS0070 doesn't
    NutDelay(1);                                // accept combined 4-bit mode & 5x10 dot mode programming

    //LcdWriteByte(WRITE_COMMAND, 0x24);        // function set: 4-bit mode, 5x10 dot mode, 1-line
    LcdWriteByte(WRITE_COMMAND, 0x28);          // function set: 4-bit mode, 5x7 dot mode, 2-lines
    NutDelay(5);

    LcdWriteByte(WRITE_COMMAND, 0x0C);          // display ON/OFF: display ON, cursor OFF, blink OFF
    NutDelay(5);

    LcdWriteByte(WRITE_COMMAND, 0x01);          // display clear
    NutDelay(5);

    LcdWriteByte(WRITE_COMMAND, 0x06);          // entry mode set: increment mode, entire shift OFF


    LcdWriteByte(WRITE_COMMAND, 0x80);          // DD-RAM address counter (cursor pos) to '0'
}
Example #2
0
void lcd_show_cursor(bool value)
{
    if(value)
        LcdWriteByte(WRITE_COMMAND, 0x0F);  // 0E: underline cursor. Or: 0F for block cursor
    else
        LcdWriteByte(WRITE_COMMAND, 0x0C);
}
Example #3
0
void LcdSetPos(LcdSpi* lcd, uint8_t page, uint8_t col)
{
	if (!lcd) {
		return;
	}
	GpioSetValue(PIN_LCD_A0, 0);
	LcdWriteByte(lcd->mS0, 0xB0 + page);
	LcdWriteByte(lcd->mS0, 0x10 + ((col >> 4) & 0xf0));
	LcdWriteByte(lcd->mS0, 0x00 + (col & 0x0f));
}
void setCursorPos(int YPos, int XPos)
{
	// 0 is the first line. 1 the second line
	switch (YPos)
	{
	case 0:	LcdWriteByte(WRITE_COMMAND, 0x80 + XPos);
		break;
	case 1:	LcdWriteByte(WRITE_COMMAND, 0xC0 + XPos);
		break;
	}


}
Example #5
0
void setXCursorPos(int leftRight,int count)
{
    int i;
    for ( i = 0; i <count ; ++i)
    {
        switch(leftRight)
        {
            case 0: LcdWriteByte(1,0x18);		// shift rechts
                break;
            case 1: LcdWriteByte(1,0x1c);		// shift links
                break;
        }
    }
}
void createCustomChar(int characters) {
	int ch = 0;
	int k = 0;
	LcdWriteByte(WRITE_COMMAND, 64 );
	for (k = 0; k < characters; k++)
	{
		
		for (ch = 0; ch < 8; ch++)
		{
			LcdWriteByte(WRITE_DATA, charset[k][ch]|(ch << 5)); // schrijf data in CG-RAM | 
		}
	}

	LcdWriteByte(WRITE_COMMAND, 0x80);
}
Example #7
0
void LcdInit(LcdSpi* lcd)
{
	uint8_t i;
	// 132x32
	uint8_t initSeqTx[] = {0x40, 0xA1, 0xC0, 0xA6, 0xA2, 0x2F, 0xF8, 0x00, 0x23, 0x81, 0x1F, 0xAC, 0x00, 0xAF};
	// 128x64
	//uint8_t initSeqTx[] = {0x40, 0xA1, 0xC0, 0xA6, 0xA2, 0x2F, 0xF8, 0x00, 0x27, 0x81, 0x10, 0xAC, 0x00, 0xAF};
	
	if (!lcd) {
		return;
	}
	
	GpioExport(PIN_LCD_nRST);
	GpioExport(PIN_LCD_A0);
	
	GpioSetDirection(PIN_LCD_nRST, 1);
	GpioSetDirection(PIN_LCD_A0, 1);

	GpioSetValue(PIN_LCD_nRST, 0);
	usleep(10000);
	GpioSetValue(PIN_LCD_nRST, 1);
	usleep(10000);	
	GpioSetValue(PIN_LCD_A0, 0);
	for (i = 0; i < sizeof(initSeqTx); i++) {
		LcdWriteByte(lcd->mS0, initSeqTx[i]);
		usleep(10000);
	}
}
Example #8
0
/**
 * Clears the LCD display and sets the cursor to [0][0]
 */
void lcd_clear()
{
    LcdWriteByte(WRITE_COMMAND, 0x01);          // Display clear command.
    NutDelay(2);

    lcd_cursor_home();
}
Example #9
0
void LcdArrayLineTwo(char *data, int size){
	int i;
	LcdWriteByte(WRITE_COMMAND, 0xC0);
	NutSleep(2);
	for(i = 0; i < size; i = i + 1){
		LcdChar(data[i]);
	}
}
Example #10
0
/**
 * Place cursor at the given position.
 * @param The x-coordinate on the display (0-15)
 * @param The y-coordinate on the display (0-1)
 * @return 0 on success, -1 on failure
 */
int lcd_place_cursor_at(int x, int y)
{
    if(x < 0 || x > 15 || y < 0 || y > 1)
        return -1;
    
    LcdWriteByte(WRITE_COMMAND, 0x80 + (y * 64) + x );          // DD-RAM address counter (cursor pos) to the requested position.
    
    return 0;
}
Example #11
0
uint8_t LcdWriteImagePng(LcdSpi* lcd, const char *filename)
{
	uint16_t x = 100;
	uint16_t y = 100;
	uint16_t xm = 0;
	uint16_t ym = 0;
	uint16_t i = 0;
	int c;
	gdImagePtr img;
	FILE *filePtr;
	uint8_t b;
	
	if (!lcd) {
		return 1;
	}
	if (!filename) {
		return 2;
	}

	filePtr = fopen(filename, "rb");
	if (filePtr == NULL) {
		return 3;
	}
	img = gdImageCreateFromPng(filePtr);
	if (img == NULL) {
		return 4;
	}
	xm = gdImageSX(img);
	ym = gdImageSY(img);
	printf("%i x %i\n", xm, ym);
	
	if (xm != 132 || ym != 32) {
		return 5;
	}
	
	for (y = 0; y < ym; y += 8) {
		LcdSetPos(lcd, y / 8, 0);
		
		GpioSetValue(PIN_LCD_A0, 1);
		for (x = 0; x < xm; x++) {
			b = 0;
			for (i = 0; i < 8; i++) {
				c = gdImageGetPixel(img, x, y + i);
				if (img->red[c] < 0x7f || img->green[c] < 0x7f || img->blue[c] < 0x7f) {
				//if (c) {
					b |= (1 << i);
				}
			}
			LcdWriteByte(lcd->mS0, b);
		}
	}
	fclose(filePtr);
	gdImageDestroy(img);
	
	return 0;
}
Example #12
0
/**
 * Displays the given string on the LCD display at the given location.
 * @param string The string to display
 * @param x The x-coordinate of the first letter of the string, ranging from 0 - 15
 * @param y The y-coordinate of the first letter of the string, ranging from 0 - 1
 * @return 0 on success, -1 on failure
 */
int lcd_display_string_at(char* string, int x, int y)
{
    if(x < 0 || x > 15 || y < 0 || y > 1)
        return -1;
    
    // TODO: TEST CURSOR POSITION
    LcdWriteByte(WRITE_COMMAND, 0x80 + (y * 64) + x );          // DD-RAM address counter (cursor pos) to the requested position.
    int i;
    for(i = 0; (string[i] != '\0') && (i < 16 -x); i++)        // Loop through the string and display each character individually.
        LcdChar(string[i]);
    
    return 0;
}
Example #13
0
void LcdCls(LcdSpi* lcd)
{
	uint8_t i;
	uint8_t j;
	
	if (!lcd) {
		return;
	}
	
	for (i = 0; i < 8; i++) {
		LcdSetPos(lcd, i, 0);
		
		GpioSetValue(PIN_LCD_A0, 1);
		for (j = 0; j < 132; j++) {
			LcdWriteByte(lcd->mS0, 0x00);
		}
	}
}
Example #14
0
uint8_t LcdWriteImageScreen(LcdSpi* lcd, ScreenData *screen)
{
	uint8_t x = 0;
	uint8_t y = 0;
	uint16_t i = 0;
	uint8_t c;
	uint8_t b;
	uint8_t xScreen;
	uint8_t yScreen;
	
	if (!lcd) {
		return 1;
	}
	if (!screen) {
		return 2;
	}
	xScreen = screen->mX;
	yScreen = screen->mY;
	
	for (y = 0; y < yScreen; y += 8) {
		LcdSetPos(lcd, y / 8, 0);
		
		GpioSetValue(PIN_LCD_A0, 1);
		for (x = 0; x < xScreen; x++) {
			b = 0;
			for (i = 0; i < 8; i++) {
				c = screen->mData[((y + i) * xScreen) + x];
				if (c) {
					b |= (1 << i);
				}
			}
			LcdWriteByte(lcd->mS0, b);
		}
	}
	if (gDebuglevel >= 100) {
		DebugWriteScreen(lcd, screen->mData, xScreen, yScreen);
	}
	
	return 0;
}
Example #15
0
//clears the Lcd screen
void ClearLcd()
{
	LcdWriteByte(WRITE_COMMAND, 0x01);
}
void clearScreen()
{
	LcdWriteByte(WRITE_COMMAND, 0x01);
	NutDelay(5);
}
Example #17
0
/*
 * Sets the cursor position to [0][0] (top left, first position)
 */
void lcd_cursor_home()
{
    LcdWriteByte(WRITE_COMMAND, 0x02);          // Set cursor to home command.
}
Example #18
0
/* ����������������������������������������������������������������������� */
void LcdChar(char MyChar)
{
    LcdWriteByte(WRITE_DATA, MyChar);
}
Example #19
0
/* ����������������������������������������������������������������������� */
void WriteByteToLocation(u_char locationByte, u_char byteToWrite)
{
        LcdWriteByte(WRITE_COMMAND, locationByte);
        LcdWriteByte(WRITE_DATA, byteToWrite);
}
Example #20
0
/*!
 * \brief Send data byte to LCD controller.
 *
 * \param data Byte to send.
 */
static void LcdWriteData(uint8_t data)
{
    /* RS high selects data register. */
	LCD_RS_SET();
    LcdWriteByte(data);
}
Example #21
0
/*!
 * \brief Send command byte to LCD controller.
 *
 * \param cmd Byte to send.
 */
static void LcdWriteCmd(uint8_t cmd)
{
    /* RS low selects instruction register. */
    LCD_RS_CLR();
    LcdWriteByte(cmd);
}