Need Help With a pic18f4550 circuit and/or code

Status
Not open for further replies.

TheDasDet

Newbie level 2
Joined
Apr 25, 2013
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,293
I'm designing a simple archery traffic light circuit with an auto and manual mode. I'm using Proteus to simulate and mplab to right the code (c code using the c18 compiler). The problem is when I'm simulating on Proteus the inputs RB0 and RB1 aren't doing the right thing (there low instead of high) which is messing up the function of the circuit. Has any body got any ideas on what I'm doing wrong cause I can't seem to figure it out.
Circuit:

Code:
/****************************************************************************************
* File Name 	: Triffic Light														        	*                                    
* Version 		: 0.0			                                 	 					                                        *
* Description 	: Archery Traffic Light sytem with both manual and auto modes.                                                           *
* Author		: Cameron Ross							 								        *
* Target		: Archery Traffic Lights													                *
* Compiler		: Microchip C18 V3.40  C Compiler										                        *
* IDE			: Microchip MPLAB IDE v8.87												                *
* Programmer	: PICKit2 or PICKit3													                *
* Last Updated	: 26 Mar 2013															        *
*																				        *
**********************************************************************************************/

#pragma config PLLDIV = 5
#pragma config USBDIV = 2
#pragma config FOSC = HSPLL_HS
#pragma config PBADEN = OFF						

  #pragma config CPUDIV = OSC1_PLL2       		

#pragma config WDT = OFF, LVP = OFF

#include "p18f4550.h"
#include "delays.h"

unsigned char LightState[3] = {0x01, 0x04, 0x02};
unsigned char LightStatePointer = 0;
unsigned char Pswitch;                                                      
unsigned long Timer1 = 0x240; 			//2  min											
unsigned long Timer2 = 0x480; 			//4  min
unsigned long Timer3 = 0x030; 			//10 sec
unsigned long Timer4 = 0x060; 			//20 sec
unsigned long Timer5 = 0xF50; 			//30 sec			
unsigned long TimeRemaining;			//Sequence length
unsigned long TimeRemaining2;			//start delay length
unsigned char test;

void main()
{
	
	TRISD = 0x00;				
	TRISB = 0xFF;
	INTCON2bits.RBPU = 0;

	while(1)
	{			
		PORTD = LightState[LightStatePointer];
		while((PORTB == 0x38) || (PORTB == 0x3A) || (PORTB == 0x34) || (PORTB == 0x36) || (PORTB == 0x34) || (PORTB == 0x2E) || (PORTB == 0x3F) || (PORTB == 0x3C) )	//automatick sequence set
		{	
			LightStatePointer = 0;
			PORTD = LightState[LightStatePointer];
			if((PORTB == 0x2E) || (PORTB == 0x2C) || (PORTB == 0x36) || (PORTB == 0x34))
			{
				if((PORTB == 0x34) || (PORTB == 0x2C))
				{
					TimeRemaining2 = Timer4; 				//set 20sec start delay
				}
				if((PORTB == 0x36) || (PORTB == 0x2E))
				{
					TimeRemaining2 = Timer3; 				//set 10sec start delay
				}
				if((PORTB ==  0x2E) || (PORTB == 0x2C))
				{
					TimeRemaining = Timer1; 				//2 min sequence length set
				}
				if((PORTB == 0x36) || (PORTB == 0x2C))
				{
					TimeRemaining = Timer2;  				//4 min sequence length set
				}
				while(LightStatePointer < 2) 
				{
					while(TimeRemaining2 > 0)
					{
						Delay10KTCYx(250);
						TimeRemaining2 --;					//start delay while loop
					}
					LightStatePointer = 1;					//sets light to green at start of sequence
					PORTD = LightState[LightStatePointer];	//set Port d to the value at lightStatePointer

					while(TimeRemaining > 0)
					{
						Delay10KTCYx(250);
						TimeRemaining--;					//Sequence length while loop

						if((PORTB == 0x3A) || (PORTB == 0x38))
						{
							TimeRemaining = 0;  			//force stop
						}
						if(TimeRemaining == Timer5)
						{
							PORTD = 0X02;          			//turns on amber at 30s to go
						}	
					}
					LightStatePointer++;
				}
			}
		}
		if(PORTB == 0x3B)
		{
			LightStatePointer = 0; 					//manualy set light to Red
		}
		if(PORTB == 0x2F)
		{
			LightStatePointer = 1; 					//manualy set light to Green
		}
		if(PORTB == 0x37)
		{
			LightStatePointer = 2;					//manualy set light to Amber
		}
	}
}
 

Your resistor pad used for the RB0, RB1, etc... is wrong. Use a resistor pad with 8 resistors and one common pin and connect the commkon pin to Vcc.

I understand what you mean I just don't understand the implementation if I do that as soon as I activate one the the switch all the inputs go to low.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…