Pues nocturno creo que es assembler, te posteo el codigo en realidad he partido de un diseño de diselc.es, qeu me parecio sencillo para empezar, por tanto no era asi en un principio, lo qeu he hecho es hacerme un plaquita con unos led y estoy variando parametros y provando distintas cosillas, vamos... ir aprendiendo a base te toquetear:
;******************************************************************************
;********************************** INICIO **********************************
;******************************************************************************
reset org 0x00 ;El programa comienza en la dirección 0.
goto inicio ;pasa a la posicion de inicio para evitar la int.
org 0x04 ;aqui se atienden las interupciones
DT " INICIADOR DE CD ver.01 ACTIVA CUANDO HAY CORRIENTE "
DT "tecla RANDOM 500ms tecla PLAY 500ms repeticion 5 min "
inicio bsf STATUS,5 ;Banco 1.
call 0x3ff ; CALIBRACION DEL
movwf OSCCAL ; OSCILADOR INTERNO
;movlw b'111110' ;0=salida, 1=entrada
;movwf TRISIO ;lo tranfiere al puerto
bcf RANDOM ; configuro el pin como salida
bcf PLAY ; configuro el pin como salida
bsf puerta ; configuro el pin como entrada
;habilitar resistencias internas
movlw b'00001111'
movwf OPTION_REG
movlw b'00111111' ;selecciono los pines donde quiero las resistencias
movwf WPU
bcf STATUS,5 ;Banco 0.
;instrucciones para poder utilizar GP0 y GP1 como entradas
movlw b'00000111' ; desactiva el comparador
movwf CMCON ; selecciona GPIO en vez de comparador
clrf GPIO ;todas las salidas puestas a 0
;******************************************************************************
;******************************* PRINCIPAL ***********************************
;******************************************************************************
principal clrwdt
sigue call RANDOM
call Retardo_500ms ;tiempo entre RANDON Y PLAY
call PLAY
call Retardo_5m ;tiempo que tarda en volver a iniciar
goto principal
;******************************************************************************
;******************************* RANDON ***********************************
;******************************************************************************
RANDOM clrwdt
bsf llamar ;actuo sobre el pulsador de RANDON
call demora_500ms
bcf llamar ;suelto el pulsador de RANDON
call demora_500ms
return
;******************************************************************************
;******************************* PLAY ***********************************
;******************************************************************************
PLAY clrwdt
bsf colgar ;actuo sobre el pulsador de PLAY
call demora_250ms
bcf colgar ;suelto el pulsador de PLAY
call demora_250ms
return
;******************************************************************************
;**** RETARDOS hasta 24 Horas - cuidado no sobrepasar la PILA *******
;******************************************************************************
Retardo_24h call Retardo_1h
Retardo_23h call Retardo_1h
Retardo_22h call Retardo_1h
Retardo_21h call Retardo_1h
Retardo_20h call Retardo_1h
Retardo_19h call Retardo_1h
Retardo_18h call Retardo_1h
Retardo_17h call Retardo_1h
Retardo_16h call Retardo_1h
Retardo_15h call Retardo_1h
Retardo_14h call Retardo_1h
Retardo_13h call Retardo_1h
Retardo_12h call Retardo_1h
Retardo_11h call Retardo_1h
Retardo_10h call Retardo_1h
Retardo_9h call Retardo_1h
Retardo_8h call Retardo_1h
Retardo_7h call Retardo_1h
Retardo_6h call Retardo_1h
Retardo_5h call Retardo_1h
Retardo_4h call Retardo_1h
Retardo_3h call Retardo_1h
Retardo_2h call Retardo_1h
;******************************************************************************
;**** RETARDOS hasta 1 Hora - cuidado no sobrepasar la PILA *******
;******************************************************************************
Retardo_1h call Retardo_1m
call Retardo_1m
call Retardo_1m
call Retardo_1m
call Retardo_1m
Retardo_55m call Retardo_1m
call Retardo_1m
call Retardo_1m
call Retardo_1m
call Retardo_1m
Retardo_50m call Retardo_1m
call Retardo_1m
call Retardo_1m
call Retardo_1m
call Retardo_1m
Retardo_45m call Retardo_1m
call Retardo_1m
call Retardo_1m
call Retardo_1m
call Retardo_1m
Retardo_40m call Retardo_1m
call Retardo_1m
call Retardo_1m
call Retardo_1m
call Retardo_1m
Retardo_35m call Retardo_1m
call Retardo_1m
call Retardo_1m
call Retardo_1m
call Retardo_1m
Retardo_30m call Retardo_1m
call Retardo_1m
call Retardo_1m
call Retardo_1m
call Retardo_1m
Retardo_25m call Retardo_1m
call Retardo_1m
call Retardo_1m
call Retardo_1m
call Retardo_1m
Retardo_20m call Retardo_1m
call Retardo_1m
call Retardo_1m
call Retardo_1m
call Retardo_1m
Retardo_15m call Retardo_1m
call Retardo_1m
call Retardo_1m
call Retardo_1m
call Retardo_1m
Retardo_10m call Retardo_1m
call Retardo_1m
call Retardo_1m
call Retardo_1m
call Retardo_1m
Retardo_5m call Retardo_1m
call Retardo_1m
call Retardo_1m
Retardo_2m call Retardo_1m
;******************************************************************************
;*************************** RETARDO hasta 10seg *******************
;******************************************************************************
Retardo_1m call Retardo_1s
call Retardo_1s
call Retardo_1s
call Retardo_1s
call Retardo_1s
Retardo_55s call Retardo_1s
call Retardo_1s
call Retardo_1s
call Retardo_1s
call Retardo_1s
Retardo_50s call Retardo_1s
call Retardo_1s
call Retardo_1s
call Retardo_1s
call Retardo_1s
Retardo_45s call Retardo_1s
call Retardo_1s
call Retardo_1s
call Retardo_1s
call Retardo_1s
Retardo_40s call Retardo_1s
call Retardo_1s
call Retardo_1s
call Retardo_1s
call Retardo_1s
Retardo_35s call Retardo_1s
call Retardo_1s
call Retardo_1s
call Retardo_1s
call Retardo_1s
Retardo_30s call Retardo_1s
call Retardo_1s
call Retardo_1s
call Retardo_1s
call Retardo_1s
Retardo_25s call Retardo_1s
call Retardo_1s
call Retardo_1s
call Retardo_1s
call Retardo_1s
Retardo_20s call Retardo_1s
call Retardo_1s
call Retardo_1s
call Retardo_1s
call Retardo_1s
Retardo_15s call Retardo_1s
call Retardo_1s
call Retardo_1s
call Retardo_1s
call Retardo_1s
Retardo_10s call Retardo_1s
call Retardo_1s
call Retardo_1s
call Retardo_1s
call Retardo_1s
Retardo_5s call Retardo_1s
call Retardo_1s
call Retardo_1s
call Retardo_1s
;******************************************************************************
;*************************** RETARDO 1seg ***************************
;******************************************************************************
Retardo_1s call demora_250ms
call demora_250ms
call demora_250ms
;******************************************************************************
;***************** demora 250ms ********************
;******************************************************************************
demora_250ms
DEMORA movlw .195 ; 1 set numero de repeticion (B)
movwf PDel0 ; 1 |
PLoop1 movlw .213 ; 1 set numero de repeticion (A)
movwf PDel1 ; 1 |
PLoop2 clrwdt ; 1 clear watchdog
PDelL1 goto PDelL2 ; 2 ciclos delay
PDelL2
decfsz PDel1, 1 ; 1 + (1) es el tiempo 0 ? (A)
goto PLoop2 ; 2 no, loop
decfsz PDel0, 1 ; 1 + (1) es el tiempo 0 ? (B)
goto PLoop1 ; 2 no, loop
clrwdt ; 1 ciclo delay
return ; 2+2 Fin.
;----------------------------------------------------------------------------
org 0x3FF ; OSSCAL --------------------
retlw 0x20 ; VALOR DE CALIBRACION --------------------
;----------------------------------------------------------------------------
END