Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 #include "mbed.h" 00002 00003 00004 DigitalOut myled(PC_0); 00005 DigitalOut myled2(PC_1); 00006 DigitalOut PC2(PC_2); 00007 00008 void EX1IRQhandler(void) 00009 { 00010 PC2=!PC2; 00011 } 00012 00013 void TIM6_IRQHandler(void) 00014 { 00015 myled=!myled; 00016 TIM6->SR=0; 00017 HAL_NVIC_ClearPendingIRQ(TIM6_IRQn); 00018 } 00019 void TIM7_IRQHandler(void) 00020 { 00021 myled2=!myled2; 00022 TIM7->SR=0; 00023 HAL_NVIC_ClearPendingIRQ(TIM7_IRQn); 00024 } 00025 InterruptIn PA1(PA_1); 00026 void EX1init(void) 00027 { 00028 PA1.rise(&EX1IRQhandler); 00029 PA1.mode(PullDown); 00030 } 00031 00032 void NVIC_Init(void) 00033 { 00034 /* TIM6_IRQn interrupt configuration */ 00035 NVIC_SetVector(TIM6_IRQn, (uint32_t)&TIM6_IRQHandler); 00036 HAL_NVIC_EnableIRQ(TIM6_IRQn); 00037 /* TIM7_IRQn interrupt configuration */ 00038 NVIC_SetVector(TIM7_IRQn, (uint32_t)&TIM7_IRQHandler); 00039 HAL_NVIC_EnableIRQ(TIM7_IRQn); 00040 } 00041 00042 /* TIM6 init function */ 00043 void TIM6_Init(void) 00044 { 00045 RCC->APB1ENR|=0b10000; //Clock Enable 00046 TIM6->PSC=3199; //Prescaler 100µs 00047 TIM6->ARR=5000; //Autoreload 5000*100µs = 0,5s 00048 TIM6->DIER=1; //UIE = 1 (Update Interrupt Enable) 00049 TIM6->SR=0; //UIF =0 (Update Interrupt Flag) 00050 TIM6->CR1=1; //CEN=1 (Counter Enable) 00051 } 00052 void TIM7_Init(void) 00053 { 00054 RCC->APB1ENR|=0b100000; //Clock Enable 00055 TIM7->PSC=3199; //Prescaler 100µs 00056 TIM7->ARR=15000; //Autoreload 15000*100µs = 1,5s 00057 TIM7->DIER=1; //UIE = 1 (Update Interrupt Enable) 00058 TIM7->SR=0; //UIF =0 (Update Interrupt Flag) 00059 TIM7->CR1=1; //CEN=1 (Counter Enable) 00060 } 00061 00062 int main() 00063 { 00064 TIM6_Init(); 00065 TIM7_Init(); 00066 EX1init(); 00067 NVIC_Init(); 00068 while(1) { 00069 } 00070 00071 }
Generated on Thu Nov 10 2022 04:41:21 by
1.7.2