• Witaj na Forum Arduino Polska! Zapraszamy do rejestracji!
  • Znajdziesz tutaj wiele informacji na temat hardware / software.
Witaj! Logowanie Rejestracja


Ocena wątku:
  • 0 głosów - średnia: 0
  • 1
  • 2
  • 3
  • 4
  • 5
proszę o pomoc w programie
#1
Witajcie.
Chcę zrobić skalę z wyświetlaczem do tokarki. Korzystając z zasobów arduino w sieci i z własnych dokonań w c zmontowałem sobie taki oto kodzik:

Kod:
 
#define LATCH  6  //pin 12 of BBFuino connect to RCK of 8x7segment module
#define CLOCK  7  //pin 11 of BBFuino connect to SCK of 8x7segment module
#define DATA   8  //pin 10 of BBFuino connect to DIO of 8x7segment module
#define LED    9  //LED is connected to pin 13 of Arduino
#define  MultiplexDelay  0  //delay for multiplexing between digit on 8x7segment module
#define LEFT   0  // define the value for left justify
#define RIGHT  1  // define the value for right justify
#define BLANK 11  //array element to make 7segment blank
#define PRZYCISK 4

// Rotary encoder declarations
static int pinA = 2;  // Our first hardware interrupt pin is digital pin 2
static int pinB = 3;  // Our second hardware interrupt pin is digital pin 3
volatile long last=0;
volatile long nowy=0;
volatile long enkoder_cnt=0;
byte minus_flag =0;
//volatile int a1;
//volatile uint8_t b=0;


// adresy cyferek w wyswietlaczu
byte anode[6] = {   0b00000100,  //digit 1 from right
                   0b00000010,  //digit 2 from right
                   0b00000001,  //digit 3 from right
                   0b01000000,  //digit 4 from right
                   0b00100000,  //digit 5 from right
                   0b00010000,  //digit 6 from right
//                    0b00000000,  //digit 7 from right
//                    0b00000000   //digit 8 from right                                        
                   };
                   
//tablica znaków wyswietlacza
                   //PGFEDCBA, segment on 7 segment, P is the dot
byte cathode[13] = {0b11000000,  // 0
                   0b11111001,  // 1
                   0b10100100,  // 2
                   0b10110000,  // 3
                   0b10011001,  // 4
                   0b10010010,  // 5
                   0b10000010,  // 6
                   0b11111000,  // 7
                   0b10000000,  // 8
                   0b10010000,  // 9  
                   0b01111111,  //dot                  
                   0b11111111,   //blank
                   0b10111111, //minus
                   };    

//fucntion to send the serial data out to two 74HC595 serial to parallel shift register and activate the 7 segment.                  
void display8x7segment(byte datapin, byte clockpin, byte latchpin, byte digit, byte number)
{
   digitalWrite(latchpin, LOW);
   shiftOut(datapin, clockpin, MSBFIRST, digit); // clears the right display
   shiftOut(datapin, clockpin, MSBFIRST, number); // clears the left display
   digitalWrite(latchpin, HIGH);  
}



//function to display value on 8x7 segment display according to the justify state
void displayNumber6x7segment(byte justify, long value)
{

byte bufor[6] = {0};  
//   value = value % 100000000;  //ensure the value is within 8 digits only
//   decimal[7] = value / 10000000;  //extract digit 7 from value
//   value = value % 10000000;       //extract the rest of 7 digit value
//   if(minus_flag=1)
//   {
//    decimal[6] =0b10111111;
//   }
//   else
//   bufor[6] = value / 1000000;
//   value = value % 1000000;
  bufor[5] = value / 100000;
  value = value % 100000;
  bufor[4] = value / 10000;
  value = value % 10000;
  bufor[3] = value / 1000;
  value = value % 1000;
 bufor[2] = value / 100;
  value = value % 100;
bufor[1] = value / 10;
  bufor[0] = value % 10;
  byte zero =0;

byte decimal[6] = {0};

  decimal[5]=bufor[5];
  decimal[4]=bufor[4];
  decimal[3]=bufor[3];
  decimal[2]=bufor[2];
  decimal[1]=bufor[1];
  decimal[0]=bufor[0];
 
  if (justify == RIGHT)
  {  
    for(byte e = 6; e > 0 ; e --)
    {
 
      if(zero == 0)
      {
        if(decimal[e-1] != 0) ;//[e-1] != 0)          
        {
          display8x7segment(DATA, CLOCK, LATCH, cathode[decimal[e-1]], anode[e-1]);
          zero = 1;    
        }
      }
      else display8x7segment(DATA, CLOCK, LATCH, cathode[decimal[e-1]], anode[e-1]);
   
    delay(MultiplexDelay);
    }
  }
  else  //if justify == left
  {
    byte d = 0;    
    for(byte e = 6; e > 0; e --)
    {      
      if(zero == 0)
      {
        if(decimal[e-1] != 0)        
        {
          display8x7segment(DATA, CLOCK, LATCH, cathode[decimal[e-1]], anode[5]);
          zero = 1;
          d ++;    
         // delay(MultiplexDelay);
        }
      }
      else
      {
        display8x7segment(DATA, CLOCK, LATCH, cathode[decimal[e-1]], anode[5-d]);
        d ++;
       // delay(MultiplexDelay);
      }    
     
    }
   
  }
}

void setup() {
 pinMode(LATCH, OUTPUT);
 pinMode(CLOCK, OUTPUT);
 pinMode(DATA, OUTPUT);
 pinMode(LED, OUTPUT);
 pinMode(4, INPUT_PULLUP);
 pinMode(13, OUTPUT);
 digitalWrite(LATCH, HIGH);  
 digitalWrite(LED, LOW);  //off LED  
//Rotary encoder section of setup
PCICR |= 1<<PCIE2;
PCMSK2 |=(1<<PCINT18);
PCMSK2 |=(1<<PCINT19);
  pinMode(pinA, INPUT_PULLUP);  // set pinA as an input, pulled HIGH to the logic voltage (5V or 3.3V for most cases)
  pinMode(pinB, INPUT_PULLUP);  // set pinB as an input, pulled HIGH to the logic voltage (5V or 3.3V for most cases)
 
}

void loop(){

 
// glowna funkcja
 for (;;)
 {    
   uint8_t odczyt;
   odczyt=digitalRead(PRZYCISK);
   if (odczyt==LOW) enkoder_cnt=0;
   int value = 0;

  if(enkoder_cnt<0)
  {
   value=enkoder_cnt/4;
   value=(~value)+1;
   minus_flag=1;
   digitalWrite(13, HIGH);
  }
  else
   value=enkoder_cnt/4,minus_flag=0, digitalWrite(13, LOW);
   
    for(byte i = 0; i <2 ; i ++)
     {
 
     displayNumber6x7segment(RIGHT, value);  
    }      
 }

 
}




ISR (PCINT2_vect)
{
   nowy=(PIND & B00001100);  
 if(!(last==nowy))
 {
   switch(nowy)
   {
     case 0:

     if(last==4) --enkoder_cnt;
     if(last==8) ++enkoder_cnt;
     last=nowy;
     break;

     case 4:

     if(last==0) ++enkoder_cnt;
     if(last==12) --enkoder_cnt;
     last=nowy;
     break;


     case 12:

     if(last==4) ++enkoder_cnt;
     if(last==8) --enkoder_cnt;
     last=nowy;
     break;

     case 8:

     if(last==12) ++enkoder_cnt;
     if(last==0) --enkoder_cnt;
     last=nowy;
     break;
   }

 }
}
  i teraz moje pytanie. Jak zrobić aby jedna z cyferek wyświetlała się z kropką? tak aby skala pokazywała setne części milimetra? Cyfry mi działają normalnie, jeśli wartosć wyniku jest ujemna też pokazuje prawidłowo ale nie mam pojęcia jak odpalić tą kropkę jednocześnie z cyfrą? Bardzo proszę o pomoc bardziej doświadczonych kolegów.
 
Odpowiedź
#2
Wszystko masz tu:

Kod:
byte cathode[13] = {0b11000000,  // 0
                  0b11111001,  // 1
                  0b10100100,  // 2
                  0b10110000,  // 3
                  0b10011001,  // 4
                  0b10010010,  // 5
                  0b10000010,  // 6
                  0b11111000,  // 7
                  0b10000000,  // 8
                  0b10010000,  // 9  
                  0b01111111,  //dot                  
                  0b11111111,   //blank
                  0b10111111, //minus
                  };
   
Kropka to 7 bit=0.
Czyli jeśli chcesz ustawić kropke z cyfrą to musisz zrobić
Kod:
cyfra = cyfra & 0b01111111;
Pomagam za darmo więc szanuj mój czas.
Wklejaj tekst a nie jego zdjęcie.
Nie pisz następnego postu jak nie odpowiedziałeś na poprzedni.
Jak mądrze zadawać pytania
 
Odpowiedź
  


Skocz do:


Przeglądający: 1 gości