Jump to content
ELFORUM - Forumul electronistilor
bogdan546

problema afisare numarator pe lcd 16x2

Recommended Posts

Am realizat un numarator folosind un encoder cu afisare pe serial si pe un lcd 16x2 . Problema este ca pe serial functioneza corect, dar pe lcd in momentul cand decrementez sub -10 sau incementez peste 10 ramane ultima coloana 0 si in loc sa afiseze la decementare 9,8,7 ...0 afiseaza 09, 08,07 ...01  .

 

#include <LiquidCrystal.h>
const int rs=12, en=11, d4=5, d5=4, d6=3, d7=2;
LiquidCrystal lcd(rs,en,d4,d5,d6,d7);
 int counter = 0; 
 int counter1 = 0;
 int currentStateCLK;
 int previousStateCLK; 
 String encdir ="";
 void setup() { 
   // setare encoder ca intrare D6 si D7 
  DDRD &= B00000000; 
   // setare pini iesire leduri D8 si D9 
  DDRB |=B00000011;
   // Setup Serial Monitor
   Serial.begin (9600);
   lcd.begin(16,2);
   // citire initiala a  inputCLK
   previousStateCLK = (PIND >>6 & B01000000 >> 6);
 } 
 void loop() { 
  // citire curenta  inputCLK
   currentStateCLK = (PIND >> 6 & B01000000 >> 6);  
   if (currentStateCLK != previousStateCLK){ 
     if ((PIND >> 7 & B10000000 >> 7) != currentStateCLK) { 
       counter --;
       counter1 --;
       encdir ="CCW";
       PORTB &= ~B00000001;
       PORTB |= B00000010;
     } else {
       counter ++;
       counter1 ++;
       encdir ="CW";
       PORTB &= ~B00000010;
       PORTB |= B00000001;
     }
     Serial.print("Directie: ");
     Serial.print(encdir);
     Serial.print(" -- Valoare: ");
     Serial.println(counter);
      lcd.setCursor(0,1);
      lcd.print("counter1= ");
      lcd.print(counter1);
     
   } 
   
   previousStateCLK = currentStateCLK; 
 }

 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.Terms of Use si Guidelines