——来自迪文开发者论坛
本期为大家推送迪文开发者论坛获奖开源案例——安卓与迪文屏的无线交互应用。工程师采用T5L智能屏,通过串口2与蓝牙模块通讯,实现与安卓手机APP进行数据交互。该方案支持迪文屏与安卓手机无延时数据收发、数据回显、多设备通信、导出和导入文件,还支持ASCII码、Char、GBK、UNICODE等多种编码格式,更有意思的是实现了16*16LED点阵广告屏的功能,让我们一睹为快!
方案框架 方案由T5L智能屏、HC-05或HC-06蓝牙模块、安卓手机构成。T5L智能屏通过串口2与蓝牙模块通讯,实现屏幕与安卓手机的数据交互。
UI素材展示
C51工程设计
(1)串口2与蓝牙通讯的代码参考如下:
#if(1)
#define MODBUS_RECV_TIMEOUT 50
static bit is_modbus_recv_complete = 0;
static u8 modbus_recv_buff[1024];
static u16 modbus_recv_len = 0;
static u8 modbus_recv_timeout = 0;
void modbus_recv_byte(u8 byte)
{
if(is_modbus_recv_complete)
return;
if(modbus_recv_len
modbus_recv_buff[modbus_recv_len++] = byte;
modbus_recv_timeout = MODBUS_RECV_TIMEOUT;
}
void modbus_check_recv_timeout()
{
if(modbus_recv_timeout)
{
modbus_recv_timeout--;
if(modbus_recv_timeout==0)
{
is_modbus_recv_complete = 1;
}
}
}
void uart2_isr() interrupt 4
{
if(RI0)
{
RI0 = 0;
modbus_recv_byte(SBUF0);
}
}
#endif
void uart2_init(u32 baud)
{
MUX_SEL |= 0x40;
P0MDOUT &= 0xCF;
P0MDOUT |= 0x10;
ADCON = 0x80;
SCON0 = 0x50;
PCON &= 0x7F;
baud = 1024-(u16)(3225600.0f/baud);
SREL0H = (baud>>8)&0xff;
SREL0L = baud&0xff;
#if(1)
ES0 = 1;
EA = 1;
#else
ES0 = 0;
#endif
}
void uart2_send_byte(u8 byte)
{
ES0 = 0;
SBUF0 = byte;
while(!TI0);
TI0 = 0;
#if(1)
ES0 = 1;
#endif
}
void uart2_send_bytes(u8 *bytes,u16 len)
{
u16 i;
ES0 = 0;
for(i=0;i
{
SBUF0 = bytes;
while(!TI0);
TI0 = 0;
}
#if(1)
ES0 = 1;
#endif
}
char putchar(char c)
{
uart2_send_byte(c);
return c;
}
(2)给安卓APP发送数据的部分代码如下:
u8 buff[200];
void get_str(u8 *val,u8 len)
{
u8 i; for(i=0;i
{
if(val==0xff)
{
val = 0x00;
val[i+1] = 0x00;
return;
}
}
}
void start_win_btn_click_handler(u16 btn_val)
{
if(btn_val==0x01)
{
sys_read_vp(0x2100, buff, 50);
get_str(buff,100);
uart2_send_bytes(buff, strlen(buff));
}
}
(3)接收安卓APP数据的部分代码如下:void uart2_handler()
{
if(is_modbus_recv_complete)
{
if(modbus_recv_len==33)
{
disp_16x16_char(modbus_recv_buff+1);
}else
{
modbus_recv_buff[modbus_recv_len++] = 0;
modbus_recv_buff[modbus_recv_len++] = 0;
sys_write_vp(0x2000, modbus_recv_buff, modbus_recv_len/2+2);
}
modbus_recv_len = 0;
is_modbus_recv_complete = 0;
}
}(4)16*16点阵屏显示的部分代码如下:void disp_16x16_char(u8 *buff)
{
u8 i,j;
u16 val;
u16 pos = 0; for(i=0;i<32;i++)
{
j = 8;
while(j--)
{
val = (buff>>j)&0x01;
sys_write_vp(0x3000+pos, (u8*)&val, 1);
pos++;
}
}
}
全部0条评论
快来发表一下你的评论吧 !