blob: 9ff5b42d3dcb89afc7da248869caf06607033b06 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
#include "xc.h"
#include "lab4_servo.h"
void setServo(int Val)
{
OC1RS=Val;
}
void initServo() {
TRISB &= 1111111111011111;
//TIMER 3
T3CON = 0x0010; //Stop Timer, Tcy clk source, PRE 1:8
T3CONbits.TCKPS = 0b01;
T3CONbits.TCS=0;
TMR3 = 0; // Initialize to zero
PR3 = 39999; // Set period in order to make 20ms cycle
T3CONbits.TON = 1;
//OC1
OC1CON = 0;
OC1R = 1234; // servo start position. We won?t touch OC1R again
OC1RS = 1234; // We will only change this once PWM is turned on
OC1CONbits.OCM = 0b110;
OC1CONbits.OCTSEL = 1;
}
|