forked from trocache/RefKEIL
Compare commits
No commits in common. "125c801a01fd2c38a07f69f91f00efa5e991110d" and "56875f8dcb676d074c86577265e36763af33e4ef" have entirely different histories.
125c801a01
...
56875f8dcb
6 changed files with 10 additions and 235 deletions
|
@ -1,19 +0,0 @@
|
|||
#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 MyTimer_ActiveIT(TIM_TypeDef * Timer, char Prio, void (*IT_function) (void));
|
||||
void MyTimer_PWM(TIM_TypeDef * Timer ,char Channel);
|
||||
void MyTimer_DutyCycle(TIM_TypeDef * Timer, char Channel, unsigned char DutyCycle);
|
||||
|
||||
#define MyTimer_Base_Start(Tim) (Tim.Timer->CR1 |= TIM_CR1_CEN)
|
||||
#define MyTimer_Base_Stop(Tim) (Tim.Timer->CR1 &= ~TIM_CR1_CEN)
|
||||
|
||||
#endif
|
|
@ -70,10 +70,5 @@ void MyGPIO_Reset(GPIO_TypeDef * GPIO, char GPIO_Pin) {
|
|||
}
|
||||
|
||||
void MyGPIO_Toggle(GPIO_TypeDef * GPIO, char GPIO_Pin) {
|
||||
if (MyGPIO_Read(GPIO, GPIO_Pin) == 0x1) {
|
||||
MyGPIO_Reset(GPIO, GPIO_Pin);
|
||||
}
|
||||
else {
|
||||
MyGPIO_Set(GPIO, GPIO_Pin);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,162 +0,0 @@
|
|||
#include "timer.h"
|
||||
#include "gpio.h"
|
||||
|
||||
void plantage(void) {
|
||||
while(1);
|
||||
}
|
||||
|
||||
void (*IT_Tim2) (void) = plantage;
|
||||
void (*IT_Tim3) (void) = plantage;
|
||||
void (*IT_Tim4) (void) = plantage;
|
||||
|
||||
void MyTimer_Base_Init(MyTimer_Struct_Typedef * Timer) {
|
||||
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;
|
||||
|
||||
Timer->Timer->PSC = Timer->PSC;
|
||||
Timer->Timer->ARR = Timer->ARR;
|
||||
}
|
||||
|
||||
void MyTimer_ActiveIT(TIM_TypeDef * Timer, char Prio, void (*IT_function) (void)) {
|
||||
Timer->DIER |= TIM_DIER_UIE;
|
||||
|
||||
if (Timer == TIM2) {
|
||||
NVIC_EnableIRQ(TIM2_IRQn);
|
||||
NVIC_SetPriority(TIM2_IRQn, Prio);
|
||||
IT_Tim2 = IT_function;
|
||||
}
|
||||
if (Timer == TIM3) {
|
||||
NVIC_EnableIRQ(TIM3_IRQn);
|
||||
NVIC_SetPriority(TIM3_IRQn, Prio);
|
||||
IT_Tim3 = IT_function;
|
||||
}
|
||||
if (Timer == TIM4) {
|
||||
NVIC_EnableIRQ(TIM4_IRQn);
|
||||
NVIC_SetPriority(TIM4_IRQn, Prio);
|
||||
IT_Tim4 = IT_function;
|
||||
}
|
||||
}
|
||||
|
||||
void TIM2_IRQHandler(void) {
|
||||
TIM2->SR &= ~TIM_SR_UIF;
|
||||
(*IT_Tim2)();
|
||||
}
|
||||
|
||||
void TIM3_IRQHandler(void) {
|
||||
TIM3->SR &= ~TIM_SR_UIF;
|
||||
(*IT_Tim3)();
|
||||
}
|
||||
|
||||
void TIM4_IRQHandler(void) {
|
||||
TIM4->SR &= ~TIM_SR_UIF;
|
||||
(*IT_Tim4)();
|
||||
}
|
||||
|
||||
void MyTimer_PWM(TIM_TypeDef * Timer ,char Channel)
|
||||
{
|
||||
MyGPIO_Struct_TypeDef PWM_OUT;
|
||||
PWM_OUT.GPIO_Conf = AltOut_Ppull;
|
||||
switch (Channel) {
|
||||
case 1:
|
||||
case 2:
|
||||
Timer->CCMR1 &= ~TIM_CCMR1_OC1M_0;
|
||||
Timer->CCMR1 |= (TIM_CCMR1_OC1M_1| TIM_CCMR1_OC1M_2);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
case 4:
|
||||
Timer->CCMR2 &= ~TIM_CCMR1_OC1M_0;
|
||||
Timer->CCMR2 |= (TIM_CCMR1_OC1M_1| TIM_CCMR1_OC1M_2);
|
||||
break;
|
||||
}
|
||||
|
||||
Timer->CCER |= (TIM_CCER_CC1E << (4*(Channel-1)));
|
||||
|
||||
if(Timer == TIM2)
|
||||
{
|
||||
PWM_OUT.GPIO = GPIOA;
|
||||
switch (Channel) {
|
||||
case 1:
|
||||
PWM_OUT.GPIO_Pin = 0;
|
||||
break;
|
||||
case 2:
|
||||
PWM_OUT.GPIO_Pin = 1;
|
||||
break;
|
||||
case 3:
|
||||
PWM_OUT.GPIO_Pin = 2;
|
||||
break;
|
||||
case 4:
|
||||
PWM_OUT.GPIO_Pin = 3;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(Timer == TIM3)
|
||||
{
|
||||
switch (Channel) {
|
||||
case 1:
|
||||
PWM_OUT.GPIO = GPIOA;
|
||||
PWM_OUT.GPIO_Pin = 6;
|
||||
break;
|
||||
case 2:
|
||||
PWM_OUT.GPIO = GPIOA;
|
||||
PWM_OUT.GPIO_Pin = 7;
|
||||
break;
|
||||
case 3:
|
||||
PWM_OUT.GPIO = GPIOB;
|
||||
PWM_OUT.GPIO_Pin = 0;
|
||||
break;
|
||||
case 4:
|
||||
PWM_OUT.GPIO = GPIOB;
|
||||
PWM_OUT.GPIO_Pin = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(Timer == TIM4)
|
||||
{
|
||||
PWM_OUT.GPIO = GPIOB;
|
||||
switch (Channel) {
|
||||
case 1:
|
||||
PWM_OUT.GPIO_Pin = 6;
|
||||
break;
|
||||
case 2:
|
||||
PWM_OUT.GPIO_Pin = 7;
|
||||
break;
|
||||
case 3:
|
||||
PWM_OUT.GPIO_Pin = 8;
|
||||
break;
|
||||
case 4:
|
||||
PWM_OUT.GPIO_Pin = 9;
|
||||
break;
|
||||
}
|
||||
}
|
||||
MyGPIO_Init(&PWM_OUT);
|
||||
}
|
||||
|
||||
void MyTimer_DutyCycle(TIM_TypeDef * Timer, char Channel, unsigned char DutyCycle)
|
||||
{
|
||||
unsigned int RC;
|
||||
RC = ((Timer->ARR)/100)*(DutyCycle);
|
||||
switch (Channel) {
|
||||
case 1:
|
||||
Timer->CCR1 = RC;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
Timer->CCR2 = RC;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
Timer->CCR3 = RC;
|
||||
break;
|
||||
|
||||
case 4:
|
||||
Timer->CCR4 = RC;
|
||||
break;
|
||||
}
|
||||
}
|
|
@ -1,13 +1,9 @@
|
|||
#include "stm32f10x.h"
|
||||
#include "gpio.h"
|
||||
#include "timer.h"
|
||||
|
||||
void changer_led(void);
|
||||
|
||||
int main(void) {
|
||||
MyGPIO_Struct_TypeDef led2;
|
||||
MyGPIO_Struct_TypeDef b1;
|
||||
MyTimer_Struct_Typedef t3;
|
||||
|
||||
MyGPIO_InitClock();
|
||||
|
||||
|
@ -17,30 +13,17 @@ int main(void) {
|
|||
b1.GPIO = GPIOC;
|
||||
b1.GPIO_Pin = 13;
|
||||
b1.GPIO_Conf = In_PullUp;
|
||||
t3.Timer = TIM3;
|
||||
t3.ARR = 7199;
|
||||
t3.PSC = 4999;
|
||||
|
||||
MyGPIO_Init(&led2);
|
||||
MyGPIO_Init(&b1);
|
||||
MyTimer_Base_Init(&t3);
|
||||
MyTimer_ActiveIT(TIM3, 0, &changer_led);
|
||||
MyTimer_PWM(TIM3, 1);
|
||||
MyTimer_DutyCycle(TIM3,1,10);
|
||||
MyTimer_Base_Start(t3);
|
||||
|
||||
|
||||
do
|
||||
{
|
||||
/*if (MyGPIO_Read(GPIOC, 13) == 0x1) {
|
||||
if (MyGPIO_Read(GPIOC, 13) == 0x1) {
|
||||
MyGPIO_Reset(GPIOA, 5);
|
||||
}
|
||||
else {
|
||||
MyGPIO_Set(GPIOA, 5);
|
||||
}*/
|
||||
}
|
||||
} while (1);
|
||||
}
|
||||
|
||||
void changer_led(void) {
|
||||
MyGPIO_Toggle(GPIOA, 5);
|
||||
}
|
||||
}
|
|
@ -75,7 +75,7 @@
|
|||
<OPTFL>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<IsCurrentTarget>1</IsCurrentTarget>
|
||||
<IsCurrentTarget>0</IsCurrentTarget>
|
||||
</OPTFL>
|
||||
<CpuCode>18</CpuCode>
|
||||
<DebugOpt>
|
||||
|
@ -125,7 +125,7 @@
|
|||
<SetRegEntry>
|
||||
<Number>0</Number>
|
||||
<Key>DLGDARM</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=920,358,1341,785,0)(121=-1,-1,-1,-1,0)(122=-1,-1,-1,-1,0)(123=-1,-1,-1,-1,0)(140=-1,-1,-1,-1,0)(240=105,137,504,482,0)(190=-1,-1,-1,-1,0)(200=-1,-1,-1,-1,0)(170=120,153,405,449,0)(130=-1,-1,-1,-1,0)(131=931,121,1525,872,0)(132=973,161,1567,912,1)(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)(234=-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=920,358,1341,785,0)(121=-1,-1,-1,-1,0)(122=-1,-1,-1,-1,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=120,153,405,449,0)(130=-1,-1,-1,-1,0)(131=150,186,744,937,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)(234=-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>
|
||||
|
@ -245,7 +245,7 @@
|
|||
<OPTFL>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<IsCurrentTarget>0</IsCurrentTarget>
|
||||
<IsCurrentTarget>1</IsCurrentTarget>
|
||||
</OPTFL>
|
||||
<CpuCode>18</CpuCode>
|
||||
<DebugOpt>
|
||||
|
@ -406,7 +406,7 @@
|
|||
<GroupNumber>2</GroupNumber>
|
||||
<FileNumber>2</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\Drivers\src\gpio.c</PathWithFileName>
|
||||
|
@ -414,18 +414,6 @@
|
|||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>2</GroupNumber>
|
||||
<FileNumber>3</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\Drivers\src\timer.c</PathWithFileName>
|
||||
<FilenameWithoutPath>timer.c</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
</Group>
|
||||
|
||||
<Group>
|
||||
|
@ -438,7 +426,7 @@
|
|||
|
||||
<Group>
|
||||
<GroupName>::Device</GroupName>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<cbSel>0</cbSel>
|
||||
<RteFlg>1</RteFlg>
|
||||
|
|
|
@ -339,7 +339,7 @@
|
|||
<MiscControls></MiscControls>
|
||||
<Define></Define>
|
||||
<Undefine></Undefine>
|
||||
<IncludePath>..\Drivers\inc;.\inc</IncludePath>
|
||||
<IncludePath>.\Include</IncludePath>
|
||||
</VariousControls>
|
||||
</Cads>
|
||||
<Aads>
|
||||
|
@ -398,11 +398,6 @@
|
|||
<FileType>1</FileType>
|
||||
<FilePath>..\Drivers\src\gpio.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>timer.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\Drivers\src\timer.c</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
|
@ -805,11 +800,6 @@
|
|||
<FileType>1</FileType>
|
||||
<FilePath>..\Drivers\src\gpio.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>timer.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\Drivers\src\timer.c</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
|
|
Loading…
Reference in a new issue