Exemple #1
0
static int lcdi2c_probe(struct i2c_client *client, const struct i2c_device_id *id)
{

    data = (LcdData_t *) devm_kzalloc(&client->dev, sizeof(LcdData_t),
				      GFP_KERNEL);
    if (!data)
        return -ENOMEM;

    i2c_set_clientdata(client, data);
    sema_init(&data->sem, 1);

    data->row = 0;
    data->column = 0;
    data->handle = client;
    data->backlight = 1;
    data->cursor = cursor;
    data->blink = blink;
    data->deviceopencnt = 0;
    data->major = major;

    lcdinit(data, topo);
    lcdprint(data, "HD44780\nDriver");

    dev_info(&client->dev, "%ux%u LCD using bus 0x%X, at address 0x%X",
	     data->organization.columns,
	     data->organization.rows, busno, address);

    return 0;
}
Exemple #2
0
static ssize_t lcdi2c_fopwrite(struct file *file, const char __user *buffer,
			    size_t length, loff_t *offset)
{
    u8 i, str[81];

    CRIT_BEG(data, EBUSY);

    for(i = 0; i < length && i < (data->organization.columns * data->organization.rows); i++)
      get_user(str[i], buffer + i);
    str[i] = 0;
    (*offset) = lcdprint(data, str);

    CRIT_END(data);
    return i;
}
void main()
{
 for(i=0;i<8;i++) // used to fill data to be displayed in the arry. You can put any value in the array.
 data_array[i] = i; 

 i = 0; //reset i to 0 for data_array [0] increment display on the LCD
 
 buzzer = 1; // buzzer off
 lcd_init(); //Initialize LCD

 while(1)
 {
  lcdprint(data_array);//call this function to print the array onto the screen
  delay_ms(1000);
  i++;
  data_array [0] = i;
 }
}
void main()
{
 unsigned char i=0;
 output_enable = 0;
 start_conv = 0;    //de-assert all control signals to ADC
 
 buzzer = 1;  //buzzer off
 lcd_init(); //Initialize LCD
 pca_init(); //Initialize PCA to genarate PWM

forward();
left_motor_velocity(0x4F);  //0x00 will give full (100% duty cycle) velocity, while 0xFF will give zero (0% duty cycle) velocity. Any value in between 0x00 and 0xFF will give intermediate velocity.			
right_motor_velocity(0x4F); //0x00 will give full (100% duty cycle) velocity, while 0xFF will give zero (0% duty cycle) velocity. Any value in between 0x00 and 0xFF will give intermediate velocity.


 while(1)
 {
  for(i=0;i<8;i++)	 //Doing ADC conversion
  {
  data_array[i] = ADC_conversion(i);
  }

  left_whiteline = data_array[4];   
  center_whiteline = data_array[5];
  right_whiteline = data_array[6];
  front_sharp_sensor = data_array[2];

  flag = 0; //reset the flag to 0
     
   //check if robot's center white line sensor is on the white line
  if(center_whiteline < 25)
  {
   flag = 1;  //set the flag to 0 so that further white line sensor comparision is disabled
   left_motor_velocity(0x4F);  //left and right motor is at same velocity
   right_motor_velocity(0x4F);
  }

  //robot is drifting towards left side, increase velocity of the left wheel and decrease velocity of the right wheel
  if ((left_whiteline > 25) && (flag == 0))
  {
   flag = 1;  //set the flag to 0 so that further white line sensor comparision is disabled
   left_motor_velocity(0x3F);   //increase left motor velocity
   right_motor_velocity(0x5F);	//decrease  right motor velocity
  }

  //robot is drifting towards right side, decrease velocity of the left wheel and increase velocity of the right wheel
  if ((right_whiteline > 25) && (flag == 0))
  {
   flag = 1;  //set the flag to 0 so that further white line sensor comparision is disabled
   left_motor_velocity(0x5F);	//decrease  right motor velocity
   right_motor_velocity(0x3F);  //increase left motor velocity
  }

  if(front_sharp_sensor >= 110) // obstacle is near the robot, stop and turn on the buzzer
  {
   stop();
   buzzer = 0;  //buzzer on
  }
  
  else
  {
   forward();
   buzzer = 1;  //buzzer off
  }

  if((left_whiteline > 25) && (center_whiteline > 25) && (right_whiteline > 25)) // no whiteline is detected, stop (buzzer will not turn on)
  {
   stop();
  }
  
  lcdprint(data_array);//call this function to print the array onto the screen
  delay_ms(250);
 }
}