Advertisement
GeeckoDev

air cochon

May 15th, 2012
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.84 KB | None | 0 0
  1. #include <stm32f10x.h>
  2. #include "main.h"
  3.  
  4. void Enable_GPIO(void)
  5. {
  6.         RCC->APB2ENR |= 0x013C;
  7. }
  8.  
  9. void Init_GPIO(void)
  10. {
  11.         GPIOA->CRL = 0x00030004; // PA4 (Speaker) en Push-Pull et PA0 (Wake Up) en Floating Input
  12. }
  13.  
  14. void TIM1_UP_IRQHandler(void)
  15. {
  16.         if (TIM1->SR & 1)
  17.       {
  18.                 GPIOA->ODR ^= 0x10;
  19.               TIM1->SR &= ~1;
  20.         }
  21. }
  22.  
  23. int main (void)
  24. {
  25.         int notes[] = {50, 500, 80, 90, 500, 68 };
  26.         int i=0;
  27.    
  28.         Enable_GPIO();
  29.         Init_GPIO();
  30.        
  31.         /* Initialisation Timer 1 (TIM1) */
  32.    
  33.         RCC->APB2ENR |= (1 << 11); // Validation Timer 1
  34.         TIM1->CR1    |= 0x0001; // Timer 1 Enable
  35.         TIM1->DIER   |= 1;
  36.         TIM1->ARR     = 500;
  37.         *(volatile unsigned long *)0xE000E100 |= (1<<25);
  38.        
  39.         while (1)
  40.         {
  41.                 unsigned int cochon = 4000000;
  42.                 while (cochon--);
  43.  
  44.                 TIM1->PSC = notes[i++];
  45.                 if (i >= sizeof(notes) / 4) i= 0;
  46.         }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement