Matriz 8x8
MATRIZ 8x8 CON INTEGRADO MAX7219 UTILIZANDO SPI EN TARJETA STM32 NUCLEO-F446
Bienvenidos a nuestra wiki, esperamos que nuestros códigos sean de gran ayuda.
MATERIALES
- Matriz 8x8 con max7219.
- NUCLEO F446RE.
1. Laboratorio primer paso :
funcionamiento matriz 7x5 ... demostramos su funcionamiento con las letras: A, B, C , X, Y, Z.
Import programmatriz7X5
realizamos la primera parte del laboratorio realizando un programa en el cual se pueda ingresar fácilmente cualquier letra o símbolo en una matriz 7x5
2. Laboratorio segundo paso:
Realizamos un programa para la visualización de la matriz 8x8 utilizando la librería "max7219.h"
CONEXIONES: *Declaración: Max7219 pantalla(PB_15, PB_14, PB_13, PB_12);
PIN / MAX7219 / NOTA
PB_15 / DIN / MOSI
PB_14 / NC / MISO
PB_13 / CLK / SCLK
PB_12 / CS / SSEL
U5V / VCC / 5 V
GND / GND / TIERRA
Explicación del programa
el programa consta de dos partes
1. Main.h : es la cabecera del programa. aquí encontramos los códigos:
Modificables: lo que encontramos dentro de las {} podemos modificarlo colocando otros números para cambiar las figuras a mostrar, el primer número hexadecimal escribirá la primera fila de abajo hacia arriba, el segundo la segunda fila de abajo hacia arriba... etc.
unsigned char led1[]= {0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55}; secuencia uno
unsigned char led2[]= {0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa}; secuencia dos
unsigned char led3[]= {0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,0xff}; secuencia tres
- los void los declaramos aquí para que puedan usarse en cualquier lado del programa (declaración global)
void Print_pantalla_tabla(unsigned char *pValor); declaración del puntero
void print_punto(); declaración secuencia de puntos
2. Main.cpp aquí llamaremos en el inicio a la cabecera y a la librería ( #include "main.h", #include "max7219.h" ) y declararemos los pines (Max7219 pantalla(PB_15, PB_14, PB_13, PB_12))
- en ... int main() ... aquí va lo que hace el programa
- primero configuramos el max7219
max7219_configuration_t cfg = {
.device_number = 1,
.decode_mode = 0,
.intensity = Max7219::MAX7219_INTENSITY_5,
.scan_limit = Max7219::MAX7219_SCAN_8 };
- testeamos la matriz, esto encendera todos los leds:
pantalla.init_device(cfg);
pantalla.enable_device(1);
pantalla.set_display_test();
wait(1);
pantalla.clear_display_test();
- hacemos un ciclo para que se muestren las distintas secuencias que dejamos en la cabecera
while(1){
Print_pantalla_tabla(led1); secuencia uno
wait(1); tiempo de espera
Print_pantalla_tabla(led)2; secuencia dos
wait(1);
Print_pantalla_tabla(led3); secuencia tres
wait(1);
print_punto(); secuencia de puntos (esta llamará una función, la cual se encuentra abajo, pero también se encuentra declarada en la cabecera) }
}
VOIDS (FUNCIONES)
- funciòn de puntero:
void Print_pantalla_tabla(unsigned char *pValor)
{
int i;
for (i =0;i<8;i++)
pantalla.write_digit(1,i+1,pValor[i]); }
- función secuencia de puntos
void print_punto() {
unsigned char personal[8]= {0x0,0x0,0,0,0,0,0,0};
unsigned char filas[8]= {1,3,7,0x0f,0x1f,0x3f,0x7f,0xff};
int i,j;
for (i=0;i<8;i++)
personal[i]= 0;
for (j=0;j<8;j++)
for (i=0;i<8;i++){
personal[i]= filas[j];
Print_pantalla_tabla(personal);
wait(0.2);
} }
main.cpp@0:bb2c52d4cc8f, 2017-03-11 (annotated)
- Committer:
- Paxtel
- Date:
- Sat Mar 11 22:23:11 2017 +0000
- Revision:
- 0:bb2c52d4cc8f
prueba1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Paxtel | 0:bb2c52d4cc8f | 1 | #include "main.h" |
Paxtel | 0:bb2c52d4cc8f | 2 | #include "max7219.h" |
Paxtel | 0:bb2c52d4cc8f | 3 | |
Paxtel | 0:bb2c52d4cc8f | 4 | Max7219 pantalla(PB_15, PB_14, PB_13, PB_12); |
Paxtel | 0:bb2c52d4cc8f | 5 | void Print_pantalla_tabla(unsigned char *pValor); |
Paxtel | 0:bb2c52d4cc8f | 6 | |
Paxtel | 0:bb2c52d4cc8f | 7 | int main() |
Paxtel | 0:bb2c52d4cc8f | 8 | { |
Paxtel | 0:bb2c52d4cc8f | 9 | |
Paxtel | 0:bb2c52d4cc8f | 10 | unsigned char personal[8]= {0x0,0x0,0,0,0,0,0,0}; |
Paxtel | 0:bb2c52d4cc8f | 11 | unsigned char filas[8]= {1,3,7,0x0f,0x1f,0x3f,0x7f,0xff}; |
Paxtel | 0:bb2c52d4cc8f | 12 | |
Paxtel | 0:bb2c52d4cc8f | 13 | max7219_configuration_t cfg = { |
Paxtel | 0:bb2c52d4cc8f | 14 | .device_number = 1, |
Paxtel | 0:bb2c52d4cc8f | 15 | .decode_mode = 0, |
Paxtel | 0:bb2c52d4cc8f | 16 | .intensity = Max7219::MAX7219_INTENSITY_5, |
Paxtel | 0:bb2c52d4cc8f | 17 | .scan_limit = Max7219::MAX7219_SCAN_8 |
Paxtel | 0:bb2c52d4cc8f | 18 | }; |
Paxtel | 0:bb2c52d4cc8f | 19 | |
Paxtel | 0:bb2c52d4cc8f | 20 | pantalla.init_device(cfg); |
Paxtel | 0:bb2c52d4cc8f | 21 | pantalla.enable_device(1); |
Paxtel | 0:bb2c52d4cc8f | 22 | pantalla.set_display_test(); |
Paxtel | 0:bb2c52d4cc8f | 23 | wait(1); |
Paxtel | 0:bb2c52d4cc8f | 24 | pantalla.clear_display_test(); |
Paxtel | 0:bb2c52d4cc8f | 25 | |
Paxtel | 0:bb2c52d4cc8f | 26 | |
Paxtel | 0:bb2c52d4cc8f | 27 | |
Paxtel | 0:bb2c52d4cc8f | 28 | while(1){ |
Paxtel | 0:bb2c52d4cc8f | 29 | Print_pantalla_tabla(led3); |
Paxtel | 0:bb2c52d4cc8f | 30 | wait(1); |
Paxtel | 0:bb2c52d4cc8f | 31 | Print_pantalla_tabla(led2); |
Paxtel | 0:bb2c52d4cc8f | 32 | wait(1); |
Paxtel | 0:bb2c52d4cc8f | 33 | Print_pantalla_tabla(led1); |
Paxtel | 0:bb2c52d4cc8f | 34 | wait(1); |
Paxtel | 0:bb2c52d4cc8f | 35 | |
Paxtel | 0:bb2c52d4cc8f | 36 | int i; |
Paxtel | 0:bb2c52d4cc8f | 37 | int j; |
Paxtel | 0:bb2c52d4cc8f | 38 | |
Paxtel | 0:bb2c52d4cc8f | 39 | while(1){ |
Paxtel | 0:bb2c52d4cc8f | 40 | for (i=0;i<8;i++) |
Paxtel | 0:bb2c52d4cc8f | 41 | personal[i]= 0; |
Paxtel | 0:bb2c52d4cc8f | 42 | for (j=0;j<8;j++) |
Paxtel | 0:bb2c52d4cc8f | 43 | for (i=0;i<8;i++){ |
Paxtel | 0:bb2c52d4cc8f | 44 | personal[i]= filas[j]; |
Paxtel | 0:bb2c52d4cc8f | 45 | Print_pantalla_tabla(personal); |
Paxtel | 0:bb2c52d4cc8f | 46 | wait(0.2); |
Paxtel | 0:bb2c52d4cc8f | 47 | } |
Paxtel | 0:bb2c52d4cc8f | 48 | |
Paxtel | 0:bb2c52d4cc8f | 49 | |
Paxtel | 0:bb2c52d4cc8f | 50 | } |
Paxtel | 0:bb2c52d4cc8f | 51 | } |
Paxtel | 0:bb2c52d4cc8f | 52 | |
Paxtel | 0:bb2c52d4cc8f | 53 | } |
Paxtel | 0:bb2c52d4cc8f | 54 | |
Paxtel | 0:bb2c52d4cc8f | 55 | |
Paxtel | 0:bb2c52d4cc8f | 56 | void Print_pantalla_tabla(unsigned char *pValor) |
Paxtel | 0:bb2c52d4cc8f | 57 | { |
Paxtel | 0:bb2c52d4cc8f | 58 | int i; |
Paxtel | 0:bb2c52d4cc8f | 59 | for (i =0;i<8;i++) |
Paxtel | 0:bb2c52d4cc8f | 60 | pantalla.write_digit(1,i+1,pValor[i]); |
Paxtel | 0:bb2c52d4cc8f | 61 | |
Paxtel | 0:bb2c52d4cc8f | 62 | } |