• 若何往完成一種基于STM32F103ZET6的LED BEEP KEY驅動?938
• 如何往處理STM32F103ZET6庫函數法式移植的Delay函數異常題目1261
• stm32f103zet6與stm32f407zg是如何停止spi通訊的985
******************************/
void Lcd_SetRegion(u16 x_start,u16 y_start,u16 x_end,u16 y_end)
{
Lcd_WriteIndex(0x2a);
Lcd_WriteData(0x00);
Lcd_WriteData(x_start+2);
Lcd_W包養心得riteData(0x00);
Lcd_WriteData(x_end+2);
Lcd_WriteIndex(0x2b);
Lcd_WriteData(0x00);
Lcd_WriteData(y_start+1);
Lcd_WriteData(0x00);
Lcd_WriteData(y_end+1);
Lcd_WriteIndex(0x2c);
}
//—————包養價格—————————————————————————————————-
// @brief 液晶初始化
// @return void
// @since v1.0
// Sample usage:
//————————————————————————————包養dcard——————————-
void lcd_init(void)
{
Lcd_Reset(); //Reset before LCD Init.
delay_ms(10);
Lcd_WriteIndex(0x11);
delay_ms(120);
Lcd_WriteIndex(0xB1);
Lcd_Wr台灣包養iteData(0x01);
Lcd_WriteData(0x2C);
Lcd_WriteData(0x2D);
Lcd_WriteIndex(0xB2);
Lcd_WriteData(0x01);
Lcd_WriteData(0x2C);
Lcd_WriteData(0x2D);
Lcd_WriteIndex(0xB3);
Lcd_WriteData(0x01);
Lcd_WriteData(0x2C);
Lcd_WriteData(0x2D);
Lcd_WriteData(0x01);
Lcd_WriteData(0x2C);
Lcd_WriteData(0x2D);
Lcd_WriteIndex(0xB4);
Lcd_WriteData(0x07);
Lcd_WriteIndex(0xC0);
Lcd_WriteData(0xA2);
Lcd_WriteData(0x02);
Lcd_WriteData(0x84);
Lcd_WriteIndex(0xC1);
Lcd_WriteData(0xC5);
Lcd_WriteIndex(0xC2);
Lcd_WriteData(0x0A);
Lcd_WriteData(0x00);
Lcd_WriteIndex(0xC3);
Lcd_WriteData(0x8A);
Lcd_WriteData(0x2A);
Lcd_WriteIndex(0xC4);
Lcd_WriteData(0x8A);
Lcd_WriteData(0xEE);
Lcd_WriteIndex(0xC5);
Lcd_WriteData(0x0E);
Lcd_WriteIndex(0x36);
// switch(TFT_DISPLAY_DIR)//y x v
// {
// case 0: Lcd_WriteData(1>TFT –SCL/SCK
//#define LCD_SDA GPIO_Pin_15 //PB15 MOSI—>>TFT –SDA/DIN
//#define LCD_CS GPIO_Pin_4 //MCU_PB11—>>TFT –CS/CE
PB10 PB1 PB0
//#define LCD_LED GPIO_Pin_10 //MCU_PB9—>>TFT –BL
//#define LCD_RS GPIO_Pin_1 //PB11—>>TFT –RS/DC DC數據號令位
//#defin們就過來了。護院勢力的排名分別是第二和第三,可見藍學士對這個獨生女的重視和喜愛。e LCD_RST GPIO_Pin_0 //PB10—>>TFT –RST
//#define LCD_CS_SET(甜心花園x) LCD_CTRL->ODR=(LCD_CTRL->ODR&~LCD_CS)|(x ? LCD_CS:0)
#define LCD_SCL PBout(13)
#define LCD_SDA PBout(15)
#define LCD_CS PAout(4) //片選
#define LCD_RS PBout(1) //時鐘/數據
#define LCD_RST PBout(0)
液晶把持口置1操縱語句宏界說
//#define LCD_SCL_SET LCD_CTRLB->BSRR=LCD_SCL
//#define LCD_SDA_SET LCD_CTRLB->BSRR=LCD_SDA
//#define LCD_CS_SET LCD_CTRLA->BSRR=LCD_CS
//
//#define LCD_LED_SET LCD_CTRLB->BSRR=LCD_包養一個月LED
//#define LCD_RS_SET LCD_CTRLB->BSRR=LCD_RS
//#define LCD_RST_SET LCD_CTRLB->BSRR=LCD_RST
液晶把持口置0操縱語句宏界說
//#define LCD_SCL_CLR LCD_CTRLA->BRR=LCD_SCL
//#define LCD_SDA_CLR LCD_CTRLA->包養情婦BRR=LCD_SDA
//#define LCD_CS_CLR LCD_CTRLA->BRR=LCD_CS
//
//#define LCD_LED_CLR LCD_CTRLB->BRR=LCD_LED
//#define LCD_RST_CLR LCD_CTRLB->BRR=LCD_RST
//#define LCD_RS_CLR LCD_CTRLB->BRR=LCD_RS
//#define LCD_DATAOUT(x) LCD_DATA->ODR=x; //數據輸入
//#define LCD_DATAIN LCD_DATA->IDR; //數據輸出
u8 SPI2_WriteData(u8 qq);
void Lcd_WriteIndex(u8 Index);
void Lcd_WriteData(u8 aa);
void Lcd_WriteData_包養網VIP16Bit(u16 dd);
void Lcd_Reset(void);
void Lcd_SetRegion(u16 x_start,u16 y_sta包養網站rt,u16 x_end,u16 y_end);
void l包養網比較cd_init(void);
void lcd_drawpoint(u包養故事16 x,u16 y,u16 color);
void dsp_single_colour(int color);
void Lcd_WriteReg(u8 Cmd,u8 Data);
#endif
三、spi.c文件
#include “spi.h”
#inclu包養俱樂部de “tft.h”
#include “delay.h”
//以下是SPI模塊的初始化代碼,設置裝備擺設成主機形式,拜訪SD Card/W25Q64/NRF24L01
//SPI口初始化
//這里針是對SPI2的初始化
//初始化IO口B12、B14、B15
void SPI2_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
SPI_InitTypeDef SPI_InitStructure;
RCC_APB2PeriphCloc甜心寶貝包養網kCmd( RCC_APB2Periph_GPIOD|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOA|RCC_APB2Periph_AFIO, ENABLE );台灣包養網//PB時鐘使能
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 |GPI包養意思O_Pin_15|GPIO_Pin_10 | GPIO_Pin_0 | GPIO_Pin_1;//GPIO_Pin_13 |
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //PB13/14/15復用推挽輸入
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure)包養行情;//初始化包養網dcardGP包養站長IOB
// GPIO_SetBits(GPIOB,GPIO_Pin_13 |GPIO_Pin_15|GPIO_Pin_10 | G台灣包養PIO_Pin_0 | GPIO_Pin_1); //PB13/14/15上拉//GPIO_Pin_13|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4|GPIO_Pin_13 |GPIO_Pin_15;//GPIO_Pin_13 |
GPIO_InitStr包養站長ucture.GPIO_Mode = GPIO_Mode_Out_PP; //PB13/14/15復用推挽輸入
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);//初始化GPIOB
GPIO_SetBits(GPIOA,GPIO_Pin_4); //PB13/14/15上拉//GPIO_Pin_13|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 |GPIO_Pin_15|GPIO包養網評價_Pin_10 | GPIO_Pin_0 | GPIO_Pin_1;//GPIO_Pin_13 |
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //PB13/14/15復用推挽輸入
GPIO_InitStructure.GPIO_Speed = GPIO_Spee包養行情d_50MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);//初始化GPIOB
GPIO_SetBits(GPIOD,GPIO_Pin_13 |GPIO_Pin_15|GPIO_Pin_10 | GPIO_Pin_0 | GPIO_Pin_1); //PB13/14/15上拉//GPIO_Pin_13|
RCC_APB1PeriphClockCmd( RCC_APB1Periph_SPI2, ENABLE );//SPI2時鐘使能
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; //設置SPI單向或許雙向的數據形式:SPI設置為雙線雙向全雙工
SPI_InitStructure.SPIsd包養_Mode = SPI_Mode_Master; //設置SPI任務形式:設置為主SPI
SPI_InitStructure.SPI_D包養犯法嗎ataSize = SPI_DataSize_8b; //設置SPI的數據鉅細:SPI發送接受8位幀構造
SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; //串行同步時鐘的空閑狀況為低電平
SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; //串行同步時鐘的第1個跳變沿(上升或降落)數據被采樣
SPI_InitStructure.SPI_NSS =包養一個月價錢 SPI_NSS_Soft; //NSS電子訊號由硬件(NSS管腳)仍是軟件(應用SSI位)治理:外部NSS電子訊號有SSI位把持
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256; //界說波特率預分頻的值:波特率預分頻值為256
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; //指定命據傳輸從MSB位仍是LSB位開端:數據傳輸從MSB位開端
SPI_InitStructure.SPI_CRCPol包養網車馬費ynomial = 7; //CRC值盤算的多項式
SPI_Init(SPI2, &SPI_InitStructure); //依據SPI_InitStruct中指定的參數初始化外設SPI包養條件x存放器
SPI_Cmd(SPI2, ENABLE); //使能SPI外設
SPI2_WriteData(0xFF);//啟動傳輸
}
SPIx 讀寫一個字節包養網dcard
TxData:要寫進的字節
前往值:讀取到的字節
//u8 SPI2_WriteData(u8 TxData)甜心寶貝包養網
//{
// u8 re包養甜心網try=0;
//
// while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET) //檢討指定的SPI標志位設置與否:發送緩存空標志位
// {
// retry++;
// if(retry>200)return 0;
// }
//
// SPI_I2S_SendData(SPI2, TxData); //經由過程外設SPIx發送一個數據
//
// retry=0;
//
// while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == RESET) //檢討指定的SPI標志位設置與否:接收緩存非空標志位
// {
//
// retry++;
//
// if(retry>200)return 0;
// }
//
// return SPI_I2S_ReceiveData(SPI2); //前往經由過程SPIx比來接受的數據
//}
uint8_t SPI2_WriteData(u8 byte)
{
while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET);
SPI_I2S_SendData(SPI2,byte);
while (SPI_I2S_GetFlagStatus(短期包養SPI2, SPI_I2S_FLAG_RXNE) == RESET);
return SPI_I2S_ReceiveData(SPI2);
}
向SPI寫一個8位數據
//u8 SPI2_WriteData(u8 D台灣包養ata)
//{
// unsigned char i=0;
//
LCD_CS_SET;
delay_us(20);
// for(i=8;i>0;i–)
// {
//
// if(Data&0x80)
//
// LCD_SDA=1; //數據線拉高,輸入數據
// else LCD_SDA=0;
//
//
delay_us(20);
// LCD_SCL=0;
delay_us(20);
//
// LCD_SCL=1;
// Data