coding porblem~~~~~~~

Thread Starter

Jackerq1

Joined Nov 1, 2011
4
i use MBLAB PIC 16f628A
here the coding below ~~~~~~~~~~~~~~~
i wan work as normal traffic light , then my coding all can work but why the else if (RA2) cannot work ? is that i set the I\O pin wrondly ?

#include<pic.h>


__CONFIG(0x3F38);
unsigned long int i;
delay1s()
{
for(i=0;i<30000;i++)
{
NOP();
}
}

void main()
{
CMCON=7;
TRISA=0x00001111;
TRISB=0b00000000;
PORTB=0b00000000;
PORTA=0b00000000;

while(RA0)
{
while(1)
{
if(RA1)
{
PORTB=0b01001011;
delay1s();
delay1s();
delay1s();
PORTB=0b10100001;
delay1s();
delay1s();
delay1s();
delay1s();
delay1s();
delay1s();
delay1s();
delay1s();
delay1s();
delay1s();
goto s3;
}




else if(RA2)
{
PORTA=0b00001000;
delay1s();
PORTA=0b00000000;
delay1s();
break;
}
s0:
PORTB=0b01001100;
delay1s();
delay1s();
delay1s();
delay1s();
delay1s();
delay1s();
delay1s();
delay1s();
delay1s();
delay1s();
goto s1;

s1:
PORTB=0b01001011;
delay1s();
delay1s();
delay1s();
goto s2;

s2:
PORTB=0b01100001;
delay1s();
delay1s();
delay1s();
delay1s();
delay1s();
delay1s();
delay1s();
delay1s();
delay1s();
delay1s();
goto s3;

s3:
PORTB=0b01011001;
delay1s();
delay1s();
delay1s();




}
}
}
 

SgtWookie

Joined Jul 17, 2007
22,210
I am simply re-indenting your code and using the CODE tags to preserve your formatting.

Rich (BB code):
#include<pic.h>


__CONFIG(0x3F38);
unsigned long int i; 
delay1s()
{
	for(i=0;i<30000;i++)
	{
		NOP();
	}
}	

void main()
{
	CMCON=7;
	TRISA=0x00001111;
	TRISB=0b00000000;
	PORTB=0b00000000;
	PORTA=0b00000000;

	while(RA0)
	{
		while(1)
		{ 
			if(RA1) 
			{
				PORTB=0b01001011;
				delay1s();
				delay1s();
				delay1s(); 
				PORTB=0b10100001;
				delay1s();
				delay1s();
				delay1s();
				delay1s();
				delay1s();
				delay1s();
				delay1s();
				delay1s();
				delay1s();
				delay1s(); 
				goto s3;
			}




			else if(RA2)
			{
				PORTA=0b00001000;
				delay1s();
				PORTA=0b00000000;
				delay1s();
				break;
			} 
s0:
			PORTB=0b01001100;
			delay1s();
			delay1s();
			delay1s();
			delay1s();
			delay1s();
			delay1s();
			delay1s();
			delay1s();
			delay1s();
			delay1s(); 
			goto s1;

s1: 
			PORTB=0b01001011;
			delay1s();
			delay1s();
			delay1s(); 
			goto s2;

s2: 
			PORTB=0b01100001;
			delay1s();
			delay1s();
			delay1s();
			delay1s();
			delay1s();
			delay1s();
			delay1s();
			delay1s();
			delay1s();
			delay1s(); 
			goto s3;

s3:
			PORTB=0b01011001;
			delay1s();
			delay1s();
			delay1s(); 

		}
	} 
}
 
Rich (BB code):
void main()
{
    CMCON=7;
    TRISA=0x00001111; //should this not be 0b00001111?
    TRISB=0b00000000;
    PORTB=0b00000000;
    PORTA=0b00000000;
*SNIP*
 
Top