Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * M328P-matrix-7219-text.c
- *
- * Created: 13. 12. 2019 22:17:17
- * Author : martin
- */
- #define F_CPU 16000000ul
- #include <avr/io.h>
- #include <util/delay.h>
- #define NUMMAX 4 // sem dej po4et MAXu za sebou
- #define CLK_HIGH() PORTB |= (1<<PB5)
- #define CLK_LOW() PORTB &= ~(1<<PB5)
- #define CS_HIGH() PORTB |= (1<<PB2)
- #define CS_LOW() PORTB &= ~(1<<PB2)
- #define DATA_HIGH() PORTB |= (1<<PB3)
- #define DATA_LOW() PORTB &= ~(1<<PB3)
- #define GPIO_INIT() DDRB |= (1<<PB5) | (1<<PB3) | (1<<PB2)
- void spi_send(uint8_t data)
- {
- uint8_t i;
- for (i = 0; i < 8; i++, data <<= 1)
- {
- CLK_LOW();
- if (data & 0x80)
- DATA_HIGH();
- else
- DATA_LOW();
- CLK_HIGH();
- }
- }
- void max7219_writec(uint8_t high_byte, uint8_t low_byte)
- {
- CS_LOW();
- spi_send(high_byte);
- spi_send(low_byte);
- CS_HIGH();
- }
- void max7219_init(void)
- {
- GPIO_INIT();
- for (uint8_t a=1; a<=NUMMAX; a++)
- {
- // Decode mode: none
- max7219_writec(0x09, 0xff);
- // Intensity: 3 (0-15)
- max7219_writec(0x0A, 5);
- // Scan limit: All "digits" (rows) on
- max7219_writec(0x0B, 7);
- //Shutdown register: Display on
- max7219_writec(0x0C, 1);
- // Display test: off
- max7219_writec(0x0F, 0);
- }
- }
- int main(void)
- {
- max7219_init();
- // ALL OFF
- for (uint8_t b=1; b<=8; b++)
- for (uint8_t a=1; a<=NUMMAX; a++)
- max7219_writec(b, 0);
- while (1)
- {
- // Vypis na mista 1-8
- for (uint8_t b=1; b<=8; b++)
- {
- for (uint8_t a=0; a<=9; a++)
- {
- for (uint8_t d=1; d<=NUMMAX; d++)
- max7219_writec(9-b, b); // 9-b vypisujeme zleva
- _delay_ms(100);
- }
- _delay_ms(100);
- }
- // smazani
- for (uint8_t b=1; b<=8; b++)
- {
- for (uint8_t a=1; a<=NUMMAX; a++)
- max7219_writec(b, 0);
- }
- _delay_ms(1000);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement