#define F_CPU 1000000UL /* กำหนดความถี่ของ CPU เป็น 1 MHz (ไม่ใช่ 16 MHz ตามที่ระบุไว้ในคอมเมนต์เดิม)
* Define CPU frequency as 1 MHz (The comment incorrectly mentions 16 MHz).
* This macro is used by the delay function to calculate timing correctly. */
#include <avr/io.h> // นำเข้าหรือสืบทอดไลบรารี avr/io.h เพื่อใช้ฟังก์ชันและคำสั่งที่เกี่ยวข้องกับการทำงานของ I/O registers ของ AVR microcontroller
// Include the avr/io.h library to access the Input/Output register definitions and functions specific to AVR microcontrollers.
#include <stdio.h> // นำเข้าไลบรารี stdio.h เพื่อใช้ฟังก์ชันพื้นฐานสำหรับการจัดการ I/O (แต่ไม่ได้ใช้งานในโค้ดนี้)
// Include the standard I/O library for basic input/output functions (not used in this code).
#include <util/delay.h> // นำเข้าไลบรารี util/delay.h เพื่อใช้ฟังก์ชันการหน่วงเวลาที่กำหนดโดยผู้ใช้
// Include the util/delay.h library to use the _delay_ms() function for creating time delays.
int main(void) // ฟังก์ชันหลักของโปรแกรม เริ่มต้นการทำงาน
// Main function of the program, execution starts here.
{
// ตั้งค่า PORTB bit 5 (PB5) ให้เป็น output โดยตั้งค่า DDRB เป็น 0x20 (บิตที่ 5 เป็น 1)
// Initialize PORTB bit 5 (PB5) as an output by setting DDRB to 0x20 (bit 5 set to 1).
DDRB = 0x20;
while(1) // วนลูปไม่สิ้นสุดเพื่อทำการกระพริบ LED ตลอดเวลา
// Infinite loop to continuously blink the LED.
{
PORTB = 0x20; // เปิดไฟ LED โดยตั้งค่า PORTB bit 5 (PB5) เป็น 1
// Turn the LED on by setting PORTB bit 5 (PB5) to 1.
_delay_ms(500); // รอ 500 มิลลิวินาที
// Wait for 500 milliseconds.
PORTB = 0x00; // ปิดไฟ LED โดยตั้งค่า PORTB bit 5 (PB5) เป็น 0
// Turn the LED off by setting PORTB bit 5 (PB5) to 0.
_delay_ms(500); // รอ 500 มิลลิวินาที
// Wait for 500 milliseconds.
}
}