traffic lights

Thread Starter

djstar

Joined Jan 26, 2008
39
hi , im very new to assembly langauge and im doing a unit at college on it. my assignment is to write a program that would simulate a pelican crosing. ive had a good go at writting it but when i load it into the assembler it comes up with erros.


th sequence should go

TURN ON GREEN LED
DELAY
TURN ON AMBER LED ON
SMALL DELAY
TURN RED LED ON AND SOUND A BUZER
DELAY
FLASH AMBER LED ON AND OF



ive had a go at the program up to the buzer but im a bit confused to whi it isent workong.

p3 is port 3 of the robot is a bank of leds and port 2.7 is the buzzer.

if you need any more information then just say.

many thanks laura

Rich (BB code):
 main1()
 
 {
 
 #pragma asm



start:

                mov P3, #0Dfh                 ;// turn on green led//
                

    
                mov r7, #0ffh                 ;// move ffh to reg 7 ( DELAY)//
outerloop1:            
                

                mov r6, #0ffh                ;// move ffh to reg 6 (DELAY)//
innerloop1:    


                mov r5, #0ffh
inner:        

                djnz r5 inner
                
                djnz r6 innerloop1
                
                djnz r7 outerloop1
                
                mov P3, #0bfh                 ;// turn amber led on //
            
            
            
            
            
                
                mov r7, #3fh                 ;// move ffh to reg 7//
outerloop2:                    

                mov r6, #0ffh                ;// move ffh to reg 6//
innerloop2:                
                
                mov r5, #0ffh
inner2:                
                djnz r5 inner2
                
                djnz r6 innerloop2
                
                djnz r7 outerloop2
                
            
                mov P3, #7fh                  ;// turn red led on //
            
            
            
buzzer:        
            
                mov P2, #80h                  ;// siren on //

                ACALL, delay:                 ;//  (delay)//
                                
                mov P2, #00h                 ;// siren off//
                
                ACALL, delay:                 ;//  (delay)//
                
                



delay:    
                            

                mov r2, #0fh                ;// move ffh to reg 6//
innerloop8:    


                mov r1, #0ffh                ;// move ffh to reg 5//
inner8:        

                djnz r1 inner8
                
                djnz r2 innerloop8
                
                ret
                
                
                
#pragma endasm

}
 
Last edited:

spinnaker

Joined Oct 29, 2009
7,830
Aren't pelicans color blind? :)


It might help if you listed the error you are getting.

Do you have to do this in assembler? C and BASIC are so much easier.
 

Thread Starter

djstar

Joined Jan 26, 2008
39
Thansk for the reply guys. we are doing a microcontroller module and it is all about assembly langague so that is what we have to program in. ive edited the script a bit because i realised one thing that was going wrong. The only thing i am stuck on is how to loop a sub routine.

on the label "buzzerr:" the buzer is turned on and then it jumps to the delay and then turns the buzzer off then jumps down to the delay again, i need to loop this "buzzerr:" for this delay

Rich (BB code):
				mov r7, #0ffh 				;// move ffh to reg 7 ( DELAY)//
outerloop1:			
				

				mov r6, #0ffh				;// move ffh to reg 6 (DELAY)//
innerloop1:	


				mov r5, #0ffh
inner:		

				djnz r5 inner
				
				djnz r6 innerloop1
				
				djnz r7 outerloop1

so what i am after is the buzer to turn on and of for a set time. Im not sure if you need this information but the controller i am using is a 8051 and the spare registeries i have left are R3 R4

many thanks
 

Markd77

Joined Sep 7, 2009
2,806
I'd just put a loop around the buzzer part so it flashes 10 times (change as required).
Make sure it finishes with buzzer off.
In your delay sub you can reuse R7 and R6 if you want instead of r1 and r2.
 

PRS

Joined Aug 24, 2008
989
Use a software delay. This is just a loop that counts to a number then exits. The number determines the length of the delay.
 

Markd77

Joined Sep 7, 2009
2,806
This is a loop: it just turns the siren on and off about 10 times.
(not sure about my syntax, this is my first 8051 code).
Rich (BB code):
mov r6, #0Ah
buzzer:        
            
                mov P2, #80h                  ;// siren on //

                ACALL, delay:                 ;//  (delay)//
                                
                mov P2, #00h                 ;// siren off//
                
                ACALL, delay:                 ;//  (delay)//

djnz r6 buzzer
 

maxpower097

Joined Feb 20, 2009
816
What would be cool is to take it a step further and add sensors to the red lights to make them change when a car pulls up to the red. This would require a little more hardware and coding but would be a real representation of a stop light. Also find out the formula for yellow light lengths. There is a formula involving the type of street and mph. You could also add the white led at the bottom so police can tell if the light is red from the other direction. That should give you some extra credit. Have it where you can select 25mph light, 35mph, .... 55mph light. Sensors to detect cars for rural lights, Flashing yellow/red, flashing red for all stop, Then may be think about a turn light system and how it ties into all the other lights.
 
Last edited:

thatoneguy

Joined Feb 19, 2009
6,359
What would be cool is to take it a step further and add sensors to the red lights to make them change when a car pulls up to the red. This would require a little more hardware and coding but would be a real representation of a stop light. Also find out the formula for yellow light lengths. There is a formula involving the type of street and mph. You could also add the white led at the bottom so police can tell if the light is red from the other direction. That should give you some extra credit. Have it where you can select 25mph light, 35mph, .... 55mph light. Sensors to detect cars for rural lights, Flashing yellow/red, flashing red for all stop, Then may be think about a turn light system and how it ties into all the other lights.

I don't think pelicans can walk over 25mph.
 

maxpower097

Joined Feb 20, 2009
816
Sorry I must be dislesic. My mind kept reading pedestrian not pelican. So I kept thinking it would be a normal light. LOL Whoops my bad for not reading left to right.
 

thatoneguy

Joined Feb 19, 2009
6,359
Sorry I must be dislesic. My mind kept reading pedestrian not pelican. So I kept thinking it would be a normal light. LOL Whoops my bad for not reading left to right.
We are all only human and make errors. Being corrected keeps us on our toes, since some people think we can never be wrong.
 

Markd77

Joined Sep 7, 2009
2,806
Are you thinking something like this?
(Actually pelican crossings are just what we call pedestrian crossings on this side of the pond).
 

Attachments

Top