Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
- Committer:
- SMART_CLEO
- Date:
- 2017-09-28
- Revision:
- 0:3f43ed494764
- Child:
- 1:93504aad8a05
File content as of revision 0:3f43ed494764:
#include "mbed.h"
#include "font_5x7.h"
struct UART_buf
{
uint8_t STA;
uint8_t MODE;
uint8_t CMD;
uint8_t LEN;
uint8_t DATA[32];
uint8_t END;
};
// I2C address
int DoT_ADDR = 0x71<<1;
I2C Dotmatrix(I2C_SDA, I2C_SCL);
char Data_BUF[17] = {0, 0 ,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
Serial SerialUART(PA_2, PA_3);
UART_buf RX_BUF;
void SerialUARTRX_ISR(void);
void data_write(char *data, int len);
void Command_Write(uint8_t com);
void Dotmatrix_init(void);
void char_data_write(char data);
int main() {
SerialUART.baud(115200);
SerialUART.attach(&SerialUARTRX_ISR);
Dotmatrix_init();
while(1)
{
}
}
void SerialUARTRX_ISR(void)
{
static uint8_t RX_count = 0, RX_Len = 32, RX_Status = 0;
uint8_t rx_da = SerialUART.getc();
switch(RX_Status)
{
case 0:
if(rx_da == 0x76)
{
RX_BUF.STA = rx_da;
RX_Status++;
}
break;
case 1:
RX_BUF.MODE = rx_da;
RX_Status++;
break;
case 2:
RX_BUF.CMD = rx_da;
RX_Status++;
break;
case 3:
RX_BUF.LEN = rx_da;
RX_Len = RX_BUF.LEN;
RX_Status++;
if(RX_Len == 0)
RX_Status++;
break;
case 4:
RX_BUF.DATA[RX_count] = rx_da;
RX_count++;
if(RX_count == RX_Len)
{
RX_Status++;
RX_count = 0;
RX_Len = 32;
}
break;
case 5:
if(rx_da == 0x3E)
{
RX_BUF.END = rx_da;
RX_Status = 0;
switch(RX_BUF.MODE)
{
case 0x01:
if(RX_BUF.CMD == 0x17)
{
char_data_write(RX_BUF.DATA[0]);
}
break;
}
}
break;
}
}
void data_write(char *data, int len)
{
data[0] = 0;
Dotmatrix.write(DoT_ADDR, data, len);
}
void Command_Write(char com)
{
Dotmatrix.write(DoT_ADDR, &com, 1);
}
void Dotmatrix_init(void)
{
// Internal System Clock enable
Command_Write((char)0x21);
// INT/ROW output pin Set -> ROW Driver output
Command_Write((char)0xA0);
// Dimming Set -> 15
Command_Write((char)0xEF);
// Blinking Set -> off
// Display Set -> on
Command_Write((char)0x81);
}
void char_data_write(char data)
{
uint8_t read_c, i, j, c_buff[8] = {0, 0, 0, 0, 0, 0, 0, 0};
for(i=0; i<5; i++)
{
read_c = font[data-0x20][i];
if(read_c)
{
for(j=0; j<8; j++)
{
if(read_c & (0x80 >> j))
{
c_buff[j] |= (0x01 << (i+1));
}
}
}
}
for(i=0; i<8; i++)
Data_BUF[i*2+1] = c_buff[i];
data_write(Data_BUF, 17);
}