Ð˜Ð½Ð´Ð¸ÐºÐ°Ñ†Ð¸Ñ Ð½Ð° трёх Ñеми Ñегментных трёх знаковых Ñветодиодных индикаторах через SPI
Материал из Automata.
(Различия между версиями)
м (Полностью удалено содержимое страницы) |
(Отмена правки № 1787 участника Kern (обсуждение)) |
||
Строка 1: | Строка 1: | ||
+ | #include <stdint.h> | ||
+ | #include <avr/io.h> | ||
+ | #include <avr/interrupt.h> | ||
+ | //MISO - RCK; | ||
+ | #define LATCH 0x40 | ||
+ | |||
+ | /*0*/ /*1*/ /*2*/ /*3*/ /*4*/ /*5*/ /*6*/ /*7*/ /*8*/ /*9*/ /*.*/ | ||
+ | static const uint8_t LEDS[11] = {~0x5f,~0x42,~0x37,~0x76,~0x6a,~0x7c,~0x7d,~0x46,~0x7f,~0x7e,~0x00 }; | ||
+ | static volatile uint8_t i = 0; | ||
+ | |||
+ | void Indicate (void) | ||
+ | { | ||
+ | SPCR |= _BV(SPE); | ||
+ | |||
+ | register uint8_t k; | ||
+ | for (k = 0; k < 9; k++) | ||
+ | { | ||
+ | SPDR = i == k ? LEDS[k+1] : 0xFF; | ||
+ | while (!(SPSR & _BV(SPIF))); | ||
+ | } | ||
+ | |||
+ | SPCR &= ~_BV(SPE); | ||
+ | |||
+ | PORTB |= LATCH; | ||
+ | PORTB &= ~LATCH; | ||
+ | } | ||
+ | |||
+ | ISR (TIMER1_COMPA_vect) | ||
+ | { | ||
+ | Indicate(); | ||
+ | if (i++ == 9) | ||
+ | i = 0; | ||
+ | } | ||
+ | |||
+ | int main (void) | ||
+ | { | ||
+ | DDRB = 0xff; | ||
+ | PORTB = 0x00; | ||
+ | |||
+ | SPCR = _BV(SPE) | _BV(MSTR) | _BV(SPR1); | ||
+ | |||
+ | TCCR1B = _BV(WGM12) | _BV(CS12); | ||
+ | TIMSK = _BV(OCIE1A); | ||
+ | OCR1A = 11250; | ||
+ | |||
+ | sei(); | ||
+ | |||
+ | while (1); | ||
+ | } |
Текущая версия
#include <stdint.h> #include <avr/io.h> #include <avr/interrupt.h>
//MISO - RCK; #define LATCH 0x40
/*0*/ /*1*/ /*2*/ /*3*/ /*4*/ /*5*/ /*6*/ /*7*/ /*8*/ /*9*/ /*.*/ static const uint8_t LEDS[11] = {~0x5f,~0x42,~0x37,~0x76,~0x6a,~0x7c,~0x7d,~0x46,~0x7f,~0x7e,~0x00 }; static volatile uint8_t i = 0;
void Indicate (void) { SPCR |= _BV(SPE); register uint8_t k; for (k = 0; k < 9; k++) { SPDR = i == k ? LEDS[k+1] : 0xFF; while (!(SPSR & _BV(SPIF))); } SPCR &= ~_BV(SPE); PORTB |= LATCH; PORTB &= ~LATCH; }
ISR (TIMER1_COMPA_vect) { Indicate(); if (i++ == 9) i = 0; }
int main (void) { DDRB = 0xff; PORTB = 0x00; SPCR = _BV(SPE) | _BV(MSTR) | _BV(SPR1); TCCR1B = _BV(WGM12) | _BV(CS12); TIMSK = _BV(OCIE1A); OCR1A = 11250; sei(); while (1); }