MCU:MSP430F16X系列,RF無(wú)線模塊:NRF24L01,液晶顯示:ST7920串行控制128*64液晶,發(fā)送數(shù)據(jù)是把4X4矩陣鍵盤(pán)對(duì)應(yīng)的鍵值發(fā)送出去。IRQ是采用中斷查詢(xún)法,具體的可以參考下面代碼://p4口為液晶屏//p1口中斷//nRF24L01無(wú)線通信//p5.0 csn //p5.1 mosi//p5.3 sck//p5.2 miso//p1.2 irq//p5.7 ce//ST7920串行控制128*64液晶//rst p4.3 復(fù)位//rs p4.0 片選//rw p4.1 數(shù)據(jù)//E p4.2 時(shí)鐘#include #include #define uchar unsigned char#define uint unsigned int#define ulong unsigned long#define LCD_CLK_1 (P4OUT |= BIT2)#define LCD_CLK_0 (P4OUT &=~ BIT2)#define LCD_D_1 (P4OUT |= BIT1)#define LCD_D_0 (P4OUT &=~ BIT1)#define LCD_RST_1 (P4OUT |= BIT3)#define LCD_RST_0 (P4OUT &=~ BIT3)#define LCD_CS_1 (P4OUT |= BIT0)#define LCD_CS_0 (P4OUT &= ~BIT0)#define TMP121_CS_1 (P5OUT |= BIT7)#define TMP121_CS_0 (P5OUT &= ~BIT7)#define TMP121_CLK_1 (P5OUT |= BIT3)#define TMP121_CLK_0 (P5OUT &= ~BIT3)#define send_1 (P2OUT |= BIT0)#define send_0 (P2OUT &= ~BIT0)#define CPU_F ((double)1000000) // MCLK=1MHZ主頻#define Delayus_us(x) __Delayus_cycles((long)(CPU_F*(double)x/1000000.0))#define Delayus_ms(x) __Delayus_cycles((long)(CPU_F*(double)x/1000.0))#define Delayus_s(x) __Delayus_cycles((long)(CPU_F*(double)x/1.0))uint alldata[32],keyflg;uchar char11[16]={0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f};uchar busy=A,hang,lie,flash_flag,bostart;uchar key0=0,key1=T,key2,boflg,flg,key2flg=0,tab1=1,newsflag1,newsflag2;uchar key11,key12;uint LCDL;uchar tu[32][32]={0x00};uint Rdata[8]={0},botu[98]={0x0000};uchar Tx_Payload[32]={4,1,9};uchar Tx_Address[5]={100,101,102,103,104};void Delayus(ulong ilinshi){ ulong ii;for(ii=0;ii<=ilinshi;ii++){key0=key0;}}#define nRF24L01_CE_1 (P5OUT|= BIT7)#define nRF24L01_CE_0 (P5OUT&=~BIT7)#define nRF24L01_CSN_1 (P5OUT|= BIT0)#define nRF24L01_CSN_0 (P5OUT&=~BIT0)#define nRF24L01_SCK_1 (P5OUT|= BIT3)#define nRF24L01_SCK_0 (P5OUT&=~BIT3)#define nRF24L01_MOSI_1 (P5OUT|= BIT1)#define nRF24L01_MOSI_0 (P5OUT&=~BIT1)//SPI Commands#define nRF24L01_R_REGISTER 0x00#define nRF24L01_W_REGISTER 0x20#define nRF24L01_R_RX_PAYLOAD 0x61#define nRF24L01_W_TX_PAYLOAD 0xA0#define nRF24L01_FLUSH_TX 0xE1#define nRF24L01_FLUSH_RX 0xE2#define nRF24L01_REUSE_TX_PL 0xE3#define nRF24L01_NOP 0xFF//NRF24L01寄存器地址#define nRF24L01_CONFIG 0x00#define nRF24L01_EN_AA 0x01#define nRF24L01_EN_RXADDR 0x02#define nRF24L01_SETUP_AW 0x03#define nRF24L01_SETUP_RETR 0x04#define nRF24L01_RF_CH 0x05#define nRF24L01_RF_SETUP 0x06#define nRF24L01_STATUS 0x07#define nRF24L01_OBSERVE_TX 0x08#define nRF24L01_CD 0x09#define nRF24L01_RX_ADDR_P0 0x0A#define nRF24L01_RX_ADDR_P1 0x0B#define nRF24L01_RX_ADDR_P2 0x0C#define nRF24L01_RX_ADDR_P3 0x0D#define nRF24L01_RX_ADDR_P4 0x0E#define nRF24L01_RX_ADDR_P5 0x0F#define nRF24L01_TX_ADDR 0x10#define nRF24L01_RX_PW_P0 0x11#define nRF24L01_RX_PW_P1 0x12#define nRF24L01_RX_PW_P2 0x13#define nRF24L01_RX_PW_P3 0x14#define nRF24L01_RX_PW_P4 0x15#define nRF24L01_RX_PW_P5 0x16#define nRF24L01_FIFO_STATUS 0x17void IO_Init(void) //初始化端口{P2SEL = 0;P3SEL = 0;P4SEL = 0;P4DIR|=0x0f; //P4.0,1,2,3=OUTP4OUT|=0x0f;P2DIR=0xfd; //P2.1=in qita=OUTP3DIR&=0xf7; //p3.3=in}void Init_Port1(void) //P1.0、P1.1為中斷,下降沿觸發(fā){ P1SEL=0; //設(shè)置為普通I/O口功能P1DIR=0; //設(shè)置為輸入方向P1IE=0;P1IES=0; P1IE|=BIT2; //打開(kāi)中斷允許P1IES|=BIT2; //下降沿觸發(fā)P1IFG=0; //P1IES的切換可能使P1IFG置位,需清除}/*******************************************************************************///無(wú)線通信void Init_nRF24L01_IO(){nRF24L01_CE_0;nRF24L01_CSN_1;nRF24L01_SCK_0;nRF24L01_MOSI_0;}//NRF24L01的SPI寫(xiě)時(shí)序void nRF24L01SpiWrite(unsigned char byte){unsigned char i;nRF24L01_SCK_0;Delayus(1);for (i=0;i<8;i++) // Setup byte circulation bits{if ((byte&BIT7)==BIT7) // Put DATA_BUF.7 on data linenRF24L01_MOSI_1; //MOSI=1;elsenRF24L01_MOSI_0; //MOSI=0;nRF24L01_SCK_1; // Set clock line highDelayus(2);byte=byte<<1;nRF24L01_SCK_0; // Set clock line lowDelayus(2);}Delayus(1);}//NRF24L01的SPI讀時(shí)序unsigned char nRF24L01SpiRead(void){unsigned char i;unsigned char temp=0;nRF24L01_SCK_0;Delayus(2);for (i=0;i<8;i++) // Setup byte circulation bits{nRF24L01_SCK_1; // Set clock line highDelayus(2);temp=temp<<1; // Right shift DATA_BUFif ((P5IN&BIT2==BIT2)){temp|=1;} // Read datanRF24L01_SCK_0; // Set clock line lowDelayus(2);}Delayus(2);return temp;}//void nRF24L01_Flush_TX_FIFO(void)//Clear TX FIFO{nRF24L01_CSN_1;nRF24L01_CSN_0;nRF24L01SpiWrite(nRF24L01_FLUSH_TX);nRF24L01_CSN_1;}//void nRF24L01_Flush_RX_FIFO(void)//Clear RX FIFO{nRF24L01_CSN_1;nRF24L01_CSN_0;nRF24L01SpiWrite(nRF24L01_FLUSH_RX);nRF24L01_CSN_1;}//void nRF24L01SpiWriteReg(unsigned char SpiCommand,unsigned char Content){nRF24L01_CSN_1;nRF24L01_CSN_0;nRF24L01SpiWrite(SpiCommand);nRF24L01SpiWrite(Content);nRF24L01_CSN_1;}//void nRF24L01_Set_Rx_Address(unsigned char RX_Address_Pipex,unsigned char *Address,unsigned char Length)//Local//Address{unsigned char i=0;nRF24L01_CSN_1;nRF24L01_CSN_0;nRF24L01SpiWrite(RX_Address_Pipex);for(i=0;i
評(píng)論