有大神帮下忙吗,下面这些程序是根据51自己改成meg16的程序,弄了2天多了,一点头绪都没有
lcd.c文件
/**********************************************************
* *
* 彩屏驱动程序 *
* *
**********************************************************/
#include <iom16v.h>
#include "lcd.h"
uint colors[]=
{
0xf800,0x07e0,0x001f,0xffe0,0x0000,0x07ff,0xf81f,0xffff
};
/**********************************************************
延时子函数
**********************************************************/
void delay_ms(uint ms)
{
unsigned char k;
while (ms--)
{
for (k = 0; k < 228; k++)
;
}
}
/**********************************************************
写8位数据子函数
**********************************************************/
void WriteDAT(uchar value) // color data
{
LCD_CS_L;
LCD_RS_H;
// LCD_WR = 0;
PORTB=value;
LCD_WR_L;
LCD_WR_H;
LCD_CS_H;
}
/**********************************************************
写8位命令子函数
**********************************************************/
void WriteCOM(uchar value) // color data
{
LCD_CS_L;
LCD_RS_L;
// LCD_WR = 0;
PORTB=value;
LCD_WR_L;
LCD_WR_H;
LCD_CS_H;
}
/**********************************************************
设置显示窗口子函数
**********************************************************/
void LCD_SetRamAddr(uint xStart, uint xEnd, uint yStart, uint yEnd)
{
WriteCOM(0x2a); //行
WriteDAT(xStart>>8); //XS15-XS8
WriteDAT(xStart); //XS7-XS0 (X start address)
WriteDAT(xEnd>>8); //XE15-XE8
WriteDAT(xEnd); //XE7-XE0 (X end address)
WriteCOM(0x2b); //列 row address set (RASET)
WriteDAT(yStart>>8); //YS15-YS8
WriteDAT(yStart); //YS7-YS0 (Y start address)
WriteDAT(yEnd>>8); //YE15-YE8
WriteDAT(yEnd); //YE7-YE0 (Y end address)
WriteCOM(0x2c); //display on 显示打开命令
}
/**********************************************************/
void LCD_init(void)
{ //请看数据手册的命令部分 了解其个命令的功能
LCD_RST_H;
delay_ms(100);
LCD_RST_L;
delay_ms(100);
LCD_RST_H;
delay_ms(100);
WriteCOM(0x01); //software reset软件复位
delay_ms(100);
WriteCOM(0x11); //sleep out/power on(SLPOUT) 退出睡眠
delay_ms(50);
WriteCOM(0x20); //display inversion off 关闭取反
delay_ms(50);
WriteCOM(0x38); //ID mode off (IDMOFF)
delay_ms(50);
WriteCOM(0x13); //Normal display mode on (Partial mode off)
WriteCOM(0x3a); //color mode Interface pixel format (COLMOD)
WriteDAT(0x05); //16-bit/pixel , 1-times data transfer
WriteCOM(0xc0); //power control 1 (PWCTR1)
WriteDAT(0x03); //default value LCM=0 set the GVDD voltage=4.65
WriteCOM(0xc5);
WriteDAT(0xc8); //VCOMH voltage set 4.300V
WriteCOM(0xc6);
WriteDAT(0x1f); //VCOMAC voltage set 5.550V ;
delay_ms(10);
WriteCOM(0xfe);
WriteDAT(0x00);
WriteDAT(0x04);
WriteCOM(0x26); //gamma sel
WriteDAT(0x04);
WriteCOM(0x2a); //column address set (CASET)
WriteDAT(0x00); //XS15-XS8
WriteDAT(0x00); //XS7-XS0 (X start address)
WriteDAT(0x00); //XE15-XE8
WriteDAT(0x7f); //XE7-XE0 (X end address)
WriteCOM(0x2b); //row address set (RASET)
WriteDAT(0x00); //YS15-YS8
WriteDAT(0x00); //YS7-YS0 (Y start address)
WriteDAT(0x00); //YE15-YE8
WriteDAT(0x9f); //YE7-YE0 (Y end address)
WriteCOM(0x36); //memory data access control (MADCTR)
WriteDAT(0xc0);
WriteCOM(0x29); // display on
}
/**********************************************************
清屏子函数
**********************************************************/
void LCD_clear(uchar n)
{
uint num;
LCD_SetRamAddr(0,127, 0,159); //设置显示的坐标
for(num=20480;num>0;num--) //160*128=20480
{
WriteDAT(colors[n]>>8); //高8位
WriteDAT(colors[n]); //低8位
}
}
lcd.h文件
/**********************************************************
file: Lcd.h
**********************************************************/
/**********************************************************
file: Lcd.h
**********************************************************/
#define uchar unsigned char
#define uint unsigned int
#define TYPE_LCD_DATA 1
#define TYPE_LCD_COMMAND 0
#define LCD_SIZE_X 128
#define LCD_SIZE_Y 160
#define DATA PORTB
#define LCD_RST_H PORTD|=(1 << PD6)
#define LCD_RST_L PORTD&=~(1 << PD6)
//RST 引脚定义
//#define LCD_RD_H PORTD|=(1 << PD7)
//#define LCD_RD_L PORTD&=~(1 << PD7)
//RD 引脚定义
#define LCD_WR_H PORTC|=(1 << PC3)
#define LCD_WR_L PORTC&=~(1 << PC3)
//WR 引脚定义
#define LCD_RS_H PORTD|=(1 << PD5)
#define LCD_RS_L PORTD&=~(1 << PD5)
//RS 引脚定义
#define LCD_CS_H PORTD|=(1 << PD4)
#define LCD_CS_L PORTD&=~(1 << PD4)
//CS 引脚定义
extern uint colors[];
extern void delay_ms(uint ms);
extern void LCD_SetRamAddr(uint xStart, uint xEnd, uint yStart, uint yEnd);
extern void LCD_init(void);
extern void LCD_clear(uchar n);
extern void LCD_ShowChar(uchar x,uchar y,uint For_color,uint Bk_color,char ch);
extern void LCD_ShowString(uchar x,uchar y,uint For_color,uint Bk_color,char *p);
extern void ChineseChar(uint x,uint y,int size,uint For_color, uint Bk_color , char c);
void WriteDAT(uchar value) ;
main函数
#include <iom16v.h>
#include "lcd.h"
/**********************************************************
主函数
**********************************************************/
void main(void)
{
DDRB = 0xff;
DDRC = 0xff;
DDRD = 0xff;
LCD_init();
LCD_clear(6);
while(1) ;
}
/*********************************************************/
此帖出自
小平头技术问答
一周热门 更多>