求解软件模拟spi驱动st7735r

2019-08-19 20:52发布

求解lm3s通过软件模拟spi驱动st7735r,程序如下,为何初始化后还是白屏呢?


#define SPILCD_BASE GPIO_PORTD_BASE #define SPILCD_CS GPIO_PIN_4   //PD4 #define SPILCD_SDA GPIO_PIN_6    //PD6 #define SPILCD_SCL GPIO_PIN_5   //PD5 #define SPILCD_RS GPIO_PIN_7   //PD7 //片选使能 #define LCD_CS_L()  GPIOPinWrite(SPILCD_BASE, SPILCD_CS, 0) #define LCD_CS_H()  GPIOPinWrite(SPILCD_BASE, SPILCD_CS, SPILCD_CS) //命令片选 #define LCD_CMD_RS_L()  GPIOPinWrite(SPILCD_BASE, SPILCD_RS, 0) //数据片选 #define LCD_DATA_RS_H()  GPIOPinWrite(SPILCD_BASE, SPILCD_RS, SPILCD_RS) //SCL时钟 #define LCD_SCL_L()  GPIOPinWrite(SPILCD_BASE, SPILCD_SCL, 0) #define LCD_SCL_H()  GPIOPinWrite(SPILCD_BASE, SPILCD_SCL, SPILCD_SCL) //SDA #define LCD_SDA_L() GPIOPinWrite(SPILCD_BASE, SPILCD_SDA, 0) #define LCD_SDA_H() GPIOPinWrite(SPILCD_BASE, SPILCD_SDA, SPILCD_SDA) //液晶屏尺寸定义 #if (SPILCD_TYPE == 1) //1.8寸 #define SPILCD_W 128 #define SPILCD_H 160 #elif (SPILCD_TYPE == 2) //2.2寸 #define SPILCD_W 176 #define SPILCD_H 220 #endif //TFTLCD部分外要调用的函数     //u16  OINT_COLOR;//前景 {MOD}    //u16  BACK_COLOR; //背景 {MOD} ////////////////////////////////////////////////////////////////////// //字体 #define ASCII1206   0 #define ASCII1608   1 #define ASCII1608C 2 ////////////////////////////////////////////////////////////////////// //画笔颜 {MOD} #define WHITE 0xFFFF #define BLACK 0x0000    #define BLUE 0x001F   #define BRED 0XF81F #define GRED 0XFFE0 #define GBLUE 0X07FF #define RED 0xF800 #define MAGENTA 0xF81F #define GREEN 0x07E0 #define CYAN 0x7FFF #define YELLOW 0xFFE0 #define BROWN 0XBC40 //棕 {MOD} #define BRRED 0XFC07 //棕红 {MOD} #define GRAY 0X8430 //灰 {MOD} //GUI颜 {MOD} #define DARKBLUE        0X01CF //深蓝 {MOD} #define LIGHTBLUE        0X7D7C //浅蓝 {MOD}   #define GRAYBLUE         0X5458 //灰蓝 {MOD} //以上三 {MOD}为PANEL的颜 {MOD}  #define LIGHTGREEN       0X841F //浅绿 {MOD} #define LIGHTGRAY        0XEF5B //浅灰 {MOD}(PANNEL) #define LGRAY  0XC618 //浅灰 {MOD}(PANNEL),窗体背景 {MOD} #define LGRAYBLUE        0XA651 //浅灰蓝 {MOD}(中间层颜 {MOD}) #define LBBLUE           0X2B12 //浅棕蓝 {MOD}(选择条目的反 {MOD}) //////////////////////////// //前景 {MOD} 背景 {MOD} unsigned short POINT_COLOR = 0xffff,BACK_COLOR = 0x0000;   //函数名:SPILCD_WR_REG //参  数:无 //        实现写入一字节命令 void SPILCD_WR_REG(unsigned char ucData) { unsigned char i = 8; LCD_CS_L(); LCD_CMD_RS_L(); while(i--) { LCD_SCL_L(); if(ucData & 0x80) { LCD_SDA_H(); } else { LCD_SDA_L(); } LCD_SCL_H(); ucData <<=1; /* 左移一位,准备发送下一位数据 */ } LCD_CS_H(); } //函数名:LCD_WR_REG //参  数:无 //        实现写入一字节数据 void SPILCD_WR_DATA(unsigned char ucData) {     unsigned char i = 8; LCD_CS_L(); LCD_DATA_RS_H(); while(i--) { LCD_SCL_L(); if(ucData & 0x80) { LCD_SDA_H(); } else { LCD_SDA_L(); } LCD_SCL_H(); ucData <<=1; /* 左移一位,准备发送下一位数据 */ } LCD_CS_H(); } //函数名:SPILCD_Init //参  数:无 //        LCD 硬件初始化 void SPILCD_Init() { SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);   SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);   // GPIODirModeSet(SPILCD_BASE,LCD_PIN_D,GPIO_DIR_MODE_OUT); // GPIOPadConfigSet(SPILCD_BASE, LCD_PIN_D, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); GPIOPinTypeGPIOOutput(SPILCD_BASE,SPILCD_CS); GPIOPadConfigSet(SPILCD_BASE,SPILCD_CS, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD); GPIOPinTypeGPIOOutput(SPILCD_BASE,SPILCD_SCL); GPIOPadConfigSet(SPILCD_BASE,SPILCD_SCL, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD); GPIOPinTypeGPIOOutput(SPILCD_BASE,SPILCD_SDA); GPIOPadConfigSet(SPILCD_BASE,SPILCD_SDA, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD); GPIOPinTypeGPIOOutput(SPILCD_BASE,SPILCD_RS); GPIOPadConfigSet(SPILCD_BASE,SPILCD_RS, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD); GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE,GPIO_PIN_2); GPIOPadConfigSet(GPIO_PORTF_BASE,GPIO_PIN_2, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); /* SPILCD_RST=1; DelayMs (1); //Delay 1ms SPILCD_RST=0; DelayMs (1); //Delay 1ms SPILCD_RST=1; DelayMs (120); //Delay 120ms
PreciseDelay_ms(120); */ SPILCD_WR_REG(0x11);//Sleep out PreciseDelay_ms(120); //ST7735R Frame Rate SPILCD_WR_REG(0xB1); SPILCD_WR_DATA(0x01); SPILCD_WR_DATA(0x2C); SPILCD_WR_DATA(0x2D); SPILCD_WR_REG(0xB2); SPILCD_WR_DATA(0x01); SPILCD_WR_DATA(0x2C); SPILCD_WR_DATA(0x2D); SPILCD_WR_REG(0xB3); SPILCD_WR_DATA(0x01); SPILCD_WR_DATA(0x2C); SPILCD_WR_DATA(0x2D); SPILCD_WR_DATA(0x01); SPILCD_WR_DATA(0x2C); SPILCD_WR_DATA(0x2D); //------------------------------------End ST7735R Frame Rate-----------------------------------------// SPILCD_WR_REG(0xB4);//Column inversion SPILCD_WR_DATA(0x07); //------------------------------------ST7735R Power Sequence-----------------------------------------// SPILCD_WR_REG(0xC0); SPILCD_WR_DATA(0xA2); SPILCD_WR_DATA(0x02); SPILCD_WR_DATA(0x84); SPILCD_WR_REG(0xC1); SPILCD_WR_DATA(0xC5); SPILCD_WR_REG(0xC2); SPILCD_WR_DATA(0x0A); SPILCD_WR_DATA(0x00); SPILCD_WR_REG(0xC3); SPILCD_WR_DATA(0x8A); SPILCD_WR_DATA(0x2A); SPILCD_WR_REG(0xC4); SPILCD_WR_DATA(0x8A); SPILCD_WR_DATA(0xEE); //---------------------------------End ST7735R Power Sequence-------------------------------------// SPILCD_WR_REG(0xC5);//VCOM SPILCD_WR_DATA(0x0E); SPILCD_WR_REG(0x36);//MX, MY, RGB mode SPILCD_WR_DATA(0xC8); //------------------------------------ST7735R Gamma Sequence-----------------------------------------// SPILCD_WR_REG(0xe0); SPILCD_WR_DATA(0x02); SPILCD_WR_DATA(0x1c); SPILCD_WR_DATA(0x07); SPILCD_WR_DATA(0x12); SPILCD_WR_DATA(0x37); SPILCD_WR_DATA(0x32); SPILCD_WR_DATA(0x29); SPILCD_WR_DATA(0x2d); SPILCD_WR_DATA(0x29); SPILCD_WR_DATA(0x25); SPILCD_WR_DATA(0x2b); SPILCD_WR_DATA(0x39); SPILCD_WR_DATA(0x00); SPILCD_WR_DATA(0x01); SPILCD_WR_DATA(0x03); SPILCD_WR_DATA(0x10); SPILCD_WR_REG(0xe1); SPILCD_WR_DATA(0x03); SPILCD_WR_DATA(0x1d); SPILCD_WR_DATA(0x07); SPILCD_WR_DATA(0x06); SPILCD_WR_DATA(0x2e); SPILCD_WR_DATA(0x2c); SPILCD_WR_DATA(0x29); SPILCD_WR_DATA(0x2d); SPILCD_WR_DATA(0x2e); SPILCD_WR_DATA(0x2e); SPILCD_WR_DATA(0x37); SPILCD_WR_DATA(0x3f); SPILCD_WR_DATA(0x00); SPILCD_WR_DATA(0x00); SPILCD_WR_DATA(0x02); SPILCD_WR_DATA(0x10); SPILCD_WR_REG(0x2A); SPILCD_WR_DATA(0x00); SPILCD_WR_DATA(0x02); SPILCD_WR_DATA(0x00); SPILCD_WR_DATA(0x81);    SPILCD_WR_REG(0x2B); SPILCD_WR_DATA(0x00); SPILCD_WR_DATA(0x01); SPILCD_WR_DATA(0x00); SPILCD_WR_DATA(0xA0); //------------------------------------End ST7735R Gamma Sequence-----------------------------------------// SPILCD_WR_REG(0x3A);  SPILCD_WR_DATA(0x05);   //SPILCD_WR_REG(0x3A);//65k mode //LCD_WR_DATA(0x05); SPILCD_WR_REG(0x29);//Display on

PreciseDelay_ms(10); SPILCD_Clear(BACK_COLOR); SPILCD_Clear(RED); SPILCD_DrawLine(20,20,60,60); }

//参  数:无 //        准备开始写入GRAM void SPILCD_WriteRAM_Prepare(void) { SPILCD_WR_REG(0x2c);   //写RAM }   //函数名:LCD_WR_REG //参  数:无 //        写GRAM数据 void SPILCD_WriteRAM(unsigned short RGB_Code) {          SPILCD_WR_DATA(RGB_Code>>8);     SPILCD_WR_DATA(RGB_Code);  } //函数名:LCD_DisplayOn //参  数:无 //        开启显示 void LCD_DisplayOn(void) {         SPILCD_WR_REG(0x29);   // }   //函数名:LCD_DisplayOff //参  数:无 //        关闭显示 void LCD_DisplayOff(void) {         SPILCD_WR_REG(0x28);   // }    //函数名:LCD_SetWindow //参  数:Xpos:横坐标 // Ypos:纵坐标 void SPILCD_SetWindow(unsigned short xstat,unsigned short xend,unsigned short ystat,unsigned short yend) {    SPILCD_WR_REG(0x2A);    SPILCD_WR_DATA(xstat>>8);    SPILCD_WR_DATA(xstat);    SPILCD_WR_DATA(xend>>8);    SPILCD_WR_DATA(xend);    SPILCD_WR_REG(0x2B);    SPILCD_WR_DATA(ystat>>8);    SPILCD_WR_DATA(ystat);    SPILCD_WR_DATA(yend>>8); SPILCD_WR_DATA(yend); } //开启反 {MOD}显示 void LCD_InvDisplayOn() {   SPILCD_WR_REG(0x21);   } //关闭反 {MOD}显示 void LCD_InvDisplayOff() {   SPILCD_WR_REG(0x20);  }   
//------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------ //SPILCD DRIVER  LV1层    ----   LV1 在LV0的基础上实现 //打点 //清屏 //填充 //画线 //矩形边框 //画园 //函数名:SPILCD_Init //参  数:X Y 坐标  //        在X Y上打点 void SPILCD_DrawPoint(unsigned short x,unsigned short y) {   SPILCD_SetWindow(x,x+1,y,y+1);//设置光标位置  SPILCD_WriteRAM_Prepare();     //开始写入GRAM   SPILCD_WriteRAM(POINT_COLOR); }   
//函数名:SPILCD_Clear //参  数:Color 颜 {MOD}       void SPILCD_Clear(unsigned short Color) { unsigned long index=0;       SPILCD_SetWindow(0,SPILCD_W-1,0,SPILCD_H-1);   SPILCD_WriteRAM_Prepare();     //开始写入GRAM      for(index=0;index<SPILCD_W*SPILCD_H;index++) { SPILCD_WriteRAM(Color);//显示所填充的颜 {MOD}.  } }   //函数名:SPILCD_Fill //参  数:起始终点坐标 void SPILCD_Fill(unsigned short xsta,unsigned short ysta,unsigned short xend,unsigned short yend,unsigned short color) {                     unsigned long n; //设置窗口   SPILCD_SetWindow(xsta,xend,ysta,yend); SPILCD_WriteRAM_Prepare();  //开始写入GRAM           n=(unsigned long)(yend-ysta+1)*(xend-xsta+1);     while(n--){SPILCD_WriteRAM(color);}//显示所填充的颜 {MOD}.  //恢复设置 SPILCD_SetWindow(0,SPILCD_W-1,0,SPILCD_H-1);      } //函数名:SPILCD_DrawLine //参  数:起始终点坐标 void SPILCD_DrawLine(unsigned short x1,unsigned short y1,unsigned short x2,unsigned short y2) { unsigned short t;  int xerr=0,yerr=0,delta_x,delta_y,distance;  int incx,incy,uRow,uCol;  delta_x=x2-x1; //计算坐标增量  delta_y=y2-y1;  uRow=x1;  uCol=y1;  if(delta_x>0)incx=1; //设置单步方向  else if(delta_x==0)incx=0;//垂直线  else {incx=-1;delta_x=-delta_x;}  if(delta_y>0)incy=1;  else if(delta_y==0)incy=0;//水平线  else{incy=-1;delta_y=-delta_y;}  if( delta_x>delta_y)distance=delta_x; //选取基本增量坐标轴  else distance=delta_y;  for(t=0;t<=distance+1;t++ )//画线输出  {   SPILCD_DrawPoint(uRow,uCol);//画点  xerr+=delta_x ;  yerr+=delta_y ;  if(xerr>distance)  xerr-=distance;  uRow+=incx;  if(yerr>distance)  yerr-=distance;  uCol+=incy;  }   } 
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。