TFT

Dependencies:   mbed

Fork of Ovation_Controller_1 by Andrew R

Committer:
andrewcrussell
Date:
Sat Nov 27 15:12:30 2010 +0000
Revision:
0:3811b20051b1
Child:
1:ecf8078bf531

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
andrewcrussell 0:3811b20051b1 1 /******************Ovation SCA-1 Control Program *********************/
andrewcrussell 0:3811b20051b1 2 /* Nov 2010 V1.00 */
andrewcrussell 0:3811b20051b1 3
andrewcrussell 0:3811b20051b1 4
andrewcrussell 0:3811b20051b1 5
andrewcrussell 0:3811b20051b1 6 #include "mbed.h"
andrewcrussell 0:3811b20051b1 7 /* System Definitions */
andrewcrussell 0:3811b20051b1 8 /* the follwoing are the pin assignments on the mbed controller */
andrewcrussell 0:3811b20051b1 9 DigitalOut pga2320(p30); /* normally LOW; take HIGH to select PGA2320 */
andrewcrussell 0:3811b20051b1 10 DigitalOut phono(p29);
andrewcrussell 0:3811b20051b1 11 DigitalIn IRx(p28); /* need to add p27 which is an interrupt pin */
andrewcrussell 0:3811b20051b1 12 DigitalIn IRxint(p27);
andrewcrussell 0:3811b20051b1 13 DigitalIn IPSELPB(p26);
andrewcrussell 0:3811b20051b1 14 DigitalIn IPSELB(p25);
andrewcrussell 0:3811b20051b1 15 DigitalIn IPSELA(p24);
andrewcrussell 0:3811b20051b1 16 DigitalIn VOLPB(p23);
andrewcrussell 0:3811b20051b1 17 DigitalIn VOLB(p22);
andrewcrussell 0:3811b20051b1 18 DigitalIn VOLA(p21);
andrewcrussell 0:3811b20051b1 19 AnalogIn ALS(p20);
andrewcrussell 0:3811b20051b1 20 DigitalOut SBUSON(p19);
andrewcrussell 0:3811b20051b1 21 DigitalOut NAOE(p18);
andrewcrussell 0:3811b20051b1 22 DigitalOut DC(p17);
andrewcrussell 0:3811b20051b1 23 DigitalOut RD(p16); /* also ASTROBE */
andrewcrussell 0:3811b20051b1 24 DigitalOut WR(p15); /* MDATA */
andrewcrussell 0:3811b20051b1 25 DigitalOut RS(p14); /* ACLK */
andrewcrussell 0:3811b20051b1 26 DigitalOut CS(p13);
andrewcrussell 0:3811b20051b1 27 BusInOut DB(p12, p11, p10, p9, p8, p7, p6, p5);
andrewcrussell 0:3811b20051b1 28
andrewcrussell 0:3811b20051b1 29
andrewcrussell 0:3811b20051b1 30 /* global defines */
andrewcrussell 0:3811b20051b1 31 int volume=0;
andrewcrussell 0:3811b20051b1 32 int balance_left =0;
andrewcrussell 0:3811b20051b1 33 int balance_right=0;
andrewcrussell 0:3811b20051b1 34 //int power=0;
andrewcrussell 0:3811b20051b1 35 int bright=8; /* this is the backlight brightness */
andrewcrussell 0:3811b20051b1 36 int control_bus=0; /* this is the intial setting for all the main board relays */
andrewcrussell 0:3811b20051b1 37 int relay=0; /* this is just a counter */
andrewcrussell 0:3811b20051b1 38 int control=0; /* this the 8 bits for the control outputs on the CPU board. this is the intial setting */
andrewcrussell 0:3811b20051b1 39
andrewcrussell 0:3811b20051b1 40 /*lower case defines are bit positions and upper case are TRUE or FALSE slect indicators */
andrewcrussell 0:3811b20051b1 41
andrewcrussell 0:3811b20051b1 42 #define POWERON 64;
andrewcrussell 0:3811b20051b1 43 #define POWEROFF 0;
andrewcrussell 0:3811b20051b1 44 int power=0;
andrewcrussell 0:3811b20051b1 45 #define ZLG 32
andrewcrussell 0:3811b20051b1 46 #define LG 0
andrewcrussell 0:3811b20051b1 47 int loopgain=0;
andrewcrussell 0:3811b20051b1 48 #define TRIGON 16
andrewcrussell 0:3811b20051b1 49 #define TRIGOFF 0
andrewcrussell 0:3811b20051b1 50 int trigger=0;
andrewcrussell 0:3811b20051b1 51 #define OPOFF 1
andrewcrussell 0:3811b20051b1 52 #define OPON 1
andrewcrussell 0:3811b20051b1 53 int mutebit=0;
andrewcrussell 0:3811b20051b1 54 #define HPOFF 0
andrewcrussell 0:3811b20051b1 55 #define HPON 128
andrewcrussell 0:3811b20051b1 56 int hpmutebit=0;
andrewcrussell 0:3811b20051b1 57 #define RECON 2
andrewcrussell 0:3811b20051b1 58 #define RECOFF 0
andrewcrussell 0:3811b20051b1 59 int recloop1bit=0;
andrewcrussell 0:3811b20051b1 60
andrewcrussell 0:3811b20051b1 61
andrewcrussell 0:3811b20051b1 62
andrewcrussell 0:3811b20051b1 63 /* the relay bits occupy the top 8 MSB's and the control bites the 8 LSB's in the 16 */
andrewcrussell 0:3811b20051b1 64 /* bit serial data stream from the CPU */
andrewcrussell 0:3811b20051b1 65
andrewcrussell 0:3811b20051b1 66
andrewcrussell 0:3811b20051b1 67 /* system constants */
andrewcrussell 0:3811b20051b1 68
andrewcrussell 0:3811b20051b1 69 #define HIGH 1;
andrewcrussell 0:3811b20051b1 70 #define LOW 0;
andrewcrussell 0:3811b20051b1 71 #define TRUE 1;
andrewcrussell 0:3811b20051b1 72 #define FALSE 0;
andrewcrussell 0:3811b20051b1 73 #define incdec 1;
andrewcrussell 0:3811b20051b1 74 #define VOLA (p21);
andrewcrussell 0:3811b20051b1 75 #define VOLB (p22);
andrewcrussell 0:3811b20051b1 76 #define VOLPB (p23);
andrewcrussell 0:3811b20051b1 77 #define IPSELA (p24);
andrewcrussell 0:3811b20051b1 78 #define IPSELB (p25);
andrewcrussell 0:3811b20051b1 79 #define IPSELPB (p26);
andrewcrussell 0:3811b20051b1 80 #define SERIN (p27);
andrewcrussell 0:3811b20051b1 81 #define IRxINT (p28);
andrewcrussell 0:3811b20051b1 82 /* these are the input select relay bit position assignments */
andrewcrussell 0:3811b20051b1 83 int inputrelay=1; /* inputrelay holds the bit position of the selected relay */
andrewcrussell 0:3811b20051b1 84 #define Aux2 4
andrewcrussell 0:3811b20051b1 85 #define Aux1 8
andrewcrussell 0:3811b20051b1 86 #define Tuner 16
andrewcrussell 0:3811b20051b1 87 #define CD 32
andrewcrussell 0:3811b20051b1 88 #define Phono 64
andrewcrussell 0:3811b20051b1 89
andrewcrussell 0:3811b20051b1 90 /********************** declare all interrupts here****************************/
andrewcrussell 0:3811b20051b1 91 InterruptIn volumein(p21); /* interuppt from the volume control encoder */
andrewcrussell 0:3811b20051b1 92 InterruptIn inputsel(p24); /* for the input select encoder */
andrewcrussell 0:3811b20051b1 93 InterruptIn mutesw(p26); /* this mutes the output - pb att to the sel encoder */
andrewcrussell 0:3811b20051b1 94 InterruptIn powersw(p23); /* this turns the main power on-off. Att. to the vol control encoder */
andrewcrussell 0:3811b20051b1 95
andrewcrussell 0:3811b20051b1 96
andrewcrussell 0:3811b20051b1 97 //void mutesw.fall(void);
andrewcrussell 0:3811b20051b1 98 //void volumein.fall(void);
andrewcrussell 0:3811b20051b1 99 //void inputsel.fall(void);
andrewcrussell 0:3811b20051b1 100 //void powersw.fall(void);
andrewcrussell 0:3811b20051b1 101
andrewcrussell 0:3811b20051b1 102 /*************** Serial bus routine for control relays and digital I/O ***************/
andrewcrussell 0:3811b20051b1 103 /* this routine takes the 8 bit relay data and the 8 bit control data and joins them */
andrewcrussell 0:3811b20051b1 104 /* and writes 16 bits out on the serial bus */
andrewcrussell 0:3811b20051b1 105 /* it is called by the relay function or the control function */
andrewcrussell 0:3811b20051b1 106
andrewcrussell 0:3811b20051b1 107 void serialout(void) {
andrewcrussell 0:3811b20051b1 108
andrewcrussell 0:3811b20051b1 109 mutesw.fall(NULL);
andrewcrussell 0:3811b20051b1 110 volumein.fall(NULL);
andrewcrussell 0:3811b20051b1 111 inputsel.fall(NULL);
andrewcrussell 0:3811b20051b1 112
andrewcrussell 0:3811b20051b1 113 int unsigned serialdata=0;/* the 16 bits of serial data to go out to the analog board - flush it so its clean */
andrewcrussell 0:3811b20051b1 114 int m=1;
andrewcrussell 0:3811b20051b1 115 int unsigned shift_out_bit=0;
andrewcrussell 0:3811b20051b1 116 int SCOUNT=0;
andrewcrussell 0:3811b20051b1 117 int control=0; /*control is temporary storage of the lower 8 bits of the serial bitstream */
andrewcrussell 0:3811b20051b1 118
andrewcrussell 0:3811b20051b1 119
andrewcrussell 0:3811b20051b1 120 /* put the hpmute, mute and recloop1 bits into the relay part of the output bitstream */
andrewcrussell 0:3811b20051b1 121 inputrelay=(inputrelay|hpmutebit|mutebit|recloop1bit);
andrewcrussell 0:3811b20051b1 122
andrewcrussell 0:3811b20051b1 123 //printf("1 %d %d\n\r",relay,inputrelay);
andrewcrussell 0:3811b20051b1 124
andrewcrussell 0:3811b20051b1 125 /* relay now has the input selection and the status of the mute and recloop1 relays */
andrewcrussell 0:3811b20051b1 126 /* next shift the relay data into the top 8 MSB's */
andrewcrussell 0:3811b20051b1 127
andrewcrussell 0:3811b20051b1 128 serialdata=(inputrelay<<8);
andrewcrussell 0:3811b20051b1 129
andrewcrussell 0:3811b20051b1 130 //printf("2 serialdata=%u\n\r",serialdata);
andrewcrussell 0:3811b20051b1 131
andrewcrussell 0:3811b20051b1 132 /* top 8 MSB's now have the relay data including mute, hpmute and recloop1 and the bottom 8 LSB's are filled with 0's */
andrewcrussell 0:3811b20051b1 133 /* now add the bottom 8 control bits below */
andrewcrussell 0:3811b20051b1 134
andrewcrussell 0:3811b20051b1 135
andrewcrussell 0:3811b20051b1 136 control=(control|bright|trigger|power|loopgain); /* last bit position is unused in the control word */
andrewcrussell 0:3811b20051b1 137 // printf("3 control=%d\n\r",control);
andrewcrussell 0:3811b20051b1 138 serialdata=(serialdata|control); /* we now have all the data to send to the analog board */
andrewcrussell 0:3811b20051b1 139
andrewcrussell 0:3811b20051b1 140
andrewcrussell 0:3811b20051b1 141 RD=LOW; /* ASTROBE - it must be LOW on the analog board intitially */
andrewcrussell 0:3811b20051b1 142 WR=HIGH; /* MDATA */
andrewcrussell 0:3811b20051b1 143 RS=HIGH; /* ACLK - so the clock line on the analog board is now LOW*/
andrewcrussell 0:3811b20051b1 144 SBUSON=HIGH; /* turn the SBUS on */
andrewcrussell 0:3811b20051b1 145 wait_ms(0.5);
andrewcrussell 0:3811b20051b1 146 do {
andrewcrussell 0:3811b20051b1 147
andrewcrussell 0:3811b20051b1 148 shift_out_bit = (serialdata & m); /* ADATA = the LSB (k=1) */
andrewcrussell 0:3811b20051b1 149
andrewcrussell 0:3811b20051b1 150 if (shift_out_bit==1)
andrewcrussell 0:3811b20051b1 151 {
andrewcrussell 0:3811b20051b1 152 WR=HIGH;
andrewcrussell 0:3811b20051b1 153 }
andrewcrussell 0:3811b20051b1 154 else if (shift_out_bit==0)
andrewcrussell 0:3811b20051b1 155 {
andrewcrussell 0:3811b20051b1 156 WR=LOW;
andrewcrussell 0:3811b20051b1 157 }
andrewcrussell 0:3811b20051b1 158
andrewcrussell 0:3811b20051b1 159 wait_ms(1);
andrewcrussell 0:3811b20051b1 160 RS=LOW; /* clock goes high on main board - data latches */
andrewcrussell 0:3811b20051b1 161 wait_ms(1);
andrewcrussell 0:3811b20051b1 162 RS=HIGH; /* clock goes low */
andrewcrussell 0:3811b20051b1 163 SCOUNT++; /* increment the bit counter */
andrewcrussell 0:3811b20051b1 164 m=(m<<1); /* shift bit mask up one position towards the MSB */
andrewcrussell 0:3811b20051b1 165 printf("%d\n\r",m);
andrewcrussell 0:3811b20051b1 166 } while (SCOUNT<16);
andrewcrussell 0:3811b20051b1 167
andrewcrussell 0:3811b20051b1 168 wait_ms(1);
andrewcrussell 0:3811b20051b1 169 RD=HIGH; /* Strobe the data into the A6821*/
andrewcrussell 0:3811b20051b1 170 wait_ms(1);
andrewcrussell 0:3811b20051b1 171 RD=LOW; /* Strobe now goes LOW again on the main board */
andrewcrussell 0:3811b20051b1 172 wait_ms(1);
andrewcrussell 0:3811b20051b1 173 SBUSON=LOW; /* remember to enable the outputs after intial set-up */
andrewcrussell 0:3811b20051b1 174 wait_ms(1);
andrewcrussell 0:3811b20051b1 175
andrewcrussell 0:3811b20051b1 176 //mutesw.fall(&mute_output);
andrewcrussell 0:3811b20051b1 177 //volumein.fall(&volumecontrol);
andrewcrussell 0:3811b20051b1 178 //inputsel.fall(&inputselect);
andrewcrussell 0:3811b20051b1 179 //powersw.fall(&power_on_off);
andrewcrussell 0:3811b20051b1 180
andrewcrussell 0:3811b20051b1 181 }
andrewcrussell 0:3811b20051b1 182 /******************* volume control interrupt routine **********************/
andrewcrussell 0:3811b20051b1 183
andrewcrussell 0:3811b20051b1 184 void volumecontrol(void) {
andrewcrussell 0:3811b20051b1 185 //int encoder =0; /* flush encoder to make sure its clean */
andrewcrussell 0:3811b20051b1 186 long lrvol =0; /* lrvol (i.e. left and right volume) is the concatenated left & right volume setting */
andrewcrussell 0:3811b20051b1 187 int vol_shift_bit=0;
andrewcrussell 0:3811b20051b1 188
andrewcrussell 0:3811b20051b1 189 wait_ms(3); /* wait for contact bounces to subside */
andrewcrussell 0:3811b20051b1 190
andrewcrussell 0:3811b20051b1 191 PortIn encoder(Port2, 48); /* extract data on mbed pins 21 and 22 - bit positions 8 and 16 on p2 */
andrewcrussell 0:3811b20051b1 192
andrewcrussell 0:3811b20051b1 193 switch (encoder) {
andrewcrussell 0:3811b20051b1 194 case 32:
andrewcrussell 0:3811b20051b1 195 break;
andrewcrussell 0:3811b20051b1 196 case 48:
andrewcrussell 0:3811b20051b1 197 break;
andrewcrussell 0:3811b20051b1 198 case 0: { /* rotary encoder was turned clockwise */
andrewcrussell 0:3811b20051b1 199 volume++; /* increment the volume */
andrewcrussell 0:3811b20051b1 200 }
andrewcrussell 0:3811b20051b1 201 break;
andrewcrussell 0:3811b20051b1 202
andrewcrussell 0:3811b20051b1 203 case 16: {
andrewcrussell 0:3811b20051b1 204 volume--;
andrewcrussell 0:3811b20051b1 205 }
andrewcrussell 0:3811b20051b1 206 break;
andrewcrussell 0:3811b20051b1 207 }
andrewcrussell 0:3811b20051b1 208 printf("%d ",volume);
andrewcrussell 0:3811b20051b1 209 if (volume>127)
andrewcrussell 0:3811b20051b1 210 volume=127;
andrewcrussell 0:3811b20051b1 211 if (volume <1)
andrewcrussell 0:3811b20051b1 212 volume=0;
andrewcrussell 0:3811b20051b1 213
andrewcrussell 0:3811b20051b1 214 /******************* Write the data out to the PGA2320 ************************/
andrewcrussell 0:3811b20051b1 215
andrewcrussell 0:3811b20051b1 216 int volshift=0;
andrewcrussell 0:3811b20051b1 217 int SCOUNT=0;
andrewcrussell 0:3811b20051b1 218 int k = 1;
andrewcrussell 0:3811b20051b1 219
andrewcrussell 0:3811b20051b1 220 volshift=volume;
andrewcrussell 0:3811b20051b1 221 lrvol = (volume<<9); /* volume value now occupies bits 7-14 with bits 0-6 filled with 0's */
andrewcrussell 0:3811b20051b1 222 lrvol = (lrvol|volshift); /* now have a copy of volume in botton 7 LSB's - so 14 bits of data in total*/
andrewcrussell 0:3811b20051b1 223
andrewcrussell 0:3811b20051b1 224 printf("%d\n\r",lrvol);
andrewcrussell 0:3811b20051b1 225
andrewcrussell 0:3811b20051b1 226 pga2320=LOW; /* make sure the PGA2320 is de-selected */
andrewcrussell 0:3811b20051b1 227 RD=LOW; /* ASTROBE - we do NOT use STROBE when writing the volume to the PGA2320 */
andrewcrussell 0:3811b20051b1 228 WR=LOW; /* MDATA */
andrewcrussell 0:3811b20051b1 229 RS=HIGH; /* ACLK - it is now LOW on the isolated side*/
andrewcrussell 0:3811b20051b1 230 SBUSON=HIGH; /* turn the SBUS on */
andrewcrussell 0:3811b20051b1 231 wait_us(50);
andrewcrussell 0:3811b20051b1 232 pga2320=HIGH; /* chip select the PGA2320-so it goes LOW on the analog board */
andrewcrussell 0:3811b20051b1 233 do {
andrewcrussell 0:3811b20051b1 234 vol_shift_bit = (lrvol&k); /* ADATA = the LSB (k=1) */
andrewcrussell 0:3811b20051b1 235 WR=vol_shift_bit; /* put the 1st bit to be written on the WR pin */
andrewcrussell 0:3811b20051b1 236 wait_ms(1);
andrewcrussell 0:3811b20051b1 237 RS=LOW; /* clock it out */
andrewcrussell 0:3811b20051b1 238 wait_ms(1);
andrewcrussell 0:3811b20051b1 239 RS=HIGH;
andrewcrussell 0:3811b20051b1 240 SCOUNT=SCOUNT+1; /* increment the bit counter */
andrewcrussell 0:3811b20051b1 241 k=(k<<1); /* shift bit mask up one position towards the MSB */
andrewcrussell 0:3811b20051b1 242 } while (SCOUNT<16); /* send all 16 bits for L & R channel */
andrewcrussell 0:3811b20051b1 243
andrewcrussell 0:3811b20051b1 244 wait_ms(1);
andrewcrussell 0:3811b20051b1 245 //RD=HIGH;
andrewcrussell 0:3811b20051b1 246 wait_ms(1);
andrewcrussell 0:3811b20051b1 247 //RD=LOW;
andrewcrussell 0:3811b20051b1 248
andrewcrussell 0:3811b20051b1 249 wait_us(100);
andrewcrussell 0:3811b20051b1 250 pga2320=LOW; /* deslect PGA2320 */
andrewcrussell 0:3811b20051b1 251 wait_us(100);
andrewcrussell 0:3811b20051b1 252 SBUSON=LOW; /* remember to enable the outputs after intial set-up */
andrewcrussell 0:3811b20051b1 253 wait_us(100);
andrewcrussell 0:3811b20051b1 254 }
andrewcrussell 0:3811b20051b1 255
andrewcrussell 0:3811b20051b1 256 /******************************* Input Selector Encoder Routine ****************************/
andrewcrussell 0:3811b20051b1 257 /* this function controls which relays are energized on the main analog board */
andrewcrussell 0:3811b20051b1 258 /* It calls the serialout function to send the data */
andrewcrussell 0:3811b20051b1 259
andrewcrussell 0:3811b20051b1 260 void inputselect(void) {
andrewcrussell 0:3811b20051b1 261 inputsel.fall(NULL);
andrewcrussell 0:3811b20051b1 262 //mutesw.fall(NULL);
andrewcrussell 0:3811b20051b1 263 //volumein.fall(NULL);
andrewcrussell 0:3811b20051b1 264 //powersw.fall(NULL);
andrewcrussell 0:3811b20051b1 265 wait_ms(10); /*wait for contact bounce to subside */
andrewcrussell 0:3811b20051b1 266
andrewcrussell 0:3811b20051b1 267 PortIn select(Port2, 6); /* extract data on mbed pins 24 and 25 - bit positions 2 and 4 on p2 */
andrewcrussell 0:3811b20051b1 268 //wait_ms(3);
andrewcrussell 0:3811b20051b1 269 switch (select) {
andrewcrussell 0:3811b20051b1 270 case 0: { /* rotary encoder was turned clockwise */
andrewcrussell 0:3811b20051b1 271 relay++; /* increment the selection */
andrewcrussell 0:3811b20051b1 272 }
andrewcrussell 0:3811b20051b1 273 break;
andrewcrussell 0:3811b20051b1 274 case 4: {} break; /* fall through values - ignore */
andrewcrussell 0:3811b20051b1 275 case 6: {} break;
andrewcrussell 0:3811b20051b1 276 case 2: {
andrewcrussell 0:3811b20051b1 277 relay--;
andrewcrussell 0:3811b20051b1 278 }
andrewcrussell 0:3811b20051b1 279 break;
andrewcrussell 0:3811b20051b1 280 }
andrewcrussell 0:3811b20051b1 281
andrewcrussell 0:3811b20051b1 282 if (relay>=6) /* here we make sure the select knob rotates from 1-8 to again */
andrewcrussell 0:3811b20051b1 283 relay=1;
andrewcrussell 0:3811b20051b1 284 if (relay<=0)
andrewcrussell 0:3811b20051b1 285 relay=5;
andrewcrussell 0:3811b20051b1 286 /* set the correct value in the serial bit position */
andrewcrussell 0:3811b20051b1 287 switch (relay) {
andrewcrussell 0:3811b20051b1 288 case 1:
andrewcrussell 0:3811b20051b1 289 inputrelay=4;
andrewcrussell 0:3811b20051b1 290 break; /* this is Aux2*/
andrewcrussell 0:3811b20051b1 291 case 2:
andrewcrussell 0:3811b20051b1 292 inputrelay=8;
andrewcrussell 0:3811b20051b1 293 break; /*aux1 */
andrewcrussell 0:3811b20051b1 294 case 3:
andrewcrussell 0:3811b20051b1 295 inputrelay=16;
andrewcrussell 0:3811b20051b1 296 break; /*tuner */
andrewcrussell 0:3811b20051b1 297 case 4:
andrewcrussell 0:3811b20051b1 298 inputrelay=32;
andrewcrussell 0:3811b20051b1 299 break; /*CD*/
andrewcrussell 0:3811b20051b1 300 case 5:
andrewcrussell 0:3811b20051b1 301 inputrelay=64;
andrewcrussell 0:3811b20051b1 302 break; /*phono*/
andrewcrussell 0:3811b20051b1 303 }
andrewcrussell 0:3811b20051b1 304
andrewcrussell 0:3811b20051b1 305 printf("hello");
andrewcrussell 0:3811b20051b1 306 //mutesw.fall(&mute_output);
andrewcrussell 0:3811b20051b1 307 //volumein.fall(&volumecontrol);
andrewcrussell 0:3811b20051b1 308 //powersw.fall(&power_on_off);
andrewcrussell 0:3811b20051b1 309 //wait_ms(1);
andrewcrussell 0:3811b20051b1 310 //inputsel.fall(&inputselect);
andrewcrussell 0:3811b20051b1 311 serialout();
andrewcrussell 0:3811b20051b1 312 inputsel.fall(&inputselect);
andrewcrussell 0:3811b20051b1 313
andrewcrussell 0:3811b20051b1 314 }
andrewcrussell 0:3811b20051b1 315 /**************************** output mute via front panel push button********************************/
andrewcrussell 0:3811b20051b1 316
andrewcrussell 0:3811b20051b1 317 void mute_output(void) { /* this is the interrupt handler routine */
andrewcrussell 0:3811b20051b1 318
andrewcrussell 0:3811b20051b1 319 //mutesw.fall(NULL);
andrewcrussell 0:3811b20051b1 320
andrewcrussell 0:3811b20051b1 321 wait_ms(10); /* debounce time - CRITICAL - MORE THAN 10 OR LESS THAN 5 GIVES PROBLEMS! */
andrewcrussell 0:3811b20051b1 322 if (mutebit==0) { /* it must have been off */
andrewcrussell 0:3811b20051b1 323 mutebit=1; /* so turn it ON */
andrewcrussell 0:3811b20051b1 324 volumein.fall(&volumecontrol);
andrewcrussell 0:3811b20051b1 325 inputsel.fall(&inputselect);
andrewcrussell 0:3811b20051b1 326 printf("\n\r %d Output ON",mutebit);
andrewcrussell 0:3811b20051b1 327 }
andrewcrussell 0:3811b20051b1 328
andrewcrussell 0:3811b20051b1 329 else if (mutebit==1) { /* it currently ON */
andrewcrussell 0:3811b20051b1 330 mutebit=0; /* so turn the output OFF */
andrewcrussell 0:3811b20051b1 331 volumein.fall(NULL); /* while the output is muted, you cannot change the volume or input selection */
andrewcrussell 0:3811b20051b1 332 inputsel.fall(NULL);
andrewcrussell 0:3811b20051b1 333 printf("\n\r %d Output OFF", mutebit);
andrewcrussell 0:3811b20051b1 334 }
andrewcrussell 0:3811b20051b1 335 //wait_ms(10);
andrewcrussell 0:3811b20051b1 336
andrewcrussell 0:3811b20051b1 337 serialout();
andrewcrussell 0:3811b20051b1 338 //mutesw.fall(&mute_output);
andrewcrussell 0:3811b20051b1 339
andrewcrussell 0:3811b20051b1 340 }
andrewcrussell 0:3811b20051b1 341 /**********************************initialize *****************************************/
andrewcrussell 0:3811b20051b1 342 /* this routine sets up the pre-amp at initial power-up. all relays on the main board */
andrewcrussell 0:3811b20051b1 343 /* are de-energized, volume is set to 0, display off, system in standby */
andrewcrussell 0:3811b20051b1 344
andrewcrussell 0:3811b20051b1 345 void initialize(void) {
andrewcrussell 0:3811b20051b1 346
andrewcrussell 0:3811b20051b1 347 int SCOUNT=0;
andrewcrussell 0:3811b20051b1 348 int k=1; /*this is the bit place holder that gets shifted through the data to be sent */
andrewcrussell 0:3811b20051b1 349 int flushit=0; /* flushit explicitly declared since we may want a setting other than all OFF */
andrewcrussell 0:3811b20051b1 350 int shift_flush =0;
andrewcrussell 0:3811b20051b1 351
andrewcrussell 0:3811b20051b1 352 RD=LOW; /* ASTROBE */
andrewcrussell 0:3811b20051b1 353 WR=LOW; /* MDATA */
andrewcrussell 0:3811b20051b1 354 RS=LOW; /* ACLK */
andrewcrussell 0:3811b20051b1 355 SBUSON=HIGH; /* turn the SBUS on */
andrewcrussell 0:3811b20051b1 356
andrewcrussell 0:3811b20051b1 357 do {
andrewcrussell 0:3811b20051b1 358 shift_flush=(flushit&k); /* ADATA = the LSB (k=1) */
andrewcrussell 0:3811b20051b1 359 WR=shift_flush;
andrewcrussell 0:3811b20051b1 360 wait_ms(1);
andrewcrussell 0:3811b20051b1 361 RS=HIGH; /* clock it out */
andrewcrussell 0:3811b20051b1 362 wait_ms(1);
andrewcrussell 0:3811b20051b1 363 RS=LOW;
andrewcrussell 0:3811b20051b1 364 SCOUNT=SCOUNT+1; /* increment the bit counter */
andrewcrussell 0:3811b20051b1 365 k=(k<<1); /* shift bit mask up one position towards the MSB */
andrewcrussell 0:3811b20051b1 366 } while (SCOUNT<8); /* counting starts from 0! */
andrewcrussell 0:3811b20051b1 367
andrewcrussell 0:3811b20051b1 368 wait_ms(1);
andrewcrussell 0:3811b20051b1 369 RD=HIGH; /* Strobe the data into the A6821*/
andrewcrussell 0:3811b20051b1 370 wait_ms(1);
andrewcrussell 0:3811b20051b1 371 RD=LOW; /* Strobe now goes HIGH again on the main board */
andrewcrussell 0:3811b20051b1 372 wait_ms(1);
andrewcrussell 0:3811b20051b1 373 SBUSON=LOW; /* remember to enable the outputs after intial set-up */
andrewcrussell 0:3811b20051b1 374 wait_ms(1);
andrewcrussell 0:3811b20051b1 375 printf("\n\r");
andrewcrussell 0:3811b20051b1 376 }
andrewcrussell 0:3811b20051b1 377
andrewcrussell 0:3811b20051b1 378
andrewcrussell 0:3811b20051b1 379 /******************** ON-OFF Pushbutton input *******************************************/
andrewcrussell 0:3811b20051b1 380
andrewcrussell 0:3811b20051b1 381 void power_on_off(void) {
andrewcrussell 0:3811b20051b1 382
andrewcrussell 0:3811b20051b1 383 wait_ms(10); /* debounce time NOTE IF ITS MUCH LONGER THAN 10mS THERE ARE RE-ENTRY PROBLEMS*/
andrewcrussell 0:3811b20051b1 384 if (power==0) { /* it must have been off so turn it ON */
andrewcrussell 0:3811b20051b1 385 mutebit=0; /* make sure output and headphone are muted */
andrewcrussell 0:3811b20051b1 386 recloop1bit=0;
andrewcrussell 0:3811b20051b1 387 loopgain=0;
andrewcrussell 0:3811b20051b1 388 hpmutebit=0;
andrewcrussell 0:3811b20051b1 389 trigger=0;
andrewcrussell 0:3811b20051b1 390 power=64; /* turn the main analog board on */
andrewcrussell 0:3811b20051b1 391 serialout();
andrewcrussell 0:3811b20051b1 392 wait(1); /* let things settle a bit */
andrewcrussell 0:3811b20051b1 393 NAOE=HIGH; /* turn the A6821's on */
andrewcrussell 0:3811b20051b1 394 hpmutebit=128;
andrewcrussell 0:3811b20051b1 395 mutebit=1;
andrewcrussell 0:3811b20051b1 396 serialout();
andrewcrussell 0:3811b20051b1 397 bright=8;
andrewcrussell 0:3811b20051b1 398 inputrelay=32; /* always power up with CD selected */
andrewcrussell 0:3811b20051b1 399 wait_ms(100);
andrewcrussell 0:3811b20051b1 400 trigger=16; /* go turn the power amp on */
andrewcrussell 0:3811b20051b1 401 serialout();
andrewcrussell 0:3811b20051b1 402 printf("\n\rPower ON\n");
andrewcrussell 0:3811b20051b1 403 /* enable the interrupts again */
andrewcrussell 0:3811b20051b1 404 mutesw.fall(&mute_output);
andrewcrussell 0:3811b20051b1 405 volumein.fall(&volumecontrol);
andrewcrussell 0:3811b20051b1 406 inputsel.fall(&inputselect);
andrewcrussell 0:3811b20051b1 407 power=64;
andrewcrussell 0:3811b20051b1 408
andrewcrussell 0:3811b20051b1 409
andrewcrussell 0:3811b20051b1 410 }
andrewcrussell 0:3811b20051b1 411
andrewcrussell 0:3811b20051b1 412 else if (power==64) { /* it currently ON, so turn it OFF */
andrewcrussell 0:3811b20051b1 413
andrewcrussell 0:3811b20051b1 414 /*disable all the interrupts straight away */
andrewcrussell 0:3811b20051b1 415 mutesw.fall(NULL);
andrewcrussell 0:3811b20051b1 416 volumein.fall(NULL);
andrewcrussell 0:3811b20051b1 417 inputsel.fall(NULL);
andrewcrussell 0:3811b20051b1 418 trigger=0; /*turn the power amp off first */
andrewcrussell 0:3811b20051b1 419
andrewcrussell 0:3811b20051b1 420 serialout();
andrewcrussell 0:3811b20051b1 421 wait_ms(500); /*let the amp diable the speaker */
andrewcrussell 0:3811b20051b1 422 mutebit=0;
andrewcrussell 0:3811b20051b1 423 hpmutebit=0;
andrewcrussell 0:3811b20051b1 424 serialout(); /* now turn the pre-amp outputs OFF */
andrewcrussell 0:3811b20051b1 425 wait_ms(100);
andrewcrussell 0:3811b20051b1 426 NAOE=LOW; /* disconnect all inputs */
andrewcrussell 0:3811b20051b1 427 printf("\n\rPower OFF\n");
andrewcrussell 0:3811b20051b1 428 power=0;
andrewcrussell 0:3811b20051b1 429 }
andrewcrussell 0:3811b20051b1 430
andrewcrussell 0:3811b20051b1 431 }
andrewcrussell 0:3811b20051b1 432
andrewcrussell 0:3811b20051b1 433
andrewcrussell 0:3811b20051b1 434
andrewcrussell 0:3811b20051b1 435 /******************** Test Mode Pushbutton input *******************************************/
andrewcrussell 0:3811b20051b1 436 /* in this mode, both volume and select pushbuttons must be depressed for 5 seconds */
andrewcrussell 0:3811b20051b1 437 /* the pre-amp then enters the test mode where all the relays are cycled continuosly */
andrewcrussell 0:3811b20051b1 438 /* and the volume is ramped up and down. To exit, depress any push button. */
andrewcrussell 0:3811b20051b1 439
andrewcrussell 0:3811b20051b1 440 /**********************************main program*****************************************/
andrewcrussell 0:3811b20051b1 441 int main () {
andrewcrussell 0:3811b20051b1 442 NAOE=LOW; /* make sure the A6821's are disabled */
andrewcrussell 0:3811b20051b1 443 wait_ms(5);
andrewcrussell 0:3811b20051b1 444 initialize(); /* call the SBUS routine to clean things up */
andrewcrussell 0:3811b20051b1 445 wait(1);
andrewcrussell 0:3811b20051b1 446
andrewcrussell 0:3811b20051b1 447
andrewcrussell 0:3811b20051b1 448 powersw.fall(&power_on_off);
andrewcrussell 0:3811b20051b1 449
andrewcrussell 0:3811b20051b1 450
andrewcrussell 0:3811b20051b1 451
andrewcrussell 0:3811b20051b1 452 do {
andrewcrussell 0:3811b20051b1 453
andrewcrussell 0:3811b20051b1 454 } while (1);
andrewcrussell 0:3811b20051b1 455 }