STM8S precise delay + LED flashing

Publisher:qazwsx007Latest update time:2018-05-18 Source: eefocusKeywords:STM8S Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
  1. #include"iostm8s105c4.h"  

  2. #define LED PC_ODR_ODR1  

  3. void GPIO_Init()  

  4. {  

  5.   PG_DDR_DDR0=1;  

  6.     

  7.   PG_CR1_C10=1;  

  8.     

  9.   PG_CR2_C20=0;  

  10.     

  11.   PG_ODR_ODR0=0;  

  12.     

  13.   PC_DDR_DDR1=1;  

  14.     

  15.   PC_CR1_C11=1;  

  16.     

  17.   PC_CR2_C21=0;  

  18.     

  19. }  

  20. /********** Microsecond delay program*********/   

  21.   

  22. void Delayus(void)   

  23. {    

  24.   asm("nop");   

  25.     

  26.   asm("nop");   

  27.     

  28.   asm("nop");   

  29.    

  30.   asm("nop");    

  31. }  

  32. /********** millisecond delay program**********/   

  33.   

  34. void Delayms(unsigned int time)   

  35.   

  36. {   

  37.       

  38.   unsigned int i;   

  39.       

  40.   while(time--)     

  41.       

  42.     for(i=900;i>0;i--)   

  43.       

  44.       DelayUse();    

  45.     

  46. }   

  47.   

  48. main()  

  49. {  

  50.   GPIO_Init();  

  51.     

  52.   while(1)  

  53.   {  

  54.     LED=~LED;  

  55.       

  56.     Delayms(125);  

  57.   }  

  58. }  


Keywords:STM8S Reference address:STM8S precise delay + LED flashing

Previous article:About the application of STC15F2K60S2 watchdog
Next article:A 430 soft reset method (original)

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号