新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > AVR驅(qū)動3.2英寸tft LCD(ssd1289)

AVR驅(qū)動3.2英寸tft LCD(ssd1289)

作者: 時間:2016-11-20 來源:網(wǎng)絡(luò) 收藏
管腳連接
D0PA0D5PA5D10PD2D15PD7
D1PA1D6PA6D11PD3CSPB0
D2PA2D7PA7D12PD4RSPB1
D3PA3D8PD0D13PD5WRPB2
D4PA4D9PD1D14PD6RDPB3






RESETPB4

#include <LCD.h>
#include
#include
#define Setbit(val,bitn) (val|=(1<<(bitn)))
#define Clcbit(val,bitn) (val&=~(1<<(bitn)))

void delay_Nms(int n)
{
unsigned int i;
for(i=1;i<(300*n);i++);
}

void LCD_WR_DATA(char VH,char VL)
{
Setbit(PORTB,1);//RS=1 PB1
Setbit(PORTB,3);//RD=1 PB3
Setbit(PORTB,2);//WR=1 PB2
PORTD=VH;
PORTA=VL;
Clcbit(PORTB,0);//CS=0 PB0
Clcbit(PORTB,2);//WR=0 PB2
asm("nop");
Setbit(PORTB,0);//CS=1 PB0
Setbit(PORTB,2);//WR=1 PB2
}

void LCD_WR_ADDR(char addr)
{
Clcbit(PORTB,1);//RS=0 PB1
Setbit(PORTB,3);//RD=1 PB3
Setbit(PORTB,2);//WR=1 PB2
PORTD=0;
PORTA=addr;
Clcbit(PORTB,0);//CS=0 PB0
Clcbit(PORTB,2);//WR=0 PB2
asm("nop");
Setbit(PORTB,0);//CS=1 PB0
Setbit(PORTB,2);//WR=1 PB2
}

void LCD_WR_CMD(char addr,char cmdH,char cmdL)
{
LCD_WR_ADDR(addr);
LCD_WR_DATA(cmdH,cmdL);
}

void LCD_SetCursor(short Xpos,short Ypos)
{
LCD_WR_CMD(0x4f,(Xpos>>8),Xpos);
LCD_WR_CMD(0x4e,(Ypos>>8),Ypos);
}

void LCD_DrawPoint(short Xpos,short Ypos,short POINT_COLOR)
{
LCD_SetCursor(Xpos,Ypos);
LCD_WR_CMD(0x22,(POINT_COLOR>>8),POINT_COLOR);
}



void LCD_Init(void)
{
LCD_WR_CMD(0x00,0x00,0x01);delay_Nms(10);
LCD_WR_CMD(0x03,0xA8,0xA4);delay_Nms(5);
LCD_WR_CMD(0x0C,0x00,0x00);delay_Nms(5);
LCD_WR_CMD(0x0D,0x08,0x0C);delay_Nms(5);
LCD_WR_CMD(0x0E,0x2B,0x00);delay_Nms(5);
LCD_WR_CMD(0x1E,0x00,0xB0);delay_Nms(5);
LCD_WR_CMD(0x01,0x2B,0x3F);delay_Nms(5);
LCD_WR_CMD(0x02,0x06,0x00);delay_Nms(5);
LCD_WR_CMD(0x10,0x00,0x00);delay_Nms(30);
LCD_WR_CMD(0x11,0x60,0x70);delay_Nms(5);
LCD_WR_CMD(0x05,0x00,0x00);delay_Nms(5);
LCD_WR_CMD(0x06,0x00,0x00);delay_Nms(5);
LCD_WR_CMD(0x16,0xEF,0x1C);delay_Nms(5);//
LCD_WR_CMD(0x17,0x00,0x03);delay_Nms(5);
LCD_WR_CMD(0x07,0x01,0x33);delay_Nms(5);
LCD_WR_CMD(0x0B,0x00,0x00);delay_Nms(5);
LCD_WR_CMD(0x0F,0x00,0x00);delay_Nms(5);
LCD_WR_CMD(0x41,0x00,0x00);delay_Nms(5);
LCD_WR_CMD(0x42,0x00,0x00);delay_Nms(5);
LCD_WR_CMD(0x48,0x00,0x00);delay_Nms(5);
LCD_WR_CMD(0x49,0x01,0x3F);delay_Nms(5);
LCD_WR_CMD(0x4A,0x00,0x00);delay_Nms(5);
LCD_WR_CMD(0x4B,0x00,0x00);delay_Nms(5);
LCD_WR_CMD(0x44,0xEF,0x00);delay_Nms(5);
LCD_WR_CMD(0x45,0x00,0x00);delay_Nms(5);
LCD_WR_CMD(0x46,0x01,0x3F);delay_Nms(5);
LCD_WR_CMD(0x30,0x07,0x07);delay_Nms(5);
LCD_WR_CMD(0x31,0x02,0x04);delay_Nms(5);
LCD_WR_CMD(0x32,0x02,0x04);delay_Nms(5);
LCD_WR_CMD(0x33,0x05,0x02);delay_Nms(5);
LCD_WR_CMD(0x34,0x05,0x07);delay_Nms(5);
LCD_WR_CMD(0x35,0x02,0x04);delay_Nms(5);
LCD_WR_CMD(0x36,0x02,0x04);delay_Nms(5);
LCD_WR_CMD(0x37,0x05,0x02);delay_Nms(5);
LCD_WR_CMD(0x3A,0x03,0x02);delay_Nms(5);
LCD_WR_CMD(0x3B,0x03,0x02);delay_Nms(5);
LCD_WR_CMD(0x23,0x00,0x00);delay_Nms(5);
LCD_WR_CMD(0x24,0x00,0x00);delay_Nms(5);
LCD_WR_CMD(0x25,0x80,0x00);delay_Nms(5);
LCD_WR_CMD(0x4F,0x00,0x00);delay_Nms(5);
LCD_WR_CMD(0x4E,0x00,0x00);delay_Nms(5);
}

void DispOneColor(unsigned int Color)
{
unsigned int i,j;
LCD_SetCursor(0,0);
LCD_WR_ADDR(0x22);
Setbit(PORTB,1);//RS=1 PB1
PORTD=Color>>8;
PORTA=Color;
Clcbit(PORTB,0);//CS=0 PB0
for(j=0;j<320;j++)
{
for(i=0;i<240;i++)
{
Clcbit(PORTB,2);//WR=0 PB2
asm("nop");
Setbit(PORTB,2);//WR=1 PB2
}
}
Setbit(PORTB,0);//CS=1 PB0
}

void DrawLine(short x0,short y0,short x1,short y1,short color)
{
short k;
short dx;
short dy;
short dx2;
short dy2;
short e;
short x;
short y;
if(x1 {
k=x0;
x0=x1;
x1=k;
k=y0;
y0=y1;
y1=k;
}

dx=x1-x0;
dy=y1-y0;
dx2=dx<<1;
dy2=dy<<1;
e=-dx;
x=x0;
y=y0;

if(y1>=y0)
{
for(x=x0;x {
LCD_DrawPoint(x,y,color);
e=e+dy2;
if(e>0)
{
y++;
e=e-dx2;
}
}
}

else
{
e=dx;
for (x=x0;x {
LCD_DrawPoint(x, y,color);
e=e+dy2;
if (e<0)
{
y--;
e=e+dx2;
}
}
}
}

void main(void)
{
DDRA=0xff;
//DDRC=0xff;
DDRB=0xff;
DDRD=0xff;
//PORTD=0x00;
//PORTC=0x00;
Clcbit(PORTB,4);//RES=0
asm("nop");
Setbit(PORTB,4);//RES=1
LCD_Init();
DispOneColor(0x0000);
//LCD_DrawPoint(180,150,0x0000);////
DrawLine(180,150,60,200,0xFFFF);
while(1);
}


關(guān)鍵詞: AVR3.2英寸tftLCDssd128

評論


技術(shù)專區(qū)

關(guān)閉