Binary to decimal to LED display

General discussion on mikroC PRO for PIC.
Post Reply
Author
Message
*Mican*
Posts: 18
Joined: 14 Aug 2009 21:53

Binary to decimal to LED display

#1 Post by *Mican* » 07 May 2020 19:45

Hello,

How to display some binary data to LED display.
It is four LED display. D4-D3-D2-D1
Example 25 dec is 0001 1001
This data I can see on PORTB (example).
PORTB show me 0001 1001 or some other value.
It can be more binary data 9-10-11-12 bits, not only eight.
But for start I need only eight bits.
I checked example folder with LED display and work fantastic.

Code: Select all

void Interrupt(){

if (ShiftA > 8u){
ShiftA = 1;
}
PORTA = ShiftA;
ShiftA <<= 1;

PORTB = ShiftB[Portbindex];
PortbIndex ++;
if (PortbIndex > 3u)
   PortbIndex = 0;

Count++;
TMR0 = 6;
T0IF_bit = 0;

}

unsigned short mask(unsigned short Num) {
switch(Num){

case 0: return 0x00;
case 1: return 0x01;
case 2: return 0x02;
case 3: return 0x03;
case 4: return 0x04;
case 5: return 0x05;
case 6: return 0x06;
case 7: return 0x07;
case 8: return 0x08;
case 9: return 0x09;
//case 10: return 0x0C;
}

}

void main() {

PORTA = 0x00;
TRISA = 0x00;

PORTB = 0x00;
TRISB = 0x00;

TMR0 = 6;
OPTION_REG = 0x83;
INTCON = 0xA0;
ShiftA = 1;

Count = 0;
Number = 0;
Digit = 0;
PortbIndex = 0;

while(1) {

if (Count > 500){
Count = 0;
Number++;
if (Number > 9999)
   Number = 0;
}

Digit = Number/1000u;
ShiftB[3] = mask(Digit);

Digit = ((Number/100u) % 10);
ShiftB[2] = mask(Digit);

Digit = (Number/10) % 10;
ShiftB[1] = mask(Digit);

Digit = Number = 10;
ShiftB[0] = mask(Digit);


}     //while
}     //main
This code is tested with CD4543B, because CD4543 is BCD to seven segment Decoder/Driver and use only four pins.
Good example is DHT 11 I need only hight humiditi or hight temperature or maybe LM75B (DS18B20, DS1621-31...)

Temp register LM75B
MSByte LSByte
7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0
D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0 X X X X X

I saw couple examples but I cant solve problem.

viewtopic.php?f=88&t=26256
viewtopic.php?f=72&t=49228

Second link is for AVR.

Post Reply

Return to “mikroC PRO for PIC General”