示例#1
0
/**
 * LCD deinitialization procedure
 *
 * @param LcdData_t* lcd handler structure address
 * @return none
 *
 */
void lcdfinalize(LcdData_t *lcd)
{
    lcdsetbacklight(lcd, 0);
    lcdclear(lcd);
    lcdclear(lcd);
    lcdcommand(lcd, LCD_DC_DISPLAYOFF | LCD_DC_CURSOROFF | LCD_DC_CURSORBLINKOFF);
}
示例#2
0
// public functions
void lcdinit() {
    // external memory config
    SFRPAGE = 0;
    EMI0CF = 0x34;                   //external interface on pins P7-P4
    EMI0CN  = 0xFF;                   //8-bit address reference off-chip memory
    SFRPAGE = 0x0F;
    P4MDOUT = 0xC0;                   //read and write control
    P6MDOUT = 0xFF;                   //address lines
    P7MDOUT = 0xFF;                   //data lines

    // external pointer config
    lcdbase  = 0xB4;
    lcdwdata = lcdbase + lcdrs;
    lcdwcmd  = lcdbase;
    lcdrdata = lcdbase + lcdrw + lcdrs;
    lcdrcmd  = lcdbase + lcdrw;

    // huh?
    _mpuwcmd(0x3C);
    delay_us(37);
    _mpuwcmd(0x0E);

    // set display on/off, cursor, and blinking.
    _lcdcmd(0x06);
    lcdclear();
}
示例#3
0
static ssize_t lcdi2c_clear(struct device* dev, struct device_attribute* attr,
			    const char* buf, size_t count)
{
    CRIT_BEG(data, ERESTARTSYS);

    if (count > 0 && buf[0] == '1')
        lcdclear(data);

    CRIT_END(data);
    return count;
}
示例#4
0
/**
 * initialization procedure of LCD
 *
 * @param LcdData_t* lcd handler structure address
 * @param lcd_topology number representing topology of LCD
 * @return none
 *
 */
void lcdinit(LcdData_t *lcd, lcd_topology topo)
{
    memset(lcd->buffer, 0x20, LCD_BUFFER_SIZE); //Fill buffer with spaces

    if (topo > LCD_TOPO_8x2)
        topo = LCD_TOPO_16x2;

    lcd->organization.topology = topo;
    lcd->organization.columns = topoaddr[topo][4];
    lcd->organization.rows = topoaddr[topo][5];
    memcpy(lcd->organization.addresses, topoaddr[topo], sizeof(topoaddr[topo]) - 2);
    lcd->organization.toponame = toponames[topo];

    lcd->displaycontrol = 0;
    lcd->displaymode = 0;

    lcd->displayfunction = LCD_FS_4BITDATA | LCD_FS_1LINE | LCD_FS_5x8FONT;
    if (lcd->organization.rows > 1)
        lcd->displayfunction |= LCD_FS_2LINES;

    MSLEEP(50);
    _buswrite(lcd, lcd->backlight ? (1 << PIN_BACKLIGHTON) : 0);
    MSLEEP(100);

    _write4bits(lcd, (1 << PIN_DB4) | (1 << PIN_DB5));
    MSLEEP(5);

    _write4bits(lcd, (1 << PIN_DB4) | (1 << PIN_DB5));
    MSLEEP(5);

    _write4bits(lcd, (1 << PIN_DB4) | (1 << PIN_DB5));
    MSLEEP(15);

    _write4bits(lcd, (1 << PIN_DB5));

    lcdcommand(lcd, lcd->displayfunction);

    lcd->displaycontrol |= LCD_DC_DISPLAYON | LCD_DC_CURSOROFF |
			   LCD_DC_CURSORBLINKOFF;
    lcdcommand(lcd, lcd->displaycontrol);

    lcdclear(lcd);
    lcdhome(lcd);

    lcdsetcursor(lcd, lcd->column, lcd->row);
    lcdcursor(lcd, lcd->cursor);
    lcdblink(lcd, lcd->blink);
}
示例#5
0
int main (void) {
	int value;
	int fd;
	int i;
	char stringa[32+1];

	fd = open("/dev/i2c-0", O_RDWR);

	if (fd < 0) {
		printf("Error opening file: %s\n", strerror(errno));
		return 1;
	}

	if (ioctl(fd, I2C_SLAVE, I2C_ADDR) < 0) {
		printf("ioctl error: %s\n", strerror(errno));
		return 1;
	}

	lcdsend(fd,0,0x38);
	lcdsend(fd,0,0x39);
	lcdsend(fd,0,0x14); //Internal OSC freq
	lcdsend(fd,0,0x72); //Set contrast
	lcdsend(fd,0,0x54); //Power/ICON control/Contrast set
	lcdsend(fd,0,0x6F); //Follower control
	lcdsend(fd,0,0x0C); //Display ON
	lcdclear(fd);

	lcdputstring(fd,"PROVAAAA");

	for (i=0;;i++) {
		lcdsetcurpos(fd,0,1);
		sprintf(stringa,"%08d",i);
		lcdputstring(fd,stringa);
	}

	return 0;
}
示例#6
0
static long lcdi2c_ioctl(struct file *file,
			unsigned int ioctl_num,
			unsigned long arg)
{

  char *buffer = (char*)arg, ccb[10];
  u8 memaddr, i, ch;
  long status = SUCCESS;

  CRIT_BEG(data, EAGAIN);

  switch (ioctl_num)
  {
    case LCD_IOCTL_SETCHAR:
      get_user(ch, buffer);
      memaddr = (1 + data->column + (data->row * data->organization.columns)) % LCD_BUFFER_SIZE;
      lcdwrite(data, ch);
      data->column = (memaddr % data->organization.columns);
      data->row = (memaddr / data->organization.columns);
      lcdsetcursor(data, data->column, data->row);
      break;
    case LCD_IOCTL_GETCHAR:
      memaddr = (data->column + (data->row * data->organization.columns)) % LCD_BUFFER_SIZE;
      ch = data->buffer[memaddr];
      put_user(ch, buffer);
      break;
    case LCD_IOCTL_GETPOSITION:
      printk(KERN_INFO "GETPOSITION called\n");
      put_user(data->column, buffer);
      put_user(data->row, buffer+1);
      break;
    case LCD_IOCTL_SETPOSITION:
      get_user(data->column, buffer);
      get_user(data->row, buffer+1);
      lcdsetcursor(data, data->column, data->row);
      break;
    case LCD_IOCTL_RESET:
      get_user(ch, buffer);
      if (ch == '1')
	lcdinit(data, data->organization.topology);
      break;
    case LCD_IOCTL_HOME:
      printk(KERN_INFO "HOME called\n");
      get_user(ch, buffer);
      if (ch == '1')
	lcdhome(data);
      break;
    case LCD_IOCTL_GETCURSOR:
      put_user(data->cursor ? '1' : '0', buffer);
      break;
    case LCD_IOCTL_SETCURSOR:
      get_user(ch, buffer);
      lcdcursor(data, (ch == '1'));
      break;
    case LCD_IOCTL_GETBLINK:
      put_user(data->blink ? '1' : '0', buffer);
      break;
    case LCD_IOCTL_SETBLINK:
      get_user(ch, buffer);
      lcdblink(data, (ch == '1'));
      break;
    case LCD_IOCTL_GETBACKLIGHT:
      put_user(data->backlight ? '1' : '0', buffer);
      break;
    case LCD_IOCTL_SETBACKLIGHT:
      get_user(ch, buffer);
      lcdsetbacklight(data, (ch == '1'));
      break;
    case LCD_IOCTL_SCROLLHZ:
      get_user(ch, buffer);
      lcdscrollhoriz(data, ch - '0');
      break;
    case LCD_IOCTL_GETCUSTOMCHAR:
      get_user(ch, buffer);
      for (i=0; i<8; i++)
	put_user(data->customchars[ch][i], buffer + i + 1);
      break;
    case LCD_IOCTL_SETCUSTOMCHAR:
      for (i = 0; i < 9; i++)
	get_user(ccb[i], buffer + i);
      lcdcustomchar(data, ccb[0], ccb+1);
      break;
    case LCD_IOCTL_CLEAR:
      get_user(ch, buffer);
      if (ch == '1')
	lcdclear(data);
      break;
    default:
      printk(KERN_INFO "Unknown IOCTL\n");
      break;
  }
  CRIT_END(data);

  return status;
}
示例#7
0
void debounce(unsigned char testbuf[] , uint8_t column){
        unsigned char test[0x6];
        uint8_t keypadvalues[4][4] = {{0xB1, 0xB4, 0xB7, 0xaa},
                                    {0xB2, 0xB5, 0xB8, 0xB0},
                                    {0xB3, 0xB6, 0xB9, 0xa3},
                                    {0xc1, 0xc2, 0xc3, 0xc4}};
        
                                                // keypad
        int colposition = (0x0F &(~column));
        if (colposition == 4){colposition = 3;}
        else if (colposition == 8){colposition = 4;}
        colposition = 4 - colposition ;
        
        //debounce
                        if(testbuf[0] == ((column<<4) | 0x07)){
                              uint8_t keypadentry[2] = {0x40, keypadvalues[colposition][0]};
                              printchar(keypadentry);    
                        }
                        else if(testbuf[0] == ((column<<4) | 0x0B)){
                              uint8_t keypadentry[2] = {0x40, keypadvalues[colposition][1]};
                              printchar(keypadentry); 
                               
                        }
                        else if(testbuf[0] == ((column<<4) | 0x0D)){
                              uint8_t keypadentry[2] = {0x40, keypadvalues[colposition][2]};
                              printchar(keypadentry);       
                        }
                        else if(testbuf[0] == ((column<<4) | 0x0E)){
                              uint8_t keypadentry[2] = {0x40, keypadvalues[colposition][3]};
                              printchar(keypadentry); 
                        }
                do{
                columnread(test);
                }
                while(test[0] == testbuf[0]); 
                
                if(count == 16){
                        uint8_t keypadthing2[2] = {0x40, keypadvalues[12]};
                        for(i = 0; i < 24; i++){
                        printchar(keypadthing2);
                }
                count = 0;
                
              

}


void keypad(void) {
        printsetup();
        I2Csetup();
        
        lcdsetup();
        lcdclear();
  
        unsigned char buf[0x6];
        unsigned char testbuf[0x6];
        
        
        while(1){
                buf[0] = 0x7F ;
                columnwrite(buf);
                columnread(testbuf);
                if (buf[0] != testbuf[0]){debounce(testbuf,0x07);}     
                            
                buf[0] = 0xBF ;
                columnwrite(buf);
                columnread(testbuf);
                if (buf[0] != testbuf[0]){debounce(testbuf,0x0B);}
               
                buf[0] = 0xDF ;
                columnwrite(buf);
                columnread(testbuf);
                if (buf[0] != testbuf[0]){debounce(testbuf,0x0D);}
                
                buf[0] = 0xEF ;
                columnwrite(buf);
                columnread(testbuf);
                if (buf[0] != testbuf[0]){debounce(testbuf,0x0E);}
                
                
                }    
}