TA的每日心情 | 开心 2021-12-2 16:03 |
---|
签到天数: 271 天 连续签到: 1 天 [LV.8]以坛为家I
|
之前用过完51单片机写过一些有关TFT彩屏的程序,本想在这里移植到SAM4N的开发板上,不过不知道为啥就是显示不了,
不过51是用两个8位端口给彩屏发送数据或者指令,用来初始化,
void LCD_Writ_Bus(char VH,char VL) //并行数据写入函数
{
LCD_DataPortH=VH; //高位P1口
LCD_DataPortL=VL; //低位P0口
LCD_WR=0;
LCD_WR=1;
}
而我用SAM4N的板子是将其直接改为串行传送数据,就是增加 2 个74hc595 IC,这样只需要三个IO口来发送数据给彩屏了
void HC595SendData(unsigned int SendVal)
{
unsigned char i;
for(i=0;i<16;i++)
{
if(((SendVal<<i)&0x8000)==0x8000)
{
SET_MOSIO;// MOSIO=1; //set dataline high 0X8000 最高位与SendVal左移的最高位 进行逻辑运算
}
else
{
CLR_MOSIO; //MOSIO=0; // 如果为真 MOSIO = 1
}
CLR_S_CLK;//S_CLK=0;
//NOP();
//NOP();
for(char j=2;j>0;j--);
SET_S_CLK;//S_CLK=1;
}
CLR_R_CLK;//R_CLK=0; //set dataline low
//NOP();
//NOP();
for(char k=2;k>0;k--);
SET_R_CLK;//R_CLK=1; //片选
}
将上面相应的程序改为
void LCD_Writ_Bus(unsigned int data) //并行数据写入函数
{
//LCD_DataPortH=VH; //高位P1口
//LCD_DataPortL=VL; //低位P0口
HC595SendData(data);
//delay_ms(1);
Clr_Wr;
Set_Wr;
}
这样理论上就实现相应的控制,可是初始化程序就是驱动不了彩屏,求解?
单步运行时发现,这里将74HC595的输出端口接了16个LED共阳极的,单步调试确实数据没有问题。
这是相应的彩屏驱动程序:
#ifndef TFT_26_DRIVER_H_
#define TFT_26_DRIVER_H_
#include "asf.h"
#define uchar unsigned char
#define uint unsigned int
//#define LCD_DataPortH P5OUT //高8位数据口,8位模式下只使用高8位
//#define LCD_DataPortL P2OUT //低8位数据口 ,8位模式下低8位可以不接线
//sbit LCD_REST = P3^3; //RST 引脚定义 1.1
//sbit LCD_RD = P3^2; //RD 引脚定义 1.2
//sbit LCD_WR = P2^5; //WR 引脚定义 1.4
//sbit LCD_RS = P2^6; //RS 引脚定义 1.5
//sbit LCD_CS = P2^7; //CS 引脚定义 1.3
//#define LCD_ctrl_DIR P1DIR
//#define LCD_Port P1OUT
#define LCD_CS PIO_PA25_IDX // BIT3
#define LCD_RESET PIO_PA21_IDX //BIT1
#define LCD_RS PIO_PA24_IDX //BIT5
#define LCD_RD PIO_PA22_IDX //BIT2
#define LCD_WR PIO_PA23_IDX //BIT4
////595senddata
#define MOSIO PIO_PA11_IDX
#define R_CLK PIO_PA12_IDX
#define S_CLK PIO_PA13_IDX
//ioport_set_pin_level(PIO_PA21_IDX, IOPORT_PIN_LEVEL_HIGH);
//ioport_set_pin_dir(PIO_PA17_IDX, IOPORT_DIR_OUTPUT);
//ioport_set_pin_level(PIO_PA17_IDX, IOPORT_PIN_LEVEL_LOW);
#define Set_Cs do{ioport_set_pin_level(LCD_CS, IOPORT_PIN_LEVEL_HIGH);}while(0)
#define Set_Rst do{ioport_set_pin_level(LCD_RESET, IOPORT_PIN_LEVEL_HIGH);}while(0)
#define Set_Rs do{ioport_set_pin_level(LCD_RS, IOPORT_PIN_LEVEL_HIGH);}while(0)
#define Set_nRd do{ioport_set_pin_level(LCD_RD, IOPORT_PIN_LEVEL_HIGH);}while(0)
#define Set_Wr do{ioport_set_pin_level(LCD_WR, IOPORT_PIN_LEVEL_HIGH);}while(0)
#define Clr_Cs do{ioport_set_pin_level(LCD_CS, IOPORT_PIN_LEVEL_LOW);}while(0)
#define Clr_Rst do{ioport_set_pin_level(LCD_RESET, IOPORT_PIN_LEVEL_LOW);}while(0)
#define Clr_Rs do{ioport_set_pin_level(LCD_RS, IOPORT_PIN_LEVEL_LOW);}while(0)
#define Clr_nRd do{ioport_set_pin_level(LCD_RD, IOPORT_PIN_LEVEL_LOW);}while(0)
#define Clr_Wr do{ioport_set_pin_level(LCD_WR, IOPORT_PIN_LEVEL_LOW);}while(0)
#define LCD_SIZE_X 240
#define LCD_SIZE_Y 320
//ioport_set_pin_level(PIO_PA21_IDX, IOPORT_PIN_LEVEL_HIGH);
//ioport_set_pin_dir(PIO_PA17_IDX, IOPORT_DIR_OUTPUT);
//ioport_set_pin_level(PIO_PA17_IDX, IOPORT_PIN_LEVEL_LOW);
#define SET_MOSIO do {ioport_set_pin_level(MOSIO, IOPORT_PIN_LEVEL_HIGH);} while (0)
#define CLR_MOSIO do {ioport_set_pin_level(MOSIO, IOPORT_PIN_LEVEL_LOW);} while (0)
#define SET_R_CLK do {ioport_set_pin_level(R_CLK, IOPORT_PIN_LEVEL_HIGH);} while (0)
#define CLR_R_CLK do {ioport_set_pin_level(R_CLK, IOPORT_PIN_LEVEL_LOW);} while (0)
#define SET_S_CLK do {ioport_set_pin_level(S_CLK, IOPORT_PIN_LEVEL_HIGH);} while (0)
#define CLR_S_CLK do {ioport_set_pin_level(S_CLK, IOPORT_PIN_LEVEL_LOW);} while (0)
extern uint colors[];
void inttpio(void);
void LCD_Init(void);
void delayms(int count) ;
void LCD_Writ_Bus(unsigned int data);
//void LCD_Writ_Bus(char VH,char VL);
void LCD_Write_COM(unsigned int data);
void LCD_Write_DATA(unsigned int data);
void Pant(unsigned int data);
void Address_set(unsigned int x1,unsigned int y1,unsigned int x2,unsigned int y2);
void LCD_color_H(void);
void LCD_color_V(void);
void HC595SendData(unsigned int SendVal);
#endif /* TFT_26_DRIVER_H_ */
#include "TFT_26_driver.h"
uint colors[]=
{0xf800,0x07e0,0x001f,0xffe0,0x0000,0x07ff,0xf81f,0xffff }; //颜色数据
void inttpio(void)
{
ioport_set_pin_dir(LCD_CS, IOPORT_DIR_OUTPUT);
ioport_set_pin_dir(LCD_RD, IOPORT_DIR_OUTPUT);
ioport_set_pin_dir(LCD_RESET, IOPORT_DIR_OUTPUT);
ioport_set_pin_dir(LCD_WR, IOPORT_DIR_OUTPUT);
ioport_set_pin_dir(LCD_RS, IOPORT_DIR_OUTPUT);
ioport_set_pin_dir(MOSIO, IOPORT_DIR_OUTPUT);
ioport_set_pin_dir(R_CLK, IOPORT_DIR_OUTPUT);
ioport_set_pin_dir(S_CLK, IOPORT_DIR_OUTPUT);
}
void LCD_Init(void)
{
//LCD_ctrl_DIR |= BIT1+BIT2+BIT3+BIT4+BIT5;
inttpio();
Set_Rst;
delayms(5);
Clr_Rst;
delayms(5);
Set_Rst;
delayms(5);
Clr_Cs ; //打开片选使能
LCD_Write_COM(0x0010); LCD_Write_DATA(0x0000); // Power Control 1 current consumption STB
delayms(10);
LCD_Write_COM(0x0011); LCD_Write_DATA(0x001c); // Power Control 2
LCD_Write_COM(0x0012); LCD_Write_DATA(0x1212); // Power Control 3 BT2-0, DC11-10, DC21-20, DC31-30
LCD_Write_COM(0x0013); LCD_Write_DATA(0x0041); // Power Control 4 DCR_EX=0, DCR2-0, GVD6-0
LCD_Write_COM(0x0014); LCD_Write_DATA(0x4050); // Power Control 5 VCOMG=0, VCM6-0, VCMR=0, VML6-0
LCD_Write_COM(0x0010); LCD_Write_DATA(0x0800); // Power Control 1
LCD_Write_COM(0x0011); LCD_Write_DATA(0x011c); // Power Control 2
delayms(300);//300ms
LCD_Write_COM(0x0011); LCD_Write_DATA(0x031c); // Power Control 2
delayms(300);//300ms
LCD_Write_COM(0x0011); LCD_Write_DATA(0x071c); // Power Control 2
delayms(300);//300ms
LCD_Write_COM(0x0011); LCD_Write_DATA(0x0f1c); // Power Control 2
delayms(40);//600ms
LCD_Write_COM(0x0011); LCD_Write_DATA(0x0f39); // Power Control 2
delayms(60);//500ms
LCD_Write_COM(0x0001); LCD_Write_DATA(0x0128); // Driver Output Control
LCD_Write_COM(0x0002); LCD_Write_DATA(0x0100); // LCD-Driving-Waveform Control
LCD_Write_COM(0x0003); LCD_Write_DATA(0x1030); // Entry Mode
LCD_Write_COM(0x0008); LCD_Write_DATA(0x0808); // Frame Cycle Control
LCD_Write_COM(0x000b); LCD_Write_DATA(0x1105); // Frame Cycle Control
LCD_Write_COM(0x000c); LCD_Write_DATA(0x0000); // External Display Interface Control
LCD_Write_COM(0x0015); LCD_Write_DATA(0x0020); //VCI Recycling (R15H) // VCIR=010 0X0020
LCD_Write_COM(0x0030); LCD_Write_DATA(0x0000); // SCN 0 Start from G1
LCD_Write_COM(0x0034); LCD_Write_DATA(0x013f); // SE1 = 100111111( 319)
LCD_Write_COM(0x0035); LCD_Write_DATA(0x0000); // SS1 = 000000000
LCD_Write_COM(0x0036); LCD_Write_DATA(0x00ef); // HEA = 011101111(239)
LCD_Write_COM(0x0037); LCD_Write_DATA(0x0000); // HSA = 000000000
LCD_Write_COM(0x0038); LCD_Write_DATA(0x013f); // VEA = 100111111( 319)
LCD_Write_COM(0x0039); LCD_Write_DATA(0x0000); // VSA = 000000000
LCD_Write_COM(0x0050); LCD_Write_DATA(0x0101); // Gamma Control
LCD_Write_COM(0x0051); LCD_Write_DATA(0x0903);
LCD_Write_COM(0x0052); LCD_Write_DATA(0x0b08);
LCD_Write_COM(0x0053); LCD_Write_DATA(0x0805);
LCD_Write_COM(0x0054); LCD_Write_DATA(0x0101);
LCD_Write_COM(0x0055); LCD_Write_DATA(0x0d06);
LCD_Write_COM(0x0056); LCD_Write_DATA(0x0e0a);
LCD_Write_COM(0x0057); LCD_Write_DATA(0x0100);
LCD_Write_COM(0x0058); LCD_Write_DATA(0x1f0b);
LCD_Write_COM(0x0059); LCD_Write_DATA(0x0201);
LCD_Write_COM(0x0020); LCD_Write_DATA(0x0000); //Set RAM Address
LCD_Write_COM(0x0021); LCD_Write_DATA(0x0000); //Set RAM Address
//0x22 RAM Data Write
//LCD_CtrlWrite(0x0022);
LCD_Write_COM(0x000f); LCD_Write_DATA(0x1f01); // Start Oscillation
delayms(300);//300ms
LCD_Write_COM(0x0007); LCD_Write_DATA(0x0016); // Display Control
delayms(32);//200ms
LCD_Write_COM(0x0007); LCD_Write_DATA(0x0017);
Set_Cs;
}
void delayms(int count) // /* X1ms */
{
delay_ms(count);
// int i,j;
// for(i=0;i<count;i++)
// for(j=0;j<500;j++);
}
void LCD_Writ_Bus(unsigned int data) //并行数据写入函数
{
//LCD_DataPortH=VH; //高位P1口
//LCD_DataPortL=VL; //低位P0口
HC595SendData(data);
//delay_ms(1);
Clr_Wr;
Set_Wr;
}
void LCD_Write_COM(unsigned int data) //发送命令
{
Clr_Rs;//LCD_RS=0;
LCD_Writ_Bus(data);
}
void LCD_Write_DATA(unsigned int data) //发送数据
{
Set_Rs;//LCD_RS=1;
LCD_Writ_Bus(data);
}
void Pant(unsigned int data)
{
int i,j;
Clr_Cs ; //打开片选使能
Address_set(0,0,239,319);
for(i=0;i<320;i++)
{
for (j=0;j<240;j++)
{
LCD_Write_DATA(data);
}
}
Set_Cs;//LCD_CS =1; //关闭片选使能
}
void Address_set(unsigned int x1,unsigned int y1,unsigned int x2,unsigned int y2)
{
LCD_Write_COM(0x0020);LCD_Write_DATA(x1); //设置X坐标位置
LCD_Write_COM(0x0021);LCD_Write_DATA(y1); //设置Y坐标位置
LCD_Write_COM(0x0037);LCD_Write_DATA(x1); //开始X
LCD_Write_COM(0x0039);LCD_Write_DATA(y1); //开始Y
LCD_Write_COM(0x0036);LCD_Write_DATA(x2); //结束X
LCD_Write_COM(0x0038);LCD_Write_DATA(y2); //结束Y
LCD_Write_COM(0x0022); //开启显示命令
}
/**********************************************************
水平彩条显示子函数
**********************************************************/
void LCD_color_H(void)
{
uint num;
uchar n;
Address_set(0, 0, 239,319);
for(n=0;n<8;n++)
{
for(num=40*240;num>0;num--)
{
LCD_Write_DATA(colors[n]);
}
}
}
/**********************************************************
垂直彩条显示子函数
**********************************************************/
void LCD_color_V(void)
{
uint num;
uchar n,x1,x2;
x1 = 0;
x2 = 30;
for(n=0;n<8;n++)
{
Address_set(x1, 0, x2-1,319);
x1 = x2;
x2 = x2+30;
for(num=30*320;num>0;num--)
{
LCD_Write_DATA(colors[n]);
}
}
}
void HC595SendData(unsigned int SendVal)
{
unsigned char i;
for(i=0;i<16;i++)
{
if(((SendVal<<i)&0x8000)==0x8000)
{
SET_MOSIO;// MOSIO=1; //set dataline high 0X8000 最高位与SendVal左移的最高位 进行逻辑运算
}
else
{
CLR_MOSIO; //MOSIO=0; // 如果为真 MOSIO = 1
}
CLR_S_CLK;//S_CLK=0;
//NOP();
//NOP();
for(char j=2;j>0;j--);
SET_S_CLK;//S_CLK=1;
}
CLR_R_CLK;//R_CLK=0; //set dataline low
//NOP();
//NOP();
for(char k=2;k>0;k--);
SET_R_CLK;//R_CLK=1; //片选
}
|
|