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 in PIC 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
I wanted to know whats wrong with my coding...I wanted to just logic high extra 2 pins which are port B5 and port B6. I put the coding as below. I could compile the coding but when I burn the coding into my PIC18f452, it shows error....Can I know whats wrong with the technique I use?

#include <18f452.h>
#fuses HS, NOWDT, NOPROTECT, NOLVP
#use delay (clock=20000000)


#define m1 pin_C0
#define m2 pin_C1
#define m3 pin_C2
#define m4 pin_C3
#define dir pin_D1
#define brake pin_D0
#define supply pin_B5
#define supply2 pin_B6
#define button1 pin_D2
#define button2 pin_D3
#define button3 pin_D4
#define button4 pin_D5
#define button5 pin_D6
#define button6 pin_B0
#define button7 pin_B1
#define button8 pin_B2
#define buttonstop pin_B4
#define on 0
#define off 1

void main (void)
{

output_high(supply); // This part which confuse me. Without this part, I could
output_high(supply2); // burn it and run the program.

loop:
if(input(button1) == on && input(button2) == off && input(button3) == off && input(button4)== off && input(button5) == off && input(button6) == off && input(button7) == off && input(button8)== off && input(buttonstop)== off )
{
delay_ms(1000);
delay_ms(1000);
output_high(m1);
output_high(m2);
output_high(m3);
output_high(m4);
output_high(dir);
output_low(brake);


}
else if(input(button1) == off && input(button2) == on && input(button3) == off && input(button4)== off && input(button5) == off && input(button6) == off && input(button7) == off && input(button8) == off && input(buttonstop)== off)
{
delay_ms(1000);
delay_ms(1000);
output_high(m1);
output_low(m2);
output_high(m3);
output_high(m4);
output_high(dir);
output_low(brake);

}
else if(input(button1) == off && input(button2) == off && input(button3) == off && input(button4)== off && input(button5) == off && input(button6) == off && input(button7) == off && input(button8) == off && input(buttonstop)== off)
{

output_low(m1);
output_low(m2);
output_low(m3);
output_low(m4);
output_low(dir);
output_low(brake);

}
else if(input(button1) == off && input(button2) == off && input(button3) == on && input(button4)== off && input(button5) == off && input(button6) == off && input(button7) == off && input(button8) == off && input(buttonstop)== off)
{
delay_ms(1000);
delay_ms(1000);
output_low(m1);
output_high(m2);
output_high(m3);
output_high(m4);
output_high(dir);
output_low(brake);


}

else if(input(button1) == off && input(button2) == off && input(button3) == off && input(button4)== on && input(button5) == off && input(button6) == off && input(button7) == off && input(button8) == off && input(buttonstop)== off)
{
delay_ms(1000);
delay_ms(1000);
output_low(m1);
output_low(m2);
output_high(m3);
output_high(m4);
output_high(dir);
output_low(brake);


}
else if(input(button1) == off && input(button2) == off && input(button3) == off && input(button4)== off && input(button5) == on && input(button6) == off && input(button7) == off && input(button8) == off && input(buttonstop)== off)
{
delay_ms(1000);
delay_ms(1000);
output_high(m1);
output_high(m2);
output_high(m3);
output_high(m4);
output_low(dir);
output_low(brake);


}
else if(input(button1) == off && input(button2) == off && input(button3) == off && input(button4)== off && input(button5) == off && input(button6) == on && input(button7) == off && input(button8) == off && input(buttonstop)== off)
{
delay_ms(1000);
delay_ms(1000);
output_high(m1);
output_low(m2);
output_high(m3);
output_high(m4);
output_low(dir);
output_low(brake);

}
else if(input(button1) == off && input(button2) == off && input(button3) == off && input(button4)== off && input(button5) == off && input(button6) == off && input(button7) == on && input(button8) == off && input(buttonstop)== off)
{
delay_ms(1000);
delay_ms(1000);
output_low(m1);
output_high(m2);
output_high(m3);
output_high(m4);
output_low(dir);
output_low(brake);


}
else if(input(button1) == off && input(button2) == off && input(button3) == off && input(button4)== off && input(button5) == off && input(button6) == off && input(button7) == off && input(button8) == on && input(buttonstop)== off)
{
delay_ms(1000);
delay_ms(1000);
output_low(m1);
output_low(m2);
output_high(m3);
output_high(m4);
output_low(dir);
output_low(brake);


}
else if(input(button1) == on && input(button2) == off && input(button3) == off && input(button4)== off && input(button5) == off && input(button6) == off && input(button7) == off && input(button8) == off && input(buttonstop) == on )
{
output_high(brake);
}

else if(input(button1) == off && input(button2) == on && input(button3) == off && input(button4)== off && input(button5) == off && input(button6) == off && input(button7) == off && input(button8) == off && input(buttonstop) == on )
{
output_high(brake);
}

else if(input(button1) == off && input(button2) == off && input(button3) == on && input(button4)== off && input(button5) == off && input(button6) == off && input(button7) == off && input(button8) == off && input(buttonstop) == on )
{
output_high(brake);
}

else if(input(button1) == off && input(button2) == off && input(button3) == off && input(button4)== on && input(button5) == off && input(button6) == off && input(button7) == off && input(button8) == off && input(buttonstop) == on )
{
output_high(brake);
}
else if(input(button1) == off && input(button2) == off && input(button3) == off && input(button4)== off && input(button5) == on && input(button6) == off && input(button7) == off && input(button8) == off && input(buttonstop) == on )
{
output_high(brake);
}
else if(input(button1) == off && input(button2) == off && input(button3) == off && input(button4)== off && input(button5) == off && input(button6) == on && input(button7) == off && input(button8) == off && input(buttonstop) == on )
{
output_high(brake);
}

else if(input(button1) == off && input(button2) == off && input(button3) == off && input(button4)== off && input(button5) == off && input(button6) == off && input(button7) == on && input(button8) == off && input(buttonstop) == on )
{
output_high(brake);
}

else if(input(button1) == off && input(button2) == off && input(button3) == off && input(button4)== off && input(button5) == off && input(button6) == off && input(button7) == off && input(button8) == on && input(buttonstop) == on )
{
output_high(brake);
}


goto loop;
}
 

GSM Man

Banned
Joined
Apr 15, 2009
Messages
671
Helped
168
Reputation
338
Reaction score
94
Trophy points
1,308
Location
New Jersey, USA
Activity points
0
Waran said:
I put the coding as below. I could compile the coding but when I burn the coding into my PIC18f452, it shows error
What's ther Error?

Also, you should use the "
Code:
" tags when post code in your message.  It will preserve the formatting and make it easier for others to read.
 

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
Thanks for replying....

Actually when I burn the HEX file into my pic18f452, the error shows that error in address when it verify Vdd(min) shows in the programmer software...

When I burn the coding without the below line coding, It can run perfectly when put in the circuit....

[ output_high(supply);
output_high(supply2); ]

I define pin B5 and pin B6 as supply and supply2 as stated above.

I am just curious if the line coding I apply in the main code is correct.
 

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
The one I highlighted in red in code below is the problem. But when I compile there was no problem. When I burn, It can't burn. Without the highlighted code, my code works perfectly and can burn. The purpose of the highlighted code is to logic high extra 2 pin which are pin B5 and B6. I just wanted to know if the code I highlighted is correct or not. Can I know the way to correct the code if the code was wrong?

#include <18f452.h>
#fuses HS, NOWDT, NOPROTECT, NOLVP
#use delay (clock=20000000)


#define m1 pin_C0
#define m2 pin_C1
#define m3 pin_C2
#define m4 pin_C3
#define dir pin_D1
#define brake pin_D0
#define supply pin_B5
#define supply2 pin_B6

#define button1 pin_D2
#define button2 pin_D3
#define button3 pin_D4
#define button4 pin_D5
#define button5 pin_D6
#define button6 pin_B0
#define button7 pin_B1
#define button8 pin_B2
#define buttonstop pin_B4
#define on 0
#define off 1

void main (void)
{

output_high(supply);
output_high(supply2);


loop:
if(input(button1) == on && input(button2) == off && input(button3) == off && input(button4)== off && input(button5) == off && input(button6) == off && input(button7) == off && input(button8)== off && input(buttonstop)== off )
{
delay_ms(1000);
delay_ms(1000);
output_high(m1);
output_high(m2);
output_high(m3);
output_high(m4);
output_high(dir);
output_low(brake);


}
else if(input(button1) == off && input(button2) == on && input(button3) == off && input(button4)== off && input(button5) == off && input(button6) == off && input(button7) == off && input(button8) == off && input(buttonstop)== off)
{
delay_ms(1000);
delay_ms(1000);
output_high(m1);
output_low(m2);
output_high(m3);
output_high(m4);
output_high(dir);
output_low(brake);

}
else if(input(button1) == off && input(button2) == off && input(button3) == off && input(button4)== off && input(button5) == off && input(button6) == off && input(button7) == off && input(button8) == off && input(buttonstop)== off)
{

output_low(m1);
output_low(m2);
output_low(m3);
output_low(m4);
output_low(dir);
output_low(brake);

}
else if(input(button1) == off && input(button2) == off && input(button3) == on && input(button4)== off && input(button5) == off && input(button6) == off && input(button7) == off && input(button8) == off && input(buttonstop)== off)
{
delay_ms(1000);
delay_ms(1000);
output_low(m1);
output_high(m2);
output_high(m3);
output_high(m4);
output_high(dir);
output_low(brake);


}

else if(input(button1) == off && input(button2) == off && input(button3) == off && input(button4)== on && input(button5) == off && input(button6) == off && input(button7) == off && input(button8) == off && input(buttonstop)== off)
{
delay_ms(1000);
delay_ms(1000);
output_low(m1);
output_low(m2);
output_high(m3);
output_high(m4);
output_high(dir);
output_low(brake);


}
else if(input(button1) == off && input(button2) == off && input(button3) == off && input(button4)== off && input(button5) == on && input(button6) == off && input(button7) == off && input(button8) == off && input(buttonstop)== off)
{
delay_ms(1000);
delay_ms(1000);
output_high(m1);
output_high(m2);
output_high(m3);
output_high(m4);
output_low(dir);
output_low(brake);


}
else if(input(button1) == off && input(button2) == off && input(button3) == off && input(button4)== off && input(button5) == off && input(button6) == on && input(button7) == off && input(button8) == off && input(buttonstop)== off)
{
delay_ms(1000);
delay_ms(1000);
output_high(m1);
output_low(m2);
output_high(m3);
output_high(m4);
output_low(dir);
output_low(brake);

}
else if(input(button1) == off && input(button2) == off && input(button3) == off && input(button4)== off && input(button5) == off && input(button6) == off && input(button7) == on && input(button8) == off && input(buttonstop)== off)
{
delay_ms(1000);
delay_ms(1000);
output_low(m1);
output_high(m2);
output_high(m3);
output_high(m4);
output_low(dir);
output_low(brake);


}
else if(input(button1) == off && input(button2) == off && input(button3) == off && input(button4)== off && input(button5) == off && input(button6) == off && input(button7) == off && input(button8) == on && input(buttonstop)== off)
{
delay_ms(1000);
delay_ms(1000);
output_low(m1);
output_low(m2);
output_high(m3);
output_high(m4);
output_low(dir);
output_low(brake);


}
else if(input(button1) == on && input(button2) == off && input(button3) == off && input(button4)== off && input(button5) == off && input(button6) == off && input(button7) == off && input(button8) == off && input(buttonstop) == on )
{
output_high(brake);
}

else if(input(button1) == off && input(button2) == on && input(button3) == off && input(button4)== off && input(button5) == off && input(button6) == off && input(button7) == off && input(button8) == off && input(buttonstop) == on )
{
output_high(brake);
}

else if(input(button1) == off && input(button2) == off && input(button3) == on && input(button4)== off && input(button5) == off && input(button6) == off && input(button7) == off && input(button8) == off && input(buttonstop) == on )
{
output_high(brake);
}

else if(input(button1) == off && input(button2) == off && input(button3) == off && input(button4)== on && input(button5) == off && input(button6) == off && input(button7) == off && input(button8) == off && input(buttonstop) == on )
{
output_high(brake);
}
else if(input(button1) == off && input(button2) == off && input(button3) == off && input(button4)== off && input(button5) == on && input(button6) == off && input(button7) == off && input(button8) == off && input(buttonstop) == on )
{
output_high(brake);
}
else if(input(button1) == off && input(button2) == off && input(button3) == off && input(button4)== off && input(button5) == off && input(button6) == on && input(button7) == off && input(button8) == off && input(buttonstop) == on )
{
output_high(brake);
}

else if(input(button1) == off && input(button2) == off && input(button3) == off && input(button4)== off && input(button5) == off && input(button6) == off && input(button7) == on && input(button8) == off && input(buttonstop) == on )
{
output_high(brake);
}

else if(input(button1) == off && input(button2) == off && input(button3) == off && input(button4)== off && input(button5) == off && input(button6) == off && input(button7) == off && input(button8) == on && input(buttonstop) == on )
{
output_high(brake);
}


goto loop;
}

Added after 4 minutes:

I used my friends programmer. I do not have it now to burn and send the error report to you. I think the one I highlighted in red is the problem. Can I put the code there to high 2 pins B5 and B6? Or I have to code in different way?
 

Ave_Rapina

Full Member level 2
Joined
Jan 6, 2004
Messages
122
Helped
18
Reputation
36
Reaction score
4
Trophy points
1,298
Location
Po
Activity points
683
Hello,

I don´t test the code, but have you already tried to use the command set_tris_portB(0b00000000) all zeros ->all pins as output, all ones -> Inputs

Regards
 

GSM Man

Banned
Joined
Apr 15, 2009
Messages
671
Helped
168
Reputation
338
Reaction score
94
Trophy points
1,308
Location
New Jersey, USA
Activity points
0
You're not giving me much details to go on, but...
B5 & B6 are the programming pins. There's no reason that using these pins should cause a problem with programming, but if you have a debugger attached while running the program you would get an error.

ll
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top