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

📄 main.c

📁 st7565P,nt7534液晶控制芯片在128X64点阵下的51环境液晶驱动程序
💻 C
📖 第 1 页 / 共 2 页
字号:
	OpenSpi();
	WriteByte(addr|READ_BURST);
	SPI_WAIT();
	x=ReadByte();		 
	CloseSpi();

	return x;
}
void RESET_CCxxx0()
{
//	OpenSpi();
	SPI_CS=0;
	while(SPI_SO);
	WriteByte(CCxxx0_SRES);
	SPI_WAIT();
	while(SPI_SO);
	CloseSpi();
}
void POWER_UP_RESET_CCxxx0()
{
	CloseSpi();//1
	halWait(1);  
	OpenSpi();//0
	halWait(1);
	CloseSpi();//1
	halWait(41);
	RESET_CCxxx0();
}
BOOL halRfReceivePacket( uchar *rxBuffer, uchar *length)
{
	uchar status[2];
    uchar packetLength;
//	halSpiStrobe(CCxxx0_SRX);
	// Wait for GDO0 to be set -> sync received
//    while (!SPI_GDO0);

    // Wait for GDO0 to be cleared -> end of packet
//    while (SPI_GDO0);
	if (( halSpiReadStatus(CCxxx0_RXBYTES) & BYTES_IN_RXFIFO))//如果接的字节数不为0
	{
		// Read length byte
        packetLength = halSpiReadReg(CCxxx0_RXFIFO);//读出第一个字节,此字节为该帧数据长度

		// Read data from RX FIFO and store in rxBuffer
        if (packetLength <= *length)//如果所要的有效数据长度小于等于接收到的数据包的长度
		{
			halSpiReadBurstReg(CCxxx0_RXFIFO, rxBuffer, packetLength); 
            *length = packetLength;//把接收数据长度的修改为当前数据的长度
        
            // Read the 2 appended status bytes (status[0] = RSSI, status[1] = LQI)
            halSpiReadBurstReg( CCxxx0_RXFIFO, status, 2); //读出CRC校验位
        
            // MSB of LQI is the CRC_OK bit
//            return (status[LQI] & CRC_OK);//如果校验成功返回接收成功
			  return 1;
		}
		else
		{
			*length = packetLength;

            // Make sure that the radio is in IDLE state before flushing the FIFO
            // (Unless RXOFF_MODE has been changed, the radio should be in IDLE state at this point) 
            halSpiStrobe(CCxxx0_SIDLE);

            // Flush RX FIFO
            halSpiStrobe(CCxxx0_SFRX);
            return FALSE;
		}
	}
	else
		return FALSE;
}/**/
//-------------------------------------------------------------------------------------------------------
// 2.4G
// Chipcon
// Product = CC2500
// Chip version = E   (VERSION = 0x03)
// Crystal accuracy = 10 ppm
// X-tal frequency = 26 MHz
// RF output power = 0 dBm
// RX filterbandwidth = 541.666667 kHz
// Phase = 1
// Datarate = 249.938965 kBaud
// Modulation = (7) MSK
// Manchester enable = (0) Manchester disabled
// RF Frequency = 2432.999908 MHz
// Channel spacing = 199.951172 kHz
// Channel number = 0
// Optimization = Sensitivity
// Sync mode = (3) 30/32 sync word bits detected
// Format of RX/TX data = (0) Normal mode, use FIFOs for RX and TX
// CRC operation = (1) CRC calculation in TX and CRC check in RX enabled
// Forward Error Correction = (0) FEC disabled
// Length configuration = (1) Variable length packets, packet length configured by the first received byte after sync word.
// Packetlength = 255
// Preamble count = (2)  4 bytes
// Append status = 1
// Address check = (0) No address check
// FIFO autoflush = 0
// Device address = 0
// GDO0 signal selection = ( 6) Asserts when sync word has been sent / received, and de-asserts at the end of the packet
// GDO2 signal selection = (41) CHIP_RDY
void cc2500_init()
{	uchar xx,dat;

	POWER_UP_RESET_CCxxx0();
	xx=0x00;
//	xx=halSpiReadStatus(0x30);
	
	// 设置寄存器值
    halSpiWriteReg(CCxxx0_PATABLE,	0xFE);
	dat=halSpiReadReg(CCxxx0_PATABLE);
	halSpiWriteReg(CCxxx0_FSCTRL1,0x07);
	halSpiWriteReg(CCxxx0_FSCTRL0,0x00);

	halSpiWriteReg(CCxxx0_FREQ2,0x5D);
	halSpiWriteReg(CCxxx0_FREQ1,0x93);
	halSpiWriteReg(CCxxx0_FREQ0,0xB1);

	halSpiWriteReg(CCxxx0_MDMCFG4,0x2D);
	halSpiWriteReg(CCxxx0_MDMCFG3,0x3B);
	halSpiWriteReg(CCxxx0_MDMCFG2,0x73);
	halSpiWriteReg(CCxxx0_MDMCFG1,0x22);
	halSpiWriteReg(CCxxx0_MDMCFG0,0xF8);

	halSpiWriteReg(CCxxx0_CHANNR,0x00);
	halSpiWriteReg(CCxxx0_DEVIATN,0x01);
	halSpiWriteReg(CCxxx0_FREND1,0xB6);
	halSpiWriteReg(CCxxx0_FREND0,0x10);
	halSpiWriteReg(CCxxx0_MCSM0,0x18);
	halSpiWriteReg(CCxxx0_FOCCFG,0x1D);
	halSpiWriteReg(CCxxx0_BSCFG,0x1C);
	halSpiWriteReg(CCxxx0_AGCCTRL2,0xC7);
	halSpiWriteReg(CCxxx0_AGCCTRL1,0x00);
	halSpiWriteReg(CCxxx0_AGCCTRL0,0xB0);

   	halSpiWriteReg(CCxxx0_FSCAL3,0xEA);
	halSpiWriteReg(CCxxx0_FSCAL2,0x0A);
	halSpiWriteReg(CCxxx0_FSCAL1,0x00);
	halSpiWriteReg(CCxxx0_FSCAL0,0x11);
	halSpiWriteReg(CCxxx0_FSTEST,0x59);
	halSpiWriteReg(CCxxx0_TEST2,0x88);
	halSpiWriteReg(CCxxx0_TEST1,0x31);
	halSpiWriteReg(CCxxx0_TEST0,0x0B);
	halSpiWriteReg(CCxxx0_FIFOTHR,0x07);
	halSpiWriteReg(CCxxx0_IOCFG2,0x29);
	halSpiWriteReg(CCxxx0_IOCFG0,0x06);
	halSpiWriteReg(CCxxx0_PKTCTRL1,0x04);
	halSpiWriteReg(CCxxx0_PKTCTRL0,0x05);
	halSpiWriteReg(CCxxx0_ADDR,0x00);
	halSpiWriteReg(CCxxx0_PKTLEN,0xFF);

	// 校正
	halSpiStrobe(CCxxx0_SCAL);
	while(halSpiReadStatus(CCxxx0_FSCAL1) == 0x3F);

	// 清空RX FIFO Buffer
	halSpiStrobe(CCxxx0_SFRX);
	

	// 进入接收状态
	halSpiStrobe(CCxxx0_SRX);
}
//************************************************************************************//
/////////////////////////////LCD12864
//************************************************************************************//
unsigned char code font1[]=
{
0x40,0x44,0x4C,0x7D,0x77,0x66,0x7C,0x5C,
0x44,0xFE,0xFE,0x42,0x62,0xFA,0x9E,0x06,
0x00,0x00,0x7E,0x7E,0x22,0x22,0x22,0x7E,
0x7E,0xFF,0xFF,0x08,0x08,0x18,0x1F,0x0F,/*"部",0*/

0x00,0x00,0xF8,0xF9,0x07,0x06,0x02,0x02,
0x02,0x02,0x02,0x02,0x02,0xFE,0xFE,0x00,
0x00,0x00,0xFF,0xFF,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x40,0xC0,0xFF,0x7F,0x00,/*"门",1*/
};
void Delay(unsigned int n)
{
    while(n--);
return;
}
void Write_Data(uchar dat) 
{
   uchar i;
	SCLK = 1;
	SCLK = 0;
   CS1 = 0;
	A0 = 1;
	for(i=0;i<8;i++)
	{
   		SID = dat & 0x80;//取最高位
   		SCLK = 1;
   		SCLK = 0;
   		dat <<= 1;//左移
	}
	CS1 = 1;     
	return;
}

void Write_Instruction(uchar cmd)
{
	uchar i;
	SCLK = 1;
	SCLK = 0;
    CS1 = 0;
	A0 = 0;
	for(i=0;i<8;i++)
	{
   		SID = cmd & 0x80;//取最高位
   		SCLK = 1;
   		SCLK = 0;
   		cmd <<= 1;//左移
	}
	CS1 = 1;      
	return;
}

void Initial_Dispay_Line(unsigned char line)
{
    line|=0x40;
    Write_Instruction(line);
	return;
}
void Set_Page_Address(unsigned char add)
{
    add=0xb0|add;
    Write_Instruction(add);
	return;
}
void Set_Column_Address(unsigned char add)
{
    Write_Instruction((0x10|(add>>4)));
	Write_Instruction((0x0f&add));
	return;
}
void Power_Control(unsigned char vol)
{
    Write_Instruction((0x28|vol));
	return;
}
void Regulor_Resistor_Select(unsigned char r)
{
    Write_Instruction((0x20|r));
	return;
}
void Set_Contrast_Control_Register(unsigned char mod)
{
    Write_Instruction(0x81);
	Write_Instruction(mod);
	return;
}
void LcmClear( void )
{
         uchar i,j;
         Write_Instruction(0x40);      //Set Display Start Line = com0
         for(i=0;i<8;i++)
         {
                 Write_Instruction(0xB0|ComTable[i]); //Set Page Address
                 Write_Instruction(0x10);      //Set Column Address = 0
                 Write_Instruction(0x01);      //Colum from 1 -> 129 auto add
                 for(j=0;j<128;j++)
                 {
                         Write_Data( 0 );
                 }
         }
}
void Initial(void)
{
	P0M1 =0x00;
	P0M2 =0x00;
	P1M1 =0x00;
	P1M2 =0x00;
	P2M1 =0x00;
	P2M2 =0x00;
    RESET();
	Delay(10000);
	CS1=0;
    CLEAR_ADC();
    SET_SHL();
    SET_BIAS();
    Power_Control(0x07);
    Regulor_Resistor_Select(0x03);
    Set_Contrast_Control_Register(0x0a);//NT7534绿0x28//ST7565蓝0x0a
	Initial_Dispay_Line(0x00);
	DISPLAY_ON();
}

void Display_Chinese(unsigned char ft[],uchar x,uchar y)
{
	unsigned char i,j,k,num=0;
	i=x;
	for(i;i<x+2;i++)  //行
	{
     	num=i<<7;
   		num=num>>3;
   		Set_Page_Address(i);
        Set_Column_Address(y);//列地址
   		for(j=0;j<0x02;j++)//行字数
   		{
            for(k=0;k<0x10;k++)
    		{
          		Write_Data(ft[num+k]);
    		}
    		num+=0x20;
   		}
	}
    return;
}

void main()
{
	uchar len,old_Count;
	Initial();
	Delay(1000);
	LcmClear();
	Display_Chinese(font1,4,2);

	SPI_Master_Init();
	cc2500_init();
	old_Count = 0x00;
	len=sizeof(package)+1;
	while(1)
	{
  		len=halSpiReadStatus(CCxxx0_RXBYTES);
//		old_Count =halSpiReadStatus(CCxxx0_MARCSTATE);
		if(halRfReceivePacket(package,PACKAGE_LEN))
		{
		//检测CC2500是否接收到数据包
		// 接收数据
  		
//		halSpiReadBurstReg(CCxxx0_RXFIFO, (uchar *)package, 0x64);

  		Display_Chinese(package,6,32);
		}

		//进入空闲模式
		halSpiStrobe(CCxxx0_SIDLE);
		// 清空接收FIFO Buffer
  		halSpiStrobe(CCxxx0_SFRX);
		// 进入接收状态
   		halSpiStrobe(CCxxx0_SRX);
		
  	}
}

⌨️ 快捷键说明

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