|
|
|
@ -54,12 +54,6 @@ void Arduinolib__lcd_init_step(Arduinolib__lcd_init_out *out){
|
|
|
|
|
Arduinolib__lcd_cmd_step(LCD_DISPLAY_ON, o9);
|
|
|
|
|
_delay_us(80); //more than 39us
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if we use this code the msg is printed ///
|
|
|
|
|
/*uint8_t msg[] = "Arduino";
|
|
|
|
|
Arduinolib__lcd_string_out *o;
|
|
|
|
|
Arduinolib__lcd_string_step(msg, o);*/
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* send an 8bit information to the LCD register in order to be written */
|
|
|
|
@ -104,9 +98,9 @@ void Arduinolib__lcd_cmd_step(uint8_t cmd, Arduinolib__lcd_cmd_out *out){
|
|
|
|
|
LCD_RS_PORT &= ~(1 << LCD_RS_PIN); //low
|
|
|
|
|
LCD_E_PORT &= ~(1 << LCD_E_PIN); //low
|
|
|
|
|
Arduinolib__lcd_write_out *o1;
|
|
|
|
|
Arduinolib__lcd_write_step(cmd, o1); // upper 4 bits
|
|
|
|
|
Arduinolib__lcd_write_step(cmd, o1); // write upper 4 bits
|
|
|
|
|
Arduinolib__lcd_write_out *o2;
|
|
|
|
|
Arduinolib__lcd_write_step(cmd << 4, o2); // lower 4 bits
|
|
|
|
|
Arduinolib__lcd_write_step(cmd << 4, o2); // write lower 4 bits
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* send an 8bit data character to the LCD register */
|
|
|
|
@ -115,9 +109,9 @@ void Arduinolib__lcd_char_step(uint8_t char_data, Arduinolib__lcd_char_out *out)
|
|
|
|
|
LCD_RS_PORT |= (1 << LCD_RS_PIN); //high
|
|
|
|
|
LCD_E_PORT &= ~(1 << LCD_E_PIN); //low
|
|
|
|
|
Arduinolib__lcd_write_out *o1;
|
|
|
|
|
Arduinolib__lcd_write_step(char_data, o1); // upper 4 bits
|
|
|
|
|
Arduinolib__lcd_write_step(char_data, o1); //write upper 4 bits
|
|
|
|
|
Arduinolib__lcd_write_out *o2;
|
|
|
|
|
Arduinolib__lcd_write_step(char_data << 4, o2); // lower 4 bits
|
|
|
|
|
Arduinolib__lcd_write_step(char_data << 4, o2); //write lower 4 bits
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* give a string to display to the LCD*/
|
|
|
|
@ -126,10 +120,10 @@ void Arduinolib__lcd_string_step(uint8_t lstring[], int line, Arduinolib__lcd_st
|
|
|
|
|
Arduinolib__lcd_cmd_out *o2;
|
|
|
|
|
if (line == 1) {
|
|
|
|
|
Arduinolib__lcd_cmd_step(LCD_CURSOR_SET | LCD_START_LINE2, o1);
|
|
|
|
|
_delay_us(80); //more than
|
|
|
|
|
_delay_us(80); //more than 39us
|
|
|
|
|
} else {
|
|
|
|
|
Arduinolib__lcd_cmd_step(LCD_CURSOR_SET | LCD_START_LINE1, o2);
|
|
|
|
|
_delay_us(80);
|
|
|
|
|
_delay_us(80); //more than 39us
|
|
|
|
|
}
|
|
|
|
|
volatile int i = 0;
|
|
|
|
|
for (i = 0; lstring[i] != 0 ; i++) {
|
|
|
|
@ -141,9 +135,61 @@ void Arduinolib__lcd_string_step(uint8_t lstring[], int line, Arduinolib__lcd_st
|
|
|
|
|
|
|
|
|
|
/* gice a number to display to the LCD */
|
|
|
|
|
void Arduinolib__lcd_int_step(uint8_t numb, int line, Arduinolib__lcd_int_out *out){
|
|
|
|
|
char lstring[80];
|
|
|
|
|
char lstring[80]; //buffer
|
|
|
|
|
itoa(numb, lstring, 10);
|
|
|
|
|
Arduinolib__lcd_string_out *o;
|
|
|
|
|
Arduinolib__lcd_string_step(lstring, line, o);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* a general read pin function. it is assuming the user uses distinct pins to read/write */
|
|
|
|
|
void Arduinolib__dread_step(int p, Arduinolib__dread_out *out){
|
|
|
|
|
if (8 <= p && p <= 13){
|
|
|
|
|
int pin = p - 8;
|
|
|
|
|
DDRB &= ~(1 << pin);
|
|
|
|
|
if ((PINB & (1 << pin)) == (1 << pin) ) {
|
|
|
|
|
out -> v = 1; //pin high so it is pressed
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
out -> v = 0; //pin low so it is not pressed
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if ( 0 <= p && p <= 7){
|
|
|
|
|
DDRD &= ~(1 << p);
|
|
|
|
|
if ((PIND & (1 << p)) == (1 << p) ) {
|
|
|
|
|
out -> v = 1; //pin high so it is pressed
|
|
|
|
|
} else {
|
|
|
|
|
out -> v = 0; //pin low so it is not pressed
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else { //by default to pin 13 of arduino
|
|
|
|
|
DDRB &= ~(1 << 5);
|
|
|
|
|
if ((PINB & (1 << 5)) == (1 << 5) ) {
|
|
|
|
|
out -> v = 1; //pin high so it is pressed
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
out -> v = 0; //pin low so it is not pressed
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Arduinolib__dwrite_step(int p, int v, Arduinolib__dwrite_out *out){
|
|
|
|
|
|
|
|
|
|
if (8 <= p && p <= 13){
|
|
|
|
|
int pin = p - 8;
|
|
|
|
|
DDRB |= (1 << pin);
|
|
|
|
|
PORTB |= (1 << pin);
|
|
|
|
|
if (v == 0) PORTB &= ~(1 << pin);
|
|
|
|
|
}
|
|
|
|
|
else if ( 0 <= p && p <= 7){
|
|
|
|
|
DDRD |= (1 << p);
|
|
|
|
|
PORTD |= (1 << p);
|
|
|
|
|
if (v == 0) PORTD &= ~(1 << p);
|
|
|
|
|
}
|
|
|
|
|
else { //by default
|
|
|
|
|
DDRB |= (1 << 5);
|
|
|
|
|
PORTB |= (1 << 5);
|
|
|
|
|
if (v == 0) PORTB &= ~(1 << 5);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|