|
|
Here's the code. Yes, I know it's ugly. But it was a testy-proglet.
#include "qc.h"
//these are the timer registers #define TCR_0 (*(unsigned char *)0xffc8) #define TCSR_0 (*(unsigned char *)0xffc9) #define TCORA_0 (*(unsigned char *)0xffca) #define TCORB_0 (*(unsigned char *)0xffcb) #define TCNT_0 (*(unsigned char *)0xffcc) #define STCR (*(unsigned char *)0xffc3)
int main() { int j; unsigned char bZap, bDelay;
LCDPrints(" READY"); //give some control so we don't have to keep removing the batteries while (getc()==RUN) { LCDPrints(" RUN"); //turn off all interupts __asm__ ("\torc #0x80,ccr\n");
//Set the Timer Control Register 0 to 0 so nothing happens while we set things up TCR_0=0;
//set the clock to increment the counter every 8 clock cycles - very quick! STCR &= !0x01; //clear bit 0 of the STCR TCR_0=9; //set bit 0 for 2x, bit 3 for clear count on A //set up the output to low on compare-match A, high on a compare match B TCSR_0=9; //set TCORA_0 to 32 TCORA_0=32; //try sound levels for (j=0;j<16;j++) { //set volume TCORB_0=j;
//zapping sound for (bZap=0;bZap<255;bZap++) { //turn speaker 'sort of on' ie using our square wave TCNT_0=0; TCR_0=9; for (bDelay=0;bDelay<bZap;bDelay++);
//turn speaker off TCR_0=0; for (bDelay=0;bDelay<bZap;bDelay++); } }
//Set the Timer Control Register back to off 0 TCR_0=0;
//turn interrupts back on __asm__ ("\tandc #0x7f,ccr\n"); LCDPrints(" READY"); } LCDPrints(" DONE"); getc(); return 0;
}
|
|