⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.i

📁 ld2330语音模块程序
💻 I
📖 第 1 页 / 共 2 页
字号:
signed char lsign(long x);
signed char fsign(float x);
unsigned char isqrt(unsigned int x);
unsigned int lsqrt(unsigned long x);
float sqrt(float x);
float floor(float x);
float ceil(float x);
float fmod(float x,float y);
float modf(float x,float *ipart);
float ldexp(float x,int expon);
float frexp(float x,int *expon);
float exp(float x);
float log(float x);
float log10(float x);
float pow(float x,float y);
float sin(float x);
float cos(float x);
float tan(float x);
float sinh(float x);
float cosh(float x);
float tanh(float x);
float asin(float x);
float acos(float x);
float atan(float x);
float atan2(float y,float x);

#pragma used-
#pragma library math.lib


    

//****************************************************
//送一帧数据
void Post_Msg(unsigned char Msg)
{
 DDRA=0xFF;                                                                
 PORTA=Msg;
 PORTB|=0x10;                       
 PORTD=0x90;                        
 (*(unsigned char *) 0x65)&=0xFE;                     
 (*(unsigned char *) 0x65)|=0x01;                       
 PORTD=0x00;                        
}

//*************************************
//送一帧命令
//*************************************
void Send_Com(unsigned char Addr,unsigned char Data)
{                 
   DDRA=0xFF;                          
   PORTA=Addr;
   PORTB&=0xEF;                     
   PORTD=0x90;                        
   (*(unsigned char *) 0x65)&=0xFE;                     
   (*(unsigned char *) 0x65)|=0x01;                       
   PORTD=0x00;                        
   PORTA=Data;
  PORTB&=0xEF;                     
  PORTD=0x90;                        
  (*(unsigned char *) 0x65)&=0xFE;                     
  (*(unsigned char *) 0x65)|=0x01;                       
  PORTD=0x00;                        
}
//*************************************************




void LCD_INIT()
{  
 
   Send_Com(0x00,0xCD);                     //WLCR: 电源正常模式,进入文本模式,屏幕开启,屏幕不闪烁,正向显示
   Send_Com(0x01,0x03);                     //MISC: CLKOUT禁止,BUSY高电平触发,12MHz频率      
   Send_Com(0x02,0x00);                     //APSR: ROM/RAM30ns读取速度,禁止ROM直读,开机滚动复位禁止
   Send_Com(0x03,0x80);                     //ADSR: 显示数据正序,水平,垂直卷动效显禁止
   Send_Com(0x10,0x2F);                     //WCCR: 读DDRAM定地址,写自加,中英文对齐,正向存储,字体正常粗细,光标ON,闪烁
   Send_Com(0x11,0x10);                     //DWLR:  光标高度2Px,行距设定2Px
   Send_Com(0x12,0xB3);                     //MAMR: 图形方式光标先垂直后水平移动,两层或显示,图层1/2运行,灰度显示   
   Send_Com(0x20,0x1D);                     //AWRR: 设定右边视窗位置
   Send_Com(0x21,0x1D);                     //DWRR: 设定右边显示位置(=240/8-1)
   Send_Com(0x30,0x7F);                     //AWBR: 设定底部视窗位置
   Send_Com(0x31,0x80);                     //DWBR: 设定底部显示位置(=128-1)
   Send_Com(0x40,0x00);                     //AWLR: 设定左边视窗位置
   Send_Com(0x41,0x00);                     //DWLR: 设定左边显示位置(0x00)
   Send_Com(0x50,0x00);                     //AWTR: 设定上部视窗位置
   Send_Com(0x51,0x00);                     //DWTR: 设定上部显示位置(0x00)
   Send_Com(0x60,0x00);                     //CPXR:  设定光标X坐标
   //Send_Com(0x61,0x00);                     //BGSG: 显示区X位置
   Send_Com(0x70,0x00);                     //CPYR:  设定光标Y坐标
   Send_Com(0x71,0x00);                     //BGCM: 设定水平移动模式下移动的起始X位置
   Send_Com(0x72,0xEF);                     //EDCM: 设定水平移动模式下移动终止X位置
   Send_Com(0x80,0x60);                     //BTMR: 设置光标闪烁频率 
   Send_Com(0x81,0x40);                     //FRCA: 通用寄存器,设置为0x40(must do that when reset the lcd)
   Send_Com(0x90,0x0F);                     //SCCR: 设定XCL周期,即刷新频率,数值越大,刷新越慢
   Send_Com(0xF0,0xA0);                     //
   Send_Com(0xF1,0x0F);                     //字体大小置
} 


//===============================================================
//--清屏函数,将文本层和图形层全清空
void Clear_Screen()
{
   unsigned int i;
  Send_Com(0x12,0xB3);            //文本层和图形层同时清零 
  Send_Com(0x60,0x00);
   Send_Com(0x70,0x00);
  for(i=0;i<3840;i++)Post_Msg(0x00);
}
//===============================================================


//===============================================================
//---显示字符串,包括中文字符,可混合中英文即符号
//X0:列设置(0-29) Y0:行设置(0-15)
void Show_Text(unsigned char X0,unsigned char Y0,unsigned char *Text)
{  
   Send_Com(0x12,0xB1);         //进入文本图层
   Send_Com(0x60,X0);
   Send_Com(0x70,Y0*8);
   while((*Text)>0)
   {
       Post_Msg(*Text);
       Text++;
   }
}
//===========================================================

//===============================================================
//---显示字符串,包括中文字符,可混合中英文即符号
//X0:列设置(0-29) Y0:行设置(0-15)
void Show_String(unsigned char X0,unsigned char Y0,unsigned char flash *Text)
{  
   Send_Com(0x12,0xB1);         //进入文本图层
   Send_Com(0x60,X0);
   Send_Com(0x70,Y0*8);
   while((*Text)>0)
   {
       Post_Msg(*Text);
       Text++;
   }
}
//===========================================================



//===========================================================
//---显示单个数字
void Show_Num(unsigned char X0,unsigned char Y0,unsigned char Num)
{
   Send_Com(0x60,X0);
   Send_Com(0x70,Y0*8);
   Post_Msg(Num+48);      
}
//============================================================


//============================================================
//---显示浮点数
void Show_Number(unsigned char X0,unsigned char Y0,float Num,unsigned char DpLen)
{
   unsigned char i=0,j=0,mynum[6];
   unsigned int sum,temp;   
   bit flag=0;							//flag:是否为负
   Send_Com(0x12,0xB1);                           //进入文本层
   Send_Com(0x60,X0);                                //消隐
   Send_Com(0x70,Y0*8); 
   for(i=0;i<6;i++)Post_Msg(0x00);
   i=0;
   Send_Com(0x60,X0); 
   Send_Com(0x70,Y0*8); 
   if(Num<0){Num=fabs(Num);Post_Msg('-');flag=1;i++;}
  //-----------得到整数部分------------------  
   temp=(unsigned int)Num; //取整
   do
   {
      mynum[j]=temp%10;
   	  temp=temp/10;											  //丢末位
	  i++;
	  j++;     												  //位累加
   }while(temp!=0);
   //---------显示整数部分--------------------
   do
   {
    Post_Msg(mynum[j-1]+48);                      //显示每位
    ;j--;
   }while(j>0);
   j=0;
   //---------处理小数部分-------------------	 
   if((flag&&i<4)||(!flag&&i<5))
   {
     i++;  			  //累加小数点位
     temp=(unsigned int)Num;		 //重新取整
     Num=Num-temp;	 //得到小数部分
     do
      {
	   Num=Num*10;
	   temp=Num;
	   mynum[j]=temp%10;	   				  
	   i++;
	   j++;
	  }while(i<6&&j<DpLen);	  //保留指定小数位
	  i=0;temp=0;
   	 do
	  {
	    temp+=mynum[i];i++;	  
	  }while(i<j);
	  i=0;
	  //-------------显示小数部分---------------
	if(DpLen)
	{
	if((DpLen<8)||(DpLen>=8&&temp!=0))
	{
	  Post_Msg('.');
	do
	  {Post_Msg(mynum[i]+48);i++;} 
	while(i<j);
	}
	}
   }	
   
}	
//************************************

//============================================================================
//本文档用于驱动nRF24L01

//********接收数据宽度*********                                                            
unsigned char flash RDW[6]={13,13,13,13,13,13};
unsigned char flash RDW[6]={13,13,13,13,13,13};
//*******接收地址**********
static unsigned char ADDR0[6]={0x0A,0,2,3,4,5};
static unsigned char ADDR1[6]={0x0B,1,2,3,4,5};
//******发送地址***********
static unsigned char TxAddr[6]={0x10,1,2,3,4,5};

 
//nRF24L01 SPI总线说明:
//   1. 低字节先传送,高字节后传送,基于小端格式的传送
//   2.字节内部高位先传送,低位后传送
//============================================================================
//功能:  向nRF24L01发送数据
void nRF24L01_WriteBytes(unsigned char *Buffer,unsigned char Bytes)
{
          PORTD=0xB0;                                                                            //选中nRF24L01 
          Buffer[0]|=0x20;                                       //加入写寄存器标记
          SPI_WriteBytes(Buffer,Bytes);               //发送数据
          PORTD=0x00;                                                                           //释放nRF24L01
}                                                                                                          
//============================================================================
//功能:  从nRF24L01接收数据
void nRF24L01_ReadBytes(unsigned char *Buffer,unsigned char Bytes)
{
          PORTD=0xB0;                                                                           //选中nRF24L01
          SPI_ReadBytes(Buffer,Bytes);            //读取数据  
          PORTD=0x00;                                                                          //释放nRF24L01
}
//============================================================================
//功能: 写nRF24L01寄存器
void nRF24L01_WriteReg(unsigned char Reg,unsigned char Value)
{
          unsigned char Buffer[2];
          PORTD=0xB0;                        
          Buffer[0]=Reg|0x20;
          Buffer[1]=Value;
          SPI_WriteBytes(Buffer,2);
          PORTD=0x00;                                  
}
//============================================================================
//功能:  读取nRF24L01的状态
unsigned char nRF24L01_GetStatus()
{
          unsigned char Status;
          Status=0xFF;
          PORTD=0xB0;                        
          SPI_ReadBytes(&Status,1);
          PORTD=0x00;                        
          return Status;
}


//============================================================================
//功能:  nRF24L01芯片初始化
//Time: 2008-4-8
//Vision: V1.0
void nRF24L01_Init()
{
     (*(unsigned char *) 0x62)&=0xFE;                    
     nRF24L01_WriteReg(0x01,0x00);            //通道0自动应答
     nRF24L01_WriteReg(0x02,0x3F);            //通道0接收使能
     nRF24L01_WriteReg(0x03,0x03);            //地址宽度为5bytes
     nRF24L01_WriteReg(0x04,0x00);            //出错自动重发,4000uS+86uS等待,重发15次
     nRF24L01_WriteReg(0x05,0x01);            //选择通道1
     nRF24L01_WriteReg(0x06,0x07);            //1Mbps,0dBm,接收放大器使能
     nRF24L01_WriteReg(0x07,0x00);            //状态寄存器复位                                                        
     nRF24L01_WriteBytes(ADDR0,6);            //设置通道0地址
     nRF24L01_WriteBytes(ADDR1,6);            //设置通道1地址     
     nRF24L01_WriteReg(0x0C,2);         //设置通道2地址 
     nRF24L01_WriteReg(0x0D,3);         //设置通道3地址 
     nRF24L01_WriteReg(0x0E,4);         //设置通道4地址 
     nRF24L01_WriteReg(0x0F,5);         //设置通道5地址 
     nRF24L01_WriteBytes(TxAddr,6);            //设置发送地址
     nRF24L01_WriteReg(0x11,RDW[0]);         //通道0接收数据长度(字节)
     nRF24L01_WriteReg(0x12,RDW[1]);         //通道1接收数据长度(字节)
     nRF24L01_WriteReg(0x13,RDW[2]);         //通道2接收数据长度(字节)
     nRF24L01_WriteReg(0x14,RDW[3]);         //通道3接收数据长度(字节)
     nRF24L01_WriteReg(0x15,RDW[4]);         //通道4接收数据长度(字节)
     nRF24L01_WriteReg(0x16,RDW[5]);         //通道5接收数据长度(字节)     
}

//=============================================================================
//功能:  nRF24L01发送数据
//Time: 2008-4-8
//Vision:  V1.0
unsigned char nRF24L01_SendData(unsigned char *TxBuffer,unsigned char TDW)
{     
      unsigned char Reg=0xA0;
      (*(unsigned char *) 0x62)&=0xFE;                     nRF24L01_WriteReg(0x00,0x0E);(*(unsigned char *) 0x62)|=0x01;                              
      PORTD=0xB0;                        
      SPI_ReadBytes(&Reg,1);
      SPI_WriteBytes(TxBuffer,TDW);
      PORTD=0x00;                        
      (*(unsigned char *) 0x62)&=0xFE;                    
      return Reg;
}

//==============================================================================
//功能:  nRF24L01接收数据
//Time: 2008-4-8
//Vision: V1.0
unsigned char nRF24L01_RecData(unsigned char *RxBuffer,unsigned char RDW)
{
        unsigned char Reg=0x61;
        PORTD=0xB0;                        
        SPI_ReadBytes(&Reg,1);
        SPI_ReadBytes(RxBuffer,RDW);
        PORTD=0x00;                                
        return Reg;
}
  
void main()
{ 
                                               
   unsigned char DataBuffer[13];               
   unsigned int k=0;
   unsigned char S;
   Board_Init();
   LCD_INIT();
   Clear_Screen(); 
   Show_String(9,0,"nRF24L01测试");
   Show_String(0,4,"当前发送数值:");      
   nRF24L01_Init();           
   while(1){                                                          
           strcpyf(DataBuffer,"12文字测试!");
           DataBuffer[0]=0x01;
           DataBuffer[1]='0'+k;           
           S=nRF24L01_SendData(DataBuffer,13);                                      
           Show_Number(15,10,S,0);                            
           k++;if(k==10)k=0;
           Show_Number(15,4,k,0);
           delay_ms(300); 
   };
}           


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -