I have written a program for my At-mega 32 in order to increase and decrease numbers from 0 to 9 and reverse (9 to 0) with the two tactile switch witch you can see in the picture.
But the problem is that while all of the numbers are demonstrated by pressing those switches, only numbers 4 and 7 don't appear properly !?.
My seven segments instead of number 4 demonstrates what you can see in the first picture and for number 7 is shows what you can see in the second picture.
I would appreciate it if someone could have a look at my codes and schematic which I have shared here and help me to find the issue.
Thank you so much,
#include <avr/io.h>
#include <util/delay.h>
#include "global.h"
#include <avr/interrupt.h>
uint8_t Codes[] = {0xFC, 0x60, 0xDA, 0xF2, 0x66, 0xB6, 0xBE, 0xE0, 0xFE, 0xF6};
uint8_t count=0;
//temp=0
void display(uint8_t digit);
void config(void);
ISR(INT0_vect)
{
if(count<9)
{
count++;
display(count);
}
}
ISR(INT1_vect)
{
if(count>0)
{
count--;
display(count);
}
}
int main(void)
{
config();
while(1)
{
}
}
void config(void)
{
DDRA=0xFF;
PORTA=0;
cbi(DDRD,2);
cbi(DDRD,3);
sbi(PORTD,2);
sbi(PORTD,3);
GICR=(1<<INT1) | (1<<INT0);
MCUCR=0; //low level sensitivity
GIFR=(1 << INTF1) | (INTF0);
sei();
}
void display(uint8_t digit)
{
PORTA=Codes[digit];}
Your code looks correct, I even checked the patterns of Codes[]
.
Each bit of the patterns is assigned to one specific segment of the display:
Port bit | Segment |
---|---|
PA7 | a |
PA6 | b |
PA5 | c |
PA4 | d |
PA3 | e |
PA2 | f |
PA1 | g |
Your wiring is wrong, unfortunately the schematic does not show the pin names of the display. It seems as if it's upside down.