Hello,
We are trying to control 8 7-segment displays by using multiplexing.
The problem we have is that we have to program buttons, how can we make it?
Best regards,
Floris
/* Ansteuerung von drei 7-Segmentanzeige im Multiplexbetrieb
* Gemeinsame Anode, PB0..PB6
* Spalten: PC0..PC2
*
* a
* f b
* g
* e c
* d
*
*/
#include <avr/io.h>
#include <util/delay.h>
#define F_CPU
void delay_ms(uint16_t);
void digit (uint8_t, uint8_t);
int main (void);
int knoppen(int pin, int getal);
const int8_t numbers [10] =
{
// 1gfedcba
0b11000000, // 0
0b11111001, // 1
0b10100100, // 2
0b10110000, // 3
0b10011001, // 4
0b10010010, // 5
0b10000010, // 6
0b11111000, // 7
0b10000000, // 8
0b10010000, // 9
};
void delay_ms (uint16_t ms)
{
for(uint16_t t=0; t<=ms; t++)
_delay_ms(1);
}
}
void digit (uint8_t wert, uint8_t pin)
{
int i;
i=1;
PORTA |= (1 << PA0) | (1 << PA1); if (i==8) i=1;
PORTB = numbers[wert];
PORTA &= ~(1 << pin);
delay_ms (15);
}
int main()
{
int i;
i=1;
DDRB = 0xFF;
DDRA |= (1 << DDA0) | (1 << DDA1) | (1 << DDA2) | (1 << DDA3) | (1 << DDA4) ;
PORTA |= (1 << PA0) | (1 << PA1); if (i==8 ) i=1;
while (1)
{
digit (1, PA0);
digit (2, PA1);
digit (3, PA2);
digit (4, PA3);
digit (5, PA4);
}
return 0;
}