From f7dddf06297f415413760f3bedf00f7297e60cf7 Mon Sep 17 00:00:00 2001 From: RossTheRoss Date: Wed, 8 Apr 2020 11:17:47 -0500 Subject: Forget to add a bunch of things oops --- Lab4.X/lab4_servo.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Lab4.X/lab4_servo.c (limited to 'Lab4.X/lab4_servo.c') diff --git a/Lab4.X/lab4_servo.c b/Lab4.X/lab4_servo.c new file mode 100644 index 0000000..9ff5b42 --- /dev/null +++ b/Lab4.X/lab4_servo.c @@ -0,0 +1,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; +} -- cgit v1.2.3