本項(xiàng)目是基于啟明6M5開(kāi)發(fā)板設(shè)計(jì)一個(gè)門(mén)鎖系統(tǒng),通過(guò)板載ESP8266網(wǎng)絡(luò)將驗(yàn)證碼發(fā)送至云端,用戶通過(guò)手機(jī)上接受到的驗(yàn)證碼打開(kāi)門(mén)鎖。項(xiàng)目功能演示如下:
一 硬件設(shè)計(jì)
拓展板原理圖:

繪制拓展板時(shí)計(jì)劃使用到液晶屏,攝像頭和指紋模塊,揚(yáng)聲器等外設(shè),所以繪制PCB時(shí)都加上去了,改了兩次板后依舊還有些硬件問(wèn)題沒(méi)解決,加上軟件沒(méi)調(diào)好,目前只能通過(guò)使用觸摸屏來(lái)驅(qū)動(dòng)舵機(jī)。圖中的GD32f103芯片打算作為攝像頭OV7670和液晶屏的中轉(zhuǎn),由于我使用的OV7670不帶緩存,故打算用GD32將16位的圖像數(shù)據(jù)通過(guò)8080時(shí)序直接傳輸給LCD,目前還沒(méi)調(diào)通該部分。
二 軟件設(shè)計(jì)
該系統(tǒng)中主要使用到了timer控制舵機(jī)完成開(kāi)門(mén)和及時(shí)關(guān)門(mén)的操作,使用RNG寄存器實(shí)現(xiàn)得到隨機(jī)的開(kāi)鎖密碼,通過(guò)ESP8266傳輸給手機(jī)設(shè)備,使用RTC更新當(dāng)前時(shí)間。

(1)ESP8266
該模塊使用Arduino軟件進(jìn)行編程,主要功能為獲取時(shí)間和MQTT協(xié)議通訊,具體代碼如下:
上下滑動(dòng)查看完整內(nèi)容
左右滑動(dòng)即可查看完整代碼
#include#include #include #include #include const char *ssid = "CMCC-416";// const char *password = "12345678";// const char* mqtt_server = "114.55.65.118";//MQTT服務(wù)器地址 char msg[200]; int msg_ind=0; WiFiUDP ntpUDP; NTPClient timeClient(ntpUDP, "ntp1.aliyun.com", 60*60*8, 30*60*1000); WiFiClient espClient; PubSubClient client(espClient); void setup(){ Serial.begin(115200); WiFi.begin(ssid, password); while ( WiFi.status() != WL_CONNECTED ) { delay ( 500 ); Serial.print ( "." ); } client.setServer(mqtt_server, 1883);//設(shè)置MQTT服務(wù)器和端口號(hào) client.setCallback(callback); //設(shè)置MQTT回傳函數(shù) timeClient.begin(); while (!client.connect("ESP8266Client")) { Serial.print ( "-" ); delay ( 500 ); }//以ESP8266Client身份連接MQTT服務(wù)器 Serial.print ("MQTTsuccess" ); client.subscribe("RA6M5/1"); } void callback(char* topic, byte* payload, unsigned int length) { if (strstr((char*)payload,(char*)"askInfo")!=NULL)//從單片機(jī)中獲取當(dāng)前信息 { Serial.print("ANDROID_ASKINFO "); } } void loop() { client.loop();//循環(huán)調(diào)用回傳函數(shù),當(dāng)訂閱的主題有新消息時(shí)能馬上進(jìn)入callback函數(shù) while(Serial.available()>0)//讀取串口 { char recvData = Serial.read(); msg[msg_ind++] = recvData;//逐個(gè)字符寫(xiě)入串口接收緩存區(qū) delay(100); if (recvData==' '){ // Serial.print("Time:"); // Serial.print(msg); if (strstr(msg,(char*)"{"))//當(dāng)串口接受的最后一個(gè)字符是' '結(jié)尾時(shí),對(duì)所有緩存區(qū)域進(jìn)行處理 { if (client.connect("ESP8266Client")) {//以ESP8266Client身份連接MQTT服務(wù)器 client.publish("RA6M5/2", msg,msg_ind-1); //將緩存區(qū)數(shù)據(jù)以RA6M5/2主題發(fā)布 } msg_ind=0;//刷新串口接收緩存 } else if (strstr(msg,(char*)"GETTIME")){ timeClient.update(); //獲取時(shí)間戳 //unsigned long epochTime = timeClient.getFormattedTime(); Serial.print("Time:"); Serial.println(timeClient.getEpochTime()); msg_ind=0;//刷新串口接收緩存 } else if (strstr(msg,(char*)"WIFISTATE")){ if ( WiFi.status() == WL_CONNECTED ) { int rss=WiFi.RSSI(); if (rss<=0&&rss>=-50) Serial.println ( "WIFI:3" ); else if (rss<=-50&&rss>=-70) Serial.println ( "WIFI:2" ); else if (rss<=-70&&rss>=-80) Serial.println ( "WIFI:1" ); else if (rss<=-80&&rss>=-100) Serial.println ( "WIFI:0" ); }else{ Serial.println ( "WIFI:No" ); } } } } }
(2)上位機(jī)部分
該部分使用Android Studio編寫(xiě),主要代碼如下:
上下滑動(dòng)查看完整內(nèi)容
左右滑動(dòng)即可查看完整代碼
public class MainActivity extends AppCompatActivity {
private static IntentFilter action;
RecyclerView recycler;
private final String payloadJson1="{"ParkingState":1}";
final int POST_DEVICE_PROPERTIES_SUCCESS = 1002;
final int POST_DEVICE_PROPERTIES_ERROR = 1003;
final int UPDATE_UI = 1004;
private MqttClient mqttClient=null;
private String responseBody = "";
private static final String TAG =MainActivity.class.getSimpleName();
private ArrayList datas = new ArrayList<>();
private String temper_str="未知";
private String humdity_str="未知";
private String passwd_str="未知";
private dataBean bean = new dataBean();
MyAdapter adapter;
private Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case POST_DEVICE_PROPERTIES_SUCCESS:
showToast("發(fā)送數(shù)據(jù)成功");
break;
case POST_DEVICE_PROPERTIES_ERROR:
showToast("post數(shù)據(jù)失敗");
break;
case UPDATE_UI:
SimpleDateFormat formatter = new SimpleDateFormat("yyyy.MM.dd
HHss");
Date curDate = new Date(System.currentTimeMillis());
String str_time = formatter.format(curDate);
datas.clear();
bean = new dataBean("濕度",humdity_str,str_time,getResources().getDrawable(R.drawable.ic_humdity, null));
datas.add(bean);
bean = new dataBean("溫度",temper_str,str_time,getResources().getDrawable(R.drawable.ic_temperature, null));
datas.add(bean);
bean = new dataBean("驗(yàn)證碼",passwd_str,str_time,getResources().getDrawable(R.drawable.ic_temperature, null));
datas.add(bean);
adapter.notifyDataSetChanged();
break;
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
recycler = findViewById(R.id.recyclerView);
RefreshLayout refreshLayout = (RefreshLayout) findViewById(R.id.refreshLayout);
refreshLayout.setRefreshHeader(new ClassicsHeader(this));
refreshLayout.setRefreshFooter(new ClassicsFooter(this));
refreshLayout.setOnRefreshListener(new OnRefreshListener() {
@Override
public void onRefresh(RefreshLayout refreshlayout) {
refreshlayout.finishRefresh(2000/*,false*/);//傳入false表示刷新失敗
mHandler.postDelayed(() -> postDeviceProperties1(), 1000);
}
});
refreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {
@Override
public void onLoadMore(RefreshLayout refreshlayout) {
refreshlayout.finishLoadMore(2000/*,false*/);//傳入false表示加載失敗
mHandler.postDelayed(() -> postDeviceProperties1(), 1000);
}
});
new Thread(() -> initMQTTClient()).start();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy.MM.dd
HHss");
Date curDate = new Date(System.currentTimeMillis());
String str_time = formatter.format(curDate);
bean = new dataBean("濕度",temper_str,str_time,getResources().getDrawable(R.drawable.ic_humdity, null));
datas.add(bean);
bean = new dataBean("溫度",humdity_str,str_time,getResources().getDrawable(R.drawable.ic_temperature, null));
datas.add(bean);
bean = new dataBean("驗(yàn)證碼",passwd_str,str_time,getResources().getDrawable(R.drawable.ic_temperature, null));
datas.add(bean);
//適配器
adapter = new MyAdapter(this, datas);
//布局
LinearLayoutManager manager = new LinearLayoutManager(this);
//設(shè)置布局
recycler.setLayoutManager(manager);
//設(shè)置動(dòng)畫(huà)
recycler.setItemAnimator(new DefaultItemAnimator());
//設(shè)置適配器
recycler.setAdapter(adapter);
}
private void initMQTTClient() {
try {
// cn-shanghai
String targetServer ="tcp://114.55.65.118:1883";
String mqttclientId = "RA6M5_Android1";
String mqttUsername = "RA6M5_Android_User1";
String mqttPassword = "123456";
connectMqtt(targetServer, mqttclientId, mqttUsername, mqttPassword);
} catch (Exception e) {
e.printStackTrace();
responseBody = e.getMessage();
mHandler.sendEmptyMessage(POST_DEVICE_PROPERTIES_ERROR);
}
}
public void connectMqtt(String url, String clientId, String mqttUsername, String mqttPassword) throws Exception {
MemoryPersistence persistence = new MemoryPersistence();
mqttClient = new MqttClient(url, clientId, persistence);
MqttConnectOptions connOpts = new MqttConnectOptions();
// MQTT 3.1.1
connOpts.setMqttVersion(4);
connOpts.setAutomaticReconnect(true);
connOpts.setCleanSession(true);
connOpts.setUserName(mqttUsername);
connOpts.setPassword(mqttPassword.toCharArray());
connOpts.setKeepAliveInterval(60);
mqttClient.connect(connOpts);
mqttClient.setCallback(new MqttCallback() {
@Override
public void connectionLost(Throwable cause) {
Log.e(TAG, "cause ---> " + cause);
}
@Override
public void messageArrived(String topic, MqttMessage message) throws Exception {
Log.e(TAG, "topic ---> " + topic + " message--->" + message);
if (topic.equals("RA6M5/2")){
String mqtt_str = new String(message.getPayload());
JSONObject json = new JSONObject(mqtt_str);
temper_str = json.getString("temper");
humdity_str = json.getString("humdity");
passwd_str = json.getString("passwd");
mHandler.sendEmptyMessage(UPDATE_UI);
Log.e(TAG, "update--finish ");
}
}
@Override
public void deliveryComplete(IMqttDeliveryToken token) {
Log.e(TAG, "token ---> " + token);
}
});
mqttClient.subscribe("RA6M5/2");
Log.d(TAG, "connected " + url);
}
private void showToast(String msg) {
Toast.makeText(MainActivity.this, msg,Toast.LENGTH_SHORT).show();
}
private void postDeviceProperties1() {
try {
Random random = new Random();
//上報(bào)數(shù)據(jù)
String payload = "askInfo";
responseBody = payload;
MqttMessage message = new MqttMessage(payload.getBytes("utf-8"));
message.setQos(1);
String pubTopic = "RA6M5/1";
mqttClient.publish(pubTopic, message);
Log.d(TAG, "publish topic=" + pubTopic + ",payload=" + payload);
mHandler.sendEmptyMessage(POST_DEVICE_PROPERTIES_SUCCESS);
} catch (Exception e) {
e.printStackTrace();
responseBody = e.getMessage();
mHandler.sendEmptyMessage(POST_DEVICE_PROPERTIES_ERROR);
Log.e(TAG, "postDeviceProperties error " + e.getMessage(), e);
}
}
}
(3)單片機(jī)部分
該部分使用Android Studio編寫(xiě),主要代碼如下:
1、屏幕顯示部分
上下滑動(dòng)查看完整內(nèi)容
左右滑動(dòng)即可查看完整代碼
void LCD_thread_entry(void * pvParameters) { uint32_t lValueToRece; uint16_t pos_x=0,pos_y=0; EventBits_t Eventbits; BaseType_t err = pdFALSE; unsigned char touch_vals[4]; unsigned char touch_tmp=0; xEventGroupClearBits(g_new_event_LCD,0x7); xEventGroupSetBits(g_new_event_LCD,0x1); FSP_PARAMETER_NOT_USED(pvParameters); R_IOPORT_Open(&g_ioport_ctrl, g_ioport.p_cfg); LCD_Init(); WIFI_Init(); PWM_Init(); R_GPT_Open(&g_timer0_ctrl, &g_timer0_cfg); R_GPT_Start(&g_timer0_ctrl); R_GPT_Disable(&g_timer0_ctrl); LCD_Clean(BLUE);//BLUE Draw_Square_Back(18,180,100,56,BRRED,LIGHTBLUE,array_renlian); Draw_Square_Back(18,240,100,56,BRRED,LIGHTBLUE,array_mima); // LCD_ShowPic(18,180,27,40,gImage_temp,BLUE); // LCD_ShowPic(18,240,27,40,gImage_humdity,BLUE); R_SCI_UART_Write(&g_uart9_wifi_ctrl, (const uint8_t*)"GETTIME ", 8); mbedtls_platform_setup(&ctx); RM_PSA_CRYPTO_TRNG_Read(passwd_Byte+6,6,&passwd_num); /* TODO: add your own code here */ while(1) { Eventbits = xEventGroupGetBits(g_new_event_LCD); if ((Eventbits&0x1)==0x1){//顯示時(shí)間 //更新wifi數(shù)據(jù) wifi_analysis(); DHT11_Read(); err = xQueueReceive(g_touch_queue,&lValueToRece,20); if (err==pdTRUE){ pos_x = lValueToRece>>16; pos_y = lValueToRece & 0xffff; if ((pos_x>18)&&(pos_x<118)) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?{ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?if ((pos_y>180)&&(pos_y<236)) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?{ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?taskENTER_CRITICAL(); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?LCD_Fill(0,0,239,319,WHITE);//BLUE ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?taskEXIT_CRITICAL(); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?}else if ((pos_y>240)&&(pos_y<316)) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?{ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?xSemaphoreGive(g_rtc_binSem); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?xEventGroupClearBits(g_new_event_LCD,0x7); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?xEventGroupSetBits(g_new_event_LCD,0x4); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?taskENTER_CRITICAL(); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?LCD_Fill(0,0,239,319,WHITE);//BLUE ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?LCD_Disp_KeyBoard(); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?getKeyBoardTRNG(); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?taskEXIT_CRITICAL(); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?} ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?} ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?} ? ? ? ? ? ? ? ? ? ? ? ?}else if((Eventbits&0x4)==0x4){ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?err = xQueueReceive(g_touch_queue,&lValueToRece,20); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?if (err==pdTRUE){ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?touch_tmp ?= LCD_Read_KeyBoard((unsigned short)(lValueToRece>>16),lValueToRece&0xffff); if (touch_tmp==0xff){ minLCD_Key_Loc(); }else if (touch_tmp<10) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?{ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?if (getLCD_Key_Loc()>0) touch_vals[getLCD_Key_Loc()-1] = touch_tmp; } LCD_Disp_Passwd(touch_vals,getLCD_Key_Loc()); if (getLCD_Key_Loc()==4) { //校驗(yàn) if ((touch_vals[0]==(passwd_Byte[0]-'0')) &&(touch_vals[1]==(passwd_Byte[1]-'0')) &&(touch_vals[2]==(passwd_Byte[2]-'0')) &&(touch_vals[3]==(passwd_Byte[3]-'0')) ) { lockState=false; R_GPT_Enable(&g_timer0_ctrl); xEventGroupClearBits(g_new_event_LCD,0x7); xEventGroupSetBits(g_new_event_LCD,0x1); taskENTER_CRITICAL(); LCD_Fill(0,0,239,319,BLUE);//BLUE taskEXIT_CRITICAL(); xSemaphoreGive(g_flush_semaphore); R_SCI_UART_Write(&g_uart9_wifi_ctrl, (const uint8_t*)"GETTIME ", 8); } } } } if (lockState){//關(guān)著 PWM_Update(5); } else{ PWM_Update(10);//打開(kāi) } } } void uart9_wifi_callback(uart_callback_args_t * p_args) { switch(p_args->event) { case UART_EVENT_RX_CHAR: wifi_rece_buff[wifi_rece_len++] = p_args->data&0xff; if (p_args->data==' '){ flag_wifi_rece=true; } break; case UART_EVENT_TX_COMPLETE: break; default: break; } } void lock_timer0_callback(timer_callback_args_t * p_args) { if (TIMER_EVENT_CYCLE_END == p_args->event) { lockState=true; R_GPT_Disable(&g_timer0_ctrl); }
2、觸摸部分
上下滑動(dòng)查看完整內(nèi)容
左右滑動(dòng)即可查看完整代碼
void Touch_thread_entry(void * pvParameters)
{
FSP_PARAMETER_NOT_USED(pvParameters);
bool Touch_flag_time=true;
bsp_io_level_t state;
fsp_err_t err = FSP_SUCCESS;
/* Open ICU module */
err = R_ICU_ExternalIrqOpen(&g_external_irq4_ctrl, &g_external_irq4_cfg);
/* 允許中斷 */
err = R_ICU_ExternalIrqEnable(&g_external_irq4_ctrl);
/* TODO: add your own code here */
while(1)
{
if (flag_touch_start){
if (Touch_num==6){
uint32_t lValueToSend;
flag_touch_start = false;
Touch_coordinate_xsum = Touch_coordinate_xsum-Touch_coordinate_xmax-Touch_coordinate_xmin;
Touch_coordinate_xsum >>=2;
Touch_coordinate_ysum = Touch_coordinate_ysum-Touch_coordinate_ymax-Touch_coordinate_ymin;
Touch_coordinate_ysum >>=2;
Touch_corrdinate_pixel(Touch_coordinate_xsum,Touch_coordinate_ysum);
lValueToSend = Touch_coordinate_xpix;
lValueToSend <<=16;
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?lValueToSend |= Touch_coordinate_ypix;
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?xQueueSendToBack(g_touch_queue,&lValueToSend,100000);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Touch_num=0;
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?vTaskDelay(100);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?}else{
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?taskENTER_CRITICAL(); ? ? ? ?//進(jìn)入基本臨界區(qū)
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?touch_curr_x = Touch_Write_CMD(READ_CHANNEL_X);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?touch_curr_y = Touch_Write_CMD(READ_CHANNEL_Y);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?taskEXIT_CRITICAL();
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?if (Touch_num==0)
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?{
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Touch_coordinate_xmax=touch_curr_x;
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Touch_coordinate_xmin=touch_curr_x;
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Touch_coordinate_ymax=touch_curr_y;
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Touch_coordinate_ymin=touch_curr_y;
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Touch_coordinate_xsum = touch_curr_x;
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Touch_coordinate_ysum = touch_curr_y;
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?}else{
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Touch_coordinate_average(touch_curr_x,0);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Touch_coordinate_average(touch_curr_y,1);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Touch_num++;
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ? ? ? ? ?}else{
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?if (Touch_flag_time)
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?R_IOPORT_PinWrite(&g_ioport_ctrl, LCD_SCK, BSP_IO_LEVEL_LOW);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?else
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?R_IOPORT_PinWrite(&g_ioport_ctrl, LCD_SCK, BSP_IO_LEVEL_HIGH);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?R_IOPORT_PinRead(&g_ioport_ctrl, LCD_IRQ, &state);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?if (state==BSP_IO_LEVEL_LOW){
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?flag_touch_start=true;
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?vTaskDelay(10);
? ? ? ? ? ? ? ? ? ? ? ?} ? ? ? //退出基本臨界區(qū)
? ? ? ? ? ? ? ? ? ? ? ?vTaskDelay(10);
// ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?xSemaphoreTake(g_touch_binary_semaphore,portMAX_DELAY);
? ? ? ? ? ? ? ?}
}
3、RTC部分
上下滑動(dòng)查看完整內(nèi)容
左右滑動(dòng)即可查看完整代碼
void RTC_thread_entry(void * pvParameters)
{
FSP_PARAMETER_NOT_USED(pvParameters);
EventBits_t Eventbits;
BaseType_t err = pdFALSE;
/* TODO: add your own code here */
while(1)
{
Eventbits = xEventGroupGetBits(g_new_event_LCD);
if ((Eventbits&0x1)==0x1)//顯示時(shí)間
{
xSemaphoreTake(g_rtc_binSem,portMAX_DELAY);
taskENTER_CRITICAL();
Time_Update();
taskEXIT_CRITICAL();
err = xSemaphoreTake(g_flush_semaphore,20);
if (err==pdTRUE)
{
taskENTER_CRITICAL();
Draw_Square_Back(18,180,100,56,BRRED,LIGHTBLUE,array_renlian);
Draw_Square_Back(18,240,100,56,BRRED,LIGHTBLUE,array_mima);
taskEXIT_CRITICAL();
}
}
else{
if (first_Disp){
LCD_Fill(0,131,239,50,WHITE);
Draw_Square(10,140,60,50,RED,GREEN,4);//4
Draw_Square(90,140,60,50,RED,GREEN,5);//5
Draw_Square(170,140,60,50,RED,GREEN,6);//6
first_Disp--;
}
vTaskDelay(1000);
}
}
}
void rtc_lcd_callback(rtc_callback_args_t * p_args)
{
switch (p_args->event)
{
/*若是周期中斷,則更新日期*/
case RTC_EVENT_PERIODIC_IRQ:
/*獲取當(dāng)前時(shí)間*/
R_RTC_CalendarTimeGet (g_rtc_lcd.p_ctrl, lcd_time);
xSemaphoreGiveFromISR(g_rtc_binSem,NULL);
break;
default:
break;
}
}
三 項(xiàng)目效果圖



審核編輯:湯梓紅
-
原理圖
+關(guān)注
關(guān)注
1338文章
6419瀏覽量
244045 -
mcu
+關(guān)注
關(guān)注
147文章
18496瀏覽量
382399 -
開(kāi)發(fā)板
+關(guān)注
關(guān)注
25文章
6063瀏覽量
111551 -
ESP8266
+關(guān)注
關(guān)注
51文章
965瀏覽量
48873 -
智能門(mén)鎖
+關(guān)注
關(guān)注
17文章
1907瀏覽量
45429
發(fā)布評(píng)論請(qǐng)先 登錄
基于啟明6M5開(kāi)發(fā)板的無(wú)線環(huán)境監(jiān)測(cè)小車(chē)系統(tǒng)設(shè)計(jì)

基于啟明6M5開(kāi)發(fā)板的智能門(mén)鎖設(shè)計(jì)
評(píng)論