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 TIM2_IRQHandler(void) 00014 { 00015 myled=!myled; 00016 TIM2->SR=0; 00017 HAL_NVIC_ClearPendingIRQ(TIM2_IRQn); 00018 } 00019 void TIM3_IRQHandler(void) 00020 { 00021 myled2=!myled2; 00022 TIM3->SR=0; 00023 HAL_NVIC_ClearPendingIRQ(TIM3_IRQn); 00024 } 00025 InterruptIn PA1(PA_1); 00026 void EX1init(void); 00027 00028 00029 void NVIC_Init(void) 00030 { 00031 /* TIM2_IRQn interrupt configuration */ 00032 NVIC_SetVector(TIM2_IRQn, (uint32_t)&TIM2_IRQHandler); 00033 HAL_NVIC_EnableIRQ(TIM2_IRQn); 00034 /* TIM3_IRQn interrupt configuration */ 00035 NVIC_SetVector(TIM3_IRQn, (uint32_t)&TIM3_IRQHandler); 00036 HAL_NVIC_EnableIRQ(TIM3_IRQn); 00037 } 00038 00039 /* TIM2 init function */ 00040 void TIM2_Init(void) 00041 { 00042 RCC->APB1ENR|=0b00001; //Clock Enable 00043 TIM2->PSC=3199; //Prescaler 100µs 00044 TIM2->ARR=5000; //Autoreload 5000*100µs = 0,5s 00045 TIM2->DIER=1; //UIE = 1 (Update Interrupt Enable) 00046 TIM2->SR=0; //UIF =0 (Update Interrupt Flag) 00047 TIM2->CR1=1; //CEN=1 (Counter Enable) 00048 } 00049 void TIM3_Init(void); 00050 00051 00052 00053 int main() 00054 { 00055 TIM2_Init(); 00056 TIM3_Init(); 00057 EX1init(); 00058 NVIC_Init(); 00059 while(1) { 00060 } 00061 00062 } 00063 00064 void EX1init(void) 00065 { 00066 PA1.rise(&EX1IRQhandler); 00067 PA1.mode(PullDown); 00068 } 00069 00070 void TIM3_Init(void) 00071 { 00072 RCC->APB1ENR|=0b000010; //Clock Enable 00073 TIM3->PSC=3199; //Prescaler 100µs 00074 TIM3->ARR=15000; //Autoreload 15000*100µs = 1,5s 00075 TIM3->DIER=1; //UIE = 1 (Update Interrupt Enable) 00076 TIM3->SR=0; //UIF =0 (Update Interrupt Flag) 00077 TIM3->CR1=1; //CEN=1 (Counter Enable) 00078 }
Generated on Tue Oct 31 2023 08:44:26 by
1.7.2