QUOTE(umair54 @ 2 Jun, 2007 - 07:02 PM)

CODE
#include <pic.h>
__CONFIG (INTIO & WDTDIS & PWRTEN & MCLRDIS & UNPROTECT & UNPROTECT & BORDIS & IESODIS & FCMDIS);
int i;
int j;
unsigned char OutputVal = 1 << 5;
int i, j, k, n, Flag;
const int ones = 225;
const int fiftyms = 2790;
const int twentyms = 1000;
const int fourms = 118;
main ()
{
PORTA = 0x3F;
PORTC = 0x3F;
CMCON0 = 7;
ANSEL = 0;
TRISA = 0b001100;
TRISC0 = 0;
while (1==1)
{
INTCON = 0;
Flag = 0; // Flag Pressed Button
for (i = 0; i < twentyms; ) // Debounce Button Press
for (i = 0; (i < twentyms) && (0 == RA2); i++)
if (0 == RA3)
Flag = 1;
PORTA = 0x00; // Turn off LEDs
PORTC = 0x00;
for (i = 0; i < twentyms; ) // Debounce Button Release
for (i = 0; (i < twentyms) && (1 == RA2); i++)
if (0 == RA3)
Flag = 1;
for (i = 0; (i < ones) && (0 == Flag); i++) // 1s Dlay
for (j = 0; j < ones; j++)
if (0 == RA3)
Flag = 1;
k = TMR0; // Get Start Random Value
for (i = 0; (i < k) && (0 == Flag); i++) // Random Dlay
for (j = 0; j < fourms; j++)
if (0 == RA3)
Flag = 1;
for (i = 0; i < 255; i++)
for (j = 0; j < 129; j++);
OutputVal = (OutputVal & 0x3c) >> 1;
if ((1 << 1) == OutputVal)
OutputVal = 1 << 5;
PORTC = OutputVal;
INTCON = 0; // Disable/Reset ALL Interrupts
Flag = 0; // Flag Pressed Button
for (i = 0; i < twentyms; ) // Debounce Button Press
for (i = 0; (i < twentyms) && (0 == RA3); i++)
if (0 == RA2)
Flag = 1;
PORTA = 0x00; // Turn off LEDs
PORTC = 0x00;
for (i = 0; i < twentyms; ) // Debounce Button Release
for (i = 0; (i < twentyms) && (1 == RA3); i++)
if (0 == RA2)
Flag = 1;
for (i = 0; (i < ones) && (0 == Flag); i++) // 1s Dlay
for (j = 0; j < ones; j++)
if (0 == RA2)
Flag = 1;
k = TMR0; // Get Start Random Value
for (i = 0; (i < k) && (0 == Flag); i++) // Random Dlay
for (j = 0; j < fourms; j++)
if (0 == RA2)
Flag = 1;
for (i = 0; i < 255; i++)
for (j = 0; j < 129; j++);
OutputVal = (OutputVal & 0x3c) << 1;
if ((1 << 6) == OutputVal)
OutputVal = 1 << 2;
PORTC = OutputVal;
}
}
hi guys..my name is Umair..and i have a very minor experience in programming on the C language...and i need some help (would really appreciate it)... the above program is supposed to make the stepper motor turn for a certain time (counter clockwise); when RA2 is pressed and its supposed to make the motor turn for the same time (clockwise); when RA3 is pressed..although it builds properly during the simulation on MPLABIDE but it wouldn't run when we wire it on (on a breadboard)
could you help me and show where my problem is..? and if possible i would also like some help on button command...as you can see mine are really really long...and some simplicity in this program would be of some great help...
here is a link to the PIC16F648 data sheet [link]
http://ww1.microchip.com/downloads/en/Devi...1202F-print.pdf [/link]
i'd applicate you help
Hi
Given that you are using the C language, why not do a little decomposition to extract common code blocks into functions. That will reduce your code considerably.
Now, as to your actual problem, without a schematic (i have about 30 years electronics experience) its not possible to guess the purpose of your code.
Can you make a schematic available for your hardware so we can see how its connected to the PIC?
regards
Greg