TIVA C Launchpad (EK-LM4F120XL LaunchPad) 一TFT步步驱动
/*硬件上占用 PB,PD口
LCD ARM
data[8~15] =====PORTB[0~7]
CS ===== PORTD[0]
CD ===== PORTD[1]
WR ===== PORTD[2]
RD ===== PORTD[3]
RST ===== PORTD[6]
BK ===== PORTF[3]
*/
// 使用8位数据总线端口和位掩码
#define LCD_DATA_PERIPH SYSCTL_PERIPH_GPIOB
#define LCD_DATA_BASE GPIO_PORTB_BASE
#define LCD_DATA_PINS 0xFF
//用于控制的端口和引脚
#define LCD_CS_PERIPH SYSCTL_PERIPH_GPIOD
#define LCD_CS_BASE GPIO_PORTD_BASE
#define LCD_CS_PIN GPIO_PIN_0
#define LCD_CD_PERIPH SYSCTL_PERIPH_GPIOD
#define LCD_CD_BASE GPIO_PORTD_BASE
#define LCD_CD_PIN GPIO_PIN_1
#define LCD_WR_PERIPH SYSCTL_PERIPH_GPIOD
#define LCD_WR_BASE GPIO_PORTD_BASE
#define LCD_WR_PIN GPIO_PIN_2
#define LCD_RD_PERIPH SYSCTL_PERIPH_GPIOD
#define LCD_RD_BASE GPIO_PORTD_BASE
#define LCD_RD_PIN GPIO_PIN_3
#define LCD_RST_PERIPH SYSCTL_PERIPH_GPIOD
#define LCD_RST_BASE GPIO_PORTD_BASE
#define LCD_RST_PIN GPIO_PIN_6
#define LCD_BKLT_PERIPH SYSCTL_PERIPH_GPIOF
#define LCD_BKLT_BASE GPIO_PORTF_BASE
#define LCD_BKLT_PIN GPIO_PIN_3
// 常见的引脚操作的宏 使用性能和紧凑的直接内存访问
#define LCD_CS_IDLE HWREG(LCD_CS_BASE + GPIO_O_DATA + (LCD_CS_PIN << 2)) = LCD_CS_PIN;
#define LCD_CS_ACTIVE HWREG(LCD_CS_BASE + GPIO_O_DATA + (LCD_CS_PIN << 2)) = 0;
#define LCD_CD_DATA HWREG(LCD_CD_BASE + GPIO_O_DATA + (LCD_CD_PIN << 2)) = LCD_CD_PIN;
#define LCD_CD_COMMAND HWREG(LCD_CD_BASE + GPIO_O_DATA + (LCD_CD_PIN << 2)) = 0;
#define LCD_WR_IDLE HWREG(LCD_WR_BASE + GPIO_O_DATA + (LCD_WR_PIN << 2)) = LCD_WR_PIN;
#define LCD_WR_ACTIVE HWREG(LCD_WR_BASE + GPIO_O_DATA + (LCD_WR_PIN << 2)) = 0;
#define LCD_RD_IDLE HWREG(LCD_RD_BASE + GPIO_O_DATA + (LCD_RD_PIN << 2)) = LCD_RD_PIN;
#define LCD_RD_ACTIVE HWREG(LCD_RD_BASE + GPIO_O_DATA + (LCD_RD_PIN << 2)) = 0;
#define LCD_RST_IDLE HWREG(LCD_RST_BASE + GPIO_O_DATA + (LCD_RST_PIN << 2)) = LCD_RST_PIN;
#define LCD_RST_ACTIVE HWREG(LCD_RST_BASE + GPIO_O_DATA + (LCD_RST_PIN << 2)) = 0;
#define LCD_BKLT_ON HWREG(LCD_BKLT_BASE + GPIO_O_DATA + (LCD_BKLT_PIN << 2)) = LCD_BKLT_PIN;
#define LCD_BKLT_OFF HWREG(LCD_BKLT_BASE + GPIO_O_DATA + (LCD_BKLT_PIN << 2)) = 0;
#define LCD_DATA_WRITE(ucByte) { HWREG(LCD_DATA_BASE + GPIO_O_DATA + (LCD_DATA_PINS << 2)) = (ucByte); }
void LCDWriteData(const unsigned short usData)
{
LCD_CD_DATA //数据
// Send higher byte //数据高8位
LCD_DATA_WRITE(usData >> 8);
// Strobe WR
LCD_WR_ACTIVE
LCD_WR_IDLE //锁存上升沿
// Send lower byte
LCD_DATA_WRITE(usData & 0xff);//数据低8位
// Strobe WR
LCD_WR_ACTIVE
LCD_WR_IDLE //锁存上升沿
}
void LCDWriteCommand(const unsigned short usAddress)
{
LCD_CD_COMMAND //命令
// Send higher byte
LCD_DATA_WRITE(usAddress >> 8);//命令高8位
// Strobe WR
LCD_WR_ACTIVE
LCD_WR_IDLE //锁存上升沿
// Send lower byte
LCD_DATA_WRITE(usAddress & 0xff);//命令低8位
// Strobe WR
LCD_WR_ACTIVE
LCD_WR_IDLE //锁存上升沿
}