/*
* File: FanashifterH.c
* Author: Stuyo
*
* Created on September 15, 2022, 3:49 PM
*/
#include <xc.h>
#define _XTAL_FREQ 4000000
#pragma config FOSC=INTRCIO, WDTE=OFF, PWRTE=OFF, MCLRE=OFF, CP=OFF, \
CPD=OFF, BOREN=OFF, IESO=OFF, FCMEN=OFF
#define G1 PORTAbits.RA4 //1st Gear switch
#define G2 PORTAbits.RA3 //2nd Gear switch
#define G3 PORTCbits.RC5 //3rd Gear switch
#define G4 PORTCbits.RC4 //4th Gear switch
#define G5 PORTCbits.RC3 //5th Gear switch
#define G6 PORTCbits.RC6 //6th Gear switch
#define G7 PORTCbits.RC7 //7th Gear switch
#define GR PORTBbits.RB7 //Reverse Gear switch
#define X1 PORTAbits.RA0 //X-Axis LOW (900Ohm)
#define X2 PORTAbits.RA1 //X-Axis MED (4.8K)
#define X3 PORTAbits.RA2 //X-Axis HIGH (8.7K)
#define Y1 PORTCbits.RC1 //Y-Axis LOW (direct connection)
#define Y2 PORTCbits.RC2 //Y-Axis LOW-MED (2.8K)
#define Y3 PORTBbits.RB4 //Y-Axis MED (4.4K)
#define Y4 PORTBbits.RB5 //Y-Axis MED-HIGH (6K)
#define Y5 PORTBbits.RB6 //Y-Axis HIGH (10K)
int main()
{
ANSEL = 0x00;
ANSELH = 0x00;
TRISA = 0b00111000; //RA0,1,2 - Digital Outputs; RA3,4,5 - Digital Input; RA6,7 - N/A
TRISB = 0b10000000; //RB4,5,6 - Digital Outputs; RB7 - Digital Input; RB0,1,2,3 - N/A
TRISC = 0b11111000; //RC0,1,2 - Digital Outputs; Rc3,4,5,6,7 - Digital Input
//Define starting reference point for Neutral
X2 = 1; //Set X-Axis in Neutral Position
Y3 = 1; //Set Y-Axis in Neutral Position
while(1){
if(G1==1){ //While 1st Gear Button Active
X1 = 1; X2 = 0; X3 = 0; //X-LOW
Y1 = 0; Y2 = 1; Y3 = 0; Y4 = 0; Y5 = 0; //Y-LOW-MED
}
else if(G2==1){ //While 2nd Gear Button Active
X1 = 0; X2 = 0; X3 = 1; //X-HIGH
Y1 = 0; Y2 = 1; Y3 = 0; Y4 = 0; Y5 = 0; //Y-LOW-MED
}
else if(G3==1){ //While 3rd Gear Button Active
X1 = 1; X2 = 0; X3 = 0; //X-LOW
Y1 = 0; Y2 = 0; Y3 = 1; Y4 = 0; Y5 = 0; //Y-MED
}
else if(G4==1){ //While 4th Gear Button Active
X1 = 0; X2 = 0; X3 = 1; //X-HIGH
Y1 = 0; Y2 = 0; Y3 = 1; Y4 = 0; Y5 = 0; //Y-MED
}
else if(G5==1){ //While 5th Gear Button Active
X1 = 1; X2 = 0; X3 = 0; //X-LOW
Y1 = 0; Y2 = 0; Y3 = 0; Y4 = 1; Y5 = 0; //Y-MED-HIGH
}
else if(G6==1){ //While 6th Gear Button Active
X1 = 0; X2 = 0; X3 = 1; //X-HIGH
Y1 = 0; Y2 = 0; Y3 = 0; Y4 = 1; Y5 = 0; //Y-MED-HIGH
}
else if(G7==1){ //While 7th Gear Button Active
X1 = 1; X2 = 0; X3 = 0; //X-LOW
Y1 = 0; Y2 = 0; Y3 = 0; Y4 = 0; Y5 = 1; //Y-HIGH
}
else if(GR==1){ //While Reverse Gear Button Active
X1 = 1; X2 = 0; X3 = 0; //X-LOW
Y1 = 1; Y2 = 0; Y3 = 0; Y4 = 0; Y5 = 0; //Y-LOW
}
else{ //Return all switches in Neutral Position
X1 = 0; X2 = 1; X3 = 0; //X-MED
Y1 = 0; Y2 = 0; Y3 = 1; Y4 = 0; Y5 = 0; //Y-MED
}
}
return 0;
}