STM8S_LED流水灯程序 附件
单片机源程序如下:
- #include "stm8s.h"
- #include "sysclock.h"
- #define LED_PORT GPIOA
- #define LED_0 GPIO_PIN_0
- #define LED_1 GPIO_PIN_1
- #define LED_2 GPIO_PIN_2
- #define LED_3 GPIO_PIN_3
- #define LED_4 GPIO_PIN_4
- #define LED_5 GPIO_PIN_5
- #define LED_6 GPIO_PIN_6
- #define LED_7 GPIO_PIN_7
- #define LED_8 GPIO_PIN_LNIB
- #define LED_9 GPIO_PIN_HNIB
- #define LED_10 GPIO_PIN_ALL
- #define ON 0
- #define OFF 0
- void Delay(u32 nCount)
- {
- u32 i;
- for(i=0;i<nCount;i++);
- }
- void LED_Init(void)
- {
- GPIO_Init(LED_PORT, LED_1, GPIO_MODE_OUT_PP_HIGH_FAST );
- GPIO_Init(LED_PORT, LED_2, GPIO_MODE_OUT_PP_HIGH_FAST );
- GPIO_Init(LED_PORT, LED_3, GPIO_MODE_OUT_PP_HIGH_FAST );
- GPIO_Init(LED_PORT, LED_4, GPIO_MODE_OUT_PP_HIGH_FAST );
- GPIO_Init(LED_PORT, LED_5, GPIO_MODE_OUT_PP_HIGH_FAST );
- GPIO_Init(LED_PORT, LED_6, GPIO_MODE_OUT_PP_HIGH_FAST );
- GPIO_Init(LED_PORT, LED_7, GPIO_MODE_OUT_PP_HIGH_FAST );
- GPIO_Init(LED_PORT, LED_0, GPIO_MODE_OUT_PP_HIGH_FAST );
-
- }
- void LED_Config(GPIO_Pin_TypeDef led, u8 state)
- {
- if(ON == state)
- {
- GPIO_WriteLow(LED_PORT, led);
- }
- else
- {
- GPIO_WriteHigh(LED_PORT, led);
- }
- }
- int main(void)
- {
- SystemClock_Init();
- LED_Init();
- while(1)
- {
- LED_Config(LED_0, ON);
- LED_Config(LED_1, ON);
- LED_Config(LED_2, ON);
- LED_Config(LED_3, ON);
- LED_Config(LED_4, ON);
- LED_Config(LED_5, ON);
- LED_Config(LED_6, ON);
- LED_Config(LED_7, ON);
- LED_Config(LED_8, ON);
- LED_Config(LED_9, ON);
- LED_Config(LED_10, ON);
- Delay(500);
- LED_Config(LED_0, OFF);
- LED_Config(LED_1, OFF);
- LED_Config(LED_2, OFF);
- LED_Config(LED_3, OFF);
- LED_Config(LED_4, OFF);
- LED_Config(LED_5, OFF);
- LED_Config(LED_6, OFF);
- LED_Config(LED_7, OFF);
- LED_Config(LED_8, OFF);
- LED_Config(LED_9, OFF);
- LED_Config(LED_10, OFF);
- Delay(500);
- }
-
- }
- #ifdef USE_FULL_ASSERT
- void assert_failed(u8* file, u32 line)
- {
- while (1)
- {
- }
- }
- #endif
复制代码
所有资料51hei提供下载:
STM8S_LED.zip
(253.97 KB, 下载次数: 39)
|