Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
12/12/10 07:04
Read: times


 
#180086 - Cristmas gift
Responding to: ???'s previous message
Without any warranty :-) :


;=============
LED1 equ P3.5
LED2 equ P3.7
LED3 equ P3.6
TimeForOneLed equ 10 ; in 'Delay' counts
;============


mybits_seg segment bit
mydata_seg segment data
mycode_seg segment code

;============
rseg mybits_seg
myinterrupt_flag ds 1 ; one bit variable defined - will be fired by interrupt routine
LED1state        ds 1 ; to track which one led to be fired   

rseg mydata_seg
delay1byte ds 1 ;some byte variables defined
delay2byte ds 1

;=============


rseg mycode_seg
;vectors area
                          org 0     ;startup vector                    
                          ljmp start
  
                          org 03h ;interrupt vector
                          ljmp  myInterruptRoutine

;code area
                           org 0200h
interupt:	           setb myinterrupt_flag                                                   			 	
		           RETI					
 																
start:				 
                           clr myinterrupt_flag                                                   
                           mov delay1byte,#0
        			mov IE, #81h				;// enbales interupts and enable external 0 interupt//

;=============================
mainloop:
                               
                                jnb myinterrupt_flag,Led3_No_Restart                                
                                
Led3Restart:                    mov delay1byte, #TimeForOneLed                                mov delay2byte ,#0
                                clr myinterrupt_flag
                                
Led3_No_Restart:                mov a,delay1byte
                                jz LEDs1_2blinking
                                    ;here LED3 is still in firing or fired for first time
                                setb LED1 ;turn off LED 1
                                setb LED2 ;turn off LED 2
                                clr LED1state            
                                clr LED3 ;turn on LED 3                           
                                dec a ;acc was loaded with delay1byte few lines above
                                mov delay1byte,a                                  
                                call DelayTick
                                jmp mainloop
;==
LEDs1_2blinking:                setb LED3 ;turn off
                                mov a,delay2byte
                                jz LEDs1_2change
                                dec a
                                mov  delay2byte
                                call DelayTick
                                jmp mainloop     
                                
LEDs1_2change                   mov delay2byte,#TimeForOneLed
                                     
                                jnb LED1state,LED1fire                                 
LED2fire:                       clr LED2 ;fire ,on 
                                setb LED1 ;off 
                                clr LED1state
                                sjmp LEDs1_2blkend  
LED1fire:                       setb LED1state
                                clr LED1 ;on
                                setb LED2 ;off
LEDs1_2blkend:                  
                                jmp mainloop
                                          
;============================


DelayTick:
	
				mov r7,#0fh 				;// 2nd register of delay //
d1:							

				mov r6, #0ffh				;// 1st register of dealy //
d2:	
                                jb myinterrupt_flag,DelayTickExit ;emergency exit - interupt happened				
				djnz r6 , d2				
				djnz r7 , d1	
DelayTickExit:			
				ret



						  



 



List of 6 messages in thread
TopicAuthorDate
t89c51ac2 interrupt            01/01/70 00:00      
   Classmate?            01/01/70 00:00      
      doesn't this seem peculiar?            01/01/70 00:00      
   Cristmas gift            01/01/70 00:00      
   Just for startup to 8051 mcu            01/01/70 00:00      
   Robo51; Robo-51            01/01/70 00:00      

Back to Subject List