forked from trocache/RefKEIL
Compteur Done
This commit is contained in:
parent
f1d1216e44
commit
d3d48cf176
5 changed files with 96 additions and 10 deletions
29
ProjetsKEIL/Drivers/Driver_timers.c
Normal file
29
ProjetsKEIL/Drivers/Driver_timers.c
Normal file
|
@ -0,0 +1,29 @@
|
|||
#include "Driver_timers.h"
|
||||
|
||||
|
||||
|
||||
void timer_init(MyTimer_Struct_TypeDef * Timer){
|
||||
if(Timer->Timer == TIM1){
|
||||
RCC->APB2ENR |= RCC_APB2ENR_TIM1EN;
|
||||
}
|
||||
if(Timer->Timer == TIM2){
|
||||
RCC->APB1ENR |= RCC_APB1ENR_TIM2EN;
|
||||
}
|
||||
if(Timer->Timer == TIM3){
|
||||
RCC->APB1ENR |= RCC_APB1ENR_TIM3EN;
|
||||
}
|
||||
if(Timer->Timer == TIM4){
|
||||
RCC->APB1ENR |= RCC_APB1ENR_TIM4EN;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MyTimer_Start(MyTimer_Struct_TypeDef *Timer)
|
||||
{
|
||||
Timer->Timer->CR1 |= TIM_CR1_CEN; // Démarre le Timer
|
||||
}
|
||||
|
||||
void MyTimer_Stop(MyTimer_Struct_TypeDef *Timer)
|
||||
{
|
||||
Timer->Timer->CR1 &= ~TIM_CR1_CEN; // Arrête le Timer
|
||||
}
|
25
ProjetsKEIL/Drivers/Driver_timers.h
Normal file
25
ProjetsKEIL/Drivers/Driver_timers.h
Normal file
|
@ -0,0 +1,25 @@
|
|||
#ifndef MYTIMER_H
|
||||
#define MYTIMER_H
|
||||
|
||||
#include "stm32f10x.h"
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
TIM_TypeDef * Timer;
|
||||
unsigned short ARR;
|
||||
unsigned short PSC;
|
||||
} MyTimer_Struct_TypeDef;
|
||||
|
||||
|
||||
void MyTimer_Base_Init(MyTimer_Struct_TypeDef * Timer);
|
||||
void timer_init(MyTimer_Struct_TypeDef * Timer);
|
||||
void MyTimer_Start(MyTimer_Struct_TypeDef *Timer);
|
||||
void MyTimer_Stop(MyTimer_Struct_TypeDef *Timer);
|
||||
|
||||
|
||||
|
||||
#define MyTimer_Base_Start(Timer)
|
||||
#define MyTimer_Base_Stop(Timer)
|
||||
|
||||
#endif
|
|
@ -1,15 +1,17 @@
|
|||
#include "stm32f10x.h"
|
||||
#include "Driver_GPIO.h"
|
||||
#include "Driver_timers.h"
|
||||
|
||||
|
||||
|
||||
// PA5 LED
|
||||
// PC13 BP
|
||||
|
||||
MyGPIO_Struct_TypeDef LED;
|
||||
MyTimer_Struct_TypeDef Timer_500ms;
|
||||
|
||||
int delay(){
|
||||
int i;
|
||||
for(i=0;i<1000000;i++);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -30,17 +32,25 @@ int main ( void )
|
|||
MyGPIO_Init(&LED);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Timer_500ms.Timer = TIM2;
|
||||
Timer_500ms.PSC = 7200; //(1/72Mhz)/7200=0.1ms
|
||||
Timer_500ms.ARR = 5000; //0.1*5000 = 500ms
|
||||
timer_init(&Timer_500ms);
|
||||
MyTimer_Start(&Timer_500ms);
|
||||
|
||||
|
||||
while(1)
|
||||
{
|
||||
|
||||
if(MyGPIO_Read(GPIOC, 13) == 0)
|
||||
{
|
||||
MyGPIO_Toggle(GPIOA, 5);
|
||||
delay();
|
||||
}
|
||||
//if(MyGPIO_Read(GPIOC, 13) == 0)
|
||||
//{
|
||||
MyGPIO_Set(GPIOA, 5);
|
||||
while(Timer_500ms.Timer->CNT != Timer_500ms.ARR -1); //CNT registre qui gère le retour à 0
|
||||
MyGPIO_Reset(GPIOA, 5);
|
||||
while(Timer_500ms.Timer->CNT != Timer_500ms.ARR -1);
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -290,7 +290,7 @@
|
|||
<SetRegEntry>
|
||||
<Number>0</Number>
|
||||
<Key>DLGTARM</Key>
|
||||
<Name>(1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0)(100=-1,-1,-1,-1,0)(110=-1,-1,-1,-1,0)(111=-1,-1,-1,-1,0)(1011=-1,-1,-1,-1,0)(180=-1,-1,-1,-1,0)(120=703,344,1124,749,0)(121=931,445,1352,850,0)(122=409,446,830,851,0)(123=-1,-1,-1,-1,0)(140=-1,-1,-1,-1,0)(240=-1,-1,-1,-1,0)(190=-1,-1,-1,-1,0)(200=-1,-1,-1,-1,0)(170=-1,-1,-1,-1,0)(130=-1,-1,-1,-1,0)(131=-1,-1,-1,-1,0)(132=-1,-1,-1,-1,0)(133=-1,-1,-1,-1,0)(160=-1,-1,-1,-1,0)(161=-1,-1,-1,-1,0)(162=-1,-1,-1,-1,0)(210=-1,-1,-1,-1,0)(211=-1,-1,-1,-1,0)(220=-1,-1,-1,-1,0)(221=-1,-1,-1,-1,0)(230=-1,-1,-1,-1,0)(231=-1,-1,-1,-1,0)(232=-1,-1,-1,-1,0)(233=-1,-1,-1,-1,0)(150=-1,-1,-1,-1,0)(151=-1,-1,-1,-1,0)</Name>
|
||||
<Name>(1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0)(100=-1,-1,-1,-1,0)(110=-1,-1,-1,-1,0)(111=-1,-1,-1,-1,0)(1011=-1,-1,-1,-1,0)(180=-1,-1,-1,-1,0)(120=703,344,1124,749,0)(121=931,445,1352,850,0)(122=409,446,830,851,0)(123=-1,-1,-1,-1,0)(140=-1,-1,-1,-1,0)(240=-1,-1,-1,-1,0)(190=-1,-1,-1,-1,0)(200=-1,-1,-1,-1,0)(170=-1,-1,-1,-1,0)(130=-1,-1,-1,-1,0)(131=872,142,1466,836,0)(132=-1,-1,-1,-1,0)(133=-1,-1,-1,-1,0)(160=-1,-1,-1,-1,0)(161=-1,-1,-1,-1,0)(162=-1,-1,-1,-1,0)(210=-1,-1,-1,-1,0)(211=-1,-1,-1,-1,0)(220=-1,-1,-1,-1,0)(221=-1,-1,-1,-1,0)(230=-1,-1,-1,-1,0)(231=-1,-1,-1,-1,0)(232=-1,-1,-1,-1,0)(233=-1,-1,-1,-1,0)(150=-1,-1,-1,-1,0)(151=-1,-1,-1,-1,0)</Name>
|
||||
</SetRegEntry>
|
||||
<SetRegEntry>
|
||||
<Number>0</Number>
|
||||
|
@ -414,6 +414,18 @@
|
|||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>2</GroupNumber>
|
||||
<FileNumber>3</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\Drivers\Driver_timers.c</PathWithFileName>
|
||||
<FilenameWithoutPath>Driver_timers.c</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
</Group>
|
||||
|
||||
<Group>
|
||||
|
|
|
@ -398,6 +398,11 @@
|
|||
<FileType>1</FileType>
|
||||
<FilePath>..\Drivers\Driver_GPIO.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>Driver_timers.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\Drivers\Driver_timers.c</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
|
@ -800,6 +805,11 @@
|
|||
<FileType>1</FileType>
|
||||
<FilePath>..\Drivers\Driver_GPIO.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>Driver_timers.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\Drivers\Driver_timers.c</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
|
|
Loading…
Reference in a new issue