Andy's LEGO® Mindstorms® Page
About this site
  
What's New?
  
Standard Disclaimer
Quite C
  
Francesco Ferrara
  
Getting Started
  
Installing Quite C
  
Compiling a project
  
Sample Code
Chess
  
The Robot Chess Project
  
Programming Chess
  
First Attempt
  
Version 0
  
Version 1
  
The Program
  
The State of Play
  
The User Interface
  
The Move Generator
  
The Move Applier
  
The Rating Algorithm
  
The Search Algorithm
  
Putting it all together
  
The Robot
  
The Head
  
Moving the head
  
Movies
  
Downloads: Source Executables, MLCad Models
4-in-a-Robot
  
4-in-a-Robot - the Robot
  
The 4-in-a-Robot Base
  
The 4-in-a-Robot Delivery Mechanism
  
The 4-in-a-Robot Controller
  
4-in-a-Robot - the Code
  
The 4-in-a-Robot Algorithm
  
The 4-in-a-Robot Control Programming
  
The 4-in-a-Robot Robot-less version
  
Installing 4-in-a-robot
  
Playing the robotless 4-in-a-robot
  
View the source code
Speech
  
The problems with speech
  
Sounds familiar
  
H8 Timers Background
  
Trial and Error
  
Volume Zapper
  
Actually Speaking
  
Speak.c - the code
  
The VB code generator
Some ideas for the future
  
Room positioning robot
  
Neural Net Bot
  
Pianola
  
Text to speech
LEGO® Mindstorms® Links

[268744]

Volume Zapper

  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;

}


Back to: Trial and Error

Show Topic: Speech

Next Page: Actually Speaking