음성 방송 모듈 JQ8400-FL 사용
113528 단어 외부 설비
문서 목록
의존성:
광원 추적기 코드:
voice.h
: #ifndef __VOICE_H
#define __VOICE_H
#include "15W4KxxS4.H"
#include "delay.h"
#include "uart.h"
#define Voice_UART4 1 //
#define Voice_OneLine 0 // OneLine
sbit Voice_Busy = P0^4; //
extern unsigned char Voice_Volume;
#if(Voice_UART4)
//
//
//
void Voice_Uart4_Init();
void Voice_Uart4_Play_Single(unsigned int index);
void Voice_Uart4_Play_Comb(unsigned char *Str);
void VOICE_UART4_playSpeed(unsigned char *Str);
#endif
#if(Voice_OneLine)
//
sbit VOICE_ONELINE = P0^0;
//
#define VOICE_ONELINE_Set() VOICE_ONELINE = 1
#define VOICE_ONELINE_Clear() VOICE_ONELINE = 0
//
void Oneline_Send_Byte(unsigned char send_byte);
void Voice_Play_Audio(unsigned char audio_index);
void Voice_Play_Single();
#endif
#endif
voice.c
: // : voice.c
// :
// ----------------------------------------------------------------
// ONELINE ,
// ----------------------------------------------------------------
#include "voice.h"
unsigned char Voice_Volume = 20;
#if(Voice_UART4)
void Voice_Uart4_Init() {
UART4_Init(2, 9600);
INT_CLKO |= 0x30; //xx11 xxxx 3, 2,
// 20
UART4_PutChar(0xAA); //
UART4_PutChar(0x13); //
UART4_PutChar(0x01);
UART4_PutChar(0x14);
UART4_PutChar(0xD2);
}
void Voice_Uart4_Play_Single(unsigned int index) {
UART4_PutChar(0xAA); //
UART4_PutChar(0x07); //
UART4_PutChar(0x02); //
UART4_PutChar((unsigned char)(index>>8)); //
UART4_PutChar((unsigned char)index); //
UART4_PutChar((unsigned char)(0xAA+0x07+0x02+(index>>8)+index));//
}
/* - */
void VOICE_UART4_playSpeed(unsigned char *Str){
unsigned char sum = 0x00;
UART4_PutChar(0xAA);//
UART4_PutChar(0x1B);//
UART4_PutChar(0x10);
sum = 0xAA+0x1B+0x10+'S'+'D'+'2'+'1'+'0'+'D'+'D'+'0'+'0'+'R'+'P';
UART4_PutChar('S');UART4_PutChar('D');
UART4_PutChar('2'); sum += *Str;UART4_PutChar(*Str++);
UART4_PutChar('1'); sum += *Str;UART4_PutChar(*Str++);
UART4_PutChar('0'); sum += *Str;UART4_PutChar(*Str++);
UART4_PutChar('D'); UART4_PutChar('D');
UART4_PutChar('0'); sum += *Str;UART4_PutChar(*Str++);
UART4_PutChar('0'); sum += *Str;UART4_PutChar(*Str++);
UART4_PutChar('R'); UART4_PutChar('P');
UART4_PutChar(sum);
}
void Voice_Uart4_Play_Comb(unsigned char *Str){
unsigned char *p = Str;
unsigned char sum = 0x00;
UART4_PutChar(0xAA);//
UART4_PutChar(0x1B);//
UART4_PutChar(0x1E);//AX;xx;xx;xx;DU;AY;xx;xx;xx;DU;JL;xx;xx;xx;CM 30
sum = 0xAA+0x1B+0x1E +'A'+'X'+'2'+'1'+'0'+'D'+'U'+'A'+'Y'+'2'+'1'+'0'+'D'+'U'+'J'+'L'+'2'+'1'+'0'+'C'+'M';
UART4_PutChar('A');
UART4_PutChar('X');
UART4_PutChar('2');
sum += *Str;
UART4_PutChar(*Str++);
UART4_PutChar('1');
sum += *Str;
UART4_PutChar(*Str++);
UART4_PutChar('0');
sum += *Str;
UART4_PutChar(*Str++);
UART4_PutChar('D');
UART4_PutChar('U');
UART4_PutChar('A');
UART4_PutChar('Y');
UART4_PutChar('2');
sum += *Str;
UART4_PutChar(*Str++);
UART4_PutChar('1');
sum += *Str;
UART4_PutChar(*Str++);
UART4_PutChar('0');
sum += *Str;
UART4_PutChar(*Str++);
UART4_PutChar('D');
UART4_PutChar('U');
UART4_PutChar('J');
UART4_PutChar('L');
UART4_PutChar('2');
sum += *Str;
UART4_PutChar(*Str++);
UART4_PutChar('1');
sum += *Str;
UART4_PutChar(*Str++);
UART4_PutChar('0');
sum += *Str;
UART4_PutChar(*Str++);
UART4_PutChar('C');
UART4_PutChar('M');
UART4_PutChar(sum);
}
void Volume_Increase_Int() interrupt 11 {// ~INT3
UART4_PutChar(0xAA); //
UART4_PutChar(0x14); //
UART4_PutChar(0x00);
UART4_PutChar(0xBE);
if(Voice_Volume < 30) {
Voice_Volume++;
}
}
void Volume_Reduce_Int() interrupt 10 {// ~INT2
UART4_PutChar(0xAA); //
UART4_PutChar(0x15); //
UART4_PutChar(0x00);
UART4_PutChar(0xBF);
if (Voice_Volume > 0) {
Voice_Volume--;
}
}
#endif
#if(Voice_OneLine)
void Oneline_Send_0() {
VOICE_ONELINE_Set();
delay_10us(40);
VOICE_ONELINE_Clear();
delay_10us(120);
}
void Oneline_Send_1() {
VOICE_ONELINE_Set();
delay_10us(120);
VOICE_ONELINE_Clear();
delay_10us(40);
}
void Oneline_Send_Byte(unsigned char send_byte) {
unsigned char i;
VOICE_ONELINE_Set();
delay_1ms(10);
VOICE_ONELINE_Clear();
delay_1ms(2);
for (i = 0; i < 8; i++) {
if ((send_byte & 0x01) == 0x01) {
Oneline_Send_1();
} else {
Oneline_Send_0();
}
send_byte = send_byte >> 1;
}
VOICE_ONELINE_Set();
}
void Voice_Volume_Increase() {
}
void Voice_Volume_Reduce() {
}
void Voice_Play_Audio(unsigned char audio_index) {
unsigned char num_bit_arr[3] = {0};
char num_bit_count = 2;
unsigned char num;
bit flag = 0; //
num = audio_index;
num_bit_arr[2] = num / 100;
num %= 100;
num_bit_arr[1] = num / 10;
num %= 10;
num_bit_arr[0] = num;
Oneline_Send_Byte(0x0A);
for (num_bit_count = 2; num_bit_count >= 0; num_bit_count--) {
if (num_bit_arr[num_bit_count] != 0) {
flag = 1;
Oneline_Send_Byte(num_bit_arr[num_bit_count]);
} else if (flag == 1) {
Oneline_Send_Byte(num_bit_arr[num_bit_count]);
} else {
;
}
}
Oneline_Send_Byte(0x0B);
}
void Voice_Play_Start() {
Oneline_Send_Byte(0x11);
}
#endif
회전 속도 측정기 코드:
voice.h
: #ifndef __VOICE_H
#define __VOICE_H
#include "15W4KxxS4.H"
#include "delay.h"
#include "uart.h"
#define VOICE_UART4 1 //
#define VOICE_OneLine 0 // OneLine
sbit VOICE_Busy = P0^4; //
extern unsigned char VOICE_Var_Volume;
/* */
#if(VOICE_UART4)
void VOICE_UART4_init();
void VOICE_UART4_playSingle(unsigned int index);
void VOICE_UART4_playComb(unsigned char *Str);
void VOICE_UART4_playSpeed(unsigned char *Str);
void VOICE_UART4_playAngle(unsigned char *Str, unsigned char flag);
void VOICE_UART4_playAll(unsigned char *Str);
#endif
/*one_line */
#if(VOICE_OneLine)
sbit VOICE_ONELINE = P0^0;
#define VOICE_ONELINE_Set() VOICE_ONELINE = 1
#define VOICE_ONELINE_Clear() VOICE_ONELINE = 0
void Oneline_Send_Byte(unsigned char send_byte);
void VOICE_Play_Audio(unsigned char audio_index);
void VOICE_Play_Single();
#endif
#endif
voice.c
: // : VOICE.c
// :
// ----------------------------------------------------------------
// ONELINE ,
// ----------------------------------------------------------------
#include "voice.h"
unsigned char VOICE_Volume = 20;
#if(VOICE_UART4)
/* , 4, 9600*/
void VOICE_UART4_init() {
UART4_Init(2, 9600);
INT_CLKO |= 0x30; //xx11 xxxx 3, 2,
// 31
UART4_PutChar(0xAA); //
UART4_PutChar(0x13); //
UART4_PutChar(0x01);
UART4_PutChar(0x1D);
UART4_PutChar(0xAA+0x13+0x01+0x1D);
}
/* */
void VOICE_UART4_playSingle(unsigned int index) {
UART4_PutChar(0xAA); //
UART4_PutChar(0x07); //
UART4_PutChar(0x02); //
UART4_PutChar((unsigned char)(index>>8)); //
UART4_PutChar((unsigned char)index); //
UART4_PutChar((unsigned char)(0xAA+0x07+0x02+(index>>8)+index));//
}
// , ,
/* - */
void VOICE_UART4_playSpeed(unsigned char *Str){
unsigned char sum = 0x00, temp;
UART4_PutChar(0xAA);//
UART4_PutChar(0x1B);//
UART4_PutChar(0x14);//20
sum = 0xAA+0x1B+0x14+'F'+'X'+'3'+'S'+'D'+'2'+'1'+'0'+'D'+'D'+'0'+'0'+'R'+'P';
//
UART4_PutChar('F'); UART4_PutChar('X');
// 3S:' ' 3N:' '
temp = *Str++; temp = temp=='+'?'S':'N';
UART4_PutChar('3'); sum += temp;UART4_PutChar(temp);
//
UART4_PutChar('S');UART4_PutChar('D');
UART4_PutChar('2'); sum += *Str;UART4_PutChar(*Str++);
UART4_PutChar('1'); sum += *Str;UART4_PutChar(*Str++);
UART4_PutChar('0'); sum += *Str;UART4_PutChar(*Str++);
UART4_PutChar('D'); UART4_PutChar('D');
UART4_PutChar('0'); sum += *Str;UART4_PutChar(*Str++);
UART4_PutChar('0'); sum += *Str;UART4_PutChar(*Str++);
UART4_PutChar('R'); UART4_PutChar('P');
UART4_PutChar(sum);
}
void VOICE_UART4_playAngle(unsigned char *Str, unsigned char flag) {
unsigned char sum = 0x00, temp;
UART4_PutChar(0xAA);//
UART4_PutChar(0x1B);//
UART4_PutChar(0x12);//18
if(flag == 'x') {
sum = 0xAA+0x1B+0x12+'H'+'X'+'4'+'2'+'1'+'0'+'D'+'D'+'0'+'0'+'D'+'U';
//
UART4_PutChar('H');UART4_PutChar('X');
} else if(flag == 'y') {
sum = 0xAA+0x1B+0x12+'F'+'Y'+'4'+'2'+'1'+'0'+'D'+'D'+'0'+'0'+'D'+'U';
//
UART4_PutChar('F');UART4_PutChar('Y');
} else if(flag == 'z') {
sum = 0xAA+0x1B+0x12+'H'+'G'+'4'+'2'+'1'+'0'+'D'+'D'+'0'+'0'+'D'+'U';
//
UART4_PutChar('H');UART4_PutChar('G');
}
// 4Z:' ' 4F:' '
temp = *Str++; temp = temp=='+'?'Z':'F';
UART4_PutChar('4'); sum += temp;UART4_PutChar(temp);
UART4_PutChar('2'); sum += *Str;UART4_PutChar(*Str++);
UART4_PutChar('1'); sum += *Str;UART4_PutChar(*Str++);
UART4_PutChar('0'); sum += *Str;UART4_PutChar(*Str++);
UART4_PutChar('D'); UART4_PutChar('D');
UART4_PutChar('0'); sum += *Str;UART4_PutChar(*Str++);
UART4_PutChar('0'); sum += *Str;UART4_PutChar(*Str++);
UART4_PutChar('D'); UART4_PutChar('U');
UART4_PutChar(sum);
}
// , ,
/* - , , , */
//void VOICE_UART4_playAll(unsigned char *Str){
// unsigned char sum = 0x00, temp, i, num;
// num = 26;
// UART4_PutChar(0xAA);//
// UART4_PutChar(0x1B);//
// UART4_PutChar(num*2);//20
// sum = 0xAA+0x1B+num*2+num*'F'+num*'X';
// for(i=0; i
// UART4_PutChar('F'); UART4_PutChar('X');
// }
// UART4_PutChar(sum);
//}
void VOICE_UART4_playAll(unsigned char *Str){
unsigned char sum = 0x00, temp;
UART4_PutChar(0xAA);//
UART4_PutChar(0x1B);//
UART4_PutChar(0x30);// 8*2*3 = 48
sum = 0xAA+0x1B+0x30;
sum += 'S'+'D'+'3'+'2'+'1'+'0'+'D'+'D'+'0'+'R'+'P'; //8
sum += 'H'+'G'+'4'+'2'+'1'+'0'+'D'+'D'+'0'+'D'+'U'; //12+6 ?
sum += 'F'+'Y'+'4'+'2'+'1'+'0'+'D'+'D'+'0'+'D'+'U'; //
//
UART4_PutChar('S');UART4_PutChar('D');
// 3S:' ' 3N:' '
temp = *Str++; temp = temp=='+'?'S':'N';
UART4_PutChar('3'); sum += temp;UART4_PutChar(temp);
UART4_PutChar('2'); sum += *Str;UART4_PutChar(*Str++);
UART4_PutChar('1'); sum += *Str;UART4_PutChar(*Str++);
UART4_PutChar('0'); sum += *Str;UART4_PutChar(*Str++);
UART4_PutChar('D'); UART4_PutChar('D');
UART4_PutChar('0'); sum += *Str;UART4_PutChar(*Str++);
Str++; // , 8
UART4_PutChar('R'); UART4_PutChar('P');
//
UART4_PutChar('H');UART4_PutChar('G');
temp = *Str++; temp = temp=='+'?'Z':'F';
UART4_PutChar('4'); sum += temp;UART4_PutChar(temp);
UART4_PutChar('2'); sum += *Str;UART4_PutChar(*Str++);
UART4_PutChar('1'); sum += *Str;UART4_PutChar(*Str++);
UART4_PutChar('0'); sum += *Str;UART4_PutChar(*Str++);
UART4_PutChar('D'); UART4_PutChar('D');
UART4_PutChar('0'); sum += *Str;UART4_PutChar(*Str++);
Str++; // , 8
UART4_PutChar('D'); UART4_PutChar('U');
//
UART4_PutChar('F');UART4_PutChar('Y');
temp = *Str++; temp = temp=='+'?'Z':'F';
UART4_PutChar('4'); sum += temp;UART4_PutChar(temp);
UART4_PutChar('2'); sum += *Str;UART4_PutChar(*Str++);
UART4_PutChar('1'); sum += *Str;UART4_PutChar(*Str++);
UART4_PutChar('0'); sum += *Str;UART4_PutChar(*Str++);
UART4_PutChar('D'); UART4_PutChar('D');
UART4_PutChar('0'); sum += *Str;UART4_PutChar(*Str++);
Str++; // , 8
UART4_PutChar('D'); UART4_PutChar('U');
UART4_PutChar(sum);
}
void Volume_Increase_Int() interrupt 11 {// ~INT3
UART4_PutChar(0xAA); //
UART4_PutChar(0x14); //
UART4_PutChar(0x00);
UART4_PutChar(0xBE);
if(VOICE_Volume < 31) {
VOICE_Volume++;
}
}
void Volume_Reduce_Int() interrupt 10 {// ~INT2
UART4_PutChar(0xAA); //
UART4_PutChar(0x15); //
UART4_PutChar(0x00);
UART4_PutChar(0xBF);
if (VOICE_Volume > 0) {
VOICE_Volume--;
}
}
#endif
#if(VOICE_OneLine)
void Oneline_Send_0() {
VOICE_ONELINE_Set();
delay_10us(40);
VOICE_ONELINE_Clear();
delay_10us(120);
}
void Oneline_Send_1() {
VOICE_ONELINE_Set();
delay_10us(120);
VOICE_ONELINE_Clear();
delay_10us(40);
}
void Oneline_Send_Byte(unsigned char send_byte) {
unsigned char i;
VOICE_ONELINE_Set();
delay_1ms(10);
VOICE_ONELINE_Clear();
delay_1ms(2);
for (i = 0; i < 8; i++) {
if ((send_byte & 0x01) == 0x01) {
Oneline_Send_1();
} else {
Oneline_Send_0();
}
send_byte = send_byte >> 1;
}
VOICE_ONELINE_Set();
}
void VOICE_Volume_Increase() {
}
void VOICE_Volume_Reduce() {
}
void VOICE_Play_Audio(unsigned char audio_index) {
unsigned char num_bit_arr[3] = {0};
char num_bit_count = 2;
unsigned char num;
bit flag = 0; //
num = audio_index;
num_bit_arr[2] = num / 100;
num %= 100;
num_bit_arr[1] = num / 10;
num %= 10;
num_bit_arr[0] = num;
Oneline_Send_Byte(0x0A);
for (num_bit_count = 2; num_bit_count >= 0; num_bit_count--) {
if (num_bit_arr[num_bit_count] != 0) {
flag = 1;
Oneline_Send_Byte(num_bit_arr[num_bit_count]);
} else if (flag == 1) {
Oneline_Send_Byte(num_bit_arr[num_bit_count]);
} else {
;
}
}
Oneline_Send_Byte(0x0B);
}
void VOICE_Play_Start() {
Oneline_Send_Byte(0x11);
}
#endif