3 Digit binary to decimal conversion

Thread Starter

RRITESH KAKKAR

Joined Jun 29, 2010
2,829
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;
}
}
    }
        }
 

ErnieM

Joined Apr 24, 2011
8,415
Your basic idea is fine but you lost track of it past the units display.
When you do a modulus division by 10 you get the units digit, but the original variable remains unchanged. You would have to do the following:
Code:
    PORTC=0b10000000;
    rem = a%10;
    a=a/10;            // add this
    PORTB=data[rem];
    __delay_ms(5);
    PORTC=0b01000000;
    rem=a%10;        // was div
    a=a/10;            // add this
    PORTB=data[rem];    // was div
    __delay_ms(5);
    PORTC=0b00100000;
    // div=a/100;        // will ONLY work when a<1000
    // PORTB=data[div];    // will ONLY work when a<1000
    rem=a%10;        // add this instead
    a=a/10;            // add this instead
    PORTB=data[rem];    // add this instead
 

Thread Starter

RRITESH KAKKAR

Joined Jun 29, 2010
2,829
Hello,

I have updated the code as per your suggestion, but the problem is that the eeprom i think save data 8 bits i.e. 255 only in display so, i need the data should be at 999 how to move above 255 as i increment it it shows 000 please tell how to do this....


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 int div;
unsigned int rem;
while(1){

b=eeprom_read(0x00);

PORTC=0b10000000;
rem = b%10;
b=b/10;
PORTB=data[rem];
__delay_ms(10);
PORTC=0b01000000;
rem=b%10;
b=b/10;
PORTB=data[rem];
__delay_ms(10);

PORTC=0b00100000;
rem=b%10;      
  
PORTB=data[rem];
__delay_ms(10);


if(RC0==1){
__delay_ms(90);
a=a+1;

eeprom_write(0x00, a);

if(a>999){
a=999;
}}

  if(RC1==1){
__delay_ms(90);
eeprom_write(0x00, a);

a=a-1;
if(a>999){
a=0;
}
}
    }
        }
 

ErnieM

Joined Apr 24, 2011
8,415
Note the method you link to employs common anode displays with two sub sets of anodes, each connected to four elements. Also, the post concerns the display having a lack of brightness, so it is not a good source of information for making a bright display. Someone does make good points about not driving LEDs directly from port pins without resistors.
No comparison can be made to your work as your work is a mystery without a schematic being posted.
 
Top