最近在弄2.8TFT屏,前几天还好好的,能清屏、显示汉字及ASCLL码。但是今天白屏了,我很郁闷,希望大虾们指点一下,感觉我的延时程序有点问题,还有液晶屏读程序没写。
这是单片机初始化程序
#include "C8051F120.h"
// Peripheral specific initialization functions,
// Called from the Init_Device() function
void Reset_Sources_Init() //关闭看门狗
{
WDTCN = 0xDE;
WDTCN = 0xAD;
}
void Port_IO_Init()
{
// P0.0 - Unassigned, Push-Pull, Digital
// P0.1 - Unassigned, Push-Pull, Digital
// P0.2 - Unassigned, Push-Pull, Digital
// P0.3 - Unassigned, Push-Pull, Digital
// P0.4 - Unassigned, Push-Pull, Digital
// P0.5 - Unassigned, Push-Pull, Digital
// P0.6 - Unassigned, Push-Pull, Digital
// P0.7 - Unassigned, Push-Pull, Digital
// P1.0 - Unassigned, Push-Pull, Digital
// P1.1 - Unassigned, Push-Pull, Digital
// P1.2 - Unassigned, Push-Pull, Digital
// P1.3 - Unassigned, Push-Pull, Digital
// P1.4 - Unassigned, Push-Pull, Digital
// P1.5 - Unassigned, Push-Pull, Digital
// P1.6 - Unassigned, Push-Pull, Digital
// P1.7 - Unassigned, Push-Pull, Digital
// P2.0 - Unassigned, Push-Pull, Digital
// P2.1 - Unassigned, Push-Pull, Digital
// P2.2 - Unassigned, Push-Pull, Digital
// P2.3 - Unassigned, Push-Pull, Digital
// P2.4 - Unassigned, Push-Pull, Digital
// P2.5 - Unassigned, Push-Pull, Digital
// P2.6 - Unassigned, Push-Pull, Digital
// P2.7 - Unassigned, Push-Pull, Digital
// P3.0 - Unassigned, Push-Pull, Digital
// P3.1 - Unassigned, Push-Pull, Digital
// P3.2 - Unassigned, Push-Pull, Digital
// P3.3 - Unassigned, Push-Pull, Digital
// P3.4 - Unassigned, Push-Pull, Digital
// P3.5 - Unassigned, Push-Pull, Digital
// P3.6 - Unassigned, Push-Pull, Digital
// P3.7 - Unassigned, Push-Pull, Digital
char SFRPAGE_SAVE = SFRPAGE;
SFRPAGE = CONFIG_PAGE;
P0MDOUT = 0x3f;
P1MDIN = 0x7F;
P1MDOUT = 0x7F;
P2MDOUT = 0xFF;
P3MDOUT = 0xFF;
P4MDOUT = 0xFF;
P5MDOUT = 0x00;
P6MDOUT = 0xFF;
P7MDOUT = 0x00;
XBR0 = 0x0F;
XBR2 = 0x40;
SFRPAGE = SFRPAGE_SAVE;
}
void Oscillator_Init() //PLL倍频50MHZ
{
int i;
char SFRPAGE_SAVE = SFRPAGE;
SFRPAGE = CONFIG_PAGE;
OSCXCN = 0x67; //外部晶体振荡器方式,4-10M之间
for (i = 0; i < 3000; i++); // Wait 1ms for initialization
while ((OSCXCN & 0x80) == 0); //等待晶体振荡器有效标志位
PLL0CN = 0x04; // PLL参考时钟为外部振荡器
CCH0CN &= ~0x20; //禁止预取引擎
SFRPAGE = LEGACY_PAGE; //
FLSCL = 0x90; //系统时钟小于50MHZ
SFRPAGE = CONFIG_PAGE; //
CCH0CN |= 0x20; //使能预取引擎
PLL0CN |= 0x01; //PLL电源使能
PLL0DIV = 0x02; //PLL预分频寄存器 00010
PLL0FLT = 0x2F; // PLL输出频率30-60MHZ。分频后PLL参考时钟5-8MHZ
PLL0MUL = 0x09; //PLL倍频寄存器0000 1001
for (i = 0; i < 15; i++); // Wait 5us for initialization
PLL0CN |= 0x02; // PLL使能
while ((PLL0CN & 0x10) == 0); //等待PLL频率锁定标志
CLKSEL = 0x02; // 系统时钟来自PLL
OSCICN = 0x00; // 禁止内部振荡器
SFRPAGE = SFRPAGE_SAVE;
}
void Init_Device(void)
{
Reset_Sources_Init();
Port_IO_Init();
Oscillator_Init();
}
主函数:
#include "C8051F120.h"
#define uchar unsigned char
#define uint unsigned int
#define WINDOW_XADDR_START 0x0050 // Horizontal Start Address Set
#define WINDOW_XADDR_END 0x0051 // Horizontal End Address Set
#define WINDOW_YADDR_START 0x0052 // Vertical Start Address Set
#define WINDOW_YADDR_END 0x0053 // Vertical End Address Set
#define GRAM_XADDR 0x0020 // GRAM Horizontal Address Set
#define GRAM_YADDR 0x0021 // GRAM Vertical Address Set
#define GRAMWR 0x0022 // memory write
/* LCD color */
#define White 0xFFFF
#define Black 0x0000
#define Blue 0x001F
#define Blue2 0x051F
#define Red 0xF800
#define Magenta 0xF81F
#define Green 0x07E0
#define Cyan 0x7FFF
#define Yellow 0xFFE0
sbit CS=P6^3; //片选
sbit RST=P6^4; //复位
sbit RS=P6^0; //数据/命令
sbit WR=P6^1; //写
sbit RD=P6^2; //读
extern void Init_Device(void);
void delayms(uint count) //50MHZ延时1ms
{
uint i,j;
for(i=0;i<count;i++)
{
for(j=0;j<500;j++);
}
}
//===================== 写数据 ===========================//
void Write_Data(uint date)
{
uchar m,n;
CS=0;
RS=1;
m=date; //低8位
P2=m;
n=date>>8; //高8位
P3=n;
WR=0;
WR=1;
CS=1;
}
//====================== 写命令 ==========================//
void Write_Cmd(uint cmd)
{
uchar m,n;
CS=0;
RS=0;
m=cmd;
P2=m;
n=cmd>>8;
P3=n;
WR=0;
WR=1;
CS=1;
}
void Init_data (uint x,uint y)
{
Write_Cmd(x);
Write_Data(y);
}
/*GS SS 两位的组合就是四个起始坐标的位置*/
void ILI9320_Initial(void)
{
CS=1;
delayms(5);
RST=0;
delayms(5);
RST=1;
delayms(5);
Init_data(0x00E7, 0x1014);
Init_data (0x0001, 0x0100); // set SS and SM bit
Init_data (0x0002, 0x0200); // set 1 line inversion
//Init_data (0x0003, 0x1030); // set GRAM write direction and BGR=1
Init_data (0x0003,(1<<12)|(0<<4)|(0<<3)|0x08);//65K
Init_data (0x0008, 0x0202); // set the back porch and front porch
Init_data (0x0009, 0x0000); // set non-display area refresh cycle ISC[3:0]
Init_data (0x000A, 0x0000); // FMARK function
Init_data (0x000C, 0x0000); // RGB interface setting
Init_data (0x000D, 0x0000); // Frame marker Position
Init_data (0x000F, 0x0000); // RGB interface polarity
//*************Power On sequence ****************//
Init_data (0x0010, 0x0000); // SAP, BT[3:0], AP, DSTB, SLP, STB
Init_data (0x0011, 0x0007); // DC1[2:0], DC0[2:0], VC[2:0]
Init_data (0x0012, 0x0000); // VREG1OUT voltage
Init_data (0x0013, 0x0000); // VDV[4:0] for VCOM amplitude
delayms(200); // Dis-charge capacitor power voltage
Init_data (0x0010, 0x1690); // SAP, BT[3:0], AP, DSTB, SLP, STB
Init_data (0x0011, 0x0227); // DC1[2:0], DC0[2:0], VC[2:0]
delayms(50); // Delay 50ms
Init_data (0x0012, 0x000C); // Internal reference voltage= Vci;
delayms(50); // Delay 50ms
Init_data (0x0013, 0x0800); // Set VDV[4:0] for VCOM amplitude
Init_data (0x0029, 0x0011); // Set VCM[5:0] for VCOMH
Init_data (0x002B, 0x000B); // Set Frame Rate
delayms(50); // Delay 50ms
Init_data (0x0020, 0x0000); // GRAM horizontal Address
Init_data (0x0021, 0x0000); // GRAM Vertical Address
// ----------- Adjust the Gamma Curve ----------//
Init_data (0x0030, 0x0000);
Init_data (0x0031, 0x0106);
Init_data (0x0032, 0x0000);
Init_data (0x0035, 0x0204);
Init_data (0x0036, 0x160A);
Init_data (0x0037, 0x0707);
Init_data (0x0038, 0x0106);
Init_data (0x0039, 0x0707);
Init_data (0x003C, 0x0402);
Init_data (0x003D, 0x0C0F);
//------------------ Set GRAM area ---------------//
Init_data (0x0050, 0x0000); // Horizontal GRAM Start Address
Init_data (0x0051, 0x00EF); // Horizontal GRAM End Address
Init_data (0x0052, 0x0000); // Vertical GRAM Start Address
Init_data (0x0053, 0x013F); // Vertical GRAM Start Address
Init_data (0x0060, 0xa700); // Gate Scan Line
Init_data (0x0061, 0x0001); // NDL,VLE, REV
Init_data (0x006A, 0x0000); // set scrolling line
//-------------- Partial Display Control ---------//
Init_data (0x0080, 0x0000);
Init_data (0x0081, 0x0000);
Init_data (0x0082, 0x0000);
Init_data (0x0083, 0x0000);
Init_data (0x0084, 0x0000);
Init_data (0x0085, 0x0000);
//-------------- Panel Control -------------------//
Init_data (0x0090, 0x0010);
Init_data (0x0092, 0x0600);
Init_data (0x0007, 0x0133); // 262K color and display ON
}
/*===========================================================*/
/*************************************************************
函数名称:LCD_DefineDispWindow
功 能:定义显示窗体
参 数:x0: 窗体中X坐标中较小者
x1: 窗体中X坐标中较大者
y0: 窗体中Y坐标中较小者
y1: 窗体中Y坐标中较大者
返 回 值:无
*************************************************************/
static void LCD_SetPos(uint x0,uint x1,uint y0,uint y1)
{
Init_data(WINDOW_XADDR_START,x0);
Init_data(WINDOW_XADDR_END,x1);
Init_data(WINDOW_YADDR_START,y0);
Init_data(WINDOW_YADDR_END,y1);
Init_data(GRAM_XADDR,x0);
Init_data(GRAM_YADDR,y0);
Write_Cmd (0x0022);//LCD_WriteCMD(GRAMWR);
}
void ClearScreen(uint bColor)
{
uint i,j;
LCD_SetPos(0,240,0,320);//320x240
for (i=0;i<320;i++)
{
for (j=0;j<240;j++)
Write_Data(bColor);
}
}
void main()
{
Init_Device();
ILI9320_Initial();
ClearScreen(Green);
while(1)
{
}
}
一周热门 更多>