Example #1
0
void lcd_string(char *message) {
	int i = 0;
	for (i = 0; i < LCD_WIDTH; i++) {
		if (i < strlen(message)) {
			lcd_byte(message[i], LCD_CHR);
		} else {
			// Fill row with empty spaces
			lcd_byte(' ', LCD_CHR);
		}
	}
}
/**
 * This method is called periodically to have the display in a correct state
 no matter the random interference that could happen from time to time.
 **/
void resetLcd(){
	#ifndef PROD
	printf("Reset LCD\n");
	#endif

	SetCmdMode(); // set for commands
	lcd_byte(0x0C); // display on, cursor off, blink off
	lcd_byte(0x01);  // clear screen
	delay(10);        // clear screen is slow!

}
Example #3
0
File: lcd.c Project: abyman/garage
void lcd_text(mraa_gpio_context *g, char *s, int line)
{
   SetCmdMode(g); // set to cmd mode to send line cmd
   if(line == 1) 
      lcd_byte(g, 0x80); // line 1
   else
      lcd_byte(g, 0xC0); // line 2
   SetChrMode(g); // set to char mode to send text
   while(*s) 
      lcd_byte(g, *s++);
}
Example #4
0
static void lcd_cls(void)
{
	/*uint8_t c;
	for(c=0;c<6;c++){
		lcd_clrrow(c);
	}
	lcd_locate(0,0);*/
	uint8_t c;
	for(c=0;c<84*3;c++){
		lcd_byte(0x00, 1);
		lcd_byte(0x00, 1);
	}
}
/**
Init the screen
**/
void lcd_init()
{
	#ifndef PROD
	printf("Full reset LCD\n");
	#endif
	SetCmdMode(); // set for commands
	lcd_byte(0x33); // full init
	lcd_byte(0x32); // 4 bit mode
	lcd_byte(0x28); // 2 line mode
	lcd_byte(0x0C); // display on, cursor off, blink off
	lcd_byte(0x01);  // clear screen
	delay(10);        // clear screen is slow!
}
Example #6
0
static void lcd_print_font(uint8_t start, uint8_t end)
{
	uint8_t i;
	for(i=start; i<end; i++){
		lcd_byte(pgm_read_byte(&(font[i])), 1);
	}
}
/**
Wrtie some text on screen
**/
void lcd_text(char *s)
{
	SetChrMode();
	while(*s)
	lcd_byte(*s++);
	SetCmdMode();
}
Example #8
0
void lcd_putchar( uint8_t d )
{
  LCD_RS = 1;
  lcd_byte( d );
  switch( ++lcd_pos ){
    case LCD_LINE1 + LCD_COLUMN:
#ifdef LCD_LINE2
      d = LCD_LINE2;
      break;
    case LCD_LINE2 + LCD_COLUMN:
#ifdef LCD_LINE3
      d = LCD_LINE3;
      break;
    case LCD_LINE3 + LCD_COLUMN:
#ifdef LCD_LINE4
      d = LCD_LINE4;
      break;
    case LCD_LINE4 + LCD_COLUMN:
#endif
#endif
#endif
      d = LCD_LINE1;
      break;
    default: 
      return;
  }
  lcd_command( d );
}
Example #9
0
static void lcd_init(void)
{
#if !SDL
	LCD_RESET_CLEAR
	//_delay_ms(10);
	LCD_RESET_SET
	//_delay_ms(10);

	lcd_byte(0x21, 0);//Horizontal addressing, extended instruction set
	lcd_byte(0x80+0x48, 0);//LCD Vop
	lcd_byte(0x04+2, 0);//Temp coefficient
	lcd_byte(0x10+3, 0);//LCD bias system
	lcd_byte(0x20, 0);//Horizontal addressing, basic instruction set
	//lcd_byte(0x08+4, 0);//Normal mode
	//lcd_cls();
#endif
}
Example #10
0
void lcd_init()
{
   wiringPiSetup() ; // use BCIM numbering
   // set up pi pins for output
   pinMode (LCD_E,  OUTPUT);
   pinMode (LCD_RS, OUTPUT);
   pinMode (LCD_D4, OUTPUT);
   pinMode (LCD_D5, OUTPUT);
   pinMode (LCD_D6, OUTPUT);
   pinMode (LCD_D7, OUTPUT);
   
   // initialise LCD
   SetCmdMode(); // set for commands
   lcd_byte(0x33); // full init 
   lcd_byte(0x32); // 4 bit mode
   lcd_byte(0x28); // 2 line mode
   lcd_byte(0x0C); // display on, cursor off, blink off
   lcd_byte(0x01);  // clear screen
   delay(3);        // clear screen is slow!
}
Example #11
0
void lcd_command( uint8_t d )
{
  LCD_RS = 0;
  lcd_byte( d );
  switch( d ){
    case 0 ... 3:                       // on longer commands
      _delay_us( LCD_TIME_CLR );
      d = LCD_LINE1;
    case 0x80 ... 0xFF:                 // set position
      lcd_pos = d;
  }
}
Example #12
0
static void next_level(bool init_game)
{
	if(init_game){
		g_level = 1;
		g_hp = 20;
		lcd_byte(0x08+4, 0);//Normal mode
		lcd_cls();
	} else {
		g_level++;
		g_seed += g_counter0;
	}
	make_current_dungeon();
}
Example #13
0
void lcd_init() {
	// Initialise display
	lcd_byte(0x33, LCD_CMD);
	lcd_byte(0x32, LCD_CMD);
	lcd_byte(0x28, LCD_CMD);
	lcd_byte(0x0C, LCD_CMD);
	lcd_byte(0x06, LCD_CMD);
	lcd_byte(0x01, LCD_CMD);
}
Example #14
0
void lcd_putchar( uint8_t d )
{
  LCD_RS = 1;
  lcd_byte( d );
  switch( ++lcd_pos ){
    case LCD_LINE1 + LCD_COLUMN:
      d = LCD_LINE2;
      break;
    case LCD_LINE2 + LCD_COLUMN:
      d = LCD_LINE1;
      break;
    default: 
      return;
  }
  lcd_command( d );
}
Example #15
0
static void lcd_print(uint8_t c)
{
	/*if(c==' '){
		for(c=0; c<5; c++) lcd_byte(0x00, 1);
	}
	else*/ //if(c>='0' && c<='9'){
		lcd_print_font((c-'0')*4, (c-'0'+1)*4);
		lcd_byte(0x00, 1);
	//}
	/*else if(c>='A' && c<='Z'){
		lcd_print_font((c-'A')*4+40, (c-'A'+1)*4+40);
		if(c=='M') lcd_byte(0x3e, 1);
		else if(c=='W') lcd_byte(0x1e, 1);
		else lcd_byte(0x00, 1);
	}*/
}
Example #16
0
File: lcd.c Project: abyman/garage
void lcd_init(mraa_gpio_context *g)
{
   // set up pi pins for output
   g[0] = mraa_gpio_init(LCD_E);
   g[1] = mraa_gpio_init(LCD_RS);
   g[2] = mraa_gpio_init(LCD_D4);
   g[3] = mraa_gpio_init(LCD_D5);
   g[4] = mraa_gpio_init(LCD_D6);
   g[5] = mraa_gpio_init(LCD_D7);
   for(int i = 0; i < 6; i++) { 
      mraa_gpio_dir(g[i], MRAA_GPIO_OUT);
   }
   // initialise LCD
   SetCmdMode(g); // set for commands
   lcd_byte(g,0x33); // 2 line mode
   lcd_byte(g,0x32); // 2 line mode
   lcd_byte(g,0x06); // 2 line mode
   lcd_byte(g,0x0C); // 2 line mode
   lcd_byte(g,0x28); // display on, cursor off, blink off
   lcd_byte(g,0x01);  // clear screen
   usleep(3000);       // clear screen is slow!
   SetChrMode(g);
}
Example #17
0
void lcd_empty() {
	// Blank display
	lcd_byte(0x01, LCD_CMD);
}
Example #18
0
int main(int argc, char *argv[]) {
	char *line;
	char lines[4][LCD_WIDTH + 1];
	int i = 0, n = 0;
	size_t bytes = LCD_WIDTH;
	int fd;

	fd = open(LOCKFILE, O_RDWR, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
	if (fd < 0) {
		fd = creat(LOCKFILE, O_RDWR | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
		if (fd < 0) {
			perror("creat");
			fprintf(stderr, "Couldn't create lockfile. Execution aborted.\n");
			exit(1);
		}
	}
	f_elock(fd);

	line = calloc(bytes + 1, sizeof (char));
	while ((n = getline(&line, &bytes, stdin)) != -1) {
		// The \n is 1 byte more
		if (n > LCD_WIDTH + 1) {
			fprintf(stderr, "Too many characters. The line will be truncated.\n");
			line[LCD_WIDTH + 1] = '\0';
		} else {
			// Strip \n
			line[strlen(line) - 1] = '\0';
		}
		snprintf(lines[i], LCD_WIDTH + 1, "%s", line);
		i++;
		if (i > 4) {
			fprintf(stderr, "Too many lines!\n");
			exit(1);
		}
	}
	free(line);

	GPIOExport(LCD_E);
	GPIOExport(LCD_RS);
	GPIOExport(LCD_D4);
	GPIOExport(LCD_D5);
	GPIOExport(LCD_D6);
	GPIOExport(LCD_D7);

	GPIODirection(LCD_E, OUT);
	GPIODirection(LCD_RS, OUT);
	GPIODirection(LCD_D4, OUT);
	GPIODirection(LCD_D5, OUT);
	GPIODirection(LCD_D6, OUT);
	GPIODirection(LCD_D7, OUT);

	// Initialise display
	lcd_init();

	if (i == 0) {
		lcd_empty();
	}
	if (i > 0) {
		lcd_byte(LCD_LINE_1, LCD_CMD);
		lcd_string(lines[0]);
	}
	if (i > 1) {
		lcd_byte(LCD_LINE_2, LCD_CMD);
		lcd_string(lines[1]);
	}
	if (i > 2) {
		lcd_byte(LCD_LINE_3, LCD_CMD);
		lcd_string(lines[2]);
	}
	if (i > 3) {
		lcd_byte(LCD_LINE_4, LCD_CMD);
		lcd_string(lines[3]);
	}

	f_unlock(fd);
	close(fd);
	unlink(LOCKFILE);
	exit(0);
}
Example #19
0
void lcd_text(char *s)
{
  while(*s) 
   lcd_byte(*s++);
 }
/*
Return at the begining of the line
*/
void goHome(){
	SetCmdMode(); // set for commands
	lcd_byte(lcd_Home);  // go home screen
	delay(7);        // You cannot write directly after putting the cursor at the 
	//beginning of the line. You have to wait for some time before it
}
Example #21
0
void lcd_gotoxy(unsigned char x, unsigned char y)
{
  unsigned char firstCharAdr[]={0x80,0xC0};
  lcd_byte(firstCharAdr[y-1] + x - 1);
}
Example #22
0
static void lcd_locate(uint8_t x, uint8_t y)
{
	lcd_byte(0x80+x, 0);
	lcd_byte(0x40+y, 0);
}
Example #23
0
static void lcd_powerdown(void)
{
	lcd_byte(0x21, 0);//Horizontal addressing, extended instruction set
	lcd_byte(0x80+0, 0);//LCD Vop 0
	lcd_byte(0x24, 0);//Horizontal addressing, basic instruction set, powerdown
}