Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

3 Digit binary to decimal conversion

Status
Not open for further replies.

koolguy

Active Member
Hello,
I have done 2 digit counter successfully with E2PROm of PIC16F877a in H tech c code.
but i have problem with 3 digit after 99 something like that the middle display get suck and brightness is now also issue.
here is my code and i am scanning it as usual

please suggest if something is wrong in it...


C:
TRISB = 0X00 ;
    TRISC = 0B00000011 ;
unsigned int a=0;
unsigned int b=0;
unsigned int div;
unsigned int rem;
while(1){
b=eeprom_read(0x00);
PORTC=0b10000000;
rem = a%10;
PORTB=data[rem];
__delay_ms(5);
PORTC=0b01000000;
div=a/10;
PORTB=data[div];
__delay_ms(5);

PORTC=0b00100000;
div=a/100;
PORTB=data[div];
__delay_ms(5);





  
if(RC0==1){
__delay_ms(100);
a=a+1;
// eeprom_write(0x00, a);
if(a>999){
a=999;
}}
  if(RC1==1){
__delay_ms(100);
//eeprom_write(0x00, a);
a=a-1;
if(a>999){
a=0;
}
}
    }
        }
 
Ritesh! Use latches then you can have them as bright as you need... 7 segment drivers. You load your BCD numbers and then its latched.. Use the cmos 4513 chip... Job done... If you need to drive several LED modules then buy the MAX7219 which drives up to 8 digits serially..
 
Hello,

I have this code for counter...
pls have a look
C:
#include <htc.h>
#include <stdio.h>
__CONFIG(LVP_OFF& BOREN_OFF & PWRTE_ON & WDTE_OFF & FOSC_HS);
#define _XTAL_FREQ 20000000

char data[13]={  0b01111110,0b00010010,0b10111100,0b10110110,0b11010010,0b11100110,0b11101110, 0b00110010,0XFF,0b11110110};

main()
   {
   TRISB = 0X00 ;
   TRISC = 0B00000011 ;
   unsigned int a=0;
   unsigned int b=0;
   unsigned char d1=0;
   unsigned char d2=0;
   unsigned int c=0;
   unsigned int div=0;
   unsigned int rem=0;
   eeprom_write(0x00, d2);
   eeprom_write(0x01, d1);
   PORTB=0x00;
   while(1){
     d2=eeprom_read(0x00);
     d1=eeprom_read(0x01);
     c=d2;
     c=c<<8;
     c=c+d1;
     PORTC=0b10000000;
     rem = c%10;
     c=c/10;
     PORTB=data[rem];
     //__delay_ms(8);
     PORTC=0b01000000;
     rem=c%10;
     PORTB=data[rem];
     //__delay_ms(8);
     c=c/10;
     PORTC=0b00100000;
     rem=c%10;   

     PORTB=data[rem];
     //__delay_ms(8);
     if(RC0==1){
       //__delay_ms(40);
       a=a+1;
       d1=a;
       d2=a>>8;
       eeprom_write(0x00, d2);
       eeprom_write(0x01, d1);
       if(a>999){
         a=999;
       }
     }
       if(RC1==1){
       //__delay_ms(40);
       if(a>999){
         a=0;
       }
       a=a-1;
       d1=a;
       d2=a>>8;
       eeprom_write(0x00, d2);
       eeprom_write(0x01, d1);
     }
     }
  }
 
Last edited by a moderator:
Hello,
I have done 2 digit counter successfully with E2PROm of PIC16F877a in H tech c code.
but i have problem with 3 digit after 99 something like that the middle display get suck and brightness is now also issue.
here is my code and i am scanning it as usual

please suggest if something is wrong in it...


C:
TRISB = 0X00 ;
    TRISC = 0B00000011 ;
unsigned int a=0;
unsigned int b=0;
unsigned int div;
unsigned int rem;
while(1){
b=eeprom_read(0x00);
PORTC=0b10000000;
rem = a%10;
PORTB=data[rem];
__delay_ms(5);
PORTC=0b01000000;
div=a/10;
PORTB=data[div];
__delay_ms(5);

PORTC=0b00100000;
div=a/100;
PORTB=data[div];
__delay_ms(5);





 
if(RC0==1){
__delay_ms(100);
a=a+1;
// eeprom_write(0x00, a);
if(a>999){
a=999;
}}
  if(RC1==1){
__delay_ms(100);
//eeprom_write(0x00, a);
a=a-1;
if(a>999){
a=0;
}
}
    }
        }
See this is where you need a R&D department.
 
every thing is fine in 2 digit i need to store 3 digits but eeprom is of 8 bits 3 digits needs 10 bits
i have written this code for this but not giving exact result.


{a=a+1;

d1=a;
d2=a>>8;

eeprom_write(0x00, d2);
eeprom_write(0x01, d1);
}

{
d2=eeprom_read(0x00);
d1=eeprom_read(0x01);
a=d2;
a=a<<8;
a=a+d1;
c=a;}
 
Just a note..
If you write the eeprom in a main loop you need a 20mS delay between them.. ( Housekeeping )

Second... Writing to the eeprom is limited... You have @ 100,000 write cycles... I know that seems a lot, but once a second is only 27 hours... Just something to think about...

We have discussed this before.... When multiplexing any LED type display you have to "share" on off time between them all... The more you interface, the duller they will become.. Two answers..

If you take a normal LED with a maximum current of 30mA... We know that said LED will still be reasonably bright enough at 10mA so if your duty cycle can be 30% you could run them at maximum current and still get reasonable results..

BUT!!! as we have said before... You really need to control the duty cycle so each digit has the correct on /off time.

Three displays, three transistors so 30% duty... They should be quite bright!!

Second... Use a driver for each LED module...
 
LEDS can be 'overdriven' with higher current for a short time. Each LED has a spec that details this. Thus you can ramp up brightness even when multiplexing, using higher currents. Just ensure that your code doesn't fail in a manner that causes the time sharing to fail and burn out a display digit. So, always test with a safe ballast (current limiting) resistor value and then decrease it to increase the current when all is functioning.

Ensure that your multiplexing refresh rate is faster then 50Hz or the LEDs will flicker.
 
Looks like it was made to display gas prices.
images
 
Hello,
penny --> a British bronze coin and monetary unit equal to one hundredth of a pound.
what that it mean i have not listen this in india i mean here gas is in total Rs not cent ...??
 
Hello,
I have doubt for making counter more than 8 bit storage counter as in 8 bits we can make 2 digit counter but in 3 digit i have to overlap the 2 addr of eeprom.
Anyway, Is there any cheap and best way with and without micro controller which can save bcd too after power down.
I was noticing pic16f877 has e2prom but is it expensive than pic16f72 so, any substitute to replace it.
and bright should be high can uln2008 can used as segment driver to over come portb less driving current..??

here is previous result...
 
Status
Not open for further replies.

Latest threads

Back
Top