-
Notifications
You must be signed in to change notification settings - Fork 2
/
motor.c
45 lines (36 loc) · 1.15 KB
/
motor.c
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
#include "motor.h"
#include "tm4c123gh6pm.h"
void motor_init(void) {
SYSCTL_RCGCGPIO_R |= SYSCTL_RCGCGPIO_R4;
while (!(SYSCTL_PRGPIO_R & SYSCTL_PRGPIO_R4));
GPIO_PORTE_DIR_R |= (MOTOR_DIR1 | MOTOR_DIR2);
GPIO_PORTE_DEN_R |= (MOTOR_DIR1 | MOTOR_DIR2);
SYSCTL_RCGCTIMER_R |= SYSCTL_RCGCTIMER_R1;
while (!(SYSCTL_PRTIMER_R & SYSCTL_PRTIMER_R1));
}
void door_open(void) {
TIMER1_ICR_R |= TIMER_ICR_TATOCINT;
TIMER1_CTL_R &= ~TIMER_CTL_TAEN;
TIMER1_CFG_R = 0;
TIMER1_TAMR_R = 0x1;
TIMER1_TAILR_R = MOVING_TIME_MS * 16000;
TIMER1_CTL_R |= TIMER_CTL_TAEN;
MOTOR_CTL |= MOTOR_DIR1;
MOTOR_CTL &= ~MOTOR_DIR2;
while (!(TIMER1_RIS_R & TIMER_RIS_TATORIS));
MOTOR_CTL &= ~MOTOR_DIR1;
MOTOR_CTL &= ~MOTOR_DIR2;
}
void door_close(void) {
TIMER1_ICR_R |= TIMER_ICR_TATOCINT;
TIMER1_CTL_R &= ~TIMER_CTL_TAEN;
TIMER1_CFG_R = 0;
TIMER1_TAMR_R = 0x1;
TIMER1_TAILR_R = MOVING_TIME_MS * 16000;
TIMER1_CTL_R |= TIMER_CTL_TAEN;
MOTOR_CTL &= ~MOTOR_DIR1;
MOTOR_CTL |= MOTOR_DIR2;
while (!(TIMER1_RIS_R & TIMER_RIS_TATORIS));
MOTOR_CTL &= ~MOTOR_DIR1;
MOTOR_CTL &= ~MOTOR_DIR2;
}