unkwntech

LED Intensity

Aug 21st, 2012
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.52 KB | None | 0 0
  1. #define STM8S105
  2. #include "features.h"
  3.  
  4. void Wait(uint16);
  5.  
  6. int main( void )
  7. {
  8.   TIM3_DeInit();
  9.   TIM3_TimeBaseInit(TIM3_PRESCALER_8, 999);
  10.   TIM3_OC2Init(TIM3_OCMODE_PWM1, TIM3_OUTPUTSTATE_ENABLE, 749, TIM3_OCPOLARITY_LOW);
  11.   TIM3_Cmd(ENABLE);
  12.  
  13.   uint16 i = 0;
  14.   while(1)
  15.   {
  16.     TIM3->CCR2H = (uint8)(i >> 8);
  17.     TIM3->CCR2L = (uint8)(i);
  18.     Wait(10000);
  19.     i += 5;
  20.    
  21.     if(i > 999)
  22.       i = 0;
  23.   }
  24.  
  25.   for(;;);
  26. }
  27. void Wait(uint16 l)
  28. {
  29.   while(l > 0)
  30.   {
  31.     asm("nop");
  32.     l--;
  33.   }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment