La práctica número 6 de mi clase de sistemas digitales, es un pequeño teclado de 8 notas. Requiere un transistor 2n 2222, una bocina (la usada en este caso es de 8 ohms) y 8 push buttons, las resistencias puden omitirse utilizando las resistencias "pull up" incorporadas en el PIC. Aquí está el código en Ensamblador. Es extenso, pero funciona.
Además incluyo el archivo.hex y la librería de retardo utilizada
Piano.hex
Librería de retardos
;Pablo Alejandro Arreola Galván
;98482
;Sistemas digitales II
;Teclado de una octava, a la salida tenemos las notas musicales de Do a Do
;Funciona:
;**************************************************
__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC
LIST P=16F84A
INCLUDE<P16F84A.INC>
ERRORLEVEL -302
CBLOCK 0x0C
ENDC
#DEFINE Salida PORTA,0
#DEFINE Do PORTB,0
#DEFINE Re PORTB,1
#DEFINE Mi PORTB,2
#DEFINE Fa PORTB,3
#DEFINE Sol PORTB,4
#DEFINE La PORTB,5
#DEFINE Si PORTB,6
#DEFINE DO PORTB,7
;****************************************************
ORG 0
Inicio bsf STATUS, RP0 ;acceso al banco 1
clrf TRISA ;Puerto A declarado como salida
movlw 0xFF
movwf TRISB ;puerto B como entrada
bcf STATUS,RP0 ; ACCESO AL BANCO 0
;******************************************************************
Main
bcf Salida
btfsc Do ;Esta presionada la nota?
goto Ver_Re ;No, ir a la siguiente
call Retardo ;Espera a terminar los rebotes
btfsc Do ;fue un rebote?
goto fin ;Si,
Sueltado
call SuenaDo
btfss Do ;Esta presionado el boton?
goto Sueltado
goto fin
Ver_Re
btfsc Re
goto Ver_Mi
call Retardo ;Espera a terminar los rebotes
btfsc Re ;fue un rebote?
goto fin ;Si,
Sueltare
call SuenaRe
btfss Re ;Esta presionado el boton?
goto Sueltare
goto fin
Ver_Mi
btfsc Mi
goto Ver_Fa
call Retardo ;Espera a terminar los rebotes
btfsc Mi ;fue un rebote?
goto fin ;Si,
Sueltami
call SuenaMi
btfss Mi ;Esta presionado el boton?
goto Sueltami
goto fin
Ver_Fa
btfsc Fa
goto Ver_Sol
call Retardo ;Espera a terminar los rebotes
btfsc Fa ;fue un rebote?
goto fin ;Si,
Sueltafa
call SuenaFa
btfss Fa ;Esta presionado el boton?
goto Sueltafa
goto fin
Ver_Sol
btfsc Sol
goto Ver_La
call Retardo ;Espera a terminar los rebotes
btfsc Sol ;fue un rebote?
goto fin ;Si,
SueltaSol
call SuenaSol
btfss Sol ;Esta presionado el boton?
goto SueltaSol
goto fin
Ver_La
btfsc La
goto Ver_Si
call Retardo ;Espera a terminar los rebotes
btfsc La ;fue un rebote?
goto fin ;Si,
Sueltala
call SuenaLa
btfss La ;Esta presionado el boton?
goto Sueltala
goto fin
Ver_DO
btfsc DO
goto Main
call Retardo ;Espera a terminar los rebotes
btfsc DO ;fue un rebote?
goto fin ;Si,
SueltaDO
call SuenaDO
btfss DO ;Esta presionado el boton?
goto SueltaDO
goto fin
Ver_Si
btfsc Si
goto Ver_DO
call Retardo ;Espera a terminar los rebotes
btfsc Si ;fue un rebote?
goto fin ;Si,
Sueltasi
call SuenaSi
btfss Si ;Esta presionado el boton?
goto Sueltasi
fin
goto NoSuena
goto Main
;**********************************
;Subrutina
NoSuena
bsf Salida
goto Main
SuenaDo
bsf Salida
call RetarDo
bcf Salida
call RetarDo
return
SuenaRe
bsf Salida
call RetarRe
bcf Salida
call RetarRe
return
SuenaMi
bsf Salida
call RetarMi
bcf Salida
Call RetarMi
return
SuenaFa
bsf Salida
call RetarFa
bcf Salida
Call RetarFa
return
SuenaSol
bsf Salida
call RetarSol
bcf Salida
Call RetarSol
return
SuenaLa
bsf Salida
Call RetarLa
bcf Salida
call RetarLa
return
SuenaSi
bsf Salida
call RetarSi
bcf Salida
call RetarSi
return
SuenaDO
bsf Salida
call RetarDO
bcf Salida
call RetarDO
return
;***************************************
;Incluir las librerias
INCLUDE<Retardo.inc>
END
Gracias Pablo Eres el mejor :P
ResponderEliminarpodrias subir el circuito de coneccion o el diagrama porfa
ResponderEliminarel codigo no funciona, tiene errores :(
ResponderEliminar