I am having trouble finding a problem with the code, it's supposed to be in C language and I'm using a PIC16F877A and an L293D motor driver IC.
Here's the code:
#include <xc.h>
#include <stdint.h>
#include "config.h"
#define _XTAL_FREQ 4000000
//--[ Pin Definitions ]--
#define Rev RB0 // Reverse Direction Button
#define LV0 RB1 // 0% Speed Button
#define LV1 RB2 // 50% Speed Button
#define LV2 RB3 // 75% Speed Button
#define LV3 RB4 // 100% Speed Button
//================================
//--[ Function Declarations ]--
void PWM1_Set_Duty(uint16_t);
void main(void)
{
//--[ Configuration For IO Pins ]--
TRISB = 0x1F; // Low 5-pins are input pins
// Set The Direction To Be Output Pins
TRISD0 = 0;
TRISD1 = 0;
// Initially (0, 1) Say it's ClockWise rotation!
// For Reversing The Direction Write (1, 0)
RD0 = 0;
RD1 = 1;
//--[ Configure The CCP Module For PWM Mode ]--
CCP1M3 = 1;
CCP1M2 = 1;
TRISC2 = 0; // The CCP1 Output Pin (PWM)
// Set The PWM Frequency (2kHz)
PR2 = 124;
// Set The PS For Timer2 (1:4 Ratio)
T2CKPS0 = 1;
T2CKPS1 = 0;
// Start CCP1 PWM !
TMR2ON = 1;
// The Main Loop (Routine)
while(1)
{
if(Rev) // Reverse The Direction
{
RD0 = ~RD0;
RD1 = ~RD1;
__delay_ms(500); // Wait For The Button To Be Released
}
if(LV0) // 0% DC
{
PWM1_Set_Duty(0);
__delay_ms(100); // Wait For The Button To Be Released
}
if(LV1) // 50% DC
{
PWM1_Set_Duty(250);
__delay_ms(100); // Wait For The Button To Be Released
}
if(LV2) // 75% DC
{
PWM1_Set_Duty(375);
__delay_ms(100); // Wait For The Button To Be Released
}
if (LV3) // 100% DC
{
PWM1_Set_Duty(500);
__delay_ms(100); // Wait For The Button To Be Released
}
__delay_ms(10); // Wait To Reduce The Simulation Overloading
}
return;
}
// Definition For PWM1_Set_Duty Function
void PWM1_Set_Duty(uint16_t DC)
{
// Check The DC Value To Make Sure it's Within 10-Bit Range
if(DC<1024)
{
CCP1Y = DC & 1;
CCP1X = DC & 2;
CCPR1L = DC >> 2;
}
}
I tried compiling and editing it but I can't build and upload it.