Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

C programming to program PIC16F877a

Status
Not open for further replies.

kokwah520

Newbie level 5
Joined
Jun 3, 2011
Messages
8
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,399
#include <pic.h>
#use delay (clock = 20000000)
#define L293D_A RB0
#define L293D_B RB1
#define L293D_C RB2
#define L293D_D RB3
#define L293D_E RB4
#define L293D_F RB5
__CONFIG(0x3f3a);

void rotate_L1(void);
void rotate_R1(void);
void rotate_L2(void);
void rotate_R2(void);
void breaksA(void);
void breaksB(void);
void delay(void);

void main()
{
TRISA= 0x0f;
TRISB = 0xf0;
PORTB = 0;
RB4 = 1;
RB5 = 1;

for(;;){
if (RA0 == 1)
{
rotate_L1();
}

else if (RA1 == 1)
{
rotate_R1();
}

else if (RA2 ==1)
{
rotate_L2();
}



else if (RA3 == 1)
{
rotate_R2();
}

else if (RA0 == 1 & RA1== 1)
{
breaksA();
}

else if (RA2 == 1 & RA3 == 1)
{
breaksB();
}
}
}

void rotate_L1()
{
L293D_A=1;
L293D_B=0;
L293D_E=1;
}

void rotate_R1()
{
L293D_A=0;
L293D_B=1;
L293D_E=1;
}

void rotate_L2()
{
L293D_C=1;
L293D_D=0;
L293D_F=1;
}

void rotate_R2()
{
L293D_C=0;
L293D_D=1;
L293D_F=1;
}

void breaksA()
{
L293D_A=0;
L293D_B=0;
L293D_E=0;
}

void breaksB()
{
L293D_C=0;
L293D_D=0;
L293D_F=0;
}


this is my coding of my project but my project is not working, hardware part i have check and is okay, my lecturer say that is software problem, can anyone tell me what is the problem? for the delay, i cant use #include <delay.h> so i use "#use delay (clock = 20000000), it is build successful but it show warning on use delay..
the statement i use void, is this okay? will affect anything?
the program is about to compare the signal of port A, RA0 with RA1 and RA2 with RA3

if RA0 is high (logic "1") then go to subroutine rotate L1
if RA1 is high (logic "1") then go to subroutine rotate R1
if RA2 is high (logic "1") then go to subroutine rotate L2
if RA3 is high (logic "1") then go to subroutine rotate R2

if RA0 and RA1 is high (logic "1") then go to subroutine breaksA
if RA2 and RA3 is high (logic "1") then go to subroutine breaksA

subroutine is to send the signal to the servo motor to make the servo motor turn clockwise or anticlockwise..
void rotate_R2()
{
L293D_C=0;
L293D_D=1;
L293D_F=1;
}

C and D is send the signal to motor driver L293D and F is to control the enable pin of the motor driver.
L293_A/C is the input pin
L293_B/D is the output pin
L294_E/F is the enable pin


can anyone tell me what is the problem of my program?

Your post is not related to "software links " category.
Moved to microcontrollrs section, post in the proper category, next time you'll get an infraction [alexan_e]
 

Hi there is an error occured while m simulating this code and the error is of #include<pic.h> what does it mean??? n which microcontroller u used for it??
 

instead of pic.h try htc.h on the include

and all that for a simple L293???

omg :O

i will try to find out what i had for that... that is easy to make you just need to focus on the [] pins enable in each step and the Enable A&B ON/OFF of the 293.


have you considered using the L297? it does that automaticaly
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top