#include <pic.h>
__CONFIG (0x3F32);
#define sw1 RB0
#define ssL C1OUT
#define led1 RB6
#define led2 RB7
#define buzzer RC3
#define motor_ra RC4
#define motor_la RC7
#define pwml CCPR1L
#define pwmr CCPR2L
// Function Prototype
//************************************************** *************************
void init(void);
void delay(unsigned long data);
void forward(void);
void reverse(void);
void motor_run(void);
void stop(void);
// Main
//************************************************** *************************
void main(void)
{
unsigned i;
init(); // call initialization function
buzzer = 0; // buzzer OFF
led1 = 1;
led2 = 1;
stop(); // robot stop
pwml = 200; // set pwm left motor = 200
pwmr = 200; // set pwm right motor = 200
while(1) // infinite loop
{
if(sw1==0) // sw1 pushed?
{
while(!sw1);
while(1)
{ // if pushed
for(i=0;i<2;i++) // buzzer ON 2 times
{
buzzer = 1;
delay(10000);
buzzer = 0;
delay(10000);
}
motor_run(); // call motor run function
}
}
else stop(); // if sw1 not pushed, robot stop
}
}
// PIC Initialization Function Routine
//************************************************** *************************
void init()
{
PR2 = 255; // set period register
T2CON = 0b00000100; // set prescale 1
CCP1CON = 0b00001100; // config for RC1 to generate PWM
TRISE = 0b000; // set PORTE I/O direction
}
void delay(unsigned long data) // delay function
{
for(;data>0;data--); // delay depend on the data given
}
void motor_run(void) // motor_run function
{
unsigned n = 0;
forward(); // motor forward
while(n==0)
{
}
}
// Description : Motor functions
//================================================== ================================================== ========
void forward(void) // forward function
{
motor_ra = 1;
motor_la = 1;
}
void stop(void) // stop function
{
motor_ra = 1;
motor_la = 1;
}
void reverse(void)
{
motor_ra = 0;
motor_la = 0;
}
__CONFIG (0x3F32);
#define sw1 RB0
#define ssL C1OUT
#define led1 RB6
#define led2 RB7
#define buzzer RC3
#define motor_ra RC4
#define motor_la RC7
#define pwml CCPR1L
#define pwmr CCPR2L
// Function Prototype
//************************************************** *************************
void init(void);
void delay(unsigned long data);
void forward(void);
void reverse(void);
void motor_run(void);
void stop(void);
// Main
//************************************************** *************************
void main(void)
{
unsigned i;
init(); // call initialization function
buzzer = 0; // buzzer OFF
led1 = 1;
led2 = 1;
stop(); // robot stop
pwml = 200; // set pwm left motor = 200
pwmr = 200; // set pwm right motor = 200
while(1) // infinite loop
{
if(sw1==0) // sw1 pushed?
{
while(!sw1);
while(1)
{ // if pushed
for(i=0;i<2;i++) // buzzer ON 2 times
{
buzzer = 1;
delay(10000);
buzzer = 0;
delay(10000);
}
motor_run(); // call motor run function
}
}
else stop(); // if sw1 not pushed, robot stop
}
}
// PIC Initialization Function Routine
//************************************************** *************************
void init()
{
PR2 = 255; // set period register
T2CON = 0b00000100; // set prescale 1
CCP1CON = 0b00001100; // config for RC1 to generate PWM
TRISE = 0b000; // set PORTE I/O direction
}
void delay(unsigned long data) // delay function
{
for(;data>0;data--); // delay depend on the data given
}
void motor_run(void) // motor_run function
{
unsigned n = 0;
forward(); // motor forward
while(n==0)
{
}
}
// Description : Motor functions
//================================================== ================================================== ========
void forward(void) // forward function
{
motor_ra = 1;
motor_la = 1;
}
void stop(void) // stop function
{
motor_ra = 1;
motor_la = 1;
}
void reverse(void)
{
motor_ra = 0;
motor_la = 0;
}
please do u hv the circuit for this codes?
ReplyDeleteWhy my DC motor producing Jerks! not rotating! could you please help me from this.
ReplyDeletehttp://www.npeducations.com
please give me circuit diagram of this code
ReplyDeletepls sent immediatly.......................
ReplyDelete