void LCDchar(char character) { int index; LCDwrite(LCD_D, 0x00); for (index = 0; index < 5; index++) { LCDwrite(LCD_D, ASCII[character - 0x20][index]); } LCDwrite(LCD_D, 0x00); }
void printNumber(uint32_t adc_value) /* Skriver ut värdet från AD-omvandlare */ { uint32_t tusental = (adc_value / 1000); uint32_t hundratal = (adc_value % 1000) / 100; uint32_t tiotal = (adc_value % 100) / 10; uint32_t ental = (adc_value % 10); LCDwrite(' ', HIGH); LCDwrite(tusental + 0x30, HIGH); LCDwrite(hundratal + 0x30, HIGH); LCDwrite(tiotal + 0x30, HIGH); LCDwrite(ental + 0x30, HIGH); }
int setupLCD(void) /* Ställer in display för första användning */ { int all_ok = 0; /*antar inget fungerar*/ LCDwrite(0b00001000, LOW); /* Display off */ LCDwrite(0b00000001, LOW); /* Display clear */ delay(3000); LCDwrite(0b00000110, LOW); /* Entry mode set: move cursor right, no display shift */ LCDwrite(0b00001111 ,LOW); /* Display on, cursor on, blinking on */ all_ok = 1; return all_ok; /*returnerar 1 om allt är ok.*/ }
void LCDclear(void) { int index; for (index = 0; index < LCD_X * LCD_Y / 8; index++) { LCDwrite(LCD_D, 0x00); } }
void LCDdrawstring(uint8_t x, uint8_t y, char *c) { cursor_x = x; cursor_y = y; while (*c) { LCDwrite(*c++); } }
void LCDwriteLineTwo(char string[]) { unsigned char i = 0; //create a counter variable LCDgotoLineTwo(); //Begin on Line two while(string[i]) //This will continue until the /0 (end of string) character is reached { LCDwrite(string[i]); //Write string one element at a time i++; //Move to the next element } }
void LCDdrawstring_P(uint8_t x, uint8_t y, const char *str) { cursor_x = x; cursor_y = y; while (1) { char c = (*str++); if (! c) return; LCDwrite(c); } }
void LCDputs(char string[]) { unsigned char i = 0; //create a counter variable LCDclear(); //Clear the LCD before writing while(string[i]) //This will continue until the /0 (end of string) character is reached { LCDwrite(string[i]); //Write the string one element at a time i++; //Move to the next element if(i==16) LCDgotoLineTwo(); //Go to line two after element 16 //otherwise the string will be written off screen } }
void LCDinit(void) { pinMode(PIN_SCE, OUTPUT); pinMode(PIN_RESET, OUTPUT); pinMode(PIN_DC, OUTPUT); pinMode(PIN_SDIN, OUTPUT); pinMode(PIN_SCLK, OUTPUT); digitalWrite(PIN_RESET, LOW); digitalWrite(PIN_RESET, HIGH); LCDwrite(LCD_C, 0x21 ); // LCD Extended Commands. LCDwrite(LCD_C, 0xB1 ); // Set LCD Vop (Contrast). LCDwrite(LCD_C, 0x04 ); // Set Temp coefficent. //0x04 LCDwrite(LCD_C, 0x14 ); // LCD bias mode 1:48. //0x13 LCDwrite(LCD_C, 0x20 ); // LCD Basic Commands LCDwrite(LCD_C, 0x0C ); // LCD in normal mode. }
void LCDgotoXY(int x, int y) { LCDwrite( 0, 0x80 | x); // Column. LCDwrite( 0, 0x40 | y); // Row. }
void putch(char data) { LCDwrite(data); }
int LCDInit(void) /* Initializes the display on the LCD shield, returns 1 if everything is ok */ { int all_ok=0; /* at the beginning assume nothing works */ /* At power on */ ioport_set_pin_dir(LCD_RS, IOPORT_DIR_OUTPUT); ioport_set_pin_dir(LCD_Enable, IOPORT_DIR_OUTPUT); ioport_set_port_dir(IOPORT_PIOC, LCD_mask_D4_D7, IOPORT_DIR_OUTPUT); ioport_set_pin_level(LCD_Enable, LOW); delay(30000); /* wait > 15 ms */ ioport_set_pin_level(LCD_RS, LOW); /* Function set (interface is 8 bit long) */ ioport_set_pin_level(LCD_D4, HIGH); ioport_set_pin_level(LCD_D5, HIGH); ioport_set_pin_level(LCD_D6, LOW); ioport_set_pin_level(LCD_D7, LOW); ioport_set_pin_level(LCD_Enable, HIGH); delay(1); /* delay 1 us */ ioport_set_pin_level(LCD_Enable, LOW); delay(4100); /* wait for more than 4,1 ms */ ioport_set_pin_level(LCD_D4, HIGH); ioport_set_pin_level(LCD_D5, HIGH); ioport_set_pin_level(LCD_D6, LOW); ioport_set_pin_level(LCD_D7, LOW); ioport_set_pin_level(LCD_Enable, HIGH); delay(1); /* delay 1 us */ ioport_set_pin_level(LCD_Enable, LOW); delay(100); /* wait 100 us */ ioport_set_pin_level(LCD_D4, HIGH); ioport_set_pin_level(LCD_D5, HIGH); ioport_set_pin_level(LCD_D6, LOW); ioport_set_pin_level(LCD_D7, LOW); ioport_set_pin_level(LCD_Enable, HIGH); delay(1); /* delay 1 us */ ioport_set_pin_level(LCD_Enable, LOW); delay(100); /* wait 100 us */ /* Set display to 4-bit input */ ioport_set_pin_level(LCD_D4, LOW); ioport_set_pin_level(LCD_D5, HIGH); ioport_set_pin_level(LCD_D6, LOW); ioport_set_pin_level(LCD_D7, LOW); ioport_set_pin_level(LCD_Enable, HIGH); delay(1); ioport_set_pin_level(LCD_Enable, LOW); delay(100); LCDwrite(0b00101000, LOW); /* Two rows, small font */ LCDwrite(0b00001000, LOW); /* Display off */ LCDwrite(0b00000001, LOW); /* Display clear */ delay(3000); LCDwrite(0b00000110, LOW); /* Entry mode set: move cursor right, no display shift */ LCDwrite(0b00001111 ,LOW); /* Display on, cursor on, blinking on */ all_ok = 1; /* simple return statement showing that the initialization of the LCD has completed */ return all_ok; }
void clearDisplay(void) /* Tömmer displayen */ { LCDwrite(0b00000001, LOW); //Tömmer display }
void printLetter(uint32_t adc_value) /* Skriver ut vilken knapp som är intryckt */ { if( ((adc_value - 100) <= UP) && ( (adc_value + 100) >= UP ) ){ LCDwrite('U', HIGH); LCDwrite('P', HIGH); } if(adc_value == RIGHT){ LCDwrite('R', HIGH); LCDwrite('I', HIGH); LCDwrite('G', HIGH); LCDwrite('H', HIGH); LCDwrite('T', HIGH); } if( ((adc_value - 100) <= DOWN) && ( (adc_value + 100) >= DOWN ) ){ LCDwrite('D', HIGH); LCDwrite('O', HIGH); LCDwrite('W', HIGH); LCDwrite('N', HIGH); } if( ((adc_value - 100) <= LEFT) && ( (adc_value + 100) >= LEFT ) ){ LCDwrite('L', HIGH); LCDwrite('E', HIGH); LCDwrite('F', HIGH); LCDwrite('T', HIGH); } if( ((adc_value - 100) <= SELECT) && ( (adc_value + 100) >= SELECT ) ){ LCDwrite('S', HIGH); LCDwrite('E', HIGH); LCDwrite('L', HIGH); LCDwrite('E', HIGH); LCDwrite('C', HIGH); LCDwrite('T', HIGH); } if(adc_value > 3000){ LCDwrite('N', HIGH); LCDwrite('O', HIGH); LCDwrite(' ', HIGH); LCDwrite('I', HIGH); LCDwrite('N', HIGH); LCDwrite('P', HIGH); LCDwrite('U', HIGH); LCDwrite('T', HIGH); } }