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

📄 main__.c

📁 ld2330语音模块程序
💻 C
📖 第 1 页 / 共 2 页
字号:
   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);
	}
	}
   }	
   
}	
//************************************
#include "nRF24L01.c"

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

//********接收数据宽度*********                                                            
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};
#define ADDR2 2
#define ADDR3 3
#define ADDR4 4
#define ADDR5 5
//******发送地址***********
static unsigned char TxAddr[6]={0x10,1,2,3,4,5};

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


//============================================================================
//功能:  nRF24L01芯片初始化
//Time: 2008-4-8
//Vision: V1.0
void nRF24L01_Init()
{
     CLI_CE
     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,ADDR2);         //设置通道2地址 
     nRF24L01_WriteReg(0x0D,ADDR3);         //设置通道3地址 
     nRF24L01_WriteReg(0x0E,ADDR4);         //设置通道4地址 
     nRF24L01_WriteReg(0x0F,ADDR5);         //设置通道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;
      nRF24L01_TxMode
      SEL_CS3
      SPI_ReadBytes(&Reg,1);
      SPI_WriteBytes(TxBuffer,TDW);
      SEL_NON
      CLI_CE
      return Reg;
}

//==============================================================================
//功能:  nRF24L01接收数据
//Time: 2008-4-8
//Vision: V1.0
unsigned char nRF24L01_RecData(unsigned char *RxBuffer,unsigned char RDW)
{
        unsigned char Reg=0x61;
        SEL_CS3
        SPI_ReadBytes(&Reg,1);
        SPI_ReadBytes(RxBuffer,RDW);
        SEL_NON        
        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 + -