//************************************************************ // // Title: OTP Controlled Sound ( Bit Banging A Boomer ) // // Compiler Used: ByteCraft COP8C compiler version 2.0 // // // Description: // // Embedded code for the OTP Controlled Sound reference design. // The code is able to fully control the LM4835 boomer amplifier. // // By: Wallace Ly // // Audio Applications Engineer // National Semiconductor Corporation // 2900 Semiconductor Drive // Santa Clara, 95052-8090 // // Date Modified: // 11/22/98 // 11/27/98 // //************************************************************* // Some constant definitions #define SD 0 #define Mode 1 #define Mute 2 #define Beep 0 #define HP_Sense 1 #define Headphone 2 #define MAX 255 // Include the library file for the COP8SGR7 microcontroller #include "cop8sgr7.h" // Prototype definition(s) static void wait(); void main(void){ // Setup of local variables char volume_hi=50; char volume_lo=50; char state=0; // For Shutdown Mode PORTDD.SD=0; // For Mode Select PORTDD.Mode=1; // For Mute Control PORTDD.Mute=0; // For Headphone Sense - Data Out 0 PORTLC.HP_Sense=1; PORTLD.HP_Sense=0; // For Headphone Reading // Setup as high impedence input PORTLC.Headphone=0; PORTLD.Headphone=1; // For button one - high impedence mode PORTFC.0=0; PORTFD.0=1; // For button two - high impedence mode PORTFC.1=0; PORTFD.1=1; // For DC Volume Control - Set it in output PORTGC.3=1; PORTGD.3=1; // INITIAL TIMER CONFIG // IN THE INCLUDE FILE // Note: Cop8 Microcontrollers allow up to 16 bit timer // accuracy! // Start the timer at zero TMRLO=0; TMRHI=0; T1RAHI=0; T1RALO=50; T1RBHI=0; T1RBLO=50; // SET THE CONTROL BITS FOR PWM, T1A Toggle CNTRL=0B10100000; // Start Timer T1 CNTRL.T1C0=1; while (1){ // Scan the buttons while (!PORTFP.0){ state=1; // Button one was depressed wait(); } while (!PORTFP.1){ // Button two was depressed state=2; wait(); } // Detect which button was depressed switch (state) { case 1: if (volume_hi0){ volume_hi--; volume_lo++; } break; default: break; } // Load the new volume into the timer registers T1RALO=volume_hi; T1RBLO=volume_lo; // Null the state variable state=0; } // Close the while } // Close the main //**************************************************************************** // FUNCTION: wait() // APPROACH: This function provides a level of delay for the program // This function really does nothing but waste CPU Cycles. // *************************************************************************** void wait(){ // A temp character - Loop it 255 times, which is approx 255ms char j; for (j=0;j<255;j++) { NOP(); } }