SMART CLEO Dotmartix

Committer:
SMART_CLEO
Date:
Thu Sep 28 02:12:40 2017 +0000
Revision:
0:4cab8e431853
SMART_CLEO

Who changed what in which revision?

UserRevisionLine numberNew contents of line
SMART_CLEO 0:4cab8e431853 1 #include "mbed.h"
SMART_CLEO 0:4cab8e431853 2 #include "font_5x7.h"
SMART_CLEO 0:4cab8e431853 3
SMART_CLEO 0:4cab8e431853 4 // I2C address
SMART_CLEO 0:4cab8e431853 5 int DoT_ADDR = 0x71<<1;
SMART_CLEO 0:4cab8e431853 6
SMART_CLEO 0:4cab8e431853 7 I2C Dotmatrix(I2C_SDA, I2C_SCL);
SMART_CLEO 0:4cab8e431853 8
SMART_CLEO 0:4cab8e431853 9 char Data_BUF[17] = {0, 0 ,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
SMART_CLEO 0:4cab8e431853 10
SMART_CLEO 0:4cab8e431853 11 void data_write(char *data, int len);
SMART_CLEO 0:4cab8e431853 12 void Command_Write(uint8_t com);
SMART_CLEO 0:4cab8e431853 13 void Dotmatrix_init(void);
SMART_CLEO 0:4cab8e431853 14 void char_data_write(char data);
SMART_CLEO 0:4cab8e431853 15
SMART_CLEO 0:4cab8e431853 16 int main()
SMART_CLEO 0:4cab8e431853 17 {
SMART_CLEO 0:4cab8e431853 18 uint8_t C_Data = 0x21;
SMART_CLEO 0:4cab8e431853 19 Dotmatrix_init();
SMART_CLEO 0:4cab8e431853 20 //data_write(Data_BUF, 17);
SMART_CLEO 0:4cab8e431853 21
SMART_CLEO 0:4cab8e431853 22 while(1){
SMART_CLEO 0:4cab8e431853 23 char_data_write(C_Data++);
SMART_CLEO 0:4cab8e431853 24 if(C_Data == 0x80)
SMART_CLEO 0:4cab8e431853 25 C_Data = 0x21;
SMART_CLEO 0:4cab8e431853 26 wait(0.8);
SMART_CLEO 0:4cab8e431853 27 }
SMART_CLEO 0:4cab8e431853 28 }
SMART_CLEO 0:4cab8e431853 29
SMART_CLEO 0:4cab8e431853 30 void data_write(char *data, int len)
SMART_CLEO 0:4cab8e431853 31 {
SMART_CLEO 0:4cab8e431853 32 data[0] = 0;
SMART_CLEO 0:4cab8e431853 33 Dotmatrix.write(DoT_ADDR, data, len);
SMART_CLEO 0:4cab8e431853 34 }
SMART_CLEO 0:4cab8e431853 35
SMART_CLEO 0:4cab8e431853 36 void Command_Write(char com)
SMART_CLEO 0:4cab8e431853 37 {
SMART_CLEO 0:4cab8e431853 38 Dotmatrix.write(DoT_ADDR, &com, 1);
SMART_CLEO 0:4cab8e431853 39 }
SMART_CLEO 0:4cab8e431853 40
SMART_CLEO 0:4cab8e431853 41 void Dotmatrix_init(void)
SMART_CLEO 0:4cab8e431853 42 {
SMART_CLEO 0:4cab8e431853 43 // Internal System Clock enable
SMART_CLEO 0:4cab8e431853 44 Command_Write((char)0x21);
SMART_CLEO 0:4cab8e431853 45 // INT/ROW output pin Set -> ROW Driver output
SMART_CLEO 0:4cab8e431853 46 Command_Write((char)0xA0);
SMART_CLEO 0:4cab8e431853 47 // Dimming Set -> 15
SMART_CLEO 0:4cab8e431853 48 Command_Write((char)0xEF);
SMART_CLEO 0:4cab8e431853 49 // Blinking Set -> off
SMART_CLEO 0:4cab8e431853 50 // Display Set -> on
SMART_CLEO 0:4cab8e431853 51 Command_Write((char)0x81);
SMART_CLEO 0:4cab8e431853 52 }
SMART_CLEO 0:4cab8e431853 53
SMART_CLEO 0:4cab8e431853 54 void char_data_write(char data)
SMART_CLEO 0:4cab8e431853 55 {
SMART_CLEO 0:4cab8e431853 56 uint8_t read_c, i, j, c_buff[8] = {0, 0, 0, 0, 0, 0, 0, 0};
SMART_CLEO 0:4cab8e431853 57 for(i=0; i<5; i++)
SMART_CLEO 0:4cab8e431853 58 {
SMART_CLEO 0:4cab8e431853 59 read_c = font[data-0x20][i];
SMART_CLEO 0:4cab8e431853 60 if(read_c)
SMART_CLEO 0:4cab8e431853 61 {
SMART_CLEO 0:4cab8e431853 62 for(j=0; j<8; j++)
SMART_CLEO 0:4cab8e431853 63 {
SMART_CLEO 0:4cab8e431853 64 if(read_c & (0x80 >> j))
SMART_CLEO 0:4cab8e431853 65 {
SMART_CLEO 0:4cab8e431853 66 c_buff[j] |= (0x01 << (i+1));
SMART_CLEO 0:4cab8e431853 67 }
SMART_CLEO 0:4cab8e431853 68 }
SMART_CLEO 0:4cab8e431853 69 }
SMART_CLEO 0:4cab8e431853 70 }
SMART_CLEO 0:4cab8e431853 71 for(i=0; i<8; i++)
SMART_CLEO 0:4cab8e431853 72 Data_BUF[i*2+1] = c_buff[i];
SMART_CLEO 0:4cab8e431853 73
SMART_CLEO 0:4cab8e431853 74 data_write(Data_BUF, 17);
SMART_CLEO 0:4cab8e431853 75 }