cualquier cosa

Dependencies:   mbed

Fork of 00_LAB_matrix8x8_SPI by ferney alberto beltran molina

Committer:
fabeltranm
Date:
Tue Sep 04 21:09:27 2018 +0000
Revision:
6:9ef1d33ed469
Parent:
3:4a8de2f71ed0
ok; ;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
fabeltranm 0:61199d9d0aed 1
fabeltranm 0:61199d9d0aed 2 #include "mbed.h"
fabeltranm 0:61199d9d0aed 3 //#include "max7219.h"
fabeltranm 0:61199d9d0aed 4
fabeltranm 0:61199d9d0aed 5 // ***************************************************************************
fabeltranm 0:61199d9d0aed 6 // option 1 : use SPI
fabeltranm 0:61199d9d0aed 7 // ***************************************************************************
fabeltranm 0:61199d9d0aed 8 SPI deviceM(PB_15, PB_14, PB_13);
fabeltranm 0:61199d9d0aed 9 DigitalOut ssel (PB_12);
fabeltranm 0:61199d9d0aed 10
fabeltranm 0:61199d9d0aed 11 #define uint8_t unsigned char
fabeltranm 6:9ef1d33ed469 12 uint8_t dat_matrix[8]={0,0,0,0,0,0,0,0};
fabeltranm 1:b732136485e0 13
fabeltranm 0:61199d9d0aed 14
fabeltranm 0:61199d9d0aed 15 void sendSPI(uint8_t d1, uint8_t d2)
fabeltranm 0:61199d9d0aed 16 {
fabeltranm 0:61199d9d0aed 17 deviceM.unlock();
fabeltranm 0:61199d9d0aed 18 ssel=0;
fabeltranm 0:61199d9d0aed 19 deviceM.write(d1);
fabeltranm 0:61199d9d0aed 20 deviceM.write(d2);
fabeltranm 0:61199d9d0aed 21 ssel=1;
fabeltranm 0:61199d9d0aed 22 deviceM.lock();
fabeltranm 0:61199d9d0aed 23 };
fabeltranm 0:61199d9d0aed 24
fabeltranm 0:61199d9d0aed 25
fabeltranm 0:61199d9d0aed 26 void printMatrix(uint8_t* vC)
fabeltranm 0:61199d9d0aed 27
fabeltranm 0:61199d9d0aed 28 {
fabeltranm 0:61199d9d0aed 29 uint8_t i =0;
fabeltranm 0:61199d9d0aed 30 for (i=1;i<9;i++){
fabeltranm 6:9ef1d33ed469 31 sendSPI(i,*(vC+i-1));
fabeltranm 0:61199d9d0aed 32 }
fabeltranm 0:61199d9d0aed 33
fabeltranm 0:61199d9d0aed 34 };
fabeltranm 2:414129d953dd 35
fabeltranm 3:4a8de2f71ed0 36 void clr_vcol()
fabeltranm 2:414129d953dd 37 {
fabeltranm 3:4a8de2f71ed0 38 for (int i=0; i<8;i++){
fabeltranm 6:9ef1d33ed469 39 dat_matrix[i]=0;
fabeltranm 2:414129d953dd 40 }
fabeltranm 0:61199d9d0aed 41
fabeltranm 2:414129d953dd 42 }
fabeltranm 2:414129d953dd 43
fabeltranm 2:414129d953dd 44 void print_Snake2()
fabeltranm 2:414129d953dd 45 {
fabeltranm 2:414129d953dd 46
fabeltranm 2:414129d953dd 47 int j, i;
fabeltranm 2:414129d953dd 48 //reset
fabeltranm 3:4a8de2f71ed0 49
fabeltranm 2:414129d953dd 50 for (j=0; j<8;j++){
fabeltranm 3:4a8de2f71ed0 51 clr_vcol();
fabeltranm 3:4a8de2f71ed0 52 if(j % 2 == 0)
fabeltranm 6:9ef1d33ed469 53 dat_matrix[j]=1;
fabeltranm 3:4a8de2f71ed0 54 else
fabeltranm 6:9ef1d33ed469 55 dat_matrix[j]=0b10000000;
fabeltranm 3:4a8de2f71ed0 56
fabeltranm 2:414129d953dd 57 for (i=0; i<8;i++){
fabeltranm 2:414129d953dd 58 if(j % 2 == 0){
fabeltranm 6:9ef1d33ed469 59 dat_matrix[j]=3<<i;
fabeltranm 2:414129d953dd 60 }
fabeltranm 2:414129d953dd 61 else{
fabeltranm 6:9ef1d33ed469 62 dat_matrix[j]=0b1100000000>>i;
fabeltranm 2:414129d953dd 63 }
fabeltranm 6:9ef1d33ed469 64 printMatrix(dat_matrix);
fabeltranm 6:9ef1d33ed469 65 wait_ms(50);
fabeltranm 2:414129d953dd 66 }
fabeltranm 2:414129d953dd 67 }
fabeltranm 2:414129d953dd 68 }
fabeltranm 2:414129d953dd 69
fabeltranm 1:b732136485e0 70 void print_Snake()
fabeltranm 1:b732136485e0 71 {
fabeltranm 2:414129d953dd 72
fabeltranm 2:414129d953dd 73 uint8_t vt1[8]={1,3,7,0xf,0x1f,0x3f, 0x7f,0xff};
fabeltranm 2:414129d953dd 74 uint8_t vt2[8]={0b10000000,0b11000000,0b11100000,0b11110000,0b11111000,0b11111100,0b11111110,0b11111111};
fabeltranm 0:61199d9d0aed 75
fabeltranm 2:414129d953dd 76
fabeltranm 1:b732136485e0 77 int j, i;
fabeltranm 2:414129d953dd 78 //reset
fabeltranm 3:4a8de2f71ed0 79 clr_vcol();
fabeltranm 1:b732136485e0 80 for (j=0; j<8;j++){
fabeltranm 1:b732136485e0 81 for (i=0; i<8;i++){
fabeltranm 2:414129d953dd 82 if(j % 2 == 0){
fabeltranm 6:9ef1d33ed469 83 dat_matrix[j]=vt1[i];
fabeltranm 2:414129d953dd 84 }else{
fabeltranm 6:9ef1d33ed469 85 dat_matrix[j]=vt2[i];
fabeltranm 2:414129d953dd 86 }
fabeltranm 6:9ef1d33ed469 87 printMatrix(dat_matrix);
fabeltranm 6:9ef1d33ed469 88 wait_ms(50);
fabeltranm 1:b732136485e0 89 }
fabeltranm 1:b732136485e0 90 }
fabeltranm 1:b732136485e0 91 }
fabeltranm 0:61199d9d0aed 92 int main() {
fabeltranm 1:b732136485e0 93 uint8_t vcol[8]={0,0,0,0,0,0,0,0};
fabeltranm 0:61199d9d0aed 94 sendSPI(0x0c,1);
fabeltranm 6:9ef1d33ed469 95 sendSPI(0x0b,7);
fabeltranm 0:61199d9d0aed 96 sendSPI(0x0F,1);
fabeltranm 6:9ef1d33ed469 97 wait (0.9);
fabeltranm 0:61199d9d0aed 98 sendSPI(0x0f,0);
fabeltranm 6:9ef1d33ed469 99
fabeltranm 6:9ef1d33ed469 100 wait (0.9);
fabeltranm 0:61199d9d0aed 101 int i =0;
fabeltranm 0:61199d9d0aed 102 while(1){
fabeltranm 1:b732136485e0 103 print_Snake();
fabeltranm 6:9ef1d33ed469 104 print_Snake2();
fabeltranm 0:61199d9d0aed 105 }
fabeltranm 0:61199d9d0aed 106 }
fabeltranm 0:61199d9d0aed 107 // ***************************************************************************
fabeltranm 0:61199d9d0aed 108 // option two: use maz7219 library
fabeltranm 0:61199d9d0aed 109
fabeltranm 0:61199d9d0aed 110 // ***************************************************************************
fabeltranm 0:61199d9d0aed 111 /*
fabeltranm 0:61199d9d0aed 112 Max7219 deviceM(PB_15, PB_14, PB_13, PB_12);
fabeltranm 0:61199d9d0aed 113
fabeltranm 0:61199d9d0aed 114
fabeltranm 0:61199d9d0aed 115 int main() {
fabeltranm 0:61199d9d0aed 116
fabeltranm 0:61199d9d0aed 117 max7219_configuration_t cfg = {
fabeltranm 0:61199d9d0aed 118 .device_number = 1,
fabeltranm 0:61199d9d0aed 119 .decode_mode = 0,
fabeltranm 0:61199d9d0aed 120 .intensity = Max7219::MAX7219_INTENSITY_8,
fabeltranm 0:61199d9d0aed 121 .scan_limit = Max7219::MAX7219_SCAN_8
fabeltranm 0:61199d9d0aed 122 };
fabeltranm 0:61199d9d0aed 123
fabeltranm 0:61199d9d0aed 124 deviceM.init_device(cfg);
fabeltranm 0:61199d9d0aed 125
fabeltranm 0:61199d9d0aed 126 deviceM.enable_device(1);
fabeltranm 0:61199d9d0aed 127
fabeltranm 0:61199d9d0aed 128 deviceM.set_display_test();
fabeltranm 0:61199d9d0aed 129 wait(1);
fabeltranm 0:61199d9d0aed 130 deviceM.clear_display_test();
fabeltranm 0:61199d9d0aed 131 wait(1);
fabeltranm 0:61199d9d0aed 132
fabeltranm 0:61199d9d0aed 133 while(1){
fabeltranm 0:61199d9d0aed 134 deviceM.write_digit(1,8,0b11111111);
fabeltranm 0:61199d9d0aed 135 deviceM.write_digit(1,1,0b01010101);
fabeltranm 0:61199d9d0aed 136 deviceM.write_digit(1,2,0b10101010);
fabeltranm 0:61199d9d0aed 137 deviceM.write_digit(1,3,0b01010101);
fabeltranm 0:61199d9d0aed 138 deviceM.write_digit(1,4,0b10101010);
fabeltranm 0:61199d9d0aed 139 deviceM.write_digit(1,5,0b01010101);
fabeltranm 0:61199d9d0aed 140 deviceM.write_digit(1,6,0b10101010);
fabeltranm 0:61199d9d0aed 141 deviceM.write_digit(1,7,0b01010101);
fabeltranm 0:61199d9d0aed 142 }
fabeltranm 0:61199d9d0aed 143 }
fabeltranm 0:61199d9d0aed 144 */
fabeltranm 0:61199d9d0aed 145