Code: Select all
Hello.
I need some help with this code : an up down counter on the 7 segment display.
The program count up until digit 9 after that "should" count down until digit 0 and so on.
Unfortunately my program just count up until 9 and start again from 0 to 9.
Could you give me some advices ?
Thank you.
#include <system.h>
#pragma DATA _CONFIG1, _EXTRC_CLKOUT & _WDT_OFF & _LVP_OFF
#define DISPLAY_SIZE 1
int cnt = 0, led_counter = 0, counter = 0;
unsigned char enable[DISPLAY_SIZE] = {8};
unsigned char patterns[10] = {0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x83, 0xf8, 0x80, 0x98};
void setup_hardware()
{
trisb = 0x00;
trisa = 0xf0;
ansel = 0x00;
cmcon = 0x07;
intcon = 0b10100000;
option_reg = 0b00000100;
}
void interrupt()
{
if(intcon & 0x04)
{
clear_bit(intcon, 2);
counter++;
if(counter >= 61)
{
counter = 0;
porta = 0;
portb = patterns[cnt];
porta = enable[led_counter];
led_counter++;
cnt++;
if(led_counter > 0)
led_counter = 0;
if(cnt > 9)
cnt = 0;
}
}
}
void main()
{
setup_hardware();
while (1)
{
}
}