📄 ml2011io.c
字号:
/******************************************************************************
*
* Oki ML2011 Driver (ML2011io.c)
* Oki Electric Industry Co.,Ltd.
* Software Development Department
*
* 2006, 5, 19 released
* ----------------------------------------------
* Read/Write Function for ML28xx.
* - L28xxWrite()
* - L28xxRead()
* - devMemToFifo()
******************************************************************************/
#include <pic18.h>
#include "..\delay.h"
#include "ML2011io.h"
//#include "../mp3_io.h"
/******************************************************************************
* Stock Index Option
* We recommend that this option is enable in parallel I/O used system.
* But, when ML28xx serial I/O is used, this option must be disabled.
******************************************************************************/
//#define _ML28XX_INDEX_STOCK_
#ifdef _ML28XX_INDEX_STOCK_
//volatile unsigned char StockIndex = 0;
#endif/*_ML28XX_INDEX_STOCK_*/
/*
#define L2011INDEX_ADR 0xF0000002
#define L2011INDEX *(volatile unsigned char *)L2011INDEX_ADR
#define L2011DATA_ADR 0xF0000000
#define L2011DATA *(volatile unsigned char *)L2011DATA_ADR
*/
#define CS RC2
#define RD RC0
#define WR RC3
#define RS RC1
#define L2011INDEX_ADR PORTD
#define L2011INDEX *(volatile unsigned char *)L2011INDEX_ADR
#define L2011DATA_ADR PORTD
#define L2011DATA *(volatile unsigned char *)L2011DATA_ADR
unsigned char temp_PortA=0xFE;
unsigned char temp_PortC=0xFF;
/******************************************************************************
* L2011drv_ReadWriteInit()
* ----------------------------------------------------------------------------
* REMARKS:
* write data to index
* PARAMETERS:
* - index : index of ML28xx's register. use "ml28xx.h"
* - data : the data to write
* RETURN VALUE: void
******************************************************************************/
signed short L2011drv_ReadWriteInit(DRV_CTRL *drvCtrl)
{
drvCtrl->StockIndex = 0;
return(0);
}
/******************************************************************************
* L2011drv_WriteReg()
* ----------------------------------------------------------------------------
* REMARKS:
* write data to index
* PARAMETERS:
* - index : index of ML28xx's register. use "ml28xx.h"
* - data : the data to write
* RETURN VALUE: void
******************************************************************************/
void L2011drv_WriteReg(DRV_CTRL *drvCtrl, unsigned char index,unsigned char data)
{
#ifdef _ML28XX_INDEX_STOCK_
/*--- Stock Current Index ---*/
unsigned char tmpIndex = drvCtrl->StockIndex;
drvCtrl->StockIndex = index;
#endif //_ML28XX_INDEX_STOCK_
/*--- Set Index ---*/
//RS=1;
temp_PortC|=0x02;//RC1
PORTC=temp_PortC;
//WR = 0;
temp_PortC&=0xF7;//RC3
PORTC=temp_PortC;
PORTD=index+1;
//asm("nop");
////DelayUs(1);
//WR = 1;
temp_PortC|=0x08;//RC3
PORTC=temp_PortC;
/*--- Write Data ---*/
//RS = 0;
temp_PortC&=0xFD;//RC1
PORTC=temp_PortC;
//WR = 0;
temp_PortC&=0xF7;//RC3
PORTC=temp_PortC;
PORTD=data;
//asm("nop");
////DelayUs(1);
//WR = 1;
temp_PortC|=0x08;//RC3
PORTC=temp_PortC;
//RS=1;
temp_PortC|=0x02;//RC1
PORTC=temp_PortC;
#ifdef _ML28XX_INDEX_STOCK_
/*--- Set Back Index ---*/
L2011INDEX = tmpIndex;
drvCtrl->StockIndex = tmpIndex;
#endif /*_ML28XX_INDEX_STOCK_*/
}
/******************************************************************************
* L2011drv_ReadReg()
* ----------------------------------------------------------------------------
* REMARKS:
* read data of index
* PARAMETERS:
* - index : index of ML28xx's register. use "ml28xx.h"
* RETURN VALUE:
* returns the value of specified register data
******************************************************************************/
unsigned char L2011drv_ReadReg(DRV_CTRL *drvCtrl, unsigned char index)
{
unsigned char ret;
#ifdef _ML28XX_INDEX_STOCK_
/*--- Stock Current Index ---*/
unsigned char tmpIndex = drvCtrl->StockIndex;
drvCtrl->StockIndex = index;
#endif //_ML28XX_INDEX_STOCK_
/*--- Set Index ---*/
//WR = 0;
temp_PortC&=0xF7;//RC3
PORTC=temp_PortC;
PORTD=index;
//asm("nop");
//DelayUs(1);
//WR = 1;
temp_PortC|=0x08;//RC3
PORTC=temp_PortC;
/*--- Read Data ---*/
TRISD = 0XFF; //change io direction for reading data
//RD = 0;
temp_PortC&=0xFE;//RC0
PORTC=temp_PortC;
asm("nop");
//DelayUs(1);
ret = PORTD; //Read Data
//RD=1;
temp_PortC|=0x01;//RC0
PORTC=temp_PortC;
TRISD = 0;
#ifdef _ML28XX_INDEX_STOCK_
/*--- Set Back Index ---*/
L2011INDEX = tmpIndex;
drvCtrl->StockIndex = tmpIndex;
#endif /*_ML28XX_INDEX_STOCK_*/
return(ret);
}
/******************************************************************************
* L2011drv_WriteFifo()
* ----------------------------------------------------------------------------
* REMARKS:
* transfers data from user's buffer to ML28xx's fifo
* INPUT:
* - index : index to the register
* [IDX_ADPFIFO_W|IDX_SCRFIFO_W|IDX_EVTFIFO_W]
* - buff : pointer to the buffer
* - length : length(Byte) to write
******************************************************************************/
unsigned short L2011drv_WriteFifo(DRV_CTRL *drvCtrl, unsigned char index, unsigned char *buffer, unsigned short length)
{
unsigned short i;
#ifdef _ML28XX_INDEX_STOCK_
/*--- Stock Index ---*/
unsigned char tmpIndex = drvCtrl->StockIndex;
drvCtrl->StockIndex = index;
#endif /*_ML28XX_INDEX_STOCK_*/
/*--- Input Data ---*/
for(i = 0; i < length; i++)
{
L2011drv_WriteReg(drvCtrl,index,*(buffer+i));
//L2011DATA = *(buffer+i);
}
#ifdef _ML28XX_INDEX_STOCK_
/*--- Set Back Index ---*/
L2011INDEX = tmpIndex;
drvCtrl->StockIndex = tmpIndex;
#endif /*_ML28XX_INDEX_STOCK_*/
return(i);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -