——Kutoka Jukwaa la Wasanidi Programu wa DWIN
Katika toleo hili, tunakuletea kesi ya chanzo huria iliyoshinda tuzo ya Jukwaa la Wasanidi Programu wa DWIN - chumba bora cha kilimo. Wahandisi walitekeleza skrini mahiri ya T5L ili kudhibiti mifumo ya kuongeza joto na kudhibiti halijoto ya feni kupitia itifaki ya Modbus. Ugavi wa umeme unaweza pia kubadilishwa ili kuiga kazi ya taa. Mfumo unaweza kukimbia kiotomatiki kulingana na vigezo vilivyowekwa kwenye skrini na kuhifadhi rekodi za historia ya makosa.
Onyesho la Nyenzo la 1.UI
![asvdfb (2)](https://ecdn6.globalso.com/upload/p/1355/source/2024-03/65f96ba08612736786.jpg)
![asvdfb (1)](https://ecdn6.globalso.com/upload/p/1355/source/2024-03/65f96ba210c7924337.jpg)
2.UI Design
1.C51 Muundo
Nambari kuu za kupata na kusasisha data kama vile halijoto, unyevunyevu na mwinuko kwenye kiolesura kikuu, na kutumia modbus rtu kudhibiti moduli za kudhibiti halijoto, injini, utambuzi wa kengele na mashine zingine za watumwa ni kama ifuatavyo.
Rejeleo kuu la msimbo wa kiolesura:
#pamoja na "main_win.h"
#pamoja na "modbus.h"
#pamoja na "sys_params.h"
#pamoja na "func_handler.h"
#pamoja na "uart2.h"
#pamoja na
#pamoja na
#fafanua TEMP_HUM_SLAVE_ADDR2
#fafanua TEMP_HUM_VAL_MAX_NUM 2
#fafanua ALERT_BIT_MAX_NUM 30
#fafanua ALERT_BYTE_NUM (ALERT_BIT_MAX_NUM/8+((ALERT_BIT_MAX_NUM%8)!=0))
#fafanua GET_ALERT_BIT(val, pos) ((val[pos/8]>>(pos%8))&0x01)
muundo wa typedef{
tarehe ya char [17];
u8 desc;
}TAHADHARI;
#fafanua ALERT_TABLE_LEN 20
tuli u8 btn_sta[MAIN_WIN_BTN_MAX_NUM] = {0};
tuli u8 btn_addr[MAIN_WIN_BTN_MAX_NUM] = {50, 51, 52, 69, 53, 54, 55, 70, 56, 57, 58, 59};
u16 kuu_win_val[MAIN_WIN_VAL_MAX_NUM];
u16 temp_hum_val[TEMP_HUM_VAL_MAX_NUM] = {0};
u16 date_val[MAIN_WIN_DATE_MAX_NUM] = {0};
u8 alert_val[ALERT_BYTE_NUM] = {0};
u8 old_alert_val[ALERT_BYTE_NUM] = {0};
Jedwali_la_tahadhari[ALERT_TABLE_LEN];
u16 alert_num = 0;
kidogo ni_main_win = 0;
utupu kuu_win_update()
{
}
batili kuu_win_disp_date()
{
u8 pekee;
len = sprintf(common_buf, "%u:%u", (u16)date_val[3], (u16)date_val[4]);
common_buf[len+1] = 0;
sys_write_vp(MAIN_WIN_DATE_VP, common_buf, len/2+2);
}
utupu kuu_win_process_alert()
{
u8 mimi;
kwa(i=0;i
{
ikiwa(GET_ALERT_BIT(valli_ya_ya_tahadhari, i))
endelea;
ikiwa(GET_ALERT_BIT(alert_val, i))
{
ikiwa(nambari_ya_tahadhari>=ALERT_TABLE_LEN)
alert_num = ALERT_TABLE_LEN-1;
alert_table[alert_num].desc = i+1;
sprintf(meza_ya_tahadhari[tarehe_ya_tahadhari], "%u/%u/%u %u:%u",
date_val[0], date_val[1], date_val[2], date_val[3], date_val[4]
);
nambari_ya_alert++;
}
}
memcpy(valli_ya_ya_ya_tahadhari, vali_ya_ya_tahadhari, saizi ya(vali_ya_ya_tahadhari));
}
utupu kuu_win_disp_alert()
{
u16 na;
na u16;
u16 pekee = 0;
common_buf[0] = 0;
kwa(i=0;i
{
val = 0;
ikiwa (i
{
val = alert_table.desc;
len += sprintf(common_buf+len, "%s\r\n", alert_table.date);
}
sys_write_vp(ALERT_WIN_DESC_START_VP+i, (u8*)&val, 1);
}
common_buf[len+1] = 0;
sys_write_vp(ALERT_WIN_DATE_VP, common_buf, len/2+2);
}
utupu kuu_win_init()
{
kuelea fixed_val;
u8 mimi;
ni_main_win = 1;
main_win_val[5] = (u16)(temp_hum_val[0]/10.0+0.5f);
main_win_val[6] = (u16)(temp_hum_val[1]/10.0+0.5f);
kwa(i=0;i
{
ikiwa(i==0)
endelea;
sys_write_vp(MAIN_WIN_WIND_SPEED_VP+MAIN_WIN_VAL_OFFSET*i, (u8*)&main_win_val, 1);
}
fixed_val = main_win_val[0]/WIND_SPEED_SCALE+FLOAT_FIX_VAL;
sys_write_vp(MAIN_WIN_WIND_SPEED_VP, (u8*)&fixed_val, 2);
}
batili_win_click_handler(u16 btn_val)
{
u8 index;
ikiwa(btn_val==0x0B)
{
main_win_disp_alert();
kurudi;
}
index = btn_val-1;
btn_sta[index] = !btn_sta[index];
ikiwa((index==3)||(index==7))
btn_sta[index] = 1;
modbus_write_bit(btn_addr[index], btn_sta[index]?0xFF00:0x0000);
btn_val = btn_sta[index];
sys_write_vp(MAIN_WIN_BTN_STA_START_VP+MAIN_WIN_BTN_STA_OFFSET* index, (u8*)&btn_val, 1);
ikiwa(index==9)
ni_main_win = 0;
vinginevyo if((index==3)||(index==7))
{
wakati(sys_get_touch_sta());
modbus_write_bit(btn_addr[index], 0x0000);
}
}
batili_win_msg_handler(u8 *msg,u16 msg_len)
{
u8 f_code = msg[MODBUS_RESPOND_POS_FUNC_CODE];
u8 data_len = ujumbe[MODBUS_RESPOND_POS_DATA_LEN];
u8 mimi;
u8 kukabiliana;
msg_len = msg_len;
ikiwa(!ni_kushinda_kuu)
kurudi;
ikiwa((f_code==MODBUS_FUNC_CODE_03)&(data_len==MAIN_WIN_VAL_MAX_NUM*2))
{
kukabiliana = MODBUS_RESPOND_POS_DATA;
kwa(i=0;i
{
main_win_val = SYS_GET_U16(msg[offset], msg[offset+1]);
kukabiliana += 2;
}
main_win_update();
}vinginevyo ikiwa((f_code==MODBUS_FUNC_CODE_01)&&(data_len==ALERT_BYTE_NUM))
{
kukabiliana = MODBUS_RESPOND_POS_DATA;
kwa(i=0;i
{
alert_val = msg[offset];
kukabiliana ++;
}
main_win_process_alert();
}vinginevyo kama((f_code==MODBUS_FUNC_CODE_03)&&(data_len==TEMP_HUM_VAL_MAX_NUM*2))
{
kukabiliana = MODBUS_RESPOND_POS_DATA;
kwa(i=0;i
{
temp_hum_val = SYS_GET_U16(msg[offset], msg[offset+1]);
kukabiliana += 2;
modbus_write_word(5+i, temp_hum_val);
}
main_win_update();
}vinginevyo kama((f_code==MODBUS_FUNC_CODE_03)&&(data_len==MAIN_WIN_DATE_MAX_NUM*2))
{
kukabiliana = MODBUS_RESPOND_POS_DATA;
kwa(i=0;i
{
date_val = SYS_GET_U16(msg[offset], msg[offset+1]);
kukabiliana += 2;
}
kuu_win_disp_tarehe();
}
}
utupu main_win_read_temp_hum()
{
u8 old_slave_addr = SLAVE_ADDR;
sys_params.user_config[5] = TEMP_HUM_SLAVE_ADDR;
modbus_read_words(0, TEMP_HUM_VAL_MAX_NUM);
sys_params.user_config[5] = old_slave_addr;//Rejesha
}
utupu main_win_handler()
{
bendera tuli ya u8 = 0;
ikiwa(ni_kushinda_kuu)
{
ikiwa(tahadhari_kusoma_kipindi==ALERT_READ_PERIOD)
{
alert_read_period = 0;
modbus_read_bits(510, ALERT_BIT_MAX_NUM);
kurudi;
}
ikiwa(date_update_period==DATE_UPDATE_PERIOD)
{
tarehe_update_period = 0;
modbus_read_words(180, MAIN_WIN_DATE_MAX_NUM);
kurudi;
}
bendera = !bendera;
ikiwa (bendera)
modbus_read_words(0, MAIN_WIN_VAL_MAX_NUM);
mwingine
main_win_read_temp_hum();
}
}
rejeleo la nambari ya modbus rtu:
#pamoja na "modbus.h"
#pamoja na "crc16.h"
#pamoja na "sys_params.h"
#fafanua UART_INNCLUDE "uart2.h"
#fafanua UART_INIT uart2_init
#fafanua UART_TUMA_BYTES uart2_tuma_baiti
#fafanua UART_BAUD 9600
#fafanua MODBUS_RECV_TIMEOUT (u8)(35000.0f/UART_BAUD+2)
#fafanua MODBUS_SEND_INTERVAL 150
#pamoja na UART_INNCLUDE
biti tuli ni_modbus_recv_complete = 0;
tuli u8 modbus_recv_buff[270];
tuli u16 modbus_recv_len = 0;//Jumla ya urefu wa baiti zilizokubaliwa
tuli u8 modbus_recv_timeout = 0;//Kubali muda wa kufurika
tuli u16 modbus_send_interval = 0;
MODBUS_PACKET pakiti;
utupu modbus_init()
{
UART_INIT(UART_BAUD);
}
modbus_send_bytes batili (u8 *baiti, u16 len)
{
UART_SEND_BYTES(baiti,len);
}
utupu modbus_recv_byte(u8 byte)
{
ikiwa(imekamilika_modbus_recv_imekamilika)
kurudi;
if(modbus_recv_len
modbus_recv_buff[modbus_recv_len++] = byte;
}
utupu modbus_check_recv_timeout()
{
ikiwa(modbus_recv_timeout)
{
modbus_recv_timeout--;
ikiwa(modbus_recv_timeout==0)
{
is_modbus_recv_complete = 1;
}
}
}
u8 modbus_send_packet(u8 *pakiti)
{
u16 pekee;
u16 crc;
u8 func_code = pakiti[1];
wakati(modbus_send_interval);
ikiwa(func_code==MODBUS_FUNC_CODE_10)
{
((MODBUS_10_PACKET*) pakiti)->byte_num = ((MODBUS_10_PACKET*) pakiti)->neno_num*2;
len = 9+((MODBUS_10_PACKET*) pakiti)->byte_num;
}vinginevyo kama(func_code==MODBUS_FUNC_CODE_0F)
{
len = ((MODBUS_0F_PACKET*) pakiti)->bit_num;
((MODBUS_0F_PACKET*) pakiti)->byte_num = len/8+(len%8?1:0);
len = 9+((MODBUS_0F_PACKET*) pakiti)->byte_num;
}mwingine
{
len = sizeof(MODBUS_PACKET);
}
crc = crc16(pakiti,len-2);
pakiti[len-2] = (u8)(crc>>8);
pakiti[len-1] = (u8)crc;
modbus_send_bytes(pakiti,len);
modbus_send_interval = MODBUS_SEND_INTERVAL;
kurudi 0;//Mafanikio
}
extern void modbus_msg_handler(u8 *msg,u16 msg_len);
utupu modbus_handler()
{
u16 crc;
ikiwa(!is_modbus_recv_complete)
kurudi;
//Angalia thamani ya crc
crc = ((u16)modbus_recv_buff[modbus_recv_len-2]
if(crc16(modbus_recv_buff,modbus_recv_len-2)==crc)
{
modbus_msg_handler(modbus_recv_buff,modbus_recv_len);
}
modbus_recv_len = 0;
is_modbus_recv_complete = 0;
}
u8 modbus_send_fcode(u8 fcode, u16 addr, u16 len)
{
packet.slave_addr = SLAVE_ADDR;
pakiti.func_code = fcode;//Msimbo wa kazi
packet.start_addr = addr;//Anwani
pakiti.data_len = len;//Thamani imeandikwa
len = modbus_send_packet((u8*)&packet);
kurudi len;
}
Muda wa kutuma: Jan-12-2024