how to make other command using C, for PIC 16f84a

Thread Starter

fiezzshah

Joined Feb 2, 2010
6
my supervisor ask me to use other looping command but i dont know what else to do(this job is not my field actually)..i need ur help to use other command(looping) for this code :

#include <16F84A.h>
#USE DELAY( CLOCK=4000000 ) /* Using a 4 Mhz clock */
#FUSES XT,NOWDT,NOPROTECT,NOPUT
/* Use XT mode, No Watch Dog, No Code Protect, No Power-up Timer */
#byte port_a=5/* define the location of register port_a */
#byte port_b=6 /* define the location of register port_b */

main(){
int cnt, value, Junc;
set_tris_a(0); /* set port_a to be outputs */
set_tris_b(0); /* set port_b to be outputs */
port_a = 0; /* initialize All port_b outp/uts to be zero */
port_b = 0; /* initialize All port_b outp/uts to be zero */
value = 0x01;
while( TRUE )
{ /* forever loop using WHILE construct */
cnt = 1;
value = 0x01;
while ( cnt<9 )
{

for (;Junc; )
{

port_b = 0x10;
port_a =0x0E;
Delay_MS(8000);

port_b = 0x01;
port_a =0x0E;
Delay_MS(2000);

port_b = 0x00;
port_a =0xFF;
Delay_MS(2000);

port_b = 0x20;
port_a = 0x0D;
Delay_MS(8000);

port_b = 0x02;
port_a = 0x0D;
Delay_MS(2000);

port_b = 0x00;
port_a =0x0F;
Delay_MS(2000);

port_b = 0x40;
port_a = 0x0B;
Delay_MS(8000);

port_b = 0x04;
port_a = 0x0B;
Delay_MS(2000);

port_b = 0x00;
port_a =0x0F;
Delay_MS(2000);

port_b = 0x80;
port_a = 0x07;
Delay_MS(8000);

port_b = 0x08;
port_a = 0x07;
Delay_MS(2000);

port_b = 0x00;
port_a = 0xFF;
Delay_MS(8000);

}
Delay_MS(2000);
value = value << 1; /* shift left will put 0x01, 0x02, 0x04, 0x08, 0x10 */
cnt++; /* 0x20, 0x40, 0x80 to port_a */
}
}
}

need ur help.....
 

spinnaker

Joined Oct 29, 2009
7,830
You are going to have to post a LOT more details than that if you want help. You might start with what you are trying to do.
 

RiJoRI

Joined Aug 15, 2007
536
You'll have troubles right here:
Rich (BB code):
main(){
int cnt, value, Junc;
set_tris_a(0); /* set port_a to be outputs */
set_tris_b(0); /* set port_b to be outputs */
port_a = 0; /* initialize All port_b outp/uts to be zero */
port_b = 0; /* initialize All port_b outp/uts to be zero */
value = 0x01;
while( TRUE )
{ /* forever loop using WHILE construct */
cnt = 1;
value = 0x01;
while ( cnt<9 )
{

for (;Junc; )
in that Junc is not given a start value. It WILL be JUNK.

And, for( ; Junc; ) is silly -- you are not initializing Junc, nor are you changing it. So why use a FOR loop?

--Rich
:confused:
 
Top