PGA2310PA controler with AVR ATtiny26L ver by UENO Tomohiro 2004 07 06

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
;
; PGA2310PA controler with AVR ATtiny26L
;
; ver 1.0
; by UENO Tomohiro 2004/07/06
.include "tn26def.inc"
.def tmp = R16
.def vol = R17
.def prev_raw_vol = R18
.def prev_vol = R19
.def data_l = R20
.def data_r = R21
.equ vr = 0 ; portA
.equ zcen = 1 ; portA
.equ cs = 2 ; portA
.equ sdi = 3 ; portA
.equ sck = 4 ; portA
.equ mute = 5 ; portA
.equ select = 7 ; portA
rjmp reset ; $000 reset vector
reti ; $001 EXT_INT0
reti ; $002 PIN_CHG
reti ; $003 TIMER1 COMPA
reti ; $004 TIMER1 COMPB
reti ; $005 TIMER1 OVF1
reti ; $006 TIMER1 OVF0
reti ; $007 USI_STRT
reti ; $008 USI_OVF
reti ; $009 EE_RDY
reti ; $00A ANA_COMP
reti ; $00B ADC
reset:
ldi tmp, LOW(RAMEND)
out SP,tmp
; portA initialize
ldi tmp,0b11111110 ; 5-1:output, 7-6,0:input
out DDRA,tmp
ldi tmp,0b11011110 ; bit 7-6:pullup
out PORTA,tmp
; portB initialize
ldi tmp,0b00000000 ; bit 7-0 input (no use)
out DDRB,tmp
ldi tmp,0b11111111 ; bit 2-0 pullup
out PORTB,tmp
; AD converter initialize
ldi tmp,0b00100000 ; REFS1=0,REFS0=0(AVCC),ADLAR=1(left adjust),convert=ADC0
out ADMUX,tmp
ldi tmp,0b11100111 ; ADEN=1,ADSC=1,ADFR=1(continue),ADIF=0,ADIE=0,ASPS2-0=111
out ADCSR,tmp
sbi PINA,zcen
ldi vol,0
mov data_r,vol
mov data_l,vol
rcall write
ldi tmp,255
wait_loop:
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
dec tmp
brne wait_loop
sbi PORTA,mute
ldi prev_vol,0
ldi prev_raw_vol,0
main_loop:
ldi tmp,255
nop
nop
dec tmp
brne PC-3
in vol,ADCH
mov tmp,vol
inc tmp
cp tmp,prev_raw_vol
brlo PC+6
mov tmp,vol
dec tmp
cp prev_raw_vol,tmp
brlo PC+2
rjmp main_loop
mov prev_raw_vol,vol
in tmp,PINA
bst tmp,select
brtc PC+4
ldi ZL,LOW(vol_data_1)
ldi ZH,HIGH(vol_data_1)
rjmp PC+3
ldi ZL,LOW(vol_data_2)
ldi ZH,HIGH(vol_data_2)
lsl ZL
rol ZH
ldi tmp,0
add ZL,vol
adc ZH,tmp
lpm vol,Z
cp vol,prev_vol
breq main_loop
mov prev_vol,vol
mov data_l,vol
mov data_r,vol
rcall write
rjmp main_loop
write:
cbi PORTA,sck
cbi PORTA,cs
ldi tmp,16
write_loop:
cbi PORTA,sdi
sbrc data_r,7
sbi PORTA,sdi
sbi PORTA,sck
nop
nop
nop
nop
nop
nop
cbi PORTA,sck
lsl data_l
rol data_r
dec tmp
brne write_loop
sbi PORTA,cs
ret
vol_data_1:
.db 32,32,33,34,34,35,36,36,37,38,38,39,40,40,41,42,42,43,44,44,45,46,46,47,48,48,49,50,50,51,52,52
.db 53,54,54,55,56,56,57,58,58,59,60,60,61,62,62,63,64,64,65,66,66,67,68,68,69,70,70,71,72,72,73,74
.db 74,75,76,76,77,78,78,79,80,80,81,82,82,83,84,84,85,86,86,87,88,88,89,90,90,91,92,92,93,94,94,95
.db 96,96,97,98,98,99,100,100,101,102,102,103,104,104,105,106,106,107,108,108,109,110,110,111,112,112,113,114,114,115,116,116
.db 117,118,118,119,120,120,121,122,122,123,124,124,125,126,126,127,128,128,129,130,130,131,132,132,133,134,134,135,136,136,137,138
.db 138,139,140,140,141,142,142,143,144,144,145,146,146,147,148,148,149,150,150,151,152,152,153,154,154,155,156,156,157,158,158,159
.db 160,160,161,162,162,163,164,164,165,166,166,167,168,168,169,170,170,171,172,172,173,174,174,175,176,176,177,178,178,179,180,180
.db 181,182,182,183,184,184,185,186,186,187,188,188,189,190,190,191,192,192,193,194,194,195,196,196,197,198,198,199,200,200,201,202
vol_data_2:
.db 72,72,73,74,74,75,76,76,77,78,78,79,80,80,81,82,82,83,84,84,85,86,86,87,88,88,89,90,90,91,92,92
.db 93,94,94,95,96,96,97,98,98,99,100,100,101,102,102,103,104,104,105,106,106,107,108,108,109,110,110,111,112,112,113,114
.db 114,115,116,116,117,118,118,119,120,120,121,122,122,123,124,124,125,126,126,127,128,128,129,130,130,131,132,132,133,134,134,135
.db 136,136,137,138,138,139,140,140,141,142,142,143,144,144,145,146,146,147,148,148,149,150,150,151,152,152,153,154,154,155,156,156
.db 157,158,158,159,160,160,161,162,162,163,164,164,165,166,166,167,168,168,169,170,170,171,172,172,173,174,174,175,176,176,177,178
.db 178,179,180,180,181,182,182,183,184,184,185,186,186,187,188,188,189,190,190,191,192,192,193,194,194,195,196,196,197,198,198,199
.db 200,200,201,202,202,203,204,204,205,206,206,207,208,208,209,210,210,211,212,212,213,214,214,215,216,216,217,218,218,219,220,220
.db 221,222,222,223,224,224,225,226,226,227,228,228,229,230,230,231,232,232,233,234,234,235,236,236,237,238,238,239,240,240,241,242