您的位置 首页 新能源

AVR驱动3.2英寸tft LCD(ssd1289)

管脚连接D0PA0D5PA5D10PD2D15PD7D1PA1D6PA6D11PD3CSPB0D2PA2D7PA7D12PD4RSPB1D3PA3D8PD0D13PD5WRPB2D4PA4D9PD1D

管脚衔接

D0 PA0 D5 PA5 D10 PD2 D15 PD7
D1 PA1 D6 PA6 D11 PD3 CS PB0
D2 PA2 D7 PA7 D12 PD4 RS PB1
D3 PA3 D8 PD0 D13 PD5 WR PB2
D4 PA4 D9 PD1 D14 PD6 RD PB3
RESET PB4

#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,0×0000);////
DrawLine(180,150,60,200,0xFFFF);
while(1);
}

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/qiche/xinnengyuan/264717.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部