;************************************
;  		LPC935 baby steps
;		10/05/2007
;
;************************************



;  		Primary controls

$NOMOD        
$TITLE(BYTE 935 Test)
$PAGEWIDTH(132)
$DEBUG
$OBJECT
$NOPAGING



;************************************
;
;  Variable declarations and equates.
;
;************************************

$include(C:\asm51\LPC935.inc) ;includes for LPC935
	
   T1COUNT 	Data 	30h  	;Timer 1 count
   ALARM1 	Bit 	01h  	;Flag for timer 0 set in timer 0 interrupt
	



	org	00H
		
	cseg
	
	ljmp 	INIT
	
	org 001Bh
	
	ljmp T1_INTERRUPT
	
INIT:

	setb P2.0	
	
MAIN:	

	
   START_50MS_TIMER #20h ;Delay for Delay_time * .05 seconds
   jnb Alarm1, $ 

   cpl P2.0
    
   ljmp main

			
;************************************
;
;	Subroutines
;
;************************************
	
;++++++++++++++++++++++++++++++++++++
;
;
;	Timer1 interrupt. Timer 1 used for multiples of .05 seconds.	
		
	
T1_INTERRUPT: 
	mov TH1,#03CH 
	mov TL1,#0B0H 
	djnz T1COUNT,T1_EXIT ;If we haven't reached 0 then jump out of int routine 
	setb ALARM1
	clr ET1		   ;stop timer
	clr TR1

T1_EXIT: 
reti 
;
;  End of Timer1 interrupt
;++++++++++++++++++++++++++++++++++++

;++++++++++++++++++++++++++++++++++++
;
;			Macros
;
;++++++++++++++++++++++++++++++++++++
		
	START_50MS_TIMER MACRO FIFTY_MS_INTERVALS 	           
           ;FIFTY_MS_INTERVALS is the 
	     ;number of .05 second
	     ;intervals to wait for
	clr ET1
	clr alarm1
	orl TMOD,#10h    ;Set timer 1 to 16-bit mode
	mov TH1,#0B0H       
	mov TL1,#03CH    ;Initialize TL1 to overflow every .05 seconds
	setb ET1         ;Enable timer interrupt 1
	setb EA          ;Enable all interrupts
      
      mov T1COUNT, FIFTY_MS_INTERVALS  ;Example - Set T1COUNT to 20 to wait for 1s
      setb TR1         ;Turn timer 1 on								

ENDM
;++++++++++++++++++++++++++++++++++++
;
;			End of Macros
;
;++++++++++++++++++++++++++++++++++++




END