打造嵌入式系統結合AI 智慧
AI 智慧
UnityMbed 由 AI 驅動,打造從撰寫程式碼到燒錄開發板的一站式開發生態系,讓嵌入式系統開發比以往更智慧、更快速。
在同一工作階段完成撰寫、建置與燒錄
實際的 N32G031 開發工作階段:設定 GPIOA 時脈、連接 DHT11,按一下即可燒錄。
UM
N32G031_OLED_DHT11-mainn32g031 已儲存至磁碟N32G031_OLED_DHT11-main
>已連結至磁碟 · ~/Projects/N32G031_OLED_DHT11
flash ok · 240 bytes · 0.8s · OpenOCD n32g031檔案
檔案
src
7misc.c
n32g031_it.c
oled.c
system_n32g031.c
utils.c
drivers
51filemain
2inc
10工具
硬體
2工具鏈
1雲端
3帳號
4進階
2⌘K快速搜尋
main.c✕
src/main.c
AI 已啟用
1#include "n32g031.h"
2#include "n32g031_gpio.h"
3#include "n32g031_rcc.h"
4#include "core_cm0.h"
5#include "dht11.h"
6#include "oled.h"
7#include "utils.h"
8#include <stdio.h>
9
10// --- 新增:LED 初始化 ---
11void leds_init(void)
12{
13 // 啟用 GPIOA 時脈(APB2PCLKEN 的第 2 位元)
14 RCC->APB2PCLKEN |= (1U << 2);
15
16 // 將 PA2(黃)、PA3(綠)、PA4(紅)設為輸出(01)
17 GPIOA->PMODE &= ~((3U << 4) | (3U << 6) | (3U << 8));
18 GPIOA->PMODE |= ((1U << 4) | (1U << 6) | (1U << 8));
19
20 // 設為推挽輸出(0)
21 GPIOA->POTYPE &= ~((1U << 2) | (1U << 3) | (1U << 4));
22
23 // 設為無上拉/下拉(00)
24 GPIOA->PUPD &= ~((3U << 4) | (3U << 6) | (3U << 8));
25
26 // 初始關閉所有 LED(向連接埠位元清除暫存器寫入 1)
27 GPIOA->PBC = (1U << 2) | (1U << 3) | (1U << 4);
28}
29// ---------------------------------
30
31int main(void)
32{
33 uint8_t current_temp = 0;
34 uint8_t current_humi = 0;
35
36 uint8_t last_temp = 255;
37 uint8_t last_humi = 255;
38 uint8_t was_error = 1;
39
40 uint8_t error_count = 0;
41
42 char buffer[20];
43
44 SystemInit();
45 SystemCoreClockUpdate();
46
47 leds_init(); // 初始化 3 顆 LED
48
49 delay_ms(500);
50 OLED_Init();
51 OLED_Clear();
52 DHT11_Init();
53
54 OLED_ShowString(10, 24, "System Ready", 16);
55 delay_ms(1500);
56
57 OLED_Clear();
58
59 while (1)
60 {
61 if (DHT11_Read_Data(¤t_temp, ¤t_humi) == 1)
62 {
63 error_count = 0;
64
65 if (was_error)
66 {
67 OLED_Clear();
68 OLED_ShowString(0, 0, "Temp: ", 8);
69 OLED_ShowString(0, 32, "Humidity: ", 8);
70 was_error = 0;
71 last_temp = 255;
72 last_humi = 255;
73 }
74
75 if (current_temp != last_temp)
76 {
77 sprintf(buffer, "%02d C ", current_temp);
78 OLED_ShowString(0, 12, buffer, 16);
79 OLED_ShowString(24, 12, "o", 8);
80 last_temp = current_temp;
81 }
82
83 if (current_humi != last_humi)
84 {
85 sprintf(buffer, "%02d %% ", current_humi);
86 OLED_ShowString(0, 44, buffer, 16);
87 last_humi = current_humi;
88 }
89
90 // --- 新增:依濕度控制 LED 的邏輯 ---
91 if (current_humi < 40)
92 {
93 GPIOA->PBSC = (1U << 3); // 綠燈亮(PA3)
94 GPIOA->PBC = (1U << 2) | (1U << 4); // 黃燈、紅燈滅
95 }
96 else if (current_humi >= 40 && current_humi <= 60)
97 {
98 GPIOA->PBSC = (1U << 2); // 黃燈亮(PA2)
99 GPIOA->PBC = (1U << 3) | (1U << 4); // 綠燈、紅燈滅
100 }
101 else
102 {
103 GPIOA->PBSC = (1U << 4); // 紅燈亮(PA4)
104 GPIOA->PBC = (1U << 2) | (1U << 3); // 綠燈、黃燈滅
105 }
106 // ------------------------------------------
107 }
108 else
109 {
110 error_count++;
111
112 if (error_count >= 3)
113 {
114 if (!was_error)
115 {
116 OLED_Clear();
117 was_error = 1;
118 }
119 OLED_ShowString(0, 0, "Sensor Error! ", 16);
120 OLED_ShowString(0, 24, "Check Wiring. ", 16);
121
122 // 選用:發生錯誤時關閉所有 LED
123 GPIOA->PBC = (1U << 2) | (1U << 3) | (1U << 4);
124 }
125 }
126
127 delay_ms(2000);
128 }
129}
AI 助理
N32G031 已連線Pro ctx 0.0k
燒錄至 N32G031 開發套件
Starter、Pro 與 Learning 套件皆採用相同的 Cortex-M0+ 開發板。旋轉查看套件,再透過下方表單訂購。
Starter Kit 開發板
採用經典的 Uno 相容板型,可廣泛搭配市售標準硬體擴充板(Shield)。
初學者友善即插即用一板整合
Partners
































選擇方案
已經訂閱?登入以管理方案 →
AI 模型依方案而異,請查看各方案包含的模型
| 方案比較 | Free | Starter | Pro 最受歡迎 | Advance | Enterprise |
|---|---|---|---|---|---|
| 價格 | 免費 | ฿249/月 | ฿550/月 | ฿990/月 | 自訂 |
| 使用人數 | 1 位使用者 | 1 位使用者 | 1 位使用者 | 1 位使用者 | 依組織架構自訂使用人數 |
| 點數 | 200 點 | 2,000 點 | 7,000 點 | 13,000 點 | 自訂點數 |
| AI 模型使用權限 | Fast | Fast | Fast · Balanced · Smart | Fast · Balanced · Smart · Pro | Fast · Balanced · Smart · Pro |
| 適用情境 | 基礎試用 | 一般使用 | 日常開發 | 進階開發 | 可依組織需求自訂 進階支援服務 |
安裝 桌面版 IDE
與我們保持聯絡
服務時間
週一至週五:09:00–20:00
週末及國定假日休息




