Any ideas?
Thank you.
Code: Select all
unsigned int POS0, POS1, POS2, POS3; // Servo position variables
unsigned int RTC=0; // Real Time Counter variable
void interrupt(void) {
if (INTCON.TMR0IF) {
RTC++; // Real Time Counter
INTCON.TMR0IF=0; // Reset Timer0 Interrupt Flag
if(RTC >= POS0) && (POS0 > 0) && (POS0 < 40) {
RC0.bit=0b00000000; // Bring servo 1 bit low
}
if(RTC >= POS1) && (POS1 > 0) && (POS1 < 40) {
RC1.bit=0b00000000; // Bring servo 2 bit low
}
if(RTC >= POS2) && (POS2 > 0) && (POS2 < 40) {
RC2.bit=0b00000000; // Bring servo 3 bit low
}
if(RTC >=POS3) && (POS3 > 0) && (POS3 < 40) {
RC3.bit=0b00000000; // Bring servo 4 bit low
}
if(RTC >= 400) {
PORTC=0b00001111; // Bring servo pins high high
}
}
}
void main() {
//Timer0 Registers Prescaler= 1; TMR0 Preset = 156; Freq = 20000.00 Hz; Period = 0.000050 seconds, Oscillator = 8MHz
//Equation: Delay=(2^8-TMR0)*1/(Fosc/(4*Prescaler))=50us
OPTION_REG.T0CS = 0; // bit 5 TMR0 Clock Source Select bit...0 = Internal Clock (CLKO) 1 = Transition on T0CKI pin
OPTION_REG.T0SE = 0; // bit 4 TMR0 Source Edge Select bit 0 = low/high 1 = high/low
OPTION_REG.PSA = 1; // bit 3 Prescaler Assignment bit...0 = Prescaler is assigned to the WDT
OPTION_REG.PS2 = 0; // bits 2-0 PS2:PS0: Prescaler Rate Select bits
OPTION_REG.PS1 = 0;
OPTION_REG.PS0 = 0;
TMR0 = 156; // preset for timer register
while(1) {
}
}