{"id":338,"date":"2025-10-15T11:47:53","date_gmt":"2025-10-15T03:47:53","guid":{"rendered":"https:\/\/dioho.me\/?p=338"},"modified":"2025-10-26T22:34:08","modified_gmt":"2025-10-26T14:34:08","slug":"%e5%9f%ba%e4%ba%8eled%e5%a4%b4%e6%96%87%e4%bb%b6%e7%9a%84led%e6%8e%a7%e5%88%b6","status":"publish","type":"post","link":"https:\/\/dioho.me\/index.php\/2025\/10\/15\/%e5%9f%ba%e4%ba%8eled%e5%a4%b4%e6%96%87%e4%bb%b6%e7%9a%84led%e6%8e%a7%e5%88%b6\/","title":{"rendered":"\u57fa\u4e8eled\u5934\u6587\u4ef6\u7684led\u4eae\u706d\u63a7\u5236"},"content":{"rendered":"\n<p>2025-10-15\u4e0a\u8bfe\u8bf4\u9879\u76ee\u7ba1\u7406\u590d\u6742\uff0c\u8981\u6539\u9879\u76ee\u7ed3\u6784\u3002\u56e0\u6b64\u9700\u8981\u5728\u9879\u76ee\u6839\u76ee\u5f55\/usr\u65b0\u5efaled\u6587\u4ef6\u5939\uff0c\u521b\u5efaled.c\u548cled.h\uff0c\u5e76\u5c06\u539f\u5148main.c\u4e2d\u7684\u5185\u5bb9\u62c6\u5206\u5f00\u6765\uff0c\u5206\u522b\u5728led.h\uff0cled.c\u4e2d\u5b9e\u73b0\u5404\u81ea\u7684\u529f\u80fd\u3002\u4e0b\u9762\u7ed9\u51fa\u80fd\u8dd1\u901a\u7684\u6240\u6709\u6587\u4ef6\uff0c\u4ee5\u4f9b\u53c2\u8003\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/Led.c\n#include \"stm32f10x.h\"\n#include \"led.h\"\n\n\/\/\u2193\u51fd\u6570\u540d\u4e0emain.c\u4e2dled\u521d\u59cb\u5316\u76f8\u540c\uff0c\u540e\u9762\u4f1a\u6807\u51fa\u3002\nvoid LedInit()\n{\n\t\/\/\u00c5\u00e4\u00d6\u00c3\n\tGPIO_InitTypeDef GPIO_InitStruct;\n\t\n\tRCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);\n\t\n\tGPIO_InitStruct.GPIO_Pin = GPIO_Pin_5;\n\tGPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;\n\tGPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz;\n\tGPIO_Init(GPIOB, &amp;GPIO_InitStruct);\n\t\n\tRCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE);\n\t\n\tGPIO_InitStruct.GPIO_Pin = GPIO_Pin_5;\n\tGPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;\n\tGPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz;\n\tGPIO_Init(GPIOE, &amp;GPIO_InitStruct);\n}\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/Led.h\n#ifndef DIO_LED_H\n#define DIO_LED_H\n\n#include \"stm32f10x.h\"\n\nvoid LedInit(void);\n\n#define Led1_Off() GPIO_WriteBit(GPIOB, GPIO_Pin_5, Bit_SET);\n#define Led2_Off() GPIO_WriteBit(GPIOE, GPIO_Pin_5, Bit_SET);\n#define Led1_On() GPIO_WriteBit(GPIOB, GPIO_Pin_5, Bit_RESET);\n#define Led2_On() GPIO_WriteBit(GPIOE, GPIO_Pin_5, Bit_RESET);\n\n\n#endif\n\n\/\/\u2191\u6ce8\u610f\u5fc5\u987b\u52a0\u7a7a\u884c\u4e0d\u7136\u4f1a\u62a5warning\u3002<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/main.c\n\/* Includes ------------------------------------------------------------------*\/\n#include \"stm32f10x.h\"\n#include \"led.h\"\n\/\/#define S_GPIOB_BASE 0X40010C00\n\/\/\/\/#define S_CRL S_GPIO_BASE + 0x00\n\/\/\/\/#define S_ODR S_GPIO_BASE + 0x0C\n\/\/#define S_GPIOB ((GPIOA_PORTTypeDef*)S_GPIOB_BASE)\n\n\/\/typedef struct{\n\/\/\tuint32_t CRL;\n\/\/\tuint32_t IDR;\n\/\/\tuint32_t ODR;\n\/\/\tuint32_t BSRR;\n\/\/\tuint32_t BRR;\n\/\/\tuint32_t CKR;\n\/\/}GPIOA_PORTTypeDef;\n\/\/\t\nvoid delay_ms(uint32_t ms){\n\tuint32_t count = 10000;\n\t\n\twhile(ms --){\n\t\tcount = 10000;\n\t\twhile(count --);\n\t}\t\n}\n\/\/int main(void)\n\/\/{\n\/\/    uint32_t temreg = 0;\n\n\/\/    \/* GPIOB Periph clock enable *\/\n\/\/    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);\n\n\/\/    temreg = S_GPIOB->CRL;\n\/\/\t  temreg &amp;= 0xFF0FFFFF;\n\/\/\t\ttemreg += 0x00200000;\n\/\/\t\tS_GPIOB->CRL = temreg;\n\/\/\t\n\/\/\t\ttemreg = S_GPIOB->ODR;\n\/\/\t\ttemreg &amp;= 0x0EF;\n\/\/\t\tS_GPIOB->ODR = temreg;\n\n\/\/    while(1);\n\/\/}\n\nint main(void)\n{\n\/\/       \u2193\u8fd9\u4e2a\u51fd\u6570\u540d\u5bf9\u5e94led.c\u4e2d\u7684void LedInit();\n\tLedInit();\n\twhile(1){\n\/\/               \u2193\u4e0d\u8981\u5206\u5f00\u5199\uff0c\u4e00\u8d77\u5f00\u5173\uff0c\u5206\u5f00\u5199\u6709bug\uff0c\u6682\u65f6\u6ca1\u641e\u61c2\u4e3a\u5565\n\t\tLed1_On();\n\t\tLed2_Off();\t    \t\n\t\tdelay_ms(500);\n\t\tLed1_Off();\n\t\tLed2_On();\n\t\tdelay_ms(500);\n        }\n\n\/\/      \u2193\u6bd4\u5982\u8fd9\u6837\u5199\u53ea\u6709\u7ea2\u706f\u95ea\uff0c\u7eff\u706f\u4e0d\u95ea\u3002\n\/\/      while(1){ \n\/\/              Led1_On(); \n\/\/              delay_ms(500); \n\/\/              Led1_Off(); \n\/\/              delay_ms(500); \n\/\/              Led2_On(); \n\/\/              delay_ms(500); \n\/\/              Led2_Off(); \n\/\/              delay_ms(500); }\n\/\/\t}\n\treturn 0;\n}\n\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>2025-10-15\u4e0a\u8bfe\u8bf4\u9879\u76ee\u7ba1\u7406\u590d\u6742\uff0c\u8981\u6539\u9879\u76ee\u7ed3\u6784\u3002\u56e0\u6b64\u9700\u8981\u5728\u9879\u76ee\u6839\u76ee\u5f55\/usr\u65b0\u5efaled\u6587\u4ef6\u5939\uff0c\u521b\u5efaled [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-338","post","type-post","status-publish","format-standard","hentry","category-5"],"_links":{"self":[{"href":"https:\/\/dioho.me\/index.php\/wp-json\/wp\/v2\/posts\/338","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dioho.me\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dioho.me\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dioho.me\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dioho.me\/index.php\/wp-json\/wp\/v2\/comments?post=338"}],"version-history":[{"count":3,"href":"https:\/\/dioho.me\/index.php\/wp-json\/wp\/v2\/posts\/338\/revisions"}],"predecessor-version":[{"id":343,"href":"https:\/\/dioho.me\/index.php\/wp-json\/wp\/v2\/posts\/338\/revisions\/343"}],"wp:attachment":[{"href":"https:\/\/dioho.me\/index.php\/wp-json\/wp\/v2\/media?parent=338"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dioho.me\/index.php\/wp-json\/wp\/v2\/categories?post=338"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dioho.me\/index.php\/wp-json\/wp\/v2\/tags?post=338"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}