#include <stdio.h>
#include <pic.h>
#include<time.h>
#include "usart.h"
__CONFIG(0x3FD4); //看門狗關(guān),內(nèi)部RC振蕩,GO0/GP1做I/O,不加密,MCLR腳做復(fù)位
#define _XTAL_FREQ 8000000 /* A simple demonstration of serial communications which
* incorporates the on-board hardware USART of the Microchip PIC16Fxxx series of devices.
* 空閑時(shí)保證sck高電平
* 上升沿采樣數(shù)據(jù)
* 公司 大聯(lián)大集團(tuán)品佳集團(tuán) 王鶴
* 時(shí)間 20100829
* UART 硬件 SPI采用軟件,沒(méi)有SPI地址
* 后續(xù)考慮 軟件UART*/
//此處CS LOW有效
#define TRUE 0
#define FALSE 1
#define ISD2100_CS RC2
#define ISD2100_CS_TRIS TRISC2
#define ISD2100_clk RC3
#define ISD2100_clk_TRIS TRISC3
#define ISD2100_DO RC5
#define ISD2100_DO_TRIS TRISC5
#define ISD2100_SI RC4
#define ISD2100_SI_TRIS TRISC4
#define ISD2100_INTB RB0
#define ISD2100_INTB_TRIS TRISB0
#define ISD2100_RST RB1
#define ISD2100_RDY RB2
#define ISD2100_RDY_TRIS TRISB2
unsigned int Rdata ;
unsigned char RdataBuf[10] ;
unsigned char SenddataBuf[10] ;
void Send8BitData(unsigned char cmd1)
{
unsigned char n=8;
ISD2100_CS = TRUE;
for (n = 0; n<8 ;n++)
{
ISD2100_clk = 0;
if((cmd1 & 0x80) == 0x80)
ISD2100_DO = 1 ;
else ISD2100_DO = 0 ;
__delay_us(1);
ISD2100_clk = 1;
__delay_us(1);
cmd1=cmd1<<1;
}
ISD2100_CS = FALSE;
}
void SendData(unsigned char SendCount)
{
unsigned char n,m;
//ISD2100_clk = 1;
for(m=0;m<SendCount;m++)
{ //while(!ISD2100_RDY);
for (n = 0; n<8 ;n++)
{ ISD2100_clk = 0;
if((SenddataBuf[m] & 0x80) == 0x80)
ISD2100_DO = 1 ;
else ISD2100_DO = 0 ;
__delay_us(1);
ISD2100_clk = 1;
__delay_us(1);
SenddataBuf[m]=SenddataBuf[m]<<1;
}
}
ISD2100_clk = 1;
}
/***************************************
發(fā)送16bit給spiEEPROM數(shù)據(jù)程序
如發(fā)送0x1234 給eeprom
調(diào)用格式為: Send16BitData(0x1234);
****************************************/
void Send16BitData(unsig the USART - settings defined in usart.h
// Output a message to prompt the user for a keypress
printf("\rPress a key and I will echo it back:\n");
while(1){
input = getch(); // read a response from the user
printf("\rI detected [%c]",input); // echo it back
if(input == 'q')
{
Send8BitData(0x10);
printf("P_Up\n"); // echo it back
}
if(input == 'w')
{
Send8BitData(0x12);
printf("P_Down\n"); // echo it back
}
if(input == 'e')
{
SenddataBuf[0]=0x14;
SendData(1);
printf("RESET\n");//Set8BitData(0x14); // echo it back
}
if(input == 'r' | input == 'f')
{
ISD2100_clk = 1;
ISD2100_CS = TRUE;
SenddataBuf[0]=0xa4;
SenddataBuf[1]=0x00;
if(input == 'r')
SenddataBuf[2]=i++;
if(input == 'f')
SenddataBuf[2]=i--;
SenddataBuf[3]=0x00;
SenddataBuf[4]=0x04;
SendData(5);
ISD2100_CS = FALSE;
printf("VP index = %c%c\n",i/10+48,i%10+48); // echo it back
}
if(input == '1')//read device 兩種方法都通過(guò)測(cè)試
{
ISD2100_clk = 1;
ISD2100_CS = TRUE;
READ_ID(); //ok 方法1
// Send8BitData(0x48); //read ID 方法2
// ReceiveData(4) ; //read ID 方法2
ISD2100_CS = FALSE;
printf("Device ID=%x%x-%x%x-%x%x-%x%x\n", RdataBuf[0]/16,RdataBuf[0]%16,
RdataBuf[1]/16,RdataBuf[1]%16,
RdataBuf[2]/16,RdataBuf[2]%16,
RdataBuf[3]/16,RdataBuf[3]%16);
}
}
}
以上代碼經(jīng)測(cè)試也可用于如 ISD3800/ISD3900等數(shù)字式 語(yǔ)音錄放IC |