历史上的今天
今天是:2024年11月08日(星期五)
2021年11月08日 | Mini2440裸机液晶屏TD35驱动
2021-11-08 来源:eefocus
我把地址定义都加到.h文件中,使用时只需包含lcd_td35.h即可。
能简单实现画点,画线,画矩形,显示图片,显示字符和字符串,显示数字功能。
// lcd_td35.h
// 2015.12.16
#ifndef __LCD_TD35_H__
#define __LCD_TD35_H__
#define U32 unsigned int
#define U16 unsigned short
#define S32 int
#define S16 short int
#define U8 unsigned char
#define S8 char
#define BYTE char
#define WORD short
#define DWORD int
#define UINT U32
#define LPSTR U8 *
#define TRUE 1
#define FALSE 0
#define OK 1
#define FAIL 0
// S3C2440地址宏定义
//=====================================================================
// I/O PORT
#define rGPACON (*(volatile unsigned *)0x56000000) //Port A control
#define rGPADAT (*(volatile unsigned *)0x56000004) //Port A data
#define rGPBCON (*(volatile unsigned *)0x56000010) //Port B control
#define rGPBDAT (*(volatile unsigned *)0x56000014) //Port B data
#define rGPBUP (*(volatile unsigned *)0x56000018) //Pull-up control B
#define rGPCCON (*(volatile unsigned *)0x56000020) //Port C control
#define rGPCDAT (*(volatile unsigned *)0x56000024) //Port C data
#define rGPCUP (*(volatile unsigned *)0x56000028) //Pull-up control C
#define rGPDCON (*(volatile unsigned *)0x56000030) //Port D control
#define rGPDDAT (*(volatile unsigned *)0x56000034) //Port D data
#define rGPDUP (*(volatile unsigned *)0x56000038) //Pull-up control D
#define rGPECON (*(volatile unsigned *)0x56000040) //Port E control
#define rGPEDAT (*(volatile unsigned *)0x56000044) //Port E data
#define rGPEUP (*(volatile unsigned *)0x56000048) //Pull-up control E
#define rGPFCON (*(volatile unsigned *)0x56000050) //Port F control
#define rGPFDAT (*(volatile unsigned *)0x56000054) //Port F data
#define rGPFUP (*(volatile unsigned *)0x56000058) //Pull-up control F
#define rGPGCON (*(volatile unsigned *)0x56000060) //Port G control
#define rGPGDAT (*(volatile unsigned *)0x56000064) //Port G data
#define rGPGUP (*(volatile unsigned *)0x56000068) //Pull-up control G
#define rGPHCON (*(volatile unsigned *)0x56000070) //Port H control
#define rGPHDAT (*(volatile unsigned *)0x56000074) //Port H data
#define rGPHUP (*(volatile unsigned *)0x56000078) //Pull-up control H
#define rGPJCON (*(volatile unsigned *)0x560000d0) //Port J control
#define rGPJDAT (*(volatile unsigned *)0x560000d4) //Port J data
#define rGPJUP (*(volatile unsigned *)0x560000d8) //Pull-up control J
// PWM TIMER 1
#define rTCFG0 (*(volatile unsigned *)0x51000000) //Timer 0 configuration
#define rTCFG1 (*(volatile unsigned *)0x51000004) //Timer 1 configuration
#define rTCON (*(volatile unsigned *)0x51000008) //Timer control
#define rTCNTB1 (*(volatile unsigned *)0x51000018) //Timer count buffer 1
#define rTCMPB1 (*(volatile unsigned *)0x5100001c) //Timer compare buffer 1
#define rTCNTO1 (*(volatile unsigned *)0x51000020) //Timer count observation 1
// TIMER 3
#define rTCNTB3 (*(volatile unsigned *)0x51000030) //Timer count buffer 3
#define rTCMPB3 (*(volatile unsigned *)0x51000034) //Timer compare buffer 3
#define rTCNTO3 (*(volatile unsigned *)0x51000038) //Timer count observation 3
// LCD CONTROLLER
#define rLCDCON1 (*(volatile unsigned *)0x4d000000) //LCD control 1
#define rLCDCON2 (*(volatile unsigned *)0x4d000004) //LCD control 2
#define rLCDCON3 (*(volatile unsigned *)0x4d000008) //LCD control 3
#define rLCDCON4 (*(volatile unsigned *)0x4d00000c) //LCD control 4
#define rLCDCON5 (*(volatile unsigned *)0x4d000010) //LCD control 5
#define rLCDSADDR1 (*(volatile unsigned *)0x4d000014) //STN/TFT Frame buffer start address 1
#define rLCDSADDR2 (*(volatile unsigned *)0x4d000018) //STN/TFT Frame buffer start address 2
#define rLCDSADDR3 (*(volatile unsigned *)0x4d00001c) //STN/TFT Virtual screen address set
#define rREDLUT (*(volatile unsigned *)0x4d000020) //STN Red lookup table
#define rGREENLUT (*(volatile unsigned *)0x4d000024) //STN Green lookup table
#define rBLUELUT (*(volatile unsigned *)0x4d000028) //STN Blue lookup table
#define rDITHMODE (*(volatile unsigned *)0x4d00004c) //STN Dithering mode
#define rTPAL (*(volatile unsigned *)0x4d000050) //TFT Temporary palette
#define rLCDINTPND (*(volatile unsigned *)0x4d000054) //LCD Interrupt pending
#define rLCDSRCPND (*(volatile unsigned *)0x4d000058) //LCD Interrupt source
#define rLCDINTMSK (*(volatile unsigned *)0x4d00005c) //LCD Interrupt mask
#define rTCONSEL (*(volatile unsigned *)0x4d000060) //LPC3600 Control --- edited by junon
#define PALETTE 0x4d000400 //Palette start address
//=================================================================================
// LCD_TD35
#define LCD_TD35
#define LCD_WIDTH 240
#define LCD_HEIGHT 320
#define LCD_PIXCLOCK 4
#define LCD_RIGHT_MARGIN 100
#define LCD_LEFT_MARGIN 0
#define LCD_HSYNC_LEN 4
#define LCD_UPPER_MARGIN 0
#define LCD_LOWER_MARGIN 0
#define LCD_VSYNC_LEN 9
// 延时Ms
void Lcd_Delay_Ms(int time);
// LCD背光
void LcdBkLtSet(U32 HiRatio);
// 初始化用于LCD的引脚
void Lcd_Port_Init(void);
// MODE_16BIT_240320
void Lcd_Init(void);
/*
* 设置是否输出LCD电源开关信号LCD_PWREN
* 输入参数:
* invpwren: 0 - LCD_PWREN有效时为正常极性
* 1 - LCD_PWREN有效时为反转极性
* pwren: 0 - LCD_PWREN输出有效
* 1 - LCD_PWREN输出无效
*/
void Lcd_PowerEnable(int invpwren, int pwren);
// LCD控制器是否输出信号
void Lcd_EnvidOnOff(int onoff);
// 完成所有初始化
void Lcd_TD35_Init(void);
// 画像素点
void PutPixel(U32 x,U32 y,U16 c);
// 用单颜色清屏(5:6:5 RGB)
void Lcd_ClearScr(U16 c);
// 画线
void Draw_Line(int x1,int y1,int x2,int y2, U16 color);
// 画矩形
void Draw_Rectangle(int x1,int y1,int x2,int y2, U16 color);
// 显示图片(240x320)
void Draw_Bmp(int x0,int y0,int h,int l,const unsigned char *bmp);
// 显示ASCII 字符
// x,y:起始坐标
// color:颜色
// size:字体大小 12/16/24
// mode:当前背景(1)自定义白色背景(0)
// ch:要显示的字符:" "--->"~"
void Draw_Char(U16 x, U16 y, U16 color, U8 size, U8 mode, U8 ch);
// 显示字符串
// x,y:起点坐标
// width,height:区域大小
// color:颜色
// size:字体大小 12/16/24
// mode:当前背景(1)自定义白色背景(0)
// *p:字符串起始地址
void Draw_String(U16 x, U16 y, U16 width, U16 height, U16 color, U8 size, U8 mode, U8 p[]);
// m^n次方
U32 Lcd_Pow(U8 m,U8 n);
// 显示数字
// x,y:起点坐标
// color:颜色
// size:字体大小 12/16/24
// mode:当前背景(1)自定义白色背景(0)
// num:
// len:显示位数
// 超过前面是否补0,是(1)
void Draw_Num(U16 x,U16 y,U16 color,U8 size,U8 mode,U32 num,U8 len,U8 show0);
// 测试用
void Lcd_TD35_Test(void);
#endif
// lcd_td35.c
// 2015.12.16
#include "lcd_td35.h"
#include "lcd_font.h"
#include "scene1_240x320.h" // 包含图片数据
#define GPB1_TO_OUT() (rGPBUP &= 0xfffd, rGPBCON &= 0xfffffff3, rGPBCON |= 0x00000004)
#define GPB1_TO_1() (rGPBDAT |= 0x0002)
#define GPB1_TO_0() (rGPBDAT &= 0xfffd)
#define LCD_XSIZE LCD_WIDTH // 240
#define LCD_YSIZE LCD_HEIGHT // 320
#define SCR_XSIZE LCD_WIDTH
#define SCR_YSIZE LCD_HEIGHT
volatile static unsigned short LCD_BUFFER[SCR_YSIZE][SCR_XSIZE];
void Lcd_Delay_Ms(int time)
{
// PCLK=50MHz
//U32 val = (PCLK>>3)/1000-1;
U32 val = (50000000>>3)/1000-1; // 6250-1=6249
rTCFG0 &= ~(0xff<<8);
rTCFG0 |= 3<<8; //prescaler = 3+1
rTCFG1 &= ~(0xf<<12);
rTCFG1 |= 0<<12; //mux = 1/2
rTCNTB3 = val; //1000Hz freq=50M/4/2/6249
rTCMPB3 = val>>1; // 50%
rTCON &= ~(0xf<<16);
rTCON |= 0xb<<16; //interval, inv-off, update TCNTB3&TCMPB3, start timer 3
rTCON &= ~(2<<16); //clear manual update bit
while(time--) {
while(rTCNTO3>=val>>1);
while(rTCNTO3 }; } void LcdBkLtSet(U32 HiRatio) { #define FREQ_PWM1 1000 if(!HiRatio) { rGPBCON = rGPBCON & (~(3<<2)) | (1<<2); rGPBDAT &= ~(1<<1); return; } rGPBCON = rGPBCON & (~(3<<2)) | (2<<2); if( HiRatio > 100 ) HiRatio = 100 ;
史海拾趣
|
我的PFC电路用的是LT1248芯片,输出500W,后面是半桥电路输出36V14A,半桥都调的没什么问题了,就是带载后PFC这边有响声,载越大响声越大,PFC电感用铁硅铝环绕了40圈,感量在700多MH,电感前电容680V225,电路就是照资料上搭的,大家看附件,多多 ...… 查看全部问答> |
|
如题,最近想试着开发一款基于WIFI下应用的小设备,但是却找不到具有WIFI功能的2410或2440的开发板,其它的ARM11的有,但不适用,只要2410和2440的,如有知道的朋友麻烦回复一下,那里有卖,最好是珠三角的城市的公司… 查看全部问答> |
|
小女子做的课题,初次接触FPGA的设计 用的是Quartus2的平台运行,综合编译已通过,但是时序仿真出了错:说是目标芯片不适用。 求各位大侠能指点指点,给出合适波形发生器的芯片型号,先在此谢过 下为VHDL开头部分程序: library ieee; use ie ...… 查看全部问答> |
|
我想实习通过串口调试助手向单片机发送一个字符,单片机接收后发回pc机,通讯线路完好,能实习单片机向pc机发送,但就是不能进入接收中断,请高手帮帮忙~谢谢 p3.4为发送,p3.5为接收,通过max3221转化。 代码: &n ...… 查看全部问答> |
|
由于项目工期缩短,寻找合作伙伴,大概情况是这样的:板子已经做好了,可以正常的启动,linux也可以运行,并且我已经做了一些测试用的驱动等,现在我想找人帮我做网络接口部分的程序,要求是:能自动拨号上网(ADSL,固定IP),掉线自 ...… 查看全部问答> |
|
本帖最后由 paulhyde 于 2014-9-15 08:58 编辑 我编了个舵机控制程序,想让舵机转到90度,延时一会,再转到180度,但无论我如何改jd,舵机总是转到最右边。我又在网上下了一个程序,也是一样的,舵机直接转到最右边,我快奔溃了。程序使用keil遍的 ...… 查看全部问答> |




