Skip to content

Instantly share code, notes, and snippets.

@peat-psuwit
Last active April 30, 2018 16:16
Show Gist options
  • Save peat-psuwit/752720a168935667a83c34aa29ca0197 to your computer and use it in GitHub Desktop.
Save peat-psuwit/752720a168935667a83c34aa29ca0197 to your computer and use it in GitHub Desktop.
/*
* PCINT7Seg.c
*
* Created: 30/4/2561 21:44:33
* Author : peath
*/
#include <avr/io.h>
#include <avr/interrupt.h>
const unsigned char LOOKUPTB[] = {
0b00111111,
0b00000110,
0b01011011,
0b01001111,
0b01100110,
0b01101101,
0b01111101,
0b00000111,
0b01111111,
0b01101111,
0b01110111,
0b01111100,
0b00111001,
0b01011110,
0b01111001,
0b01110001
};
void update7Seg() {
unsigned char num = (PINB & 0b00111110) >> 1;
unsigned char unit = num % 10;
unsigned char tenth = num / 10;
PORTC = ~LOOKUPTB[tenth];
PORTD = ~LOOKUPTB[unit];
}
ISR(PCINT0_vect) {
update7Seg();
}
int main(void)
{
// DipSW is at PB1-5 = PCINT1-5
DDRB = 0b00000000;
// Enable pull-up resistor (optional)
PORTB = 0b00111110;
// 7-seg is at PD0-6 & PC0-6
DDRC = 0b01111111;
DDRD = 0b01111111;
// Enable PCINT0
PCICR = (1 << PCIE0);
// Care about PCINT1-5
PCMSK0 = 0b00111110;
update7Seg();
sei();
while (1)
{
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment