﻿/*
 * Semaforo1.asm
 *
 * Created: 2020-02-18 00:00:00
 * Author: Víctor Alberto Salinas Reyes.
 */ 

;	****************************
;	****	IGUALDADES	****
;	****************************
		  ; VARVAR
.EQU	SL_V____R	= 0B10000100
.EQU	SL__A___R	= 0B01000100
.EQU	SL______R	= 0B00000100
.EQU	SL___RV__	= 0B00110000
.EQU	SL___R_A_	= 0B00101000
.EQU	SL___R___	= 0B00100000
;	****************************
;	****	ASIGNACIONES	****
;	****************************
	;R0 USO EN INSTRUCCIÓN LPM.
	;R1:R0 USO EN ALMACENAR EN MEMORIA DE PROGRAMA.
	;R1:R0 USO EN INSTRUCCIONES DE MULTIPLICACIÓN.
.DEF	K00	= R2	;CONSTANTE $00. == NO.
.DEF	KFF	= R3	;CONSTANTE $FF. == SÍ.
;.DEF		= R4	
;.DEF		= R5	
;.DEF		= R6	
;.DEF		= R7	
.DEF	GXL	= R8	;GENERAL DE PROGRAMA EXTRA 2 OCTETOS
.DEF	GXH	= R9	;.
.DEF	GIL	= R10	;GENERAL DE INTERRUPCIÓN 2 OCTETOS
.DEF	GIH	= R11	;.
.DEF	GPL	= R12	;GENERAL DE PROGRAMA 2 OCTETOS
.DEF	GPH	= R13	;.
.DEF	GPT	= R14	;GENERAL DE PROGRAMA.
.DEF	RAI	= R15	;ALMACÉN DE SREG EN INTERRUPCIÓN.
.DEF	TPP	= R16	;TRABAJO DE PROGRAMA.
.DEF	TII	= R17	;TRABAJO DE INTERRUPCIÓN.
.DEF	TPL	= R18	;TRABAJO DE PROGRAMA 2 OCTETOS
.DEF	TPH	= R19	;.
.DEF	TIL	= R20	;TRABAJO DE INTERRUPCIÓN 2 OCTETOS
.DEF	TIH	= R21	;.
.DEF	TPX	= R22	;TRABAJO DE PROGRAMA EXTRA.
.DEF	TIX	= R23	;TRABAJO DE INTERRUPCIÓN EXTRA.
.DEF	TWL	= R24	;OPERACIÓN INMEDIATA 2 OCTETOS
.DEF	TWH	= R25	;.
	;R25:R24 OPERANDOS EN ADIW, SBIW.
	;R27:R26 X APUNTADOR GENERAL.
	;R29:R28 Y APUNTADOR GENERAL.
	;R31:R30 Z APUNTADOR GENERAL.
;	************************************
;	****	MEMORIA DE DATOS	****
;	************************************
.DSEG
;ETIQUETA:	.BYTE	#	; # ES EL NÚMERO DE BYTES RESERVADOS.
;	********************
;	****	EEPROM	****
;	********************
.ESEG
.ORG	0
;ETIQUETA:	.BYTE	#	; # ES EL NÚMERO DE BYTES RESERVADOS.
;	************************************
;	****	MEMORIA DE PROGRAMA	****
;	************************************
.CSEG
.ORG	0
	JMP RESET ;1 0x0000 RESET External Pin, Power-on Reset, Brown-out Reset and Watchdog System Reset
	JMP ESPURIO ;2 0x0002 INT0 External Interrupt Request 0
	JMP ESPURIO ;3 0x0004 INT1 External Interrupt Request 1
	JMP ESPURIO ;4 0x0006 PCINT0 Pin Change Interrupt Request 0
	JMP ESPURIO ;5 0x0008 PCINT1 Pin Change Interrupt Request 1
	JMP ESPURIO ;6 0x000A PCINT2 Pin Change Interrupt Request 2
	JMP ESPURIO ;7 0x000C WDT Watchdog Time-out Interrupt
	JMP ESPURIO ;8 0x000E TIMER2_COMPA Timer/Counter2 Compare Match A
	JMP ESPURIO ;9 0x0010 TIMER2_COMPB Timer/Coutner2 Compare Match B
	JMP ESPURIO ;10 0x0012 TIMER2_OVF Timer/Counter2 Overflow
	JMP ESPURIO ;11 0x0014 TIMER1_CAPT Timer/Counter1 Capture Event
	JMP ESPURIO ;12 0x0016 TIMER1_COMPA Timer/Counter1 Compare Match A
	JMP ESPURIO ;13 0x0018 TIMER1_COMPB Timer/Coutner1 Compare Match B
	JMP ESPURIO ;14 0x001A TIMER1_OVF Timer/Counter1 Overflow
	JMP ESPURIO ;15 0x001C TIMER0_COMPA Timer/Counter0 Compare Match A
	JMP ESPURIO ;16 0x001E TIMER0_COMPB Timer/Coutner0 Compare Match B
	JMP ESPURIO ;17 0x0020 TIMER0_OVF Timer/Counter0 Overflow
	JMP ESPURIO ;18 0x0022 SPI0 STC SPI1 Serial Transfer Complete
	JMP ESPURIO ;19 0x0024 USART0_RX USART0 Rx Complete
	JMP ESPURIO ;20 0x0026 USART0_UDRE USART0, Data Register Empty
	JMP ESPURIO ;21 0x0028 USART0_TX USART0, Tx Complete
	JMP ESPURIO ;22 0x002A ADC ADC Conversion Complete
	JMP ESPURIO ;23 0x002C EE READY EEPROM Ready
	JMP ESPURIO ;24 0x002E ANALOG COMP Analog Comparator
	JMP ESPURIO ;25 0x0030 TWI Two-wire Serial Interface (I2C
	JMP ESPURIO ;26 0x0032 SPM READY Store Program Memory Ready
	JMP ESPURIO ;27 0x0034 USART0_START USART0 Start frame detection
	JMP ESPURIO ;28 0x0036 PCINT3 Pin Change Interrupt Request 3
	JMP ESPURIO ;29 0x0038 USART1_RX USART0 Rx Complete
	JMP ESPURIO ;30 0x003A USART1_UDRE USART0, Data Register Empty
	JMP ESPURIO ;31 0x003C USART1_TX USART0, Tx Complete
	JMP ESPURIO ;32 0x003E USART1_START USART1 Start frame detection
	JMP ESPURIO ;33 0x0040 TIMER3_CAPT Timer/Counter3 Capture Event
	JMP ESPURIO ;34 0x0042 TIMER3_COMPA Timer/Counter3 Compare Match A
	JMP ESPURIO ;35 0x0044 TIMER3_COMPB Timer/Coutner3 Compare Match B
	JMP ESPURIO ;36 0x0046 TIMER3_OVF Timer/Counter3 Overflow
	JMP ESPURIO ;37 0x0048 CFD Clock failure detection interrrupt
	JMP ESPURIO ;38 0x004A PTC_EOC PTC End of Conversion
	JMP ESPURIO ;39 0x004C PTC_WCOMP PTC Window comparator mode
	JMP ESPURIO ;40 0x004E SPI1_STC SPI1 Serial Transfer Complete
	JMP ESPURIO ;41 0x0050 TWI1 TWI1 Transfer complete
	JMP ESPURIO ;42 0x0052 TIMER4_CAPT Timer/Counter3 Capture Event
	JMP ESPURIO ;43 0x0054 TIMER4_COMPA Timer/Counter3 Compare Match A
	JMP ESPURIO ;44 0x0056 TIMER4_COMPB Timer/Coutner3 Compare Match B
	JMP ESPURIO ;45 0x0058 TIMER4_OVF Timer/Counter3 Overflow
ESPURIO:	RETI ;INTERRUPCIÓN ESPURIA; REGRESAR.
;***	INCIO DE PROGRAMA ESTABLECER	***
RESET:
	CLR K00		;ESTABLECER K00 CON $00 .
	SER TPP		;ESTABLECER KFF CON $FF
	MOV KFF,TPP	;.
;
	LDI TPP,0B11111111	;CONFIGURAR PUERTO D.
	OUT PORTD,TPP	;
	OUT DDRD,TPP	;.
;***	PROGRAMA PRINCIPAL	***
PCP:			;INICIA PROGRAMA PRINCIPAL.
	LDI TPP,SL_V____R
	OUT PORTD,TPP

	LDI TPP,SL__A___R
	OUT PORTD,TPP

	LDI TPP,SL______R
	OUT PORTD,TPP

	LDI TPP,SL___RV__
	OUT PORTD,TPP

	LDI TPP,SL___R_A_
	OUT PORTD,TPP

	LDI TPP,SL___R___
	OUT PORTD,TPP


	RJMP	PCP	;CICLO PRINCIPAL.
;***	SUBRUTINAS	***
OCIO_1:	;RETARDO DE 100 ms .
;ENTRADA:	NINGUNA
;SALIDA:	NINGUNA
;UTILIZA:	


	RET	;FIN DE SUBRUTINA.
OCIO_X:	;RETARDO DE X00 ms .
;ENTRADA:	| TPP: NÚMERO DE 100 ms |
;SALIDA:	| TPP: 0 |
;UTILIZA:	TPP {OCIO_1} 
	RCALL OCIO_1
	DEC TPP
	BRNE OCIO_X
	RET	;FIN DE SUBRUTINA.
