-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfunctions.c
More file actions
82 lines (76 loc) · 1.97 KB
/
functions.c
File metadata and controls
82 lines (76 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "stm32f10x.h"
//*********************************************************
// Light Functions
//*********************************************************
void onLight(void){
GPIO_WriteBit(GPIOB, GPIO_Pin_7, Bit_SET);
}
void offLight(void){
GPIO_WriteBit(GPIOB, GPIO_Pin_7, Bit_RESET);
}
void blinkLight(void){
if(GPIO_ReadOutputDataBit(GPIOB, GPIO_Pin_7)){
GPIO_WriteBit(GPIOB, GPIO_Pin_7, Bit_RESET);
}else{
GPIO_WriteBit(GPIOB, GPIO_Pin_7, Bit_SET);
}
}
//*********************************************************
// Motor Wheel Functions
//*********************************************************
void setForwardRight(void){
GPIO_WriteBit(GPIOC, GPIO_Pin_15, Bit_SET);
}
void setBackwardRight(void){
GPIO_WriteBit(GPIOC, GPIO_Pin_15, Bit_RESET);
}
void setForwardLeft(void){
GPIO_WriteBit(GPIOA, GPIO_Pin_0, Bit_SET);
}
void setBackwardLeft(void){
GPIO_WriteBit(GPIOA, GPIO_Pin_0, Bit_RESET);
}
void powerRight(int cycle){
if(cycle < 0){
setBackwardRight();
TIM3 -> CCR1 = -1 * cycle;
}else{
setForwardRight();
TIM3 -> CCR1 = cycle;
}
}
void powerLeft(int cycle){
if(cycle < 0){
setBackwardLeft();
TIM3 -> CCR2 = -1 * cycle;
}else{
setForwardLeft();
TIM3 -> CCR2 = cycle;
}
}
void stopMotor(void){
TIM3 -> CCR1 = 0;
TIM3 -> CCR2 = 0;
}
//*********************************************************
// Convert Hex to Decimal value
//*********************************************************
int Hex2Dec(char temp){
int val;
if(temp >= '0' && temp <= '9'){
val = temp - '0';
}
else if(temp >= 'a' && temp <= 'f'){
val = temp - 'a' + 10;
}
return val;
}
//*********************************************************
// USART2 Send
//*********************************************************
void USARTsend(char *pucBuffer, unsigned long ulCount){
while(ulCount--){
USART_SendData(USART2,*pucBuffer++);
while(USART_GetFlagStatus(USART2,USART_FLAG_TC) == RESET);
}
}