Ð˜Ð½Ð´Ð¸ÐºÐ°Ñ†Ð¸Ñ Ð½Ð° трёх Ñеми Ñегментных трёх знаковых Ñветодиодных индикаторах через SPI
Материал из Automata.
(Различия между версиями)
(Новая: #include <stdint.h> #include <avr/io.h> #include <avr/interrupt.h> //MISO - RCK; #define LATCH 0x40 - →0 - /*...) |
м |
||
Строка 1: | Строка 1: | ||
- | #include <stdint.h> | + | #include <stdint.h> |
- | #include <avr/io.h> | + | #include <avr/io.h> |
- | #include <avr/interrupt.h> | + | #include <avr/interrupt.h> |
- | //MISO - RCK; | + | //MISO - RCK; |
- | #define LATCH 0x40 | + | #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; | register uint8_t k; | ||
for (k = 0; k < 9; k++) | for (k = 0; k < 9; k++) | ||
Строка 19: | Строка 20: | ||
while (!(SPSR & _BV(SPIF))); | while (!(SPSR & _BV(SPIF))); | ||
} | } | ||
- | + | ||
SPCR &= ~_BV(SPE); | SPCR &= ~_BV(SPE); | ||
- | + | ||
PORTB |= LATCH; | PORTB |= LATCH; | ||
PORTB &= ~LATCH; | PORTB &= ~LATCH; | ||
- | } | + | } |
- | ISR (TIMER1_COMPA_vect) | + | ISR (TIMER1_COMPA_vect) |
- | { | + | { |
Indicate(); | Indicate(); | ||
if (i++ == 9) | if (i++ == 9) | ||
i = 0; | i = 0; | ||
- | } | + | } |
- | int main (void) | + | int main (void) |
- | { | + | { |
DDRB = 0xff; | DDRB = 0xff; | ||
PORTB = 0x00; | PORTB = 0x00; | ||
- | + | ||
SPCR = _BV(SPE) | _BV(MSTR) | _BV(SPR1); | SPCR = _BV(SPE) | _BV(MSTR) | _BV(SPR1); | ||
- | + | ||
TCCR1B = _BV(WGM12) | _BV(CS12); | TCCR1B = _BV(WGM12) | _BV(CS12); | ||
TIMSK = _BV(OCIE1A); | TIMSK = _BV(OCIE1A); | ||
OCR1A = 11250; | OCR1A = 11250; | ||
- | + | ||
sei(); | sei(); | ||
- | + | ||
while (1); | while (1); | ||
- | } | + | } |
Версия 20:23, 16 января 2010
#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); }