-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.c
84 lines (72 loc) · 1.92 KB
/
main.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
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
83
84
unsigned int wire_thickness = 0;
unsigned int coil_width = 0;
unsigned int number_of_turns = 0;
unsigned int rotation_speed = 0;
unsigned int turn_counter = 0;
unsigned char counter[7];
volatile unsigned int steps_per_coil_width;
volatile unsigned int round = 0;
volatile unsigned char rcbuf[25];
volatile unsigned char rcindex = 0;
volatile unsigned char t;
#include <p18f2550.h>
#include <delays.h>
#include <stdlib.h>
#include "config4.h"
#include "std_lib.h"
#include "timers.h"
#include "serial.h"
#include "stepper.h"
#include "interrupt.h"
void main(void)
{
TRISB = 0x00;
LATB = 0;
CMCON = 0x07; // turn off comparators
ADCON1 = 0x06; // turn off analog to digital converters
reset_array(rcbuf, 12);
usart_init();
usart_puts("Connection to winder is successful.\n");
RCONbits.IPEN = 1;
IPR1bits.RCIP = 0;
IPR1bits.TXIP = 0;
INTCON2bits.TMR0IP = 1;
INTCONbits.PEIE = 1;
INTCONbits.GIE = 1;
while (number_of_turns == 0);
//disable_serial_port();
if (rotation_speed > 5 && rotation_speed < 40)
{
motor1_step_time = (unsigned int)(1000.0/((float)rotation_speed));
}
else motor1_step_time = 100;
motor2_step_time = (unsigned int)((float)motor1_step_time*(float)(1250.0/(float)wire_thickness));
steps_per_coil_width = (unsigned int)(200*coil_width/1.25);
init_timer0();
while(1)
{
if (number_of_turns_motor1 >= number_of_turns)
{
stop_timer0();
if (turn_counter != number_of_turns_motor1)
{
int_to_string(number_of_turns_motor1, counter);
usart_put_array(counter);
}
usart_puts(" turns...job finished.\n");
INTCONbits.PEIE = 0;
INTCONbits.GIE = 0;
LATB = 0;
number_of_turns_motor1 = 0;
}
else
{
if (number_of_turns_motor1 > turn_counter)
{
turn_counter = number_of_turns_motor1;
int_to_string(turn_counter, counter);
usart_put_array(counter);
}
}
}
}