1

Тема: 777

// ATTINY2313 V1.25
// D4 = PB0
// D5 = PB1
// D6 = PB2
// D7 = PB3
// E  = PB4
// RS = PD6
// button HH = PD3
// button MM = PD4

int i,hh,mm,ss;
int a[8];
long ddd;
float fff=100;

void setup() {
    DDRB = 0b00011111;
    DDRD = 0b01000000;

lcdInit();
}

void loop() {   
/*
    a[0] = hh/10+48;
    a[1] = hh%10+48;
    a[2] = mm/10+48;
    a[3] = mm%10+48;
    a[4] = ss/10+48;
    a[5] = ss%10+48;
*/
    lcdCurs(0,6);
    lcdString("TIME");
    lcdCurs(1,3);
    //lcdChar(a[0]);lcdChar(a[1]);lcdString(":");lcdChar(a[2]);lcdChar(a[3]);lcdString(":");lcdChar(a[4]);lcdChar(a[5]);
    lcdInt(fff);
  //  lcdString(1);
    delay(3000);
    lcd(0b00000001);
}

void lcdSend(bool isCommand, uint8_t data) {
    if(isCommand==0){PORTD |= (1 << 6);}//RS
    if(isCommand==1){PORTD &= ~(1 << 6);}//RS
    del();
    if(((data >> 7) & 1) ==1){PORTB |= (1 << 3);}else{PORTB &= ~(1 << 3);}
    if(((data >> 6) & 1) ==1){PORTB |= (1 << 2);}else{PORTB &= ~(1 << 2);}
    if(((data >> 5) & 1) ==1){PORTB |= (1 << 1);}else{PORTB &= ~(1 << 1);}
    if(((data >> 4) & 1) ==1){PORTB |= (1 << 0);}else{PORTB &= ~(1 << 0);}
    rs();
    if(((data >> 3) & 1) ==1){PORTB |= (1 << 3);}else{PORTB &= ~(1 << 3);}
    if(((data >> 2) & 1) ==1){PORTB |= (1 << 2);}else{PORTB &= ~(1 << 2);}
    if(((data >> 1) & 1) ==1){PORTB |= (1 << 1);}else{PORTB &= ~(1 << 1);}
    if(((data >> 0) & 1) ==1){PORTB |= (1 << 0);}else{PORTB &= ~(1 << 0);}
    rs();
}

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(){delay(1);}
void rs(){PORTB |= (1 << 4);del();PORTB &= ~(1 << 4);}
void lcdCurs(byte str, byte mesto){
  if(str==0){lcd(0b10000000+mesto);}
  if(str==1){lcd(0b11000000+mesto);}
  }
void lcdInit(){
      delay(1000); 
    rs();
    lcd(0b00110000);del();
    lcd(0b00110000);del();
    lcd(0b00110000);del();
    lcd(0b00000010);
    lcd(0b00000010);
    lcd(0b00001100);
    lcd(0b00000001);
  } 

void lcdInt(long int_x){char aa;byte h[16];
   int it,xx;long int_y=int_x;
  for(it=0;int_x>0;it++){int_x=int_x/10;}
  for(xx=0;xx<it;xx++){
   h[xx]=int_y%10; int_y=int_y/10;
   aa=(char)h[it-xx-1];lcdChar(aa +'0');}
  }