Paso 1: Código fuente, generación de sonido
INICIO:. INCLUYEN "tn26def.inc"
CLR r23
CLR r24
CLR r25
CLR r26
CLR r27
CLR r28
CLR r29
CLR r30
CLR r31
LDI r25, 0b10000000; aquí es donde define el pin de salida mal... Deben ser
LDI r26, 0b00000000; 0b00000001 que creo. Para la prueba si no está seguro use 0b11111111.
a DDRA, r25
NOP
a PORTA, r26
NOP
out DDRB, r26
NOP
ENTRADA:
posibles notas 96, además de silencio (cero)
a PORTA, r26; Silencio si no hay entrada
NOP
en r28, PINB
MOV r31, r28
CPI r28, 0b00000000
breq entrada
D8S:
; 5.1 khz
CPI r28, 0b00000001
Brne D8
LDI r29, 0b00010000
LDI r30, 0b00000001
D8:
; 4.63 khz
CPI r28, 0b00000010
Brne C8S
LDI r29, 0b00010010
LDI r30, 0b00000001
C8S:
; 4.42 khz
CPI r28, 0b00000011
Brne C8
LDI r29, 0b00010011
LDI r30, 0b00000001
C8:
; 4.24 khz
CPI r28, 0b00000100
Brne B7
LDI r29, 0b00010100
LDI r30, 0b00000001
rjmp B7
INPUT91:
rjmp entrada
B7:
; 3.91 khz
CPI r28, 0b00000101
Brne A7S
LDI r29, 0b00010110
LDI r30, 0b00000001
A7S:
; 3.70 khz
CPI r28, 0b00000110
Brne A7
LDI r29, 0b00010111
LDI r30, 0b00000001
A7:
; 3.57 khz
CPI r28, 0b00000111
Brne G7
LDI r29, 0b00011001
LDI r30, 0b00000001
G7:
; 3.13 khz
CPI r28, 0b00001000
Brne F7S
LDI r29, 0b00011010
LDI r30, 0b00000001
F7S:
; 2.94 khz
CPI r28, 0b00001001
Brne F7
LDI r29, 0b00011110
LDI r30, 0b00000001
F7:
; 2.78 khz
CPI r28, 0b00001010
Brne E7
LDI r29, 0b00100000
LDI r30, 0b00000001
E7:
; 2.63 khz
CPI r28, 0b00001011
Brne D7S
LDI r29, 0b00100010
LDI r30, 0b00000001
D7S:
; 2.50 khz
CPI r28, 0b00001100
Brne D7
LDI r29, 0b00100101
LDI r30, 0b00000001
D7:
; 2.33 khz
CPI r28, 0b00001101
Brne C7S
LDI r29, 0b00100111
LDI r30, 0b00000001
C7S:
; 2.22 khz
CPI r28, 0b00001110
Brne C7
LDI r29, 0b00101010
LDI r30, 0b00000001
C7:
; 2.08 khz
CPI r28, 0b00001111
Brne B6
LDI r29, 0b00101100
LDI r30, 0b00000001
rjmp B6
INPUT92:
rjmp INPUT91
B6:
; 1.96 khz
CPI r28, 0b00010000
Brne A6S
LDI r29, 0b00101111
LDI r30, 0b00000001
A6S:
; 1.85 khz
CPI r28, 0b00010001
Brne A6
LDI r29, 0b00110010
LDI r30, 0b00000001
A6:
; 1.75 khz
CPI r28, 0b00010010
Brne G6S
LDI r29, 0b00110101
LDI r30, 0b00000001
G6S:
; 1.67 khz
CPI r28, 0b00010011
Brne G6
LDI r29, 0b00111001
LDI r30, 0b00000001
G6:
; 1.56 khz
CPI r28, 0b00010100
Brne F6S
LDI r29, 0b00111100
LDI r30, 0b00000001
F6S:
; 1.47 khz
CPI r28, 0b00010101
Brne F6
LDI r29, 0b01000000
LDI r30, 0b00000001
F6:
; 1.39 khz
CPI r28, 0b00010110
Brne E6
LDI r29, 0b01000100
LDI r30, 0b00000001
E6:
; 1.32 khz
CPI r28, 0b00010111
Brne D6S
LDI r29, 0b01001000
LDI r30, 0b00000001
D6S:
; 1,25 khz
CPI r28, 0b00011000
Brne D6
LDI r29, 0b01001101
LDI r30, 0b00000001
D6:
; 1.18 khz
CPI r28, 0b00011001
Brne C6S
LDI r29, 0b01010010
LDI r30, 0b00000001
C6S:
; 1.11 khz
CPI r28, 0b00011010
Brne C6
LDI r29, 0b01010111
LDI r30, 0b00000001
C6:
; 1.04 khz
CPI r28, 0b00011011
Brne B5
LDI r29, 0b01011100
LDI r30, 0b00000001
rjmp B5
INPUT93:
rjmp INPUT92
B5:
Hz 990
CPI r28, 0b00011100
Brne A5S
LDI r29, 0b01100010
LDI r30, 0b00000001
A5S:
Hz 935
CPI r28, 0b00011101
Brne A5
LDI r29, 0b01101000
LDI r30, 0b00000001
A5:
Hz 877
CPI r28, 0b00011110
Brne G5S
LDI r29, 0b01101110
LDI r30, 0b00000001
G5S:
Hz 833
CPI r28, 0b00011111
Brne G5
LDI r29, 0b01110101
LDI r30, 0b00000001
G5:
Hz 781
CPI r28, 0b00100000
Brne F5S
LDI r29, 0b01111100
LDI r30, 0b00000001
F5S:
741Hz
CPI r28, 0b00100001
Brne F5
LDI r29, 0b10000100
LDI r30, 0b00000001
F5:
Hz 699
CPI r28, 0b00100010
Brne E5
LDI r29, 0b10001100
LDI r30, 0b00000001
E5:
Hz 658
CPI r28, 0b00100011
Brne D5S
LDI r29, 0b10010100
LDI r30, 0b00000001
D5S:
Hz 621
CPI r28, 0b00100100
Brne D5
LDI r29, 0b10011101
LDI r30, 0b00000001
D5:
Hz 588
CPI r28, 0b00100101
Brne C5S
LDI r29, 0b10100111
LDI r30, 0b00000001
C5S:
555Hz
CPI r28, 0b00100110
Brne C5
LDI r29, 0b10110001
LDI r30, 0b00000001
C5:
Hz 524
CPI r28, 0b00100111
Brne B4
LDI r29, 0b10111100
LDI r30, 0b00000001
rjmp B4
INPUT94:
rjmp INPUT93
B4:
;
CPI r28, 0b00101000
Brne A4S
LDI r29, 0b11000111
LDI r30, 0b00000001
A4S:
;
CPI r28, 0b00101001
Brne A4
LDI r29, 0b11010011
LDI r30, 0b00000001
A4:
;
CPI r28, 0b00101010
Brne G4S
LDI r29, 0b11100000
LDI r30, 0b00000001
G4S:
;
CPI r28, 0b00101011
Brne G4
LDI r29, 0b11101101
LDI r30, 0b00000001
G4:
;
CPI r28, 0b00101100
Brne F4S
LDI r29, 0b11111100
LDI r30, 0b00000001
F4S:
;
CPI r28, 0b00101101
Brne F4
LDI r29, 0b00101011
LDI r30, 0b00000101
F4:
;
CPI r28, 0b00101110
Brne E4
LDI r29, 0b00101101
LDI r30, 0b00000101
E4:
;
CPI r28, 0b00101111
Brne D4S
LDI r29, 0b00110000
LDI r30, 0b00000101
D4S:
;
CPI r28, 0b00110000
Brne D4
LDI r29, 0b00110011
LDI r30, 0b00000101
D4:
;
CPI r28, 0b00110001
Brne C4S
LDI r29, 0b00110110
LDI r30, 0b00000101
C4S:
;
CPI r28, 0b00110010
Brne C4
LDI r29, 0b00111010
LDI r30, 0b00000101
C4:
;
CPI r28, 0b00110011
Brne B3
LDI r29, 0b00111101
LDI r30, 0b00000101
rjmp B3
INPUT95:
rjmp INPUT94
B3:
;
CPI r28, 0b00110100
Brne A3S
LDI r29, 0b01000001
LDI r30, 0b00000101
A3S:
;
CPI r28, 0b00110101
Brne A3
LDI r29, 0b01000101
LDI r30, 0b00000101
A3:
;
CPI r28, 0b00110110
Brne G3S
LDI r29, 0b01001001
LDI r30, 0b00000101
G3S:
;
CPI r28, 0b00110111
Brne G3
LDI r29, 0b01001110
LDI r30, 0b00000101
G3:
;
CPI r28, 0b00111000
Brne F3S
LDI r29, 0b01010011
LDI r30, 0b00000101
F3S:
;
CPI r28, 0b00111001
Brne F3
LDI r29, 0b01011000
LDI r30, 0b00000101
F3:
;
CPI r28, 0b00111010
Brne E3
LDI r29, 0b01011101
LDI r30, 0b00000101
E3:
;
CPI r28, 0b00111011
Brne D3S
LDI r29, 0b01100011
LDI r30, 0b00000101
D3S:
;
CPI r28, 0b00111100
Brne D3
LDI r29, 0b01101000
LDI r30, 0b00000101
D3:
;
CPI r28, 0b00111101
Brne C3S
LDI r29, 0b01101111
LDI r30, 0b00000101
C3S:
;
CPI r28, 0b00111110
Brne C3
LDI r29, 0b01110101
LDI r30, 0b00000101
C3:
;
CPI r28, 0b01111111
Brne B2
LDI r29, 0b01111101
LDI r30, 0b00000101
rjmp B2
INPUT96:
rjmp INPUT95
B2:
;
CPI r28, 0b01000000
Brne A2S
LDI r29, 0b10000101
LDI r30, 0b00000101
A2S:
;
CPI r28, 0b01000001
Brne A2
LDI r29, 0b10001101
LDI r30, 0b00000101
A2:
;
CPI r28, 0b01000010
Brne G2S
LDI r29, 0b10010101
LDI r30, 0b00000101
G2S:
;
CPI r28, 0b01000011
Brne G2
LDI r29, 0b10011110
LDI r30, 0b00000101
G2:
;
CPI r28, 0b01000100
Brne F2S
LDI r29, 0b10101000
LDI r30, 0b00000101
F2S:
;
CPI r28, 0b01000101
Brne F2
LDI r29, 0b10110010
LDI r30, 0b00000101
F2:
;
CPI r28, 0b01000110
Brne E2
LDI r29, 0b10111100
LDI r30, 0b00000101
E2:
;
CPI r28, 0b01000111
Brne D2S
LDI r29, 0b11001000
LDI r30, 0b00000101
D2S:
;
CPI r28, 0b01001000
Brne D2
LDI r29, 0b11010100
LDI r30, 0b00000101
D2:
;
CPI r28, 0b01001001
Brne C2S
LDI r29, 0b11100001
LDI r30, 0b00000101
C2S:
;
CPI r28, 0b01001010
Brne C2
LDI r29, 0b11101110
LDI r30, 0b00000101
C2:
;
CPI r28, 0b01001011
Brne B1
LDI r29, 0b11111100
LDI r30, 0b00000101
rjmp B1
INPUT97:
rjmp INPUT96
B1:
;
CPI r28, 0b01001011
Brne A1S
LDI r29, 0b00111111
LDI r30, 0b00011001
A1S:
;
CPI r28, 0b01001100
Brne A1
LDI r29, 0b01000010
LDI r30, 0b00011001
A1:
;
CPI r28, 0b01001101
Brne G1S
LDI r29, 0b01000110
LDI r30, 0b00011001
G1S:
;
CPI r28, 0b01001110
Brne G1
LDI r29, 0b01001011
LDI r30, 0b00011001
G1:
;
CPI r28, 0b01001111
Brne F1S
LDI r29, 0b01001111
LDI r30, 0b00011001
F1S:
;
CPI r28, 0b01010000
Brne F1
LDI r29, 0b01010100
LDI r30, 0b00011001
F1:
;
CPI r28, 0b01010001
Brne E1
LDI r29, 0b01011001
LDI r30, 0b00011001
E1:
;
CPI r28, 0b01010010
Brne D1S
LDI r29, 0b01011111
LDI r30, 0b00011001
D1S:
;
CPI r28, 0b01010011
Brne D1
LDI r29, 0b01100101
LDI r30, 0b00011001
D1:
;
CPI r28, 0b01010100
Brne C1S
LDI r29, 0b01101011
LDI r30, 0b00011001
C1S:
;
CPI r28, 0b01010101
Brne C1
LDI r29, 0b01110001
LDI r30, 0b00011001
C1:
;
CPI r28, 0b01010110
Brne B0
LDI r29, 0b01111000
LDI r30, 0b00011001
rjmp B0
INPUT98:
rjmp INPUT97
B0:
;
CPI r28, 0b01010111
Brne A0S
LDI r29, 0b01111111
LDI r30, 0b00011001
A0S:
;
CPI r28, 0b01011000
Brne A0
LDI r29, 0b10000111
LDI r30, 0b00011001
A0:
;
CPI r28, 0b01011001
Brne G0S
LDI r29, 0b10001111
LDI r30, 0b00011001
G0S:
;
CPI r28, 0b01011010
Brne G0
LDI r29, 0b10011000
LDI r30, 0b00011001
G0:
;
CPI r28, 0b01011011
Brne F0S
LDI r29, 0b10100001
LDI r30, 0b00011001
F0S:
;
CPI r28, 0b01011100
Brne F0
LDI r29, 0b10101011
LDI r30, 0b00011001
F0:
;
CPI r28, 0b01011101
Brne E0
LDI r29, 0b10110101
LDI r30, 0b00011001
E0:
;
CPI r28, 0b01011110
Brne D0S
LDI r29, 0b11000000
LDI r30, 0b00011001
D0S:
;
CPI r28, 0b01011111
Brne D0
LDI r29, 0b11001011
LDI r30, 0b00011001
D0:
;
CPI r28, 0b01100000
Brne C0S
LDI r29, 0b11011000
LDI r30, 0b00011001
C0S:
;
CPI r28, 0b01100001
Brne C0
LDI r29, 0b11100101
LDI r30, 0b00011001
C0:
;
CPI r28, 0b01100010
Brne Hola
LDI r29, 0b11110010
LDI r30, 0b00011001
rjmp Hola
INPUT99:
rjmp INPUT98
Hola:
a PORTA, r25
CLR r27
NOP; Para compensar la función INPUT1, haciendo alto/bajo igualdad de longitudes
NOP
NOP
NOP
NOP
TIMER0h:; 5 ciclos de cpu por cuenta
r24 Inc
NOP
CP r24, r29
Brne TIMER0h
rjmp TIMER1h
TIMER1h:; 6 ciclos de cpu por cuenta
CLR r24
r27 Inc
CP r27, r30
NOP
Brne TIMER0h
rjmp lo
lo:
a PORTA, r26
CLR r27
TIMER0l:; 5 ciclos de cpu por cuenta
r24 Inc
NOP
CP r24, r29
Brne TIMER0l
rjmp TIMER1l
TIMER1l:; 6 ciclos de cpu por cuenta
r27 Inc
NOP
CLR r24
CP r27, r30
Brne TIMER0l
rjmp INPUT1
INPUT1:; Compruebe para ver si entrada ha cambiado, si no, seguir la salida
en r28, PINB; 5 ciclos en esta función
CP r28, r31
Brne INPUT99
rjmp Hola