พื้นฐาน Embedded C - ตอนที่ 1
Embedded C Programming Part 1: พื้นฐานสำคัญ
ทำไม Embedded C ต่างจาก C ปกติ?
ทำไมต้องเข้าใจ Embedded C สำหรับ IoT และ Edge AI?
ส่วนที่ 1: Data Types
ทำไมต้องใช้ Fixed-Width Types ให้ถูกต้อง?
1.1 ปัญหาของ int ใน Embedded
1.2 Fixed-Width Integer Types (stdint.h)
Standard Integer Types (stdint.h)
Type
Size
Range
ใช้งาน
Real Application
Feature
int16_t (Signed)
uint16_t (Unsigned)
1.3 ตัวอย่างจากโค้ดจริง (Hello World)
1.4 Boolean Type (stdbool.h)
1.5 Cypress Result Type (cy_rslt_t)
Pattern: Error Checking
ส่วนที่ 2: Macros
ทำไมต้องใช้ Define/Macro?
2.1 #define Basics
2.2 ทำไมต้องใส่วงเล็บ?
2.3 ตัวอย่างจากโค้ดจริง
2.4 Function-Like Macros
ข้อควรระวัง: Macro ไม่ใช่ Function
2.5 Macro สำหรับ Array Size
ส่วนที่ 3: Functions ใน Embedded C
3.1 Function Declaration และ Definition
3.2 static Keyword
3.3 Function Parameters
3.4 ตัวอย่างจากโค้ดจริง
3.5 Return Values
ส่วนที่ 4: Conditional Compilation
4.1 #if, #ifdef, #ifndef
4.2 การใช้งานจริง
ส่วนที่ 5: Bit Operations
5.1 Bit Shifting
5.2 ใช้กับ Register Configuration
ส่วนที่ 6: Type Casting
6.1 Explicit Casting
6.2 Casting สำหรับ printf
ส่วนที่ 7: การเก็บเวลาด้วย Tick Count
7.1 Tick-Based Timing
7.2 Non-Blocking Delay Pattern
ส่วนที่ 8: Volatile Keyword
8.1 ทำไมต้องใช้ volatile?
ข้อผิดพลาด
ผลกระทบ
วิธีป้องกัน
8.2 ใช้กับ Hardware Registers
ส่วนที่ 9: สรุปภาพรวม
9.1 Embedded C Mindset: ทำไม Embedded C ถึงไม่เหมือน C บน PC
9.2 สิ่งที่ต้องจำให้ขึ้นใจจากตอน 1 (Key Takeaways)
9.3 Checklist ก่อนขยับไปตอน 2
9.4 Next: ตอน 2 จะพาไปอะไร
สรุป: Quick Reference
Data Types
Macros
Functions
Error Checking
Conditional Compilation
Timing
Last updated
Was this helpful?