mircea2012
Newbie level 4
- Joined
- Jan 2, 2013
- Messages
- 5
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,321
Hello.
I have this program on the internet.
Count from 0 to 9999, using a 7 segment display.
My question is why is need a for loop ?
I have this program on the internet.
Count from 0 to 9999, using a 7 segment display.
My question is why is need a for loop ?
Code:
#include <system.h>
#pragma DATA _CONFIG1, _HS_OSC & _WDT_OFF & _LVP_OFF
unsigned i, Digit_0, Digit_1, Digit_2, Digit_3;
unsigned int Count, counter;
unsigned mask(unsigned num)
{
switch(num)
{
case 0 : return 0xC0;
case 1 : return 0xF9;
case 2 : return 0xA4;
case 3 : return 0xB0;
case 4 : return 0x99;
case 5 : return 0x92;
case 6 : return 0x82;
case 7 : return 0xF8;
case 8 : return 0x80;
case 9 : return 0x90;
}
}
void interrupt()
{
if(intcon & 4)
{
clear_bit(intcon, 2);
counter++;
if(counter > 30)
{
counter = 0;
}
}
}
void main()
{
trisb = 0x00;
trisa = 0xf0;
intcon = 0b10100000;
option_reg = 0b00000100;
Count = 0;
do
{
Digit_0 = Count%10;
Digit_0 = mask(Digit_0);
Digit_1 = (Count/10)%10;
Digit_1 = mask(Digit_1);
Digit_2 = (Count/100)%10;
Digit_2 = mask(Digit_2);
Digit_3 = (Count/1000);
Digit_3 = mask(Digit_3);
for(i = 0; i<=10000; i++)
{
portb = Digit_0;
porta = 0x08;
interrupt();
portb = Digit_1;
porta = 0x04;
interrupt();
portb = Digit_2;
porta = 0x02;
interrupt();
portb = Digit_3;
porta = 0x01;
interrupt();
}
Count++;
if(Count > 9999)
Count = 0;
}
while(1);
}