1

Тема: lcd1602 спецсимволы

//LCD1602 NANO = RS D2,E D3,D4 D4,D5 D5,D6 D6,D7 D7

void setup(){
  lcdInit();
  lcdWrite(0, 0b00000,0b10000,0b10000,0b10000,0b10000,0b10000,0b10000,0b00000);
  lcdWrite(8, 0b00000,0b10100,0b10100,0b10100,0b10100,0b10100,0b10100,0b00000);
  lcdWrite(16, 0b00000,0b10101,0b10101,0b10101,0b10101,0b10101,0b10101,0b00000);
  
  }

void loop(){
   lcdCurs(0,0);
  // lcdString("Volume");
   lcdChar(2);
   
  delay(1000);
  }

void lcdSend(bool rs, byte data) {
    if(rs==0){PORTD |= (1 << 2);} else{PORTD &= ~(1 << 2);}//RS
    del();
    if(((data >> 7) & 1) ==1) PORTD |= (1 << 7); else PORTD &= ~(1 << 7);
    if(((data >> 6) & 1) ==1) PORTD |= (1 << 6); else PORTD &= ~(1 << 6);
    if(((data >> 5) & 1) ==1) PORTD |= (1 << 5); else PORTD &= ~(1 << 5);
    if(((data >> 4) & 1) ==1) PORTD |= (1 << 4); else PORTD &= ~(1 << 4);
    e_pin();
    if(((data >> 3) & 1) ==1) PORTD |= (1 << 7); else PORTD &= ~(1 << 7);
    if(((data >> 2) & 1) ==1) PORTD |= (1 << 6); else PORTD &= ~(1 << 6);
    if(((data >> 1) & 1) ==1) PORTD |= (1 << 5); else PORTD &= ~(1 << 5);
    if(((data >> 0) & 1) ==1) PORTD |= (1 << 4); else PORTD &= ~(1 << 4);
    e_pin();
}  
void lcd(uint8_t cmd) {lcdSend(true, cmd);}
void lcdChar(const char chr) {lcdSend(false, (uint8_t)chr);}
void lcdString(const char* str) {while(*str != '\0') {del();lcdChar(*str);str++;}}
void del(){delay(1);}
void e_pin(){PORTD |= (1 << 3);del();PORTD &= ~(1 << 3);}
void lcdCurs(byte str, byte mesto){
  if(str==0){lcd(0b10000000+mesto);}
  if(str==1){lcd(0b11000000+mesto);}
  }
void lcdInit(){ 
    DDRD |= (1 << 2) | (1 << 3)| (1 << 4) | (1 << 5) | (1 << 6) | (1 << 7);  
    delay(100);
    lcd(0x03);delayMicroseconds(4500);
    lcd(0x03);delayMicroseconds(4500);
    lcd(0x03);delayMicroseconds(200);
 
    lcd(0b00000010);del();
    lcd(0b00001100);del();
    lcdClear();
  } 
void lcdInt(long int_x){
   byte h[8];
   long int_y=int_x;
   int i,i_kol;
  if(int_x<0){int_x=abs(int_x);lcdChar('-');}    // если минус
  for(i_kol=0;int_x>0;i_kol++){int_x=int_x/10;}  // определяем кол-во цифр в long
  for(i=0;i<i_kol;i++){h[i]=int_y%10; int_y=int_y/10;}// разбиваем число на отдельные цифры
  for(i=i_kol-1;i>=0;i--){lcdChar(h[i] +'0');} // преобразуем числа в char
  if(i_kol==0){lcdChar('0');} // если long = 0, то выводить ноль
  }
void lcdClear(){lcd(0b00000001);}   

void lcdWrite(byte addr_w, byte wr1,byte wr2,byte wr3,byte wr4,byte wr5,byte wr6,byte wr7,byte wr8){
  lcd(0b01000000|addr_w);
  lcdChar(wr1);lcdChar(wr2);lcdChar(wr3);lcdChar(wr4);lcdChar(wr5);lcdChar(wr6);lcdChar(wr7);lcdChar(wr8);
  }

2

Re: lcd1602 спецсимволы

//LCD1602 NANO = RS D2,E D3,D4 D4,D5 D5,D6 D6,D7 D7

int bb = 0;


void setup(){
  lcdInit();
 // lcdWrite(0, 0b00000,0b10000,0b10000,0b10000,0b10000,0b10000,0b10000,0b00000);
 // lcdWrite(8, 0b00000,0b10100,0b10100,0b10100,0b10100,0b10100,0b10100,0b00000);
 // lcdWrite(16, 0b00000,0b10101,0b10101,0b10101,0b10101,0b10101,0b10101,0b00000);
  
  }

void loop(){
   lcdCurs(0,0);
 
    lcdInt(bb++);

  // lcdChar(2);
   
  delay(1000);
  }

void lcdSend(bool rs, byte data) {
    del();
    if(rs==0){PORTD |= (1 << 2);} else{PORTD &= ~(1 << 2);}//RS   
    if((data >> 7) & 1 ==1) PORTD |= (1 << 7); else PORTD &= ~(1 << 7);
    if((data >> 6) & 1 ==1) PORTD |= (1 << 6); else PORTD &= ~(1 << 6);
    if((data >> 5) & 1 ==1) PORTD |= (1 << 5); else PORTD &= ~(1 << 5);
    if((data >> 4) & 1 ==1) PORTD |= (1 << 4); else PORTD &= ~(1 << 4);
    e_pin();
    if(((data >> 3) & 1) ==1) PORTD |= (1 << 7); else PORTD &= ~(1 << 7);
    if(((data >> 2) & 1) ==1) PORTD |= (1 << 6); else PORTD &= ~(1 << 6);
    if(((data >> 1) & 1) ==1) PORTD |= (1 << 5); else PORTD &= ~(1 << 5);
    if(((data >> 0) & 1) ==1) PORTD |= (1 << 4); else PORTD &= ~(1 << 4);
    e_pin();  
}  
void lcd(uint8_t cmd) {lcdSend(true, cmd);}
void lcdChar(const char chr) {lcdSend(false, (uint8_t)chr);}
void lcdString(const char* str) {while(*str != '\0') {lcdChar(*str);str++;}}
void del(){delayMicroseconds(350);}
void e_pin(){PORTD &= ~(1 << 3);delayMicroseconds(1);PORTD |= (1 << 3);delayMicroseconds(1);PORTD &= ~(1 << 3);delayMicroseconds(50);}
void lcdCurs(byte str, byte mesto){if(str==0){lcd(0b10000000|mesto);}if(str==1){lcd(0b11000000|mesto);}}
void lcdInit(){ 
    DDRD |= (1 << 2) | (1 << 3)| (1 << 4) | (1 << 5) | (1 << 6) | (1 << 7);  
    _delay_ms(100);
    lcd(0x03);delayMicroseconds(4500);
    lcd(0x03);delayMicroseconds(4500);
    lcd(0x03);delayMicroseconds(200);
    lcd(0b00000010);del();
    lcd(0b00001100);del();
    lcdClear();
  } 
void lcdInt(int int_x){cli();char b_123[8];String(int_x).toCharArray(b_123,7);lcdString(b_123);sei();}
void lcdClear(){lcd(0b00000001);}   
void lcdWrite(byte addr_w, byte wr1,byte wr2,byte wr3,byte wr4,byte wr5,byte wr6,byte wr7,byte wr8){
  lcd(0b01000000|addr_w);
  lcdChar(wr1);lcdChar(wr2);lcdChar(wr3);lcdChar(wr4);lcdChar(wr5);lcdChar(wr6);lcdChar(wr7);lcdChar(wr8);
  }