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

[268743]

Speak.c - the code

  Here's the code, again it's not very tidy, but it's only really a little test



#include "qc.h"

//The timer control 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)

#define WAIT_HZ 40 //The delay to give 16KHz

unsigned char speak[]={
0x21,0x00,0x11,0x22,0x33,0x21,0x11,0x21,0x11,0x01,0x00,0x00,0x00,0x00,0x00,0x01,
0x11,0x35,0x49,0xFF,0xE7,0x66,0x43,0xCD,0xDC,0xC9,0x54,0x21,0x56,0x30,0x24,0x53,
0x33,0x55,0x54,0x02,0x56,0x8A,0xBB,0x84,0x02,0x45,0x79,0x87,0x43,0x21,0x01,0x22,
0x22,0x22,0x33,0x11,0x00,0x00,0x01,0x10,0x00,0x00,0x10,0x01,0x11,0x00,0x11,0x11,


deletia... and lots of it!



0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};

int main()
{

int j;
unsigned char 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 2 clock cycles - very quick!
STCR = 0x00; //set bit 0
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;
//32 gives reasonable control of the amplitude
TCORA_0=32;

//Run through the data
for (j=0;j<sizeof(speak);j++)
{

//set up the amplitude hi nybble
TCORB_0=(speak[j] & 0xF0) >> 4;
TCNT_0=0;
//wait a moment
for (bDelay=0;bDelay<WAIT_HZ;bDelay++);

//set up the aplitude lo nybble
TCORB_0=speak[j] & 0xF;
TCNT_0=0;
//wait a moment
for (bDelay=0;bDelay<WAIT_HZ;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: Actually Speaking

Show Topic: Speech

Next Page: The VB code generator