同样的为了适配stm32,.H文件中宏定义也做了相应调整:
1、蓝色部分引脚高低电平宏定义是根据stm引脚设置特性做的修改~
2、黄色部分是为了使stm32的引脚能够像51单片机一样直接给赋值,如:LCD_CS=0或LCD_CS=1
3、其他部分没变,这就说明了之前我们用宏定义的好处了~
#include "stm32f10x.h"
/*
引脚高低电平宏定义
*/
#define CS_SET GPIO_SetBits(GPIOA, GPIO_Pin_0)//GPIO_Mode_Out_PP
#define CS_CLEAR GPIO_ResetBits(GPIOA, GPIO_Pin_0)//普通推挽输出
#define RS_SET GPIO_SetBits(GPIOA, GPIO_Pin_1)
#define RS_CLEAR GPIO_ResetBits(GPIOA, GPIO_Pin_1)
#define RET_SET GPIO_SetBits(GPIOA, GPIO_Pin_2)
#define RET_CLEAR GPIO_ResetBits(GPIOA, GPIO_Pin_2)
#define SCL_SET GPIO_SetBits(GPIOA, GPIO_Pin_3)//GPIO_Mode_AF_PP
#define SCL_CLEAR GPIO_ResetBits(GPIOA, GPIO_Pin_3)//复用推挽输出
#define SDA_SET GPIO_SetBits(GPIOA, GPIO_Pin_4)
#define SDA_CLEAR GPIO_ResetBits(GPIOA, GPIO_Pin_4)
#define BitBand(Addr, Bit) *((volatile int*)(((int)(Addr) & 0x60000000) + 0x02000000 + (int)(Addr) * 0x20 + (Bit) * 4))
#define LCD_CS BitBand(&GPIOA->ODR, 0)
#define LCD_RS BitBand(&GPIOA->ODR, 1)
#define LCD_SDA BitBand(&GPIOA->ODR, 4)
#define LCD_SCK BitBand(&GPIOA->ODR, 3)
/*
宏定义等待函数
*/
#define DELAY_MS(n) Delay_ms(n)
//-------------------------------------------------------------
#define ROW 160 //显示的行、列数
#define COL 128
#define BLUE 0xF800 //定义颜色常量
#define GREEN 0x07E0
#define RED 0x001F
#define WHITE 0xFFFF
#define BLACK 0x0000
#define GRAY 0xEF5D //0x2410
#define GRAY75 0x39E7
#define GRAY50 0x7BEF
#define GRAY25 0xADB5
void Delay(u16 time);
void Delay_ms(u16 time);
void DrawLine(unsigned int Xstart, unsigned int Xend, unsigned int Ystart, unsigned int Yend, unsigned int color);
void PutPixel(unsigned int x, unsigned int y, unsigned int color);
void WriteOneDot(unsigned int color);
void DispColor(unsigned int color);
void BlockWrite(unsigned int Xstart, unsigned int Xend, unsigned int Ystart, unsigned int Yend);
void LCD_Init(void);
void WriteDispData(unsigned char DataH, unsigned char DataL);
void LCD_GPIO_Init(void);
|