mohammadjamal
Newbie level 6
Hi All
now i build a program to run a wave files
wave file type is Mono / Bits / 16 KHz
i do every things goood
reading from memory
and send a byte i have read to PORTB
but my problem
to play it in speaker
i know that's need DAC
but any body can help me on this ??????
this is my Code
and the schemetic of my circuit in attachments
please help :sad:
now i build a program to run a wave files
wave file type is Mono / Bits / 16 KHz
i do every things goood
reading from memory
and send a byte i have read to PORTB
but my problem
to play it in speaker
i know that's need DAC
but any body can help me on this ??????
this is my Code
Code:
#define LINE_LEN 43
#define CFILE_EXIST 1
#define CTMR0H 0xFE
#define CTMR0L 0xD4
sfr sbit Mmc_Chip_select at LATC0_bit;
sfr sbit Mmc_Chip_Select_Direction at TRISC0_bit;
sfr sbit Out_LED_Green at LATC1_bit;
sfr bit Out_LED_Red at LATC2_bit;
unsigned char AudioFile[7];
char iSample;
long int size;
char bTimerInt;
void Main_Init()
{
TRISC6_bit = 0;
TRISC7_bit = 0;
TRISC1_bit = 0;
TRISC2_bit = 0;
TRISA = 0xFF;
TRISB = 0x00;
PORTB = 0x7F;
TRISD = 0x00;
INTCON = 0;
INTCON2 = 0;
INTCON3 = 0;
T0CON = 0;
T0CON.T08BIT = 0;
T0CON.TMR0ON = 1;
T0CON.T08BIT = 0;
T0CON.T0CS = 0;
T0CON.T0SE = 0;
T0CON.PSA = 1;
T0CON.T0PS2 = 0;
T0CON.T0PS1 = 0;
T0CON.T0PS0 = 0;
TMR0H = CTMR0H;
TMR0L = CTMR0L;
ADCON1 |= 0x0F;
CMCON |= 7;
Out_LED_GREEN = 1;
Out_LED_RED = 1;
delay_ms(500);
Out_LED_GREEN = 0;
Out_LED_RED = 0;
}
void interrupt()
{
if (INTCON.TMR0IF) {
bTimerInt = 1;
TMR0H = CTMR0H;
TMR0L = CTMR0L;
INTCON.TMR0IF = 0;
}
}
void Timer_SetInterrupt(int bState)
{
if (bState) {
TMR0H = CTMR0H;
TMR0L = CTMR0L;
INTCON.TMR0IF = 0;
INTCON.GIE = 1;
INTCON.TMR0IE = 1;
T0CON.TMR0ON =1;
} else {
T0CON.TMR0ON = 0;
INTCON.TMR0IE = 0;
INTCON.GIE = 0;
}
}
void M_ReadAudioFile(int idx)
{
char iStatus;
bit bBadFile;
switch (idx)
{
case 0 :
strcpy(AudioFile,"hi.wav");
break;
default :
strcpy(AudioFile,"hi.wav");
break;
}
Out_LED_GREEN = 0;
Out_LED_RED = 0;
iStatus = Mmc_Fat_Exists(AudioFile);
bBadFile = 0;
if ((iStatus == CFILE_EXIST) && (!bBadFile)) {
Out_LED_GREEN = 1;
Mmc_Fat_Assign(AudioFile,0);
Mmc_Fat_Reset(&size);
Mmc_Fat_Seek(44);
if (size > 44) size = size - 44;
Timer_SetInterrupt(1);
{
while (size > 1) {
if (bTimerInt) {
Mmc_Fat_Read(&iSample);
PORTB = iSample;
UART1_Write_Text(iSample);
size = size - 1;
bTimerInt = 0;
}}
}
Timer_SetInterrupt(0);
{
while (size > 1){
Mmc_Fat_Read(&iSample);
PORTB = iSample;
size = size - 1;
delay_us(40);}
}
PORTB = 0x7F;
Out_LED_GREEN = 0; }
else
{
Out_LED_RED = 1;
delay_ms(500);
Out_LED_RED = 0;
}
}
void main()
{
UART1_Init(9600);
Main_Init();
SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV64,_SPI_DATA_SAMPLE_MIDDLE,_SPI_CLK_IDLE_LOW,_SPI_LOW_2_HIGH);
if (Mmc_Fat_Init() == 0) {
SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV4,_SPI_DATA_SAMPLE_MIDDLE,_SPI_CLK_IDLE_LOW,_SPI_LOW_2_HIGH);
M_ReadAudioFile(0);
}
else {
while (1) {
Out_LED_RED = 1;
delay_ms(250);
Out_LED_RED = 0;
delay_ms(250);
}}
}
and the schemetic of my circuit in attachments
please help :sad: