add opdracht 2.3

This commit is contained in:
stijn
2021-02-10 12:40:32 +01:00
parent 35ce5510a0
commit 31610eb739
12 changed files with 849 additions and 225 deletions

View File

@@ -4,7 +4,7 @@
* Created: 2/10/2021 11:45:42 AM
* Author: Sem
*/
#include <avr/interrupt.h>
#include <xc.h>
#include <avr/io.h>
#include <util/delay.h>
@@ -15,24 +15,78 @@ void wait( int ms ) {
}
}
const unsigned char Numbers [10] = {
// dPgfe dcba
0b 0011 1111, // 0
0b 0000 0110, // 1
0b 0101 1011, // 2
0b 0100 1111, // 3
0b 0110 0110, // 4
0b 0110 1101, // 5
0b 0111 1101, // 6
0b 0000 0111, // 7
0b 0111 1111, // 8
0b 0110 1111, // 9
int count;
/************************************************************************/
/* interrupt 1
walk the light 1 down */
/************************************************************************/
ISR( INT0_vect ) {
setDisplay(++count);
}
/************************************************************************/
/* interrupt 2
walk the light 1 up */
/************************************************************************/
ISR( INT1_vect ) {
setDisplay(--count);
}
const unsigned char Characters [15] = {
0b00111111, // 0
0b00000110, // 1
0b01011011, // 2
0b01001111, // 3
0b01100110, // 4
0b01101101, // 5
0b01111101, // 6
0b00000111, // 7
0b01111111, // 8
0b01101111, // 9
0b01110111, // A
0b01111100, // B
0b00111001, // C
0b01011110, // D
0b01111001, // E
0b01110001, // F
};
void initDisplay(){
DDRA = 0b11111111;
}
void setDisplay(int num){
if(num > 15 || num < 0)
num = 14;
PORTA = Characters[num];
}
int main(void)
{
initDisplay();
setDisplay(0);
/* Replace with your application code */
// Init I/O
DDRD = 0b00000000;
// Init Interrupt hardware
EICRA |= 0b00001010; // INT2 falling edge, INT1 rising edge
EIMSK |= 0b00000011; // Enable INT1 & INT0
PORTC = 0x01; // init the first bit
sei(); // enable input mechanism
while(1)
{
//TODO:: Please write your application code
if((PIND == 0b00000011) && (count != 0)){
count = 0;
setDisplay(count);
}
}
}
}