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.

Help me with this coding.....

Status
Not open for further replies.

Waran

Newbie level 5
Joined
Jul 22, 2009
Messages
10
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Malaysia
Activity points
1,523
im always come out with errors using this C language coding for my pic18f452.....
can you help me to correct the errors....

#include <p18f452.h> //We're using the PIC18F452
#include <delays.h> //We'll need the delays library

void main(void)
{

TRISA = 0x00; //Initialize these Ports as Outputs
TRISC = 0x00; //This one too
TRISD = 0x00; //This one toooo

PORTA = 0x00; //Initialize PORTA...so the LED is off

/*
The PIC is connected to the Motor Controller via 6 pins

PIN #1
PORTD Bit 0 - Used For Brake
PORTDbits.RC0

PIN#2
PORTD Bit 1 - User For Direction
PORTDbits.RC1

PINS#3-6
PORTC Bit 0 - Used For M1
PORTCbits.RC0
PORTC Bit 1 - Used For M2
PORTCbits.RC1
PORTC Bit 2 - Used For M3
PORTCbits.RC2
PORTCBit 3 - Used For M4
PORTCbits.RC3

*/

PORTCbits.RD0 = 0; //Brake Off
PORTCbits.RD1 = 1; //Direction Forward

while(1)
{

Delay_ms(500);
Delay_ms(500);
Delay_ms(500);
Delay_ms(500); //4 * 0.5 seconds = 2 Second Pause
PORTA = 0x01; //Turn LED On
PORTC = 0b00001111; // 0x0F Full Speed

Delay_ms(500);
Delay_ms(500);
Delay_ms(500);
Delay_ms(500); //4 * 0.5 seconds = 2 Second Pause
PORTA = 0x00; //Turn LED Off
PORTC = 0b00001011; //0X0B 3/4 Full Speed

Delay_ms(500);
Delay_ms(500);
Delay_ms(500);
Delay_ms(500); //4 * 0.5 seconds = 2 Second Pause
PORTA = 0x01; //Turn LED On
PORTC = 0b00000101; //0x07 1/2 Full Speed

Delay_ms(500);
Delay_ms(500);
Delay_ms(500);
Delay_ms(500); //4 * 0.5 seconds = 2 Second Pause
PORTA = 0x00; //Turn LED Off
PORTC = 0b00000011; //0x03 1/4 Full Speed

PORTDbits.RD0 = 1; //Turn Brake On
Delay_ms(500); //Pause 0.5 Seconds
PORTDbits.RD0 = 0; //Turn Brake Off

}



}



This coding actually to run a dc motor clockwise and counterclockwise....and also to control the speed....

I receive error for this line...PORTDbits
mentioned 'undeclared identifier'....
and also error for this line...#include <delays.h>
 

Sounds like the compiler can not find the include directory.
You need to set the project build options to point to the include directory.
Also, there is no function prototype in 'delays.h' for Delay_ms().
Unless you have written your own.
Also. make sure it takes a 16-bit int as the argument and not a byte.
 

void main(void)
{

TRISA = 0x00; //Initialize these Ports as Outputs
TRISC = 0x00; //This one too
TRISD = 0x00; //This one toooo

PORTA = 0x00; //Initialize PORTA...so the LED is off

/*
The PIC is connected to the Motor Controller via 6 pins

PIN #1
PORTD Bit 0 - Used For Brake
PORTDbits.RC0

PIN#2
PORTD Bit 1 - User For Direction
PORTDbits.RC1

PINS#3-6
PORTC Bit 0 - Used For M1
PORTCbits.RC0
PORTC Bit 1 - Used For M2
PORTCbits.RC1
PORTC Bit 2 - Used For M3
PORTCbits.RC2
PORTCBit 3 - Used For M4
PORTCbits.RC3

*/

PORTC.F0 = 0; //Brake Off
PORTD.F1 = 1; //Direction Forward
PORTD.F1 = 0; //Direction reverse
while(1)
{
if (PORTD.F1==1)
{
Delay_ms(500);
Delay_ms(500);
Delay_ms(500);
Delay_ms(500); //4 * 0.5 seconds = 2 Second Pause
PORTA = 0x01; //Turn LED On
PORTC = 0b00001111; // 0x0F Full Speed

Delay_ms(500);
Delay_ms(500);
Delay_ms(500);
Delay_ms(500); //4 * 0.5 seconds = 2 Second Pause
PORTA = 0x00; //Turn LED Off
PORTC = 0b00001011; //0X0B (3/4 Full Speed)

Delay_ms(500);
Delay_ms(500);
Delay_ms(500);
Delay_ms(500); //4 * 0.5 seconds = 2 Second Pause
PORTA = 0x01; //Turn LED On
PORTC = 0b00000101; //0x07 (1/2 Full Speed)

Delay_ms(500);
Delay_ms(500);
Delay_ms(500);
Delay_ms(500); //4 * 0.5 seconds = 2 Second Pause
PORTA = 0x00; //Turn LED Off
PORTC = 0b00000011; //0x03 (1/4 Full Speed)

PORTD.F0 = 1; //Turn Brake On
Delay_ms(500); //Pause 0.5 Seconds
PORTD.F0 = 0; //Turn Brake Off
}
else if (PORTD.F1 == 0)
{
Delay_ms(500);
Delay_ms(500);
Delay_ms(500);
Delay_ms(500); //4 * 0.5 seconds = 2 Second Pause
PORTA = 0x01; //Turn LED On
PORTC = 0b00001111; // 0x0F (Full Speed)

Delay_ms(500);
Delay_ms(500);
Delay_ms(500);
Delay_ms(500); //4 * 0.5 seconds = 2 Second Pause
PORTA = 0x00; //Turn LED Off
PORTC = 0b00001011; //0X0B (3/4 Full Speed)

Delay_ms(500);
Delay_ms(500);
Delay_ms(500);
Delay_ms(500); //4 * 0.5 seconds = 2 Second Pause
PORTA = 0x01; //Turn LED On
PORTC = 0b00000101; //0x07 (1/2 Full Speed)

Delay_ms(500);
Delay_ms(500);
Delay_ms(500);
Delay_ms(500); //4 * 0.5 seconds = 2 Second Pause
PORTA = 0x00; //Turn LED Off
PORTC = 0b00000011; //0x03 (1/4 Full Speed)

PORTD.F0 = 1; //Turn Brake On
Delay_ms(500); //Pause 0.5 Seconds
PORTD.F0 = 0; //Turn Brake Off

I encountered error as mentioned below:

line 108 ; expected, but '' found
line 109 '}' expected '' found
line 109 Invalid expression


Can you help me with this?
This will be very helpful....Thank you
 

Without your editor, I dont know where line 108 is?
Sounds like your missing a bracket.

Where do you get
PORTD.F0 from?
 

else if (PORTD.F1 == 0)
{ <------------------------------------Open BRACKET
Delay_ms(500);
Delay_ms(500);
Delay_ms(500);
Delay_ms(500); //4 * 0.5 seconds = 2 Second Pause
PORTA = 0x01; //Turn LED On
PORTC = 0b00001111; // 0x0F (Full Speed)

Delay_ms(500);
Delay_ms(500);
Delay_ms(500);
Delay_ms(500); //4 * 0.5 seconds = 2 Second Pause
PORTA = 0x00; //Turn LED Off
PORTC = 0b00001011; //0X0B (3/4 Full Speed)

Delay_ms(500);
Delay_ms(500);
Delay_ms(500);
Delay_ms(500); //4 * 0.5 seconds = 2 Second Pause
PORTA = 0x01; //Turn LED On
PORTC = 0b00000101; //0x07 (1/2 Full Speed)

Delay_ms(500);
Delay_ms(500);
Delay_ms(500);
Delay_ms(500); //4 * 0.5 seconds = 2 Second Pause
PORTA = 0x00; //Turn LED Off
PORTC = 0b00000011; //0x03 (1/4 Full Speed)

PORTD.F0 = 1; //Turn Brake On
Delay_ms(500); //Pause 0.5 Seconds
PORTD.F0 = 0; //Turn Brake Off


?????/WHERE is the matching closing one ??
 

Can I know what does this coding will do if i connect it to dc motor? Btw i am using mikroC PRO for PIC compiler. I am using pic18f452 with a LMD18245 H-bridge connection and a dc motor.

void main(void)
{
TRISA = 0x00; //Initialize these Ports as Outputs
TRISC = 0x00; //This one too
TRISD = 0x00; //This one toooo


PORTA = 0x00; //Initialize PORTA...so the LED is off

PORTC.F0 = 0; //Brake Off
PORTD.F1 = 1; //Direction Forward
PORTD.F1 = 0; //Direction reverse

while(1)
{
if (PORTD.F1==1)
{
Delay_ms(500);
Delay_ms(500);
Delay_ms(500);
Delay_ms(500); //4 * 0.5 seconds = 2 Second Pause
PORTA = 0x01; //Turn LED On
PORTC = 0b00001111; // 0x0F Full Speed

Delay_ms(500);
Delay_ms(500);
Delay_ms(500);
Delay_ms(500); //4 * 0.5 seconds = 2 Second Pause
PORTA = 0x00; //Turn LED Off
PORTC = 0b00001011; //0X0B (3/4 Full Speed)

Delay_ms(500);
Delay_ms(500);
Delay_ms(500);
Delay_ms(500); //4 * 0.5 seconds = 2 Second Pause
PORTA = 0x01; //Turn LED On
PORTC = 0b00000101; //0x07 (1/2 Full Speed)

Delay_ms(500);
Delay_ms(500);
Delay_ms(500);
Delay_ms(500); //4 * 0.5 seconds = 2 Second Pause
PORTA = 0x00; //Turn LED Off
PORTC = 0b00000011; //0x03 (1/4 Full Speed)

PORTD.F0 = 1; //Turn Brake On
Delay_ms(500); //Pause 0.5 Seconds
PORTD.F0 = 0; //Turn Brake Off
}
else if (PORTD.F1 = 0)
{
Delay_ms(500);
Delay_ms(500);
Delay_ms(500);
Delay_ms(500); //4 * 0.5 seconds = 2 Second Pause
PORTA = 0x01; //Turn LED On
PORTC = 0b00001111; // 0x0F (Full Speed)

Delay_ms(500);
Delay_ms(500);
Delay_ms(500);
Delay_ms(500); //4 * 0.5 seconds = 2 Second Pause
PORTA = 0x00; //Turn LED Off
PORTC = 0b00001011; //0X0B (3/4 Full Speed)

Delay_ms(500);
Delay_ms(500);
Delay_ms(500);
Delay_ms(500); //4 * 0.5 seconds = 2 Second Pause
PORTA = 0x01; //Turn LED On
PORTC = 0b00000101; //0x07 (1/2 Full Speed)

Delay_ms(500);
Delay_ms(500);
Delay_ms(500);
Delay_ms(500); //4 * 0.5 seconds = 2 Second Pause
PORTA = 0x00; //Turn LED Off
PORTC = 0b00000011; //0x03 (1/4 Full Speed)

PORTD.F0 = 1; //Turn Brake On
Delay_ms(500); //Pause 0.5 Seconds
PORTD.F0 = 0; //Turn Brake Off
}
}
}

 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top