; código ejemplo para hacer funcionar por tercera vez al PIC18F4550 mediante encendido
; y apagado de 8 led´s conectado al PORTB dependiendo del estado del pulsador en RB0
; que encenderá led´s pares e impares
; 21-Dic-2006

	LIST P=18F4550		;directive to define processor
	#include <P18F4550.INC>	;processor specific variable definitions

;#fuses XTPLL,MCLR,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL1,CPUDIV1,NOVREGEN,NOPBADEN // el fuse que configuramos anteriormente (CORREGIDO)
;#use delay(clock=48000000) // el clock que tendremos a la entrada del CPU
	
    CONFIG	FOSC = XTPLL_XT, PLLDIV = 1,CPUDIV = OSC1_PLL2,USBDIV = 2,PWRT = ON,BOR = ON, VREGEN = OFF 
	CONFIG	WDT = OFF ,WDTPS = 1,MCLRE = ON,PBADEN = OFF,LVP = OFF,XINST = OFF,DEBUG = OFF

	CBLOCK	0x0

	ENDC	

	org	0
	goto	inicio
;	org	0x8	interrup alta priori
;	org	0x18  baja prioridad
inicio:
;	clrf	LATA	; limpia los latch
;	clrf	LATB
;	clrf	LATC
;	clrf	LATD
;	clrf	LATE
    clrf	TRISA  ; configuar el port como salida  ¡que bueno!, no hay que estar cambiando de bancos ;-)
	movlw	0x1	
	movwf	TRISB	; configura RB0<- entrada, el resto -> salida
    clrf	TRISC
    clrf	TRISD
    clrf	TRISE
;//------------------------------------------------------
; ahora viene la deshabilitación de modulos (pheriperals)
;*******************************************************
	clrf,ADCON0	; desactiva el CAD
	movlw	0xf	
	movwf	ADCON1	; todas digitales
	bcf	INTCON,GIE	; desactiva interrupciones
	movlw	0x7	
	movwf	CMCON	;desactiva el modulo comparador
	;clrf	CVRCON	; desactiva el Vref del comparador no hace falta
	clrf	SPPCON	; desactiva el modulo Streaming Parallel Port (SPP)
	clrf	SSPCON1	; desactiva el modulo MSSP,SSPEN
	bcf	UCON,USBEN	; desactiva el modulo USB
	bsf	INTCON2,RBPU	; desactiva las resistencias de amarre en PORTB
   ;disable_interrupts(global);
   ;setup_adc_ports(NO_ANALOGS);
   ;setup_adc(ADC_OFF);
   ;setup_spi(FALSE);
   ;setup_psp(PSP_DISABLED);
   ;setup_comparator(NC_NC_NC_NC);
   ;setup_vref(FALSE);
;//-------------------------------------------
	;port_b_pullups(FALSE);    

ciclo:
	btfss	PORTB,0
	bra	LED_RB2
	bcf	LATB,2,0
	bcf	LATB,4,0
	bcf	LATB,6,0
	
	bsf	LATB,1,0
	bsf	LATB,3,0
	bsf	LATB,5,0
	bsf	LATB,7,0
	bra	ciclo
LED_RB2:
	bcf	LATB,1,0
	bcf	LATB,3,0
	bcf	LATB,5,0
	bcf	LATB,7,0

	bsf	LATB,2,0
	bsf	LATB,4,0
	bsf	LATB,6,0
	bra	ciclo
	end
