RT-THREAD stm32大彩驱动代码

大彩串口屏接收,大宋表格填写等代码如下

#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);
}

以上代码除了应用线序,大彩屏所有的控件驱动代码都整理出来了,用户可以直接复制,写入个人应用程序

  • 9
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值