Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Cezary Zaprawa Prosze wyswietlic sekwencje znakow na wyswietlaczu, tak, aby kazdy znak byl w oddzielnym segmencie
- //Po kliknieciu sekwencja na wyswietlaczu powinien
- #include <avr/io.h>
- #include <avr/interrupt.h>
- #include <avr/pgmspace.h>
- #define BUTTON_MASK (1<<PD2)
- #define BUTTON_PIN PIND
- #define BUTTON_PORT PORTD
- volatile uint8_t button_down;
- const char codeArray[16] PROGMEM =
- {0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8, 0x80, 0x90, 0x88, 0x83, 0xc6, 0xa1, 0x86, 0x8e};
- char array[16] =
- {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
- volatile uint8_t readByte = 0;
- volatile uint8_t displayCounter = 0;
- volatile uint8_t arrayCounter = 0;
- volatile uint8_t index = 0;
- ISR(TIMER1_OVF_vect) {
- PORTB = ~(1 << displayCounter);
- readByte = pgm_read_byte(&codeArray[array[arrayCounter + index]]);
- PORTA = readByte;
- displayCounter++;
- if (displayCounter == 4)
- displayCounter = 0;
- if(arrayCounter == index+3)
- arrayCounter = index;
- else
- arrayCounter++;
- }
- ISR(TIMER0_COMP_vect) {
- static uint8_t count = 0;
- static uint8_t button_state = 0;
- uint8_t current_state = (~BUTTON_PIN & BUTTON_MASK) != 0;
- if (current_state != button_state) {
- count++;
- if (count >= 4) {
- button_state = current_state;
- if (current_state != 0)
- button_down = 1;
- count = 0;
- }
- } else {
- count = 0;
- }
- }
- ISR(INT0_vect) {
- if(button_down) {
- button_down = 0;
- if (index < 6) index++;
- displayCounter = 0;
- }
- }
- void init(){
- cli();
- //Timer1
- ICR1 = 150;
- TCCR1A |= (1 << WGM11);
- TCCR1B |= (1 << WGM12) | (1 << WGM13) | (1 << CS10);
- TIMSK |= (1 << TOIE1);
- //Timer0
- OCR0 = 250;
- TIMSK |= (1 << OCIE0);
- TCCR0 |= (1 << WGM01) | (1 << CS01);
- //Int0
- MCUCR |= (1 << ISC01);
- GICR |= (1 << INT0);
- DDRA = 0xFF;
- PORTA = 0x00;
- DDRB = 0b00001111;
- sei();
- }
- int main(void) {
- init();
- BUTTON_PORT |= BUTTON_MASK;
- while(1) {
- asm("nop");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement