#include "stm32f10x.h" // Device header
#include "Delay.h"
#include "OLED.h"
#include "Motor.h"
#include "Key.h"
#include "Encoder.h"
#include "Timer.h"
uint8_t KeyNum;
int8_t Speed;
int16_t Num;
uint16_t TNum=0;
uint16_t Sudu=0;
int main(void)
{
OLED_Init();
Motor_Init();
Key_Init();
Encoder_Init();
Timer3_Init();//使用了定时器2 ,1秒
OLED_ShowString(1, 1, "Speed:");
OLED_ShowString(2, 1, "Num:");
OLED_ShowString(3, 1, "TNum:");
while (1)
{
KeyNum = Key_GetNum();
if (KeyNum == 1)
{
Speed += 2;
if (Speed > 100)
{
Speed = -100;
}
}
Num += Encoder_Get();
Motor_SetSpeed(Speed);
OLED_ShowSignedNum(1, 7, Speed, 5);
OLED_ShowSignedNum(2, 7, Num, 5);
OLED_ShowSignedNum(3, 7, TNum, 5);
}
}
void TIM3_IRQHandler(void)
{
if (TIM_GetITStatus(TIM3, TIM_IT_Update) == SET)
{
//TNum ++;
TNum=Num;
TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
Num=0;
}
}
|