You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.1 KiB
C
63 lines
1.1 KiB
C
#include <avr/io.h>
|
|
#include <avr/interrupt.h>
|
|
#include <stdint.h>
|
|
#include <util/delay.h>
|
|
|
|
uint8_t font[] = {
|
|
0xEE,
|
|
0x82,
|
|
0xDC,
|
|
0xD6,
|
|
0xB2,
|
|
0x76,
|
|
0x7E,
|
|
0xC2,
|
|
0xFE,
|
|
0xF6,
|
|
};
|
|
|
|
uint8_t display[4];
|
|
|
|
void timer0_init()
|
|
{
|
|
TCCR0 = (1<<WGM01); //TIMER0 SET-UP: CTC MODE
|
|
TCCR0 = (1<<CS01)|(1<<CS00); // PS 1:64
|
|
OCR0 = 249; // 1ms reach for clear (16mz:64=>250kHz:250-=>1kHz)
|
|
TIMSK |= 1<<OCIE0; //IRQ on TIMER0 output compareA
|
|
}
|
|
|
|
int main(void){
|
|
DDRB |= _BV(3) | _BV(2) | _BV(1) | _BV(0);
|
|
DDRD = 0xFC;
|
|
DDRA = 0x03 << 4;
|
|
DDRC = 0xFE;
|
|
|
|
display[3] = font[1];
|
|
display[2] = font[3];
|
|
display[1] = font[3];
|
|
display[0] = font[7];
|
|
|
|
timer0_init();
|
|
sei();
|
|
|
|
while(1){
|
|
}
|
|
|
|
}
|
|
|
|
ISR(TIMER0_COMP_vect)
|
|
{
|
|
if(PORTB & 0x01){
|
|
PORTB = 1<<1 | 1<<3;
|
|
PORTD = display[3] & 0xFC;
|
|
PORTA = (display[3] & 0x03) << 4;
|
|
PORTC = display[1];
|
|
}
|
|
else{
|
|
PORTB = 1<<0 | 1<<2;
|
|
PORTD = display[2] & 0xFC;
|
|
PORTA = (display[2] & 0x03) << 4;
|
|
PORTC = display[0];
|
|
}
|
|
}
|