谁有AVR单片机C语言程序关于lcd显示的程序谢谢啦!!!

谁有AVR单片机C语言程序关于lcd显示的程序谢谢啦!!!,第1张

//KGM913A2 DEMO 8-BIT 666MODE 此程序为本公司480*320点阵18-BIT彩色TFT液晶屏的程序

//2010-12-23 BY ERIC

//IC: ILI9481B

//---------------------------------------------------------------------------

#include <avr/io.h>

//#define F_CPU 8000000UL

#define F_CPU 12000000UL

#include <util/delay.h>

#ifndef Delayms

#define Delayms _delay_ms

#endif

#include <avr/pgmspace.h>

#include <stdio.h>

#include <string.h>

#include "font.h"

#include "AT45DB161D.h"

typedef uint16_t UINT, uint

typedef uint8_t UCHAR, uchar

#define LCD_RESET PB0

#define LCD_RS PB1

#define LCD_WR PB2

#define KB_NEXT PB3

void W_COM(UCHAR dat)

void W_DATA(UCHAR dat)

void W_RGB(UCHAR dat1,UCHAR dat2,UCHAR dat3)

void BlockWrite(UINT sx, UINT ex, UINT sy, UINT ey)

void ILI9481B_Initial(void)

void Clear(void)

void Full(void)

void Red(void)

void Green(void)

void Blue(void)

void DotsMatrix(UINT sx, UINT ex, UINT sy, UINT ey)

//void Crosstalk_A(void)

//void Crosstalk_B(void)

//void Crosstalk_C(void)

//void Flicker(void)

//void Flicker_SCT(void)

//void GAMMA(void)

void Show(UINT sx, UINT ex, UINT sy, UINT ey, UCHAR dat1,UCHAR dat2,UCHAR dat3)

//#define HexToStr(num,string) sprintf(string, "0x%02X", num)

//---------------------------------------------------------------------------

//char str[10]

int main(void)

{

UCHAR i

//DDRA = 0xFF

DDRB = 0xFF

DDRD = 0xFF

_NOP()

_NOP()

//PORTA = 0xFF

PORTB = 0xFF

PORTD = 0xFF

Flash_SPI_Init()

Delayms(10)

ReadFlashStatus()

SetPictureSize((uint32_t)480*320)

DDRB &= ~(1<<KB_NEXT)

Delayms(30)

PORTB &= ~(1<<LCD_RESET)

Delayms(50)

PORTB |= (1<<LCD_RESET)

Delayms(100)

ILI9481B_Initial()

for()

{

Full()

while( PINB &(1 <<KB_NEXT) )

Clear()

while( PINB &(1 <<KB_NEXT) )

Red()

while( PINB &(1 <<KB_NEXT) )

Green()

while( PINB &(1 <<KB_NEXT) )

Blue()

while( PINB &(1 <<KB_NEXT) )

DotsMatrix(0, 319, 0, 479)

while( PINB &(1 <<KB_NEXT) )

/* Crosstalk_A()

while( PINB &(1 <<KB_NEXT) )

Crosstalk_B()

Delayms(500)

while( PINB &(1 <<KB_NEXT) )

Crosstalk_C()

Delayms(500)

while( PINB &(1 <<KB_NEXT) )

Flicker()

Delayms(500)

while( PINB &(1 <<KB_NEXT) )

Flicker_SCT()

Delayms(500)

while( PINB &(1 <<KB_NEXT) )

GAMMA()

//Delayms(500)

//while( PINB &(1 <<KB_NEXT) )

*/

for ( i = 0i <4i++ )

{

BlockWrite(0, 319, 0, 479)

ReadFlashUchar3(i, W_RGB)

while( PINB &(1 <<KB_NEXT) )

}

}

}

//---------------------------------------------------------------------------

void W_COM(UCHAR dat)

{

PORTB &= ~(1<<LCD_RS)

PORTD = dat

PORTB &= ~(1<<LCD_WR)

PORTB |= (1<<LCD_WR)

//PORTA = dat

//PORTB &= ~(1<<LCD_WR)

//PORTB |= (1<<LCD_WR)

}

//---------------------------------------------------------------------------

void W_DATA(UCHAR dat)

{

PORTB |= (1<<LCD_RS)

PORTD = dat

PORTB &= ~(1<<LCD_WR)

PORTB |= (1<<LCD_WR)

//PORTA = dat

//PORTB &= ~(1<<LCD_WR)

//PORTB |= (1<<LCD_WR)

}

//---------------------------------------------------------------------------

void W_RGB(uchar dat1,uchar dat2,uchar dat3)

{

PORTB |= (1<<LCD_RS)

PORTD = dat1

PORTB &= ~(1<<LCD_WR)

PORTB |= (1<<LCD_WR)

PORTD = dat2

PORTB &= ~(1<<LCD_WR)

PORTB |= (1<<LCD_WR)

PORTD = dat3

PORTB &= ~(1<<LCD_WR)

PORTB |= (1<<LCD_WR)

}

//---------------------------------------------------------------------------

void BlockWrite(UINT sx, UINT ex, UINT sy, UINT ey)

{

W_COM(0x2A)

W_DATA(sx>>8)

W_DATA(sx)

W_DATA(ex>>8)

W_DATA(ex)

W_COM(0x2B)

W_DATA(sy>>8)

W_DATA(sy)

W_DATA(ey>>8)

W_DATA(ey)

W_COM(0x2c)

}

//---------------------------------------------------------------------------

void Clear(void)

{

Show(0, 319, 0, 479, 0X00,0X00,0X00)

}

//---------------------------------------------------------------------------

void Full(void)

{

Show(0, 319, 0, 479, 0xFF,0XFF,0XFF)

}

//---------------------------------------------------------------------------

void Red(void)

{

Show(0, 319, 0, 479, 0xFF,0X00,0X00)

}

//---------------------------------------------------------------------------

void Green(void)

{

Show(0, 319, 0, 479, 0x00,0XFF,0X00)

}

//---------------------------------------------------------------------------

void Blue(void)

{

Show(0, 319, 0, 479, 0x00,0X00,0XFF)

}

//---------------------------------------------------------------------------

void DotsMatrix(UINT sx, UINT ex, UINT sy, UINT ey)

{

UINT x, y, i, j

BlockWrite(sx, ex, sy, ey)

x = ex - sx

y = ey - sy

for ( i = 0i <= yi++ )

for ( j = 0j <= xj++ )

{

if ( (i + j) &1 )

{

W_RGB(0xFF,0XFF,0XFF)

}

else

{

W_RGB(0x00,0X00,0X00)

}

}

}

//---------------------------------------------------------------------------

/*void Crosstalk_A(void)

{

Show(0, 239, 0, 399, 0XEF5D)

Show(79, 159, 0, 140, 0x0000)

Show(79, 159, 262, 400, 0x0000)

}

//---------------------------------------------------------------------------

void Crosstalk_B(void)

{

Show(79, 159, 0, 140, 0XEF5D)

Show(79, 159, 262, 400, 0XEF5D)

}

//---------------------------------------------------------------------------

void Crosstalk_C(void)

{

Show(0, 79, 133, 265, 0)

Show(159, 239, 133, 265, 0)

}

//---------------------------------------------------------------------------

void Flicker(void)

{

UINT i, j

BlockWrite(0, 239, 0, 399)

for ( i = 0i <= 399i++ )

{

if(i &1)

for ( j = 0j <= 239j++ )

W_RGB(0xFFFF)

else

for ( j = 0j <= 239j++ )

W_RGB(0x0000)

}

}

//---------------------------------------------------------------------------

void Flicker_SCT(void)

{

UINT i, j

BlockWrite(0, 239, 0, 399)

for ( i = 0i <= 399i++ )

for ( j = 0j <= 239j++ )

{

if(i%3)

W_RGB(0X7BEF)

else

W_RGB(0)

}

}

//---------------------------------------------------------------------------

void GAMMA(void)

{

Show(0, 239, 0, 399, 0x0000)

ShowString(200, 380, "000")Delayms(500)while( PINB &(1 <<KB_NEXT) )

Show(0x0000, 0x00EF, 0x0000, 0x018F, 0X1082)

ShowString(200, 380, "016")Delayms(500)while( PINB &(1 <<KB_NEXT) )

Show(0x0000, 0x00EF, 0x0000, 0x018F, 0X2104)

ShowString(200, 380, "032")Delayms(500)while( PINB &(1 <<KB_NEXT) )

Show(0x0000, 0x00EF, 0x0000, 0x018F, 0X3186)

ShowString(200, 380, "048")Delayms(500)while( PINB &(1 <<KB_NEXT) )

Show(0x0000, 0x00EF, 0x0000, 0x018F, 0X4208)

ShowString(200, 380, "064")Delayms(500)while( PINB &(1 <<KB_NEXT) )

Show(0x0000, 0x00EF, 0x0000, 0x018F, 0X528A)

ShowString(200, 380, "080")Delayms(500)while( PINB &(1 <<KB_NEXT) )

Show(0x0000, 0x00EF, 0x0000, 0x018F, 0X630C)

ShowString(200, 380, "096")Delayms(500)while( PINB &(1 <<KB_NEXT) )

Show(0x0000, 0x00EF, 0x0000, 0x018F, 0X738E)

ShowString(200, 380, "112")Delayms(500)while( PINB &(1 <<KB_NEXT) )

Show(0x0000, 0x00EF, 0x0000, 0x018F, 0X8410)

ShowString(200, 380, "128")Delayms(500)while( PINB &(1 <<KB_NEXT) )

Show(0x0000, 0x00EF, 0x0000, 0x018F, 0X9492)

ShowString(200, 380, "144")Delayms(500)while( PINB &(1 <<KB_NEXT) )

Show(0x0000, 0x00EF, 0x0000, 0x018F, 0XA514)

ShowString(200, 380, "160")Delayms(500)while( PINB &(1 <<KB_NEXT) )

Show(0x0000, 0x00EF, 0x0000, 0x018F, 0XB596)

ShowString(200, 380, "176")Delayms(500)while( PINB &(1 <<KB_NEXT) )

Show(0x0000, 0x00EF, 0x0000, 0x018F, 0XC618)

ShowString(200, 380, "192")Delayms(500)while( PINB &(1 <<KB_NEXT) )

Show(0x0000, 0x00EF, 0x0000, 0x018F, 0XD69A)

ShowString(200, 380, "208")Delayms(500)while( PINB &(1 <<KB_NEXT) )

Show(0x0000, 0x00EF, 0x0000, 0x018F, 0XE71C)

ShowString(200, 380, "224")Delayms(500)while( PINB &(1 <<KB_NEXT) )

Show(0x0000, 0x00EF, 0x0000, 0x018F, 0XF79E)

ShowString(200, 380, "240")Delayms(500)while( PINB &(1 <<KB_NEXT) )

Show(0x0000, 0x00EF, 0x0000, 0x018F, 0XFFFF)

ShowString(200, 380, "255")Delayms(500)while( PINB &(1 <<KB_NEXT) )

}

//---------------------------------------------------------------------------*/

void Show(UINT sx, UINT ex, UINT sy, UINT ey, UCHAR dat1, UCHAR dat2, UCHAR dat3)

{

UINT x, y, i, j

BlockWrite(sx, ex, sy, ey)

x = ex - sx

y = ey - sy

for ( i = 0i <= yi++ )

for ( j = 0j <= xj++ )

{

W_RGB(dat1,dat2,dat3)

}

}

//---------------------------------------------------------------------------

void ILI9481B_Initial(void)

{

W_COM(0X20)

W_COM(0X11)

Delayms(20)

W_COM(0XD0)//

W_DATA(0X07) // VC[2:0]

W_DATA(0X41) // PON,BT[2:0]

W_DATA(0X16) // VCIRE,VRH[3:0]=1A

W_COM(0XD1)

W_DATA(0X00) // SELVCM

W_DATA(0X2C) // VCM[5:0]0X2C30

W_DATA(0X13) // VDV[4:0]0X111313crosstalk较重

W_COM(0XD2)

W_DATA(0X01) // AP0[2:0]0X03CROSSTALK好点

W_DATA(0X11) // DC10[2:0],DC00[2:0]

W_COM(0XC0)//****** *******

W_DATA(0X10) // REV &SM &GS

W_DATA(0X3B) // NL[5:0]

W_DATA(0X00) // SCN[6:0]

W_DATA(0X02) // NDL , PTS[2:0]

W_DATA(0X11) // PTG , ISC[3:0]

W_COM(0XC1)

W_DATA(0X10)

W_DATA(0X10)//LINE TIMMING增大改善CROSSTALK>14会闪烁

W_DATA(0X88)

W_COM(0XC5) // Frame rate

W_DATA(0X03)

W_COM(0XC8) // Gamma Setting

W_DATA(0X00) // KP1[2:0],KP0[2:0]

W_DATA(0X66) // KP3[2:0],KP2[2:0]

W_DATA(0X15) // KP5[2:0],KP4[2:0]

W_DATA(0X24) // RP1[2:0],RP0[2:0]

W_DATA(0X00) // VRP0[3:0]

W_DATA(0X08) // VRP1[4:0]

W_DATA(0X26) // KN1[2:0],KN0[2:0]

W_DATA(0X11) // KN3[2:0],KN2[2:0]

W_DATA(0X77) // KN5[2:0],KN4[2:0]

W_DATA(0X42) // RN1[2:0],RN0[2:0]

W_DATA(0X08) // VRN0[3:0]

W_DATA(0X00) // VRN1[4:0]

W_COM(0XE4)

W_DATA(0XA0)

W_COM(0XF0)

W_DATA(0X01)

W_COM(0XF3)

W_DATA(0X30)

W_DATA(0X0A)

W_COM(0XF7)

W_DATA(0X80)

W_COM(0X36) // Set_address_mode

W_DATA(0X0A) // Bit3: RGB/BGR

Delayms(120)

W_COM(0X3A)

W_DATA(0X66)

W_COM(0X29)

}

鼠标双击“Boundary  Scan”

单击鼠标右键,选择第三项“Initialize  Chain”

双击芯片模型上的“SPI”,加入要写入的目标代码。

加入目标代码后,d出的对话选择AT45DB161D(芯片类型)

可行,flash用AT45DB161D芯片,SPI串行通讯的,详细程序请用百度搜索如下关键字:

FAT 字库烧写

或者网址(需注册):http://www.openmcu.com/redirect.php?tid=1066&goto=lastpost


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/11155494.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-14
下一篇 2023-05-14

发表评论

登录后才能评论

评论列表(0条)

保存