He encontrado estos códigos para controlar la velocidad del motor de CC mediante PWM conectando dos interruptores para aumentar y disminuir el valor de PWM. El problema es que estos códigos están en MiKroc y mi compilador es XC8. ¿Puedo saber qué cambios debo cambiar para que los códigos funcionen en protues?
#define _XTAL_FREQ 8000000L
//#define RS RB0
//#define EN RB1
//#define D4 RD4
//#define D5 RD5
//#define D6 RD6
//#define D7 RD7
#include <xc.h>
// BEGIN CONFIG
#pragma config FOSC = HS // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT enabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = ON // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = OFF // Low-Voltage (Single-Supply) In-Circuit SerialProgramming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
//END CONFIG
int main()
{
short duty = 0; //initial value for duty
TRISD = 0xFF; //PORTD as input
TRISC = 0x00; //PORTC as output
TRISB = 0x00; //PORTB as output
PORTB = 0x02; //Run motor in anticlock wise
PWM1_Init(1000); //Initialize PWM1
PWM1_Start(); //start PWM1
PWM1_Set_Duty(duty); //Set current duty for PWM1
while (1) // endless loop
{
if (RD0==0 && duty<250) //if button on RD0 pressed
{
__delay_ms(40);
duty = duty + 10; //increment current_duty
PWM1_Set_Duty(duty); //Change the duty cycle
}
if (RD1==0 && duty >0) //button on RD1 pressed
{
__delay_ms(40);
duty = duty - 10; //decrement duty
PWM1_Set_Duty(duty);
}
__delay_ms(10); // slow down change pace a little
}
}