本人學的第一個STM8l152c6板子的點亮led燈的小程序,不喜勿噴,希望對初學者有幫助,項目建好之后,連接板子,先看看連接有沒有問題,如果沒問題的話,把下面代碼全部覆蓋到main.C文件,直接運行ok,有問題@我,看能不能幫上忙謝謝!- #include "stm8l15x.h"
- #include "stm8l15x_gpio.h"
- #include "stdio.h"
- #define BUTTON_GPIO_PORT GPIOC
- #define USER_GPIO_PIN GPIO_Pin_1
- #define LD4_GPIO_PORT GPIOC
- #define LD4 GPIO_Pin_7
- #define LD3_GPIO_PORT GPIOE
- #define LD3 GPIO_Pin_7
- unsigned int x,y;
- static void delay_ms(unsigned int ms)//Ñó3ùoˉêy£¬MS ¼¶±e
- {
- unsigned int x=0,y=0;
- for(x = ms;x>0;x--)
- {
- for(y = 405;y>0;y--);
- }
- }
- void main(void){
- /* ÅäÖà LED4 IO ¿úÎaêä3öÄ£ê½ £¬3õê¼×′ì¬Îaμí*/
- GPIO_Init(LD4_GPIO_PORT, LD4, GPIO_Mode_Out_PP_Low_Fast);
- /* ÅäÖà LED3 IO ¿úÎaêä3öÄ£ê½ £¬3õê¼×′ì¬Îaμí*/
- GPIO_Init(LD3_GPIO_PORT, LD3, GPIO_Mode_Out_PP_Low_Fast);
- while (1){
- if(x==0){
- delay_ms(1000);
- GPIO_ToggleBits(LD4_GPIO_PORT, LD4); //ÇD»» LED4 ×′ì¬
- x++;
- }else if(x==1){
- delay_ms(1000);
- GPIO_ToggleBits(LD3_GPIO_PORT, LD3); //ÇD»» LED3 ×′ì¬
- x=0;
- }
- }
- }
- #ifdef USE_FULL_ASSERT
- void assert_failed(uint8_t* file, uint32_t line)
- {
- while (1)
- {
- }
- }
- #endif
復制代碼
|