Here is some code I wrote for that chip . . .
Parallel:
/* HT9200B DTMF Generator Test BroHogan 7/17/09
* SETUP FOR PARALLEL MODE - Requires 5 pins - 4 data + CS (to stop tone)
* Serial Mode only req. 2 pins - no CS (cmnd to stop tone)
* Serial Mode also provides 8 "pure" tones
* Wire per data sheet - req. 3.57MHz xtal (4.0MHz works but won't dial)
*/
#define D0_PIN 2 // Data 0
#define D1_PIN 3 // Data 1
#define D2_PIN 4 // Data 2
#define D3_PIN 5 // Data 3
#define CS_PIN 6 // Chip Select LOW = On
void setup() {
pinMode(D0_PIN, OUTPUT);
pinMode(D1_PIN, OUTPUT);
pinMode(D2_PIN, OUTPUT);
pinMode(D3_PIN, OUTPUT);
pinMode(CS_PIN, OUTPUT);
}
void loop() {
//DTMF_Out (0,10000);
//Dial_Phone();
Test_DTMF();
delay(1000);
}
void DTMF_Out (byte digit, long duration){
digitalWrite(CS_PIN, LOW); // Enable chip
digitalWrite(D0_PIN, bitRead(digit,0));
digitalWrite(D1_PIN, bitRead(digit,1));
digitalWrite(D2_PIN, bitRead(digit,2));
digitalWrite(D3_PIN, bitRead(digit,3));
delay(duration);
digitalWrite(CS_PIN, HIGH); // Disable chip (req if parallel)
delay(100); // not required for dialing
}
void Test_DTMF(){ // cycles through all tones
for (byte i=0; i<16; i++){
DTMF_Out (i,400); // use this if parallel
}
}
void Dial_Phone(){ // dials phone
DTMF_Out (1,300);
DTMF_Out (8,300);
DTMF_Out (0,300); //SB 10!
DTMF_Out (0,300);
DTMF_Out (5,300);
DTMF_Out (5,300);
DTMF_Out (5,300);
DTMF_Out (1,300);
DTMF_Out (2,300);
DTMF_Out (1,300);
DTMF_Out (2,300);
}
Serial mode (better)
/* HT9200B DTMF Generator Test BroHogan 7/17/09
* SETUP FOR SERIAL MODE - Requires 3 pins - Data and Clock (100KHz) and CE
* Wire per data sheet - 3.57MHz xtal (4.0MHz won't dial) S/P to GND = serial
* Serial Mode also provides 8 "pure" tones (N/A w/ parallel)
*/
#include "HT9200.h" // defines for HT9200 DTMF chip
#define DATA_PIN 2 // Data (serial)
#define CLOCK_PIN 3 // Clock (serial)
#define CE_PIN 4 // Chip Enable pin (must control)
#define PHONE_NMBR "18005551212" // phone # to dial
char PhoneNum[] = PHONE_NMBR; // load phone # for dialer
void setup() {
pinMode(DATA_PIN, OUTPUT);
pinMode(CLOCK_PIN, OUTPUT);
pinMode(CE_PIN, OUTPUT);
Init_HT9200(); // init the chip
}
void loop() {
Dialer(); // dials phone
delay(1000);
Pure_Tones(); // plays all the pure tones
delay(3000);
}
void Init_HT9200 (){
digitalWrite(CE_PIN, HIGH); // start with chip disabled (else you go nuts)
digitalWrite(CLOCK_PIN, HIGH); // start with clock pin high
digitalWrite(CE_PIN, LOW); // now enable the chip
delay(10); // delay 10ms to ramp up the ocillator
DTMF_Out (DTMF_OFF,1,0); // turn off ant tone from previous run
}
void DTMF_Out (byte digit, long duration, long pause){ // FOR SERIAL COMM
if (digit == 0) digit = 10; // take care of 0 here
for (byte i=0; i<5; i++){
digitalWrite(CLOCK_PIN, HIGH); // clock high while setting data
digitalWrite(DATA_PIN, bitRead(digit,i)); // set data LSB->MSB
delayMicroseconds(5); // 1/2 of 100K Clock speed
digitalWrite(CLOCK_PIN, LOW); // clock low to latch data
delayMicroseconds(5); // 1/2 of 100K Clock speed
}
delay(duration); // how long tone will play
if (pause != 0){ // tone sounds continuously if zero
for (byte i=0; i<5; i++){ // same as above
digitalWrite(CLOCK_PIN, HIGH);
digitalWrite(DATA_PIN, bitRead(DTMF_OFF,i));
delayMicroseconds(5);
digitalWrite(CLOCK_PIN, LOW);
delayMicroseconds(5);
}
delay(pause); // how long pause between tones
}
}
void Dialer(){ // cycles through all tones
for (byte i=0; i<11; i++){
DTMF_Out(PhoneNum[i]-'0',500,100); // 1/2 sec tome with 1/10 pause
}
}
void Pure_Tones(){
DTMF_Out (HZ_697,1000,0);
DTMF_Out (HZ_770,1000,0);
DTMF_Out (HZ_852,1000,0);
DTMF_Out (HZ_941,1000,0);
DTMF_Out (HZ_1209,1000,0);
DTMF_Out (HZ_1336,1000,0);
DTMF_Out (HZ_1477,1000,0);
DTMF_Out (HZ_1633,1000,0);
DTMF_Out (DTMF_OFF,1,0); // turn off DTMF because zero pause used
}
and the include tab . . .
/* HT9200.h defines for HT9200 DTMF chip in serial mode */
#define DTMF_OFF 24 // SB 31 but next cmd will be lost - a not used cmnd# works fine
#define STAR 11
#define POUND 12
#define A_KEY 13
#define B_KEY 14
#define C_KEY 15
#define D_KEY 0
// pure frequencies that can be made by the chip . . .
#define HZ_697 16
#define HZ_770 17
#define HZ_852 18
#define HZ_941 19
#define HZ_1209 20
#define HZ_1336 21
#define HZ_1477 22
#define HZ_1633 23
If you're not in a big hurry, you can get them here . . .