南华大学电气工程学院课程设计(论文)
addr=0x40+x;
LcdWriteCmd(addr | 0x80); }
void LcdShowStr(uint8_t x,uint8_t y,uint8_t *str) {
LcdSetCursor(x,y); while(*str !='\\0') {
LcdWriteDat(*str++); } }
void InitLcd1602(void) {
LcdWriteCmd(0x38); LcdWriteCmd(0x0c); LcdWriteCmd(0x06); LcdWriteCmd(0x01); }
void Lcd1602_Configure(void) {
Lcd1602_GPIO_Config(); InitLcd1602(); }
//lcd1602.h
#ifndef _LCD1602_H_ #define _LCD1602_H_ #include
#include\#include\#include\#include\#include\#include\#include\#include\#include\#include\#include \
#define DATA_PIN GPIO_PIN_0 |GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7
第30页,共69页
南华大学电气工程学院课程设计(论文)
#define LCD_RS_PIN GPIO_PIN_4 #define LCD_RW_PIN GPIO_PIN_5 #define LCD_EN_PIN GPIO_PIN_6
#define LCD_CMD_PIN LCD_RS_PIN |LCD_RW_PIN |LCD_EN_PIN
#define LCD_RS_H GPIOPinWrite(GPIO_PORTC_BASE,LCD_RS_PIN,LCD_RS_PIN)
#define LCD_RS_L GPIOPinWrite(GPIO_PORTC_BASE,LCD_RS_PIN,~LCD_RS_PIN)
#define LCD_RW_H GPIOPinWrite(GPIO_PORTC_BASE,LCD_RW_PIN,LCD_RW_PIN)
#define LCD_RW_L GPIOPinWrite(GPIO_PORTC_BASE,LCD_RW_PIN,~LCD_RW_PIN)
#define LCD_EN_H GPIOPinWrite(GPIO_PORTC_BASE,LCD_EN_PIN,LCD_EN_PIN)
#define LCD_EN_L GPIOPinWrite(GPIO_PORTC_BASE,LCD_EN_PIN,~LCD_EN_PIN)
#define LCD_DATA_IN GPIOPinRead(GPIO_PORTB_BASE,DATA_PIN) #define LCD_DATA_OUT(dat) GPIOPinWrite(GPIO_PORTB_BASE,DATA_PIN,0xFF&dat)
void Lcd1602_Configure(void);
void LcdShowStr(uint8_t x,uint8_t y,uint8_t *str);
#endif //spi.c
//*********************************************************************** #include \
uint8_t SPI_RW(uint8_t data) {
uint8_t bit_ctr; SCK_LOW
for(bit_ctr=0; bit_ctr<8; bit_ctr++)
第31页,共69页
南华大学电气工程学院课程设计(论文)
{
if(data&0x80) {
MOSI_HIGH } else {
MOSI_LOW }
data=(data<<1); SCK_HIGH
data|=(GPIO_PIN_MISO==MISO); SCK_LOW }
return data; }
void SPI1_INIT(void) {
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE,GPIO_PIN_3|GPIO_PIN_2); GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_3,GPIO_PIN_3); ///CE3?ê??ˉ //**************************************************************** SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
GPIOPinTypeGPIOOutput(GPIO_PORT,GPIO_PIN_SCK|GPIO_PIN_MOSI|GPIO_PIN_CS);
GPIOPinTypeGPIOInput(GPIO_PORT,GPIO_PIN_MISO);
//************************************************************************
printf(\ complate!\\r\\n\} //spi.h
#ifndef _SPI_H_ #define _SPI_H_ #include
#include\#include\#include\#include\#include\
第32页,共69页
南华大学电气工程学院课程设计(论文)
#include\#include\#include\#include\typedef uint8_t u8;
#define GPIO_PORT GPIO_PORTF_BASE #define GPIO_PIN_CS GPIO_PIN_2 #define GPIO_PIN_SCK GPIO_PIN_1 #define GPIO_PIN_MOSI GPIO_PIN_4 #define GPIO_PIN_MISO GPIO_PIN_3
#define SCK_HIGH GPIOPinWrite(GPIO_PORT,GPIO_PIN_SCK,GPIO_PIN_SCK);
#define SCK_LOW
GPIOPinWrite(GPIO_PORT,GPIO_PIN_SCK,~GPIO_PIN_SCK);
#define MOSI_HIGH GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_2,GPIO_PIN_2);
#define MOSI_LOW GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_2,~GPIO_PIN_2);
#define MISO GPIOPinRead(GPIO_PORT,GPIO_PIN_MISO)
#defin CS_HIGH GPIOPinWrite(GPIO_PORT,GPIO_PIN_CS,GPIO_PIN_CS);
#define CS_LOW GPIOPinWrite(GPIO_PORT,GPIO_PIN_CS,~GPIO_PIN_CS);
#define SPI_CE_L() GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_3,~GPIO_PIN_3)
#define SPI_CE_H() GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_3,GPIO_PIN_3)
#define SPI_CSN_L() CS_LOW #define SPI_CSN_H() CS_HIGH
void SPI1_INIT(void); u8 SPI_RW(u8 dat);
#endif
第33页,共69页
南华大学电气工程学院课程设计(论文)
//nrf24l01.c
#include \#include \#include \#include \
//*********************************************************************************
uint8_t TX_ADDRESS[TX_ADR_WIDTH]= {0x13,0x31,0x63,0x66,0x85}; //±?μ?μ??· uint8_t RX_ADDRESS[RX_ADR_WIDTH]= {0x13,0x31,0x63,0x66,0x85}; //?óê?μ??·
uint8_t NRF24L01_RXDATA[32]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; /*
***************************************************************** ***************************************************************** */
uint8_t NRF_Write_Reg(uint8_t reg, uint8_t value) { uint8_t status; SPI_CSN_L(); status = SPI_RW(reg); SPI_RW(value); /* D′êy?Y */ SPI_CSN_H(); /* ???1???÷?t */ return status; } /*
***************************************************************** ***************************************************************** */
uint8_t NRF_Read_Reg(uint8_t reg) { uint8_t reg_val; SPI_CSN_L(); SPI_RW(reg); reg_val = SPI_RW(0); /* ?áè?????′??÷·μ??êy?Y */ SPI_CSN_H(); /* ???1???÷?t */ return reg_val; } /*
***************************************************************** *****************************************************************
第34页,共69页