bbgil
Full Member level 2
mikroc 7 segment display
hi. I have this simple code which supposed to turn on 7-segment display (common anode) counting 0-9. i'm using switch function and the TMR0. the problem is i can't make it count. it stuck at 8. i guess the problem is my TMRO and how to count it so it control the switch function. Any help from the C gurus out there will be appreciated. still learning how to use C. here is the code. thnx in advance.
unsigned cnt;
unsigned cnt1;
void interrupt() {
cnt++;
if (cnt==400)
{cnt=0;
cnt1=cnt1++;} // Increment value of cnt on every interrupt
INTCON = 0x20;
TMR0 = 96; // Set T0IE, clear T0IF
}//~
void main() {
OPTION_REG = 0x84; // Assign prescaler to TMR0
TRISb = 0; // PORTB is output
PORTb = 0xFF; // Initialize PORTB
TMR0 = 0x96;
INTCON = 0xA0; // Enable TMRO interrupt
cnt = 0;
cnt1=0; // Initialize cnt
do {
if (cnt1<0x09)
switch (cnt1){
case 0: portb = 0x81;
case 1: portb = 0xf3;
case 2: portb = 0x49;
case 3: portb = 0x61;
case 4: portb = 0x33;
case 5: portb = 0x25;
case 6: portb = 0x05;
case 7: portb = 0xf1;
case 8: portb = 0x01;
case 9: portb = 0x31;
default: portb =0x81;
}
cnt1 = 0;
// Reset cnt
} while (1);
}//~!
hi. I have this simple code which supposed to turn on 7-segment display (common anode) counting 0-9. i'm using switch function and the TMR0. the problem is i can't make it count. it stuck at 8. i guess the problem is my TMRO and how to count it so it control the switch function. Any help from the C gurus out there will be appreciated. still learning how to use C. here is the code. thnx in advance.
unsigned cnt;
unsigned cnt1;
void interrupt() {
cnt++;
if (cnt==400)
{cnt=0;
cnt1=cnt1++;} // Increment value of cnt on every interrupt
INTCON = 0x20;
TMR0 = 96; // Set T0IE, clear T0IF
}//~
void main() {
OPTION_REG = 0x84; // Assign prescaler to TMR0
TRISb = 0; // PORTB is output
PORTb = 0xFF; // Initialize PORTB
TMR0 = 0x96;
INTCON = 0xA0; // Enable TMRO interrupt
cnt = 0;
cnt1=0; // Initialize cnt
do {
if (cnt1<0x09)
switch (cnt1){
case 0: portb = 0x81;
case 1: portb = 0xf3;
case 2: portb = 0x49;
case 3: portb = 0x61;
case 4: portb = 0x33;
case 5: portb = 0x25;
case 6: portb = 0x05;
case 7: portb = 0xf1;
case 8: portb = 0x01;
case 9: portb = 0x31;
default: portb =0x81;
}
cnt1 = 0;
// Reset cnt
} while (1);
}//~!