大彩串口屏接收,大宋表格填写等代码如下
#define DEV_LCD "uart5"
/* 事件控制块 */
static struct rt_event lcdevent; // 用于界面刷新时间通知
static rt_mutex_t lcd_mutex; // 屏幕显示互斥量
static rt_sem_t sem_lcd = RT_NULL; // 屏幕数据接收信号量
static struct rt_timer timer_lcd;
static uint8_t lcd_rx_buffer[64];
static uint8_t lcd_tx_buffer[64];
static rt_device_t dev_lcd;
static rt_uint16_t revc_bytes = 0;
static rt_uint16_t cur_page = 0; // 当前页面
extern struct rt_messagequeue WM; // WellMeasure 待测量油井消息队列
#define PAGE_FRESH_EVENT (1 << 3)
// slcd 接收回调函数 统计接受的字节数
rt_err_t slcd_recv_callback(rt_device_t dev, rt_size_t size)
{
revc_bytes++;
return RT_EOK;
}
static void timer_lcd_timeout(void *parameter)
{
static rt_uint16_t oldb = 0;
if (oldb != revc_bytes)
oldb = revc_bytes;
else if (revc_bytes != 0)
{
rt_sem_release(sem_lcd);
}
}
/***************************************************
LCD接收函数
参数:buff 待接收存储的缓存指针
time 接收等待时间 单位为一个tick时间
返回值: 接收到的字节数
****************************************************/
rt_uint16_t recv_from_slcd(rt_uint8_t *buff, rt_int32_t time)
{
rt_uint16_t rx_length = 0;
rt_err_t result;
extern void dump(char txrx, char hex[], uint16_t lenth);
result = rt_sem_take(sem_lcd, time);
if (result == -RT_ETIMEOUT)
{
return 0;
}
if (result == RT_EOK)
{
if (buff != RT_NULL)
{
rx_length = rt_device_read(dev_lcd, 0, buff, revc_bytes);
revc_bytes = 0;
}
}
dump(1, (char *)buff, rx_length);
return rx_length;
}
/****************************************************
lcd发送函数
参数:buff 待发送的数据指针
length 待发送的数据长度
返回值:无
****************************************************/
void send_to_slcd(rt_uint8_t *buff, rt_uint16_t length)
{
rt_mutex_take(lcd_mutex,RT_WAITING_FOREVER);
rt_device_write(dev_lcd, 0, buff, length);
rt_mutex_release(lcd_mutex);
}
void switch_screen(rt_uint16_t screen_id)
{
rt_uint8_t *p = &lcd_tx_buffer[0];
*p++ = 0xEE;
*p++ = 0xB1;
*p++ = 0x00;
*p++ = (screen_id & 0xFF00) >> 8;
*p++ = (screen_id & 0x00FF);
#ifdef FRAME_USE_CRC16
CRC16_CACL();
#endif
*p++ = 0xFF;
*p++ = 0xFC;
*p++ = 0xFF;
*p++ = 0xFF;
send_to_slcd(lcd_tx_buffer, p - lcd_tx_buffer);
}
// 写控件值
void write_text_to_lcd(rt_uint16_t screen_id, rt_uint16_t control_id, char *string)
{
rt_uint8_t *p = &lcd_tx_buffer[0];
*p++ = 0xEE;
*p++ = 0xB1;
*p++ = 0x10;
*p++ = (screen_id & 0xFF00) >> 8;
*p++ = (screen_id & 0x00FF);
*p++ = (control_id & 0xFF00) >> 8;
*p++ = (control_id & 0x00FF);
while (*string != '\0')
{
*p++ = *string++;
}
#ifdef FRAME_USE_CRC16
CRC16_CACL();
#endif
*p++ = 0xFF;
*p++ = 0xFC;
*p++ = 0xFF;
*p++ = 0xFF;
send_to_slcd(lcd_tx_buffer, p - lcd_tx_buffer);
}
// 表格填写
void write_table_to_lcd(rt_uint16_t screen_id, rt_uint16_t table_id, char *string)
{
rt_uint8_t *p = &lcd_tx_buffer[0];
*p++ = 0xEE;
*p++ = 0xB1;
*p++ = 0x52;
*p++ = (screen_id & 0xFF00) >> 8;
*p++ = (screen_id & 0x00FF);
*p++ = (table_id & 0xFF00) >> 8;
*p++ = (table_id & 0x00FF);
while (*string != '\0')
{
*p++ = *string++;
}
#ifdef FRAME_USE_CRC16
CRC16_CACL();
#endif
*p++ = 0xFF;
*p++ = 0xFC;
*p++ = 0xFF;
*p++ = 0xFF;
send_to_slcd(lcd_tx_buffer, p - lcd_tx_buffer);
}
// 表格填写
void write_table_insert_to_lcd(rt_uint16_t screen_id, rt_uint16_t table_id, rt_uint16_t insert_line, char *string)
{
rt_uint8_t *p = &lcd_tx_buffer[0];
*p++ = 0xEE;
*p++ = 0xB1;
*p++ = 0x59;
*p++ = (screen_id & 0xFF00) >> 8;
*p++ = (screen_id & 0x00FF);
*p++ = (table_id & 0xFF00) >> 8;
*p++ = (table_id & 0x00FF);
*p++ = (insert_line & 0xFF00) >> 8;
*p++ = (insert_line & 0x00FF);
while (*string != '\0')
{
*p++ = *string++;
}
#ifdef FRAME_USE_CRC16
CRC16_CACL();
#endif
*p++ = 0xFF;
*p++ = 0xFC;
*p++ = 0xFF;
*p++ = 0xFF;
send_to_slcd(lcd_tx_buffer, p - lcd_tx_buffer);
}
void table_clear(rt_uint16_t screen_id, rt_uint16_t table_id)
{
rt_uint8_t *p = &lcd_tx_buffer[0];
*p++ = 0xEE;
*p++ = 0xB1;
*p++ = 0x53;
*p++ = (screen_id & 0xFF00) >> 8;
*p++ = (screen_id & 0x00FF);
*p++ = (table_id & 0xFF00) >> 8;
*p++ = (table_id & 0x00FF);
#ifdef FRAME_USE_CRC16
CRC16_CACL();
#endif
*p++ = 0xFF;
*p++ = 0xFC;
*p++ = 0xFF;
*p++ = 0xFF;
send_to_slcd(lcd_tx_buffer, p - lcd_tx_buffer);
}
// 设置按键状态
void set_button_status(rt_uint16_t screen_id, rt_uint16_t table_id,rt_uint16_t status)
{
rt_uint8_t *p = &lcd_tx_buffer[0];
*p++ = 0xEE;
*p++ = 0xB1;
*p++ = 0x10;
*p++ = (screen_id & 0xFF00) >> 8;
*p++ = (screen_id & 0x00FF);
*p++ = (table_id & 0xFF00) >> 8;
*p++ = (table_id & 0x00FF);
if(status)
*p++ = 1;
else
*p++ = 0;
#ifdef FRAME_USE_CRC16
CRC16_CACL();
#endif
*p++ = 0xFF;
*p++ = 0xFC;
*p++ = 0xFF;
*p++ = 0xFF;
send_to_slcd(lcd_tx_buffer, p - lcd_tx_buffer);
}
// 设置按键状态
void hide_control(rt_uint16_t screen_id, rt_uint16_t table_id,rt_uint16_t status)
{
rt_uint8_t *p = &lcd_tx_buffer[0];
*p++ = 0xEE;
*p++ = 0xB1;
*p++ = 0x03;
*p++ = (screen_id & 0xFF00) >> 8;
*p++ = (screen_id & 0x00FF);
*p++ = (table_id & 0xFF00) >> 8;
*p++ = (table_id & 0x00FF);
if(status)
*p++ = 1; // show
else
*p++ = 0; // hide
#ifdef FRAME_USE_CRC16
CRC16_CACL();
#endif
*p++ = 0xFF;
*p++ = 0xFC;
*p++ = 0xFF;
*p++ = 0xFF;
send_to_slcd(lcd_tx_buffer, p - lcd_tx_buffer);
}
以上代码除了应用线序,大彩屏所有的控件驱动代码都整理出来了,用户可以直接复制,写入个人应用程序