pic18f4550 traffic signal control

in my mini project i want to control traffic signal using pic18f4550 which is accompanied by a dc motor for barrier operation on red and green signal

following is my code and am not able to run my project. Pls hel me out and correct me.

#include<p18f4550.h>

#include<stdio.h>

void MSdelay(unsigned int itime);

void main()

{

TRISB=0x00;

TRISC=0x00;

TRISD=0x00;

LATB = 0x00;

LATC = 0x00;

LATD = 0x00;

while(1)

{

PORTCbits.RC4=1;

PORTDbits.RD0=1;

PORTDbits.RD3=1;

PORTCbits.RC0=0;

LATCbits.LATC2 =1;

LATBbits.LATB0 =1;

LATBbits.LATB1 =0;

MSdelay(50);

LATBbits.LATB0 =1;

LATBbits.LATB1 =1;

MSdelay(500);

LATCbits.LATC2 =0;

LATCbits.LATC1 =1;

MSdelay(100);

LATCbits.LATC1 =0;

LATBbits.LATB0 =0;

LATBbits.LATB1 =1;

MSdelay(50);

LATCbits.LATC0 =1;

LATBbits.LATB0 =1;

LATBbits.LATB1 =1;

PORTCbits.RC4=0;

LATCbits.LATC6 =1;

LATBbits.LATB2 =1;

LATBbits.LATB3 =0;

MSdelay(50);

LATBbits.LATB2 =1;

LATBbits.LATB3 =1;

MSdelay(500);

LATCbits.LATC6 =0;

PORTCbits.RC5 =1;

MSdelay(100);

PORTCbits.RC5 =0;

LATBbits.LATB2 =0;

LATBbits.LATB3 =1;

MSdelay(50);

PORTCbits.RC4 =1;

LATBbits.LATB2 =1;

LATBbits.LATB3 =1;

PORTDbits.RD0=0;

LATDbits.LATD2 =1;

LATBbits.LATB4 =1;

LATBbits.LATB5 =0;

MSdelay(50);

LATBbits.LATB4 =1;

LATBbits.LATB5 =1;

MSdelay(500);

LATDbits.LATD2 =0;

LATDbits.LATD1 =1;

MSdelay(100);

LATDbits.LATD1 =0;

LATBbits.LATB4 =0;

LATBbits.LATB5 =1;

MSdelay(50);

LATDbits.LATD0 =1;

LATBbits.LATB4 =1;

LATBbits.LATB5 =1;

PORTDbits.RD3=0;

LATDbits.LATD0 =1;

LATDbits.LATD5 =1;

LATBbits.LATB6 =1;

LATBbits.LATB7 =0;

MSdelay(50);

LATBbits.LATB6 =1;

LATBbits.LATB7 =1;

MSdelay(500);

LATDbits.LATD5 =0;

LATDbits.LATD4 =1;

MSdelay(100);

LATDbits.LATD4 =0;

LATBbits.LATB6 =0;

LATBbits.LATB7 =1;

MSdelay(50);

LATDbits.LATD3 =1;

LATBbits.LATB6 =1;

LATBbits.LATB7 =1;

}

}

void MSdelay(unsigned int itime)

{

unsigned int i,j;

for(i=0;i<itime;i++)

for(j=0;j<1200;j++);

}

The first big problem is you didn’t comment any of your code so no one here will know what you intended to do with each step of your program.

The second problem is you didn’t describe what your problem is. We can’t help you fix it if you don’t tell us what’s wrong.

Third problem is you should not be writing values to PORT registers. Use PORT registers for reading input pins and keep your outputs on the LAT registers.

-Bill

i want design the traffic signal in which if the red signal is ON then dc motor will start and block the road with barrier

on green signal it will unblock the road

i want program code for it, am not able to build the code

the signals are four

Any one please help me

Don’t use that busy wait delay. (Don’t use any blocking delay, really.) Track how long it has been since the state changed, and how long the state should be changed for.

Refactor your code so that your main event loop is its own function. Ideally, you should use as little global state as possible, though in the microcontroller world, globals are quite common.

As far as details of your microcontroller’s IO… well… you probably won’t find many people who can help you. If you’re happy to slog through documentation, datasheets, and compiler specs without the benefit of a huge open source community, the PIC is a great chip, and you might find people who are happy to help.

I doubt if there are any PIC users here on this forum, though. Google might help you find a place for support.

If you’re willing to change to a different microcontroller, I’d suggest an Arduino. They’re very beginner friendly, have tons of tutorials, and you’ll find someone who can help you out nearly anywhere you go.

ghedipunk:
I doubt if there are any PIC users here on this forum, though.

I'm one of them. Through a combination of schooling and the preferences of the company I work for, PICs have become the controller I'm most familiar with. They aren't the only controllers I know, but certainly the ones I know the best.

If you’re willing to change to a different microcontroller, I’d suggest an Arduino. They’re very beginner friendly, have tons of tutorials, and you’ll find someone who can help you out nearly anywhere you go.

Keep in mind that an Arduino isn't a microcontroller; it's a prototyping platform that happens to contain a microcontroller, specifically an AVR from Atmel. Microchip buying Atmel should make the 8-bit controller debates interesting!

-Bill

phalanx:
Keep in mind that an Arduino isn’t a microcontroller;

I’m aware that an Arduino is an open source system-on-a-board using the ATmega chips. I brought up using an Arduino because, looking through the code originally posted and the apparent helplessness of the second request, it seemed that OP could use a bit of a more newbie friendly device and community in their project. Arduinos provide training wheels that bare microcontrollers don’t.

(As for whether PICs or ATmegas are better? Well, yes, one is better. Which one that is depends entirely on your circumstances, and my own personal experiences and preferences have absolutely no control over your situation. Personally, I’m tired or religious arguments about the superiority of any specific architecture; as in my own domain of software development, there are plenty of people who will say Java, C, C#, PHP, etc., are all superior to the others in all cases. (In actuality, the only time it’s prima facie true that one language is better than the other is when that other language is Python.))