原创 RA8835 LCD320*240

2009-5-21 18:38 7356 7 18 分类: MCU/ 嵌入式

https://static.assets-stash.eet-china.com/album/old-resources/2009/3/24/6bf21169-4b58-4771-b540-593279fc386c.zip这是我自己参考别人写的代码,呵呵,希望对大家有用~


zip这是RA8835的数据手册~


包含以下文件:


├─汉字显示
├─图形显示
│  ├─画线
│  ├─画点
│  │  └─隧道
│  ├─画方
│  ├─画圆
│  │  └─弹球
│  ├─正弦
│  └─图片
├─滚动
├─自定义字符
├─字符显示
│  ├─字符串显示
│  ├─字符串滚动显示
│  ├─字符串依次显示
│  └─字符串显示1
└─演示程序


 


演示程序代码:


//头文件


/*--------------------------------------------------------------*/
//File: LCD320*240液晶驱动
//Chip: RA8835P3N
//Data: 09-3-24
//Time: 16:55



/*--------------------------------------------------------------*/
//防止被重复定义
#ifndef __LCD320_240_H__
#define __LCD320_240_H__



/*--------------------------------------------------------------*/
//所需头文件
#include <AT89X52.H>
#include <MATH.H>


/*--------------------------------------------------------------*/
//端口定义
sfr  LCD320_BUS = 0xa0;   //8位数据总线 P2 = 0xa0
sbit LCD320_WR = P1^0;   //写信号,低电平有效
sbit LCD320_RD = P1^1;   //读信号,低电平有效
sbit LCD320_CD = P1^2;   //高:选择指令寄存器;低:选择数据寄存器



/*--------------------------------------------------------------*/
/*8080接口信号的组合功能
CD  /RD  /WR
0  0  1  读状态标志位  
0  1  0  写指令参数和显示数据
1  0  1  读显示数据和光标指针
1  1  0  写指令代码



/*--------------------------------------------------------------*/
//定义指令代码、指令参数
#define systemset  0x40  //初始化设置,后续8字节参数串systemset_P8[]
unsigned char code systemset_P8[] = {0x30, 0x87, 0x07, 0x27, 0x4f, 0xef, 0x28, 0x00};
         //P1 P2   P3 P4   P5 P6   P7 P8


#define scroll   0x44  //设定显示起始地址和显示范围,后续10字节参数串scroll_P10[]
#define basepart1  0x00
#define basepart2  0x28
#define basepart3  0x50
#define basepart4  0x00
unsigned char code scroll_P10[]   = {0x00, basepart1, 0xf0,  //第一显示区RAM,10KB,240行
          0x00, basepart2, 0xf0,  //第二显示区RAM,10KB,240行
             0x00, basepart3,   //第三显示区RAM,10KB
          0x00, basepart4};   //第四显示区RAM,32KB


#define sleepin     0x53  //休闲模式设置  后续参数:无


#define dispoff     0x58  //显示关闭    后续参数1字节
#define dispon      0x59  //显示状态打开  后续参数1字节


#define hdotscr     0x5a  //点位移量设置  后续参数1字节
#define ovlay       0x5b  //显示合成设置  后续参数1字节
#define cgramadr    0x5c  //CGRAM首地址设置 后续参数2字节
#define csrform     0x5d  //光标形状设置  后续参数2字节


#define csrdirr     0x4c  //光标向右方向移动 后续参数:无
#define csrdirl     0x4d  //光标向左方向移动 后续参数:无
#define csrdiru     0x4e  //光标向上方向移动 后续参数:无
#define csrdird     0x4f  //光标向下方向移动 后续参数:无


#define csrw        0x46  //设置光标地址  后续参数2字节
#define csrr        0x47  //读出光标地址  后续参数2字节


#define mwrite      0x42  //显示数据写入  后续参数N字节
#define mread       0x43  //显示数据读取  后续参数N字节



/*--------------------------------------------------------------*/
#define busy        0x40  //忙信号D6   0100 0000
#define AP    (systemset_P8[6])//一行所占显示存储单元的字节数


 



/*--------------------------------------------------------------*/
//汉字
unsigned char code cgtab[][32]= {
0xDF,0xDE,0x01,0xDF,0xAF,0xAF,0x6F,0x02,0xEC,0xEF,0xE3,0x0F,0xEF,0xEF,0xE8,0xEF,
0xFF,0x03,0xF7,0xEF,0xDF,0xAF,0x73,0xFB,0x01,0xDF,0xDF,0xDF,0xDF,0xDF,0x01,0xFF,//轻3,


0xEF,0xEF,0xDF,0x83,0xBA,0xBA,0xB9,0x83,0xBB,0xBB,0xBB,0xBB,0x83,0xBB,0xBF,0xFF,
0x7F,0x7F,0x7F,0x03,0xFB,0xFB,0xFB,0x7B,0xBB,0x9B,0xDB,0xFB,0xFB,0xD7,0xEF,0xFF,//的4,


0xEE,0xE6,0xEE,0xE0,0xDE,0xBE,0xFE,0x00,0xFF,0xE0,0xEF,0xEF,0xEF,0xE0,0xEF,0xFF,
0xFF,0xFF,0xFF,0x03,0xFF,0xFF,0xFF,0x01,0xFF,0x0F,0xEF,0xEF,0xEF,0x0F,0xEF,0xFF,//告5,


0xBF,0xDF,0xCE,0xDE,0xFE,0xFE,0x1E,0xDE,0xDE,0xDE,0xDE,0xD6,0xCD,0xDD,0xFB,0xFF,
0xFF,0xE3,0x1F,0xFF,0xFF,0x01,0xEF,0xAF,0xCF,0xE7,0xE9,0xEB,0xEF,0xEF,0xEF,0xFF};



/*--------------------------------------------------------------*/
//汉字
unsigned char code tab[]={
0xBF,0xDF,0xCF,0xDF,0xFF,0xFF,0x1F,0xDF,0xDF,0xDF,0xDF,0xDF,0xD7,0xCF,0xD8,0xFF,
0xBF,0xBF,0xBF,0xBF,0xBF,0x83,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0x01,0xFF,//让0,


0xF9,0xC7,0xF7,0xF7,0xF7,0x00,0xF7,0xF7,0xF1,0xC7,0x37,0xF7,0xF6,0xF7,0xD7,0xEF,
0xBF,0xAF,0xB7,0xB7,0xBF,0x01,0xBF,0xB7,0xD7,0xCF,0xDF,0xAF,0x6D,0xF5,0xF9,0xFD,//我1,


0xDF,0xDE,0x01,0xDF,0xAF,0xAF,0x6F,0x02,0xEC,0xEF,0xE3,0x0F,0xEF,0xEF,0xE8,0xEF,
0xFF,0x03,0xF7,0xEF,0xDF,0xAF,0x73,0xFB,0x01,0xDF,0xDF,0xDF,0xDF,0xDF,0x01,0xFF,//轻2,


0xDF,0xDE,0x01,0xDF,0xAF,0xAF,0x6F,0x02,0xEC,0xEF,0xE3,0x0F,0xEF,0xEF,0xE8,0xEF,
0xFF,0x03,0xF7,0xEF,0xDF,0xAF,0x73,0xFB,0x01,0xDF,0xDF,0xDF,0xDF,0xDF,0x01,0xFF,//轻3,


0xEF,0xEF,0xDF,0x83,0xBA,0xBA,0xB9,0x83,0xBB,0xBB,0xBB,0xBB,0x83,0xBB,0xBF,0xFF,
0x7F,0x7F,0x7F,0x03,0xFB,0xFB,0xFB,0x7B,0xBB,0x9B,0xDB,0xFB,0xFB,0xD7,0xEF,0xFF,//的4,


0xEE,0xE6,0xEE,0xE0,0xDE,0xBE,0xFE,0x00,0xFF,0xE0,0xEF,0xEF,0xEF,0xE0,0xEF,0xFF,
0xFF,0xFF,0xFF,0x03,0xFF,0xFF,0xFF,0x01,0xFF,0x0F,0xEF,0xEF,0xEF,0x0F,0xEF,0xFF,//告5,


0xBF,0xDF,0xCE,0xDE,0xFE,0xFE,0x1E,0xDE,0xDE,0xDE,0xDE,0xD6,0xCD,0xDD,0xFB,0xFF,
0xFF,0xE3,0x1F,0xFF,0xFF,0x01,0xEF,0xAF,0xCF,0xE7,0xE9,0xEB,0xEF,0xEF,0xEF,0xFF,//诉6,


0xF6,0xF6,0xEE,0xEC,0xDD,0xCB,0x97,0x5D,0xDC,0xDD,0xDB,0xDB,0xD7,0xDE,0xDF,0xFF,
0xFF,0x7F,0xFB,0x01,0xFB,0xB7,0xBF,0xAF,0xB7,0xB7,0xBB,0xB9,0xBB,0xBF,0x7F,0xFF};
#define  num  sizeof(tab)


/*--------------------------------------------------------------*/
//图片
//216*14
unsigned char code tab1[]={
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x0C,0x34,0x70,0xC3,0x7F,0x00,0x1B,
0x24,0x20,0x11,0x0A,0x04,0x00,0xC0,0x6F,0x10,0xC0,0xE8,0xFF,0x03,0x04,0x84,0x82,
0x01,0x00,0x00,0x00,0x3F,0xE0,0x00,0x00,0x00,0xFF,0x60,0x90,0x10,0x20,0x40,0x80,
0x07,0x7A,0xD7,0xF8,0x10,0x28,0x76,0xFF,0x00,0x03,0x05,0x1A,0x35,0xEA,0x55,0xBE,
0xC0,0x00,0x00,0x00,0x00,0xFF,0x78,0x86,0x01,0x00,0x40,0xB8,0xCC,0x82,0x40,0x00,
0x40,0x20,0x7E,0xFF,0x00,0x00,0x00,0x81,0x42,0x37,0x1C,0x04,0x02,0x00,0x00,0x01,
0x1E,0xFF,0x38,0x45,0x83,0x21,0xC0,0x00,0x01,0x01,0x02,0x05,0x0A,0x10,0x00,0xFF,
0xF8,0xEC,0xF4,0xFA,0xF6,0x7A,0xFD,0x7F,0xBF,0x3F,0x3F,0x5F,0xAE,0xEC,//1.bmp0
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x17,0xE0,0x3F,0x98,0x00,0x63,0x1E,0x00,0x00,
0x00,0x01,0x02,0x0C,0x78,0xE0,0x83,0x0C,0x30,0xC0,0x00,0x03,0x0B,0x30,0x60,0x80,
0x07,0x09,0x1B,0x7C,0x80,0x00,0x00,0x0F,0x7F,0xFF,0x80,0x60,0x1E,0x01,0x00,0x80,
0xC0,0x60,0x30,0x18,0xFC,0xFE,0xFF,0xFF,0x00,0x00,0xFE,0x07,0xCC,0x3C,0x0E,0x07,
0x01,0x00,0x00,0x00,0x80,0xE7,0x00,0x00,0x7D,0x80,0x30,0x00,0x00,0x00,0x84,0xCF,
0x5F,0x7F,0xFF,0xFF,0x14,0x3A,0x3D,0x38,0x48,0xF0,0xF1,0xF9,0x78,0x38,0xC4,0xFF,
0xFF,0xFF,0x00,0x00,0x1F,0xCF,0x7C,0x30,0x14,0xB8,0xFF,0x3F,0x1F,0x07,0xC1,0xF0,
0x00,0x00,0xF0,0xF4,0xBA,0x1D,0x3C,0xB9,0xFA,0xF4,0xE4,0xC8,0x08,0x10,//3.bmp0
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x4F,0xA0,0xFF,0x00,0x00,
0x00,0x01,0x02,0x05,0x09,0x13,0x2D,0x27,0xFC,0xC0,0x0F,0xF0,0x1E,0x61,0x8C,0x3E,
0xE5,0xC0,0xC9,0xE0,0x78,0xFF,0x6F,0x17,0xFF,0x01,0x00,0xF0,0x0E,0x81,0xC0,0xE1,
0x50,0x62,0xA0,0x47,0xA0,0xC5,0x71,0x9E,0x00,0x00,0x00,0xC0,0x38,0x07,0x80,0x80,
0x80,0x00,0x00,0x07,0xF8,0x00,0x00,0x00,0x0E,0x31,0x40,0x80,0x00,0x20,0x10,0x98,
0x1E,0xE1,0x3F,0x00,0x00,0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x07,0x03,0x00,0xC0,
0xF0,0x0F,0x00,0x00,0x00,0x00,0x06,0x09,0x30,0xC7,0x0A,0x17,0x1C,0x20,0x40,0x80,
0x00,0x00,0x00,0x00,0x00,0x8C,0x72,0x22,0xF9,0xE5,0x05,0x03,0x00,0x00//4.bmp0
};
//216*14
unsigned char code tab2[]={
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0xFC,0x03,0xE0,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0x07,0x00,0xF8,0x07,0x00,0x00,0x01,0x02,
0x04,0x04,0x08,0x08,0x38,0xF8,0x58,0x2C,0x54,0xFE,0x00,0x7E,0x83,0x00,0x08,0x05,
0x06,0x03,0x03,0x03,0x02,0x02,0x03,0x03,0x00,0x00,0x80,0xC3,0x6E,0x38,0xB0,0x63,
0xCE,0x3C,0x6A,0xF4,0xFF,0xFF,0x00,0x0F,0x70,0x80,0x00,0x1F,0xFE,0x7C,0x78,0x78,
0x7D,0x3F,0xFE,0xAF,0x00,0x80,0xC1,0x63,0xD3,0x8E,0x06,0x04,0x00,0x84,0x06,0x8F,
0x0F,0x1F,0x3E,0xFF,0xFF,0xBF,0x0F,0x22,0x63,0x01,0x09,0x9F,0x0F,0xFB,0xFF,0xFE,
0x00,0x80,0xE0,0xF0,0xB0,0xD8,0xDC,0xEC,0xF6,0xD6,0xDB,0xBF,0xEF,0x37,//5.bmp0
0x02,0x27,0xA2,0xFF,0xA5,0x27,0x25,0x27,0x05,0x01,0x00,0xFF,0x00,0xFF,0x00,0x00,
0x04,0x84,0x04,0x04,0x04,0x0A,0x31,0x00,0x00,0xFF,0x00,0xFF,0x00,0x10,0x3C,0x09,
0x3D,0x09,0x14,0x24,0x00,0x03,0x04,0xF2,0x01,0xF8,0x00,0x00,0x0F,0xC1,0x4F,0xC8,
0x09,0x0F,0x00,0x60,0x90,0x26,0x40,0x9E,0x0D,0x04,0x07,0x07,0x06,0x06,0x0E,0x0F,
0x1F,0x1F,0x3F,0x7F,0xFF,0x3F,0x83,0x00,0x80,0xC0,0xC0,0xC0,0x40,0x00,0x10,0x10,
0x00,0x80,0x8D,0xCE,0xFF,0x07,0x7C,0xBF,0x3E,0x1C,0x0C,0x00,0x00,0x01,0x00,0x00,
0x00,0x00,0xFF,0xFF,0x7C,0x78,0x70,0x70,0x60,0xCD,0x93,0x13,0x1F,0x3F,0x7F,0xFF,
0xFC,0xFC,0xFC,0xFC,0xF8,0xF8,0xF8,0xF8,0xF8,0xF0,0xF0,0xF7,0xE0,0xEF,//6.bmp0
0xF4,0xF9,0xF2,0xF8,0xC5,0x00,0x00,0x82,0x40,0x90,0x32,0x60,0x00,0x74,0x8D,0x06,
0x45,0xC2,0x82,0x03,0x01,0x01,0x01,0x01,0x21,0x62,0x02,0x04,0xFF,0xFF,0x36,0xD1,
0x28,0x10,0x88,0xC1,0xF0,0xF8,0x08,0x04,0x03,0x54,0x80,0xC2,0xE4,0x74,0x32,0x19,
0x08,0x04,0x40,0x20,0x30,0x78,0xFC,0x06,0x80,0x00,0x00,0x00,0x00,0x80,0x78,0x07,
0x00,0x02,0x02,0x04,0x08,0x37,0x60,0x1E,0x01,0x00,0x00,0x00,0x00,0xC0,0x3F,0x00,
0x01,0x0E,0xF0,0x00,0x00,0x00,0xF0,0x0F,0x00,0x00,0x00,0x00,0x00,0x7D,0x80,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0x1C,0x03,0x00,0x00,0x80,0x00,0x00,0x01,0x03,
0x01,0x03,0x06,0x0E,0x1E,0x7C,0x3C,0x8C,0x08,0x48,0x50,0x90,0xD0,0x90//7.bmp0
};
#define  width  216  //图像宽度大小
#define  height  14  //图像高度大小



/*--------------------------------------------------------------*/
//函数声明
//void check_busy(void);   //忙状态检测
void write_cmd(unsigned char cmd); //写指令代码
void write_dat(unsigned char dat); //写指令参数、显示数据
unsigned char read_dat(void);  //读出数据


void lcd_init(void);    //液晶初始化
void lcd_cls(unsigned char part); //液晶清屏,32KB RAM 清零
void show_on(void);     //开启显示
void show_off(void);    //关闭显示
//void sleep_in(void);    //进入省电模式
//void sleep_out(void);    //退出省电模式
void delay100ms(void);    //延时100ms
void locate_xy1(unsigned char x, unsigned char y);      //1区光标定位
void locate_xy2(unsigned int  x, unsigned char y);      //2区光标定位
void locate_xy22(unsigned int  x, unsigned char y);      //2区光标定位2
void set_addr1(unsigned int addr);          //设置1区地址
void set_addr2(unsigned int addr);          //设置2区地址
void roll_h(unsigned int x, bit dir, bit part);       //水平方向滚动显示
void roll_v(unsigned char x, bit dir, bit part);      //垂直方向滚动显示
void show_char(unsigned char x, unsigned char y, unsigned char *string);//显示字符串
void load_cgram(unsigned char m, bit inverse);       //加载cgram
void show_hzg(unsigned char x, unsigned char y, unsigned char *string, bit inverse);//显示汉字(图形)
void show_hzt(unsigned char x, unsigned char y, unsigned char n_4);     //显示汉字(文本)
void show_pixel(unsigned int x, unsigned char y, bit attr);       //显示点
void show_line(unsigned int x1, unsigned char y1, unsigned int x2, unsigned char y2, bit attr);  //显示直线
void show_rectangle(unsigned int x1, unsigned char y1, unsigned int x2, unsigned char y2, bit attr);//显示方形
void show_circle(unsigned int x, unsigned char y, unsigned char r, bit attr);      //显示圆
void show_pic(unsigned char x, unsigned char y, unsigned char *string, bit inverse);    //显示图片
void show_sine(unsigned char y, unsigned char a, unsigned char n, bit attr);      //显示正弦


 


/*--------------------------------------------------------------*/
//延时100000+0us 函数定义
void delay100ms(void)
{
    unsigned char i, j, k;
    for(i = 156; i > 0; i--)
    for(j = 58; j > 0; j--)
    for(k = 4; k > 0; k--);
}



/*--------------------------------------------------------------*/
//忙状态检测
/*void check_busy(void)
{
 unsigned char  onbusy;
 LCD320_WR = 1;
 do{
  LCD320_CD = 0;   //数据
  LCD320_RD = 0;   //读出
  onbusy = LCD320_BUS;
  LCD320_RD = 1;  
 }while(onbusy&busy);
}



/*--------------------------------------------------------------*/
//写指令代码
void write_cmd(unsigned char cmd)
{
 LCD320_RD = 1;  
 LCD320_BUS = cmd;
 LCD320_CD = 1;    //指令
 LCD320_WR = 0;    //上升沿写入
 LCD320_WR = 1;
}



/*--------------------------------------------------------------*/
//写指令参数、显示数据
void write_dat(unsigned char dat)
{
 LCD320_RD = 1;
 LCD320_BUS = dat;
 LCD320_CD = 0;    //数据
 LCD320_WR = 0;    //上升沿写入
 LCD320_WR = 1;
}



/*--------------------------------------------------------------*/
//读出数据
unsigned char read_dat(void)
{
 unsigned char temp="0";
// LCD320_BUS = 0xff;   //P0口置输入方式,其它I/O口就不需要这样!!!
 LCD320_CD = 1;
 LCD320_WR = 1;
 LCD320_RD = 0;
 temp = LCD320_BUS;
 LCD320_RD = 1;
 return (temp);
}



/*--------------------------------------------------------------*/
//液晶初始化
void lcd_init(void)
{
 unsigned char i;


 write_cmd(systemset);   //初始化设置
 for(i = 0; i < 8; i++) write_dat(systemset_P8);


 write_cmd(scroll);    //设定显示起始地址和显示范围
 for(i = 0; i < 10; i++) write_dat(scroll_P10);


 write_cmd(hdotscr);    //点位移量设置
 write_dat(0x00);    //不移动 
 write_cmd(ovlay);    //显示合成设置   
 write_dat(0x00);    //二重合成,文本显示,逻辑或
 show_off();      //关闭显示
 lcd_cls(0);      //液晶清屏,32KB RAM 清零 
 show_on();      //开启显示
}



/*--------------------------------------------------------------*/
//液晶清屏, 10KB RAM 清零
//part = 0 清所有显示区 32KB RAM
//part = 1 清显示区1
//part = 2 清显示区2
//part = 3 清显示区3
//part = 4 清显示区4
void lcd_cls(unsigned char part)
{
 unsigned int i = 10240;       //10240 = 0x2800  10KB RAM
 write_cmd(csrw);        //写入光标地址
 write_dat(0x00);          //先写低八位
 if(part == 1)  write_dat(0x00);  //显示区1
 else if(part == 2) write_dat(basepart2);//显示区2
 else if(part == 3) write_dat(basepart3);//显示区3
 else if(part == 4) write_dat(basepart4);//显示区4
 else 
 {i = 32768;     write_dat(0x00);}    //所有显示区 32KB RAM
 write_cmd(csrdirr);        //光标向右方向移动
 write_cmd(mwrite);        //显示数据写入
 while(i--) write_dat(0x00);     //写入0
}



/*--------------------------------------------------------------*/
//开启显示
void show_on(void)
{
 write_cmd(dispon);    //显示状态开启
 write_dat(0x57);    //显示图像,光标1Hz闪烁
}



/*--------------------------------------------------------------*/
//关闭显示
void show_off(void)
{
 write_cmd(dispoff);    //显示状态关闭
 write_dat(0x57);    //显示图像,光标1Hz闪烁
}



/*--------------------------------------------------------------*/
//进入省电模式
/*void sleep_in(void)
{
 write_cmd(sleepin);   
}



/*--------------------------------------------------------------*/
//退出省电模式
/*void sleep_out(void)
{
 write_cmd(systemset);  
 write_dat(0x30);
 show_on();
}



/*--------------------------------------------------------------*/
//光标定位
//x横坐标: 0~319 320
//y纵坐标: 0~239 240
//图层2
void locate_xy2(unsigned int x, unsigned char y)
{
 unsigned int  addr;
 addr  = (unsigned int)(y) * AP + x/8;
 write_cmd(csrw);         //写入光标地址
 write_dat((unsigned char)(addr & 0xff));    //先写低八位
 write_dat((unsigned char)(addr >> 8) + basepart2); //后写高八位
}



/*--------------------------------------------------------------*/
//光标定位2
//x横坐标: 0~319 320
//y纵坐标: 0~239 240
//图层2
void locate_xy22(unsigned int x, unsigned char y)
{
 unsigned int  addr;
 addr  = (unsigned int)(y) * AP + x;
 write_cmd(csrw);         //写入光标地址
 write_dat((unsigned char)(addr & 0xff));    //先写低八位
 write_dat((unsigned char)(addr >> 8) + basepart2); //后写高八位
}


 



/*--------------------------------------------------------------*/
//设置1区地址
void set_addr1(unsigned int addr)
{
 addr += basepart1;
 write_cmd(scroll);
 write_dat((unsigned char)(addr & 0xff));
 write_dat((unsigned char)(addr >> 8));
}



/*--------------------------------------------------------------*/
//设置2区地址
void set_addr2(unsigned int addr)
{
 addr += basepart2;
 write_cmd(scroll);
 write_dat(scroll_P10[0]);
 write_dat(scroll_P10[1]);
 write_dat(scroll_P10[2]);
 write_dat((unsigned char)(addr & 0xff));
 write_dat((unsigned char)(addr >> 8));   
}



/*--------------------------------------------------------------*/
//水平方向滚动显示
//参数x: 滚动距离  文本--x*8像素,图形--x像素
//参数dir: 滚动方向  0--向左,1--向右
//参数part:滚动区域  0--1区, 1--2区
void roll_h(unsigned int x, bit dir, bit part)
{
 unsigned char i;
 unsigned int  addr;
 
 if(dir) addr = x;     //水平向右
 else addr = 0;     //水平向左
 
 while(x--)
 {
  for(i = 0; i < 8; i++)
  {
   write_cmd(hdotscr);
   if(dir) write_dat(7 - i); //水平向右
   else write_dat(i);  //水平向左
   delay100ms();
  }
  if(dir) addr--;     //水平向右
  else addr++;     //水平向左
  if(part) set_addr2(addr); //2区
  else  set_addr1(addr); //1区
 }
}



/*--------------------------------------------------------------*/
//垂直方向滚动显示
//参数x: 滚动距离  文本--x行,图形--x像素
//参数dir: 滚动方向  0--向上,1--向下
//参数part:滚动区域  0--1区, 1--2区
void roll_v(unsigned char x, bit dir, bit part)
{
 unsigned char i;
 unsigned int  addr = 0;
 
 for(i = 0; i <= x; i++)
 {
  if(dir) addr = AP * (x - i); //垂直向上
  else addr = AP * i;   //垂直向下
  if(part) set_addr2(addr); //2区
  else  set_addr1(addr); //1区 
  delay100ms();
 }
}



/*--------------------------------------------------------------*/
//光标定位
//x横坐标: 0~39 320/8=40
//y纵坐标: 0~29 240/8=30
void locate_xy1(unsigned char x, unsigned char y)
{
 unsigned int  addr;
 addr  =(unsigned int)(y) * AP + x;
 write_cmd(csrw);       //写入光标地址
 write_dat((unsigned char)(addr & 0xff));  //先写低八位
 write_dat((unsigned char)(addr >> 8));  //后写高八位
}



/*--------------------------------------------------------------*/
//显示字符串
//x横坐标: 0~39 320/8=40
//y纵坐标: 0~29 240/8=30
void show_char(unsigned char x, unsigned char y, unsigned char *string)
{
 locate_xy1(x, y);    //光标定位
 write_cmd(csrform);    //光标形状设置
 write_dat(0x07);    //水平显示宽度6
 write_dat(0x07);    //线状光标显示,高度8


 write_cmd(csrdirr);    //光标向右方向移动
 
 write_cmd(dispon);    //显示状态开启
 write_dat(0x57);    //显示图像,光标1Hz闪烁


 write_cmd(mwrite);    //显示数据写入
 while(*string)
 {
  write_dat(*string);
  string++;
 }
}



/*--------------------------------------------------------------*/
//显示汉字(图形)
//x横坐标: 0~39 320/8=40
//y纵坐标: 0~29 240/8=30
void show_hzg(unsigned char x, unsigned char y, unsigned char *string, bit inverse)
{
 unsigned char i, j;
 write_cmd(csrdird);    //光标向下方向移动
 for(j = 0; j < num/16; j++)
 { 
  locate_xy22(x + j, y);  //光标定位
  write_cmd(mwrite);   //显示数据写入
  for(i = 0; i < 16; i++)
  {
   if(inverse) write_dat(~*string);
   else  write_dat(*string);
   string++;
  }
 }
}



/*--------------------------------------------------------------*/
//加载cgram
void load_cgram(unsigned char m, bit inverse)
{
 unsigned char i, j;
 write_cmd(cgramadr);
 write_dat(0x00);
 write_dat(0x50);  //cgram起始地址


 write_cmd(csrdirr);


 write_cmd(csrw);
 write_dat(0x00);
 write_dat(0x54);  //cgram 1K RAM 结束地址


 write_cmd(mwrite);
 for(j = 0; j < m; j++)
 {
  for(i = 0; i < 32; i++) 
  {
   if(inverse) write_dat(~cgtab[j]);
   else  write_dat(cgtab[j]);
  }
 }
}



/*--------------------------------------------------------------*/
//显示汉字(文本)
//x横坐标: 0~39 320/8=40
//y纵坐标: 0~29 240/8=30
void show_hzt(unsigned char x, unsigned char y, unsigned char n_4)
{
 locate_xy1(x, y);
 write_cmd(csrdird);    //光标向下方向移动
 write_cmd(mwrite);
 write_dat(n_4);
 write_dat(n_4 + 1);
 locate_xy1(x + 1, y);
 write_cmd(mwrite);
 write_dat(n_4 + 2);
 write_dat(n_4 + 3);
}



/*--------------------------------------------------------------*/
//显示点
//x横坐标: 0~319 320
//y纵坐标: 0~239 240
//attr显示属性:0-画点,1-消点
void show_pixel(unsigned int x, unsigned char y, bit attr)

 unsigned char temp, tempd;
 tempd = 0x80 >> (x & 0x07);
 locate_xy2(x, y);     //光标定位
 write_cmd(mread);
 temp = read_dat();
 if(attr) temp &= ~tempd;
 else  temp |= tempd;
 locate_xy2(x, y);     //光标定位
 write_cmd(mwrite);     //显示数据写入
 write_dat(temp);
}



/*--------------------------------------------------------------*/
//显示直线
//x横坐标: 0~319 320
//y纵坐标: 0~239 240
//attr显示属性:0-画线,1-删线
void show_line(unsigned int x1, unsigned char y1, unsigned int x2, unsigned char y2, bit attr)
{
 int  dx, dy;
 char inc_x, inc_y;
 int  xerr = 0, yerr = 0;    //初始化变量
 unsigned int i, ds;


    dx = x2 - x1;       //计算坐标增量
    dy = y2 - y1;


 if(dx > 0) inc_x = 1;     //设置单步方向
 else
 {
  if(dx == 0) {inc_x = 0;     } //垂直线
  else  {inc_x = -1; dx = -dx;}
 }


 if(dy > 0) inc_y = 1;     //设置单步方向
 else
    {
  if(dy == 0) {inc_y = 0;     } //水平线
  else  {inc_y = -1; dy = -dy;}
 }


 if(dx > dy) ds = dx;     //选取基本增量坐标轴
 else  ds = dy;


 for(i = 0; i <= ds+1; i++)    //画线输出
 {
  show_pixel(x1, y1, attr);   //画点
  xerr += dx;
  yerr += dy;
  if(xerr > ds)
  {
   xerr -= ds;
   x1   += inc_x;
  }
  if(yerr > ds)
  {
   yerr -= ds;
   y1   += inc_y;
  }
 }
}



/*--------------------------------------------------------------*/
//显示方形
//x横坐标: 0~319 320
//y纵坐标: 0~239 240
//attr显示属性:0-画方,1-删方
void show_rectangle(unsigned int x1, unsigned char y1, unsigned int x2, unsigned char y2, bit attr)
{
 show_line(x1, y1, x2, y1, attr);
 show_line(x1, y1, x1, y2, attr);
 show_line(x2, y1, x2, y2, attr);
 show_line(x1, y2, x2, y2, attr);
}



/*--------------------------------------------------------------*/
//显示圆
//x横坐标: 0~319 320
//y纵坐标: 0~239 240
//r半径: 0~239 240
//attr显示属性:0-画点,1-消点
void show_circle(unsigned int x, unsigned char y, unsigned char r, bit attr)
{
 unsigned char dx, dy = r;


 for(dx = 0; dx <= r; dx++)
 {
  while((r * r + 1 - dx * dx) < (dy * dy)) dy--;
  show_pixel(x + dx, y - dy, attr);
  show_pixel(x - dx, y - dy, attr);
  show_pixel(x - dx, y + dy, attr);
  show_pixel(x + dx, y + dy, attr);


  show_pixel(x + dy, y - dx, attr);
  show_pixel(x - dy, y - dx, attr);
  show_pixel(x - dy, y + dx, attr);
  show_pixel(x + dy, y + dx, attr);
 }
}


 


/*--------------------------------------------------------------*/
//显示图片
//x横坐标: 0~39 320/8=40
//y纵坐标: 0~239 240
void show_pic(unsigned char x, unsigned char y, unsigned char *string, bit inverse)
{
 unsigned char i, j;
 write_cmd(csrdird);    //光标向下方向移动
 for(j = 0; j < width/8; j++)
 { 
  locate_xy22(x + j, y);  //光标定位
  write_cmd(mwrite);   //显示数据写入
  for(i = 0; i < height; i++)
  {
   if(inverse) write_dat(~*string);
   else  write_dat(*string);
   string++;
   delay100ms();
  }
 }
}


 


/*--------------------------------------------------------------*/
//显示正弦
//y纵坐标: 119
//attr显示属性:0-画线,1-删线
void show_sine(unsigned char y, unsigned char a, unsigned char n, bit attr)
{
 unsigned int  x1 = 0, x2;
 unsigned char y1 = 119, y2;
 for(x2 = 0; x2 < 320; x2++)
 {
  y2 = y + (a * sin(0.0175 * n * x2));
  show_line(x1, y1, x2, y2, attr);
  x1 = x2;
  y1 = y2;
 }
}


 



/*--------------------------------------------------------------*/
#endif


 


//主函数


/*--------------------------------------------------------------*/
//File: LCD320*240液晶演示程序
//Chip: RA8835P3N
//Data: 09-3-24
//Time: 17:55



/*--------------------------------------------------------------*/
#include "LCD320_240.H"



/*--------------------------------------------------------------*/
//函数声明
void delay25ms(void);   //延时25000+3us 函数定义
void delay2s(void);    //延时2000000+1us 函数定义
void demo_pixel(void);   //画点演示函数
void demo_line(void);   //画线演示函数
void demo_rectangle(void);  //画方形演示函数
void demo_circle(void);   //画圆演示函数
void demo_picture(void);  //图片演示函数
void demo_sine(void);   //正弦演示函数
void demo_roll(void);   //滚动演示函数
void demo_hz(void);    //汉字演示函数
void demo_game(void);   //弹球


/*--------------------------------------------------------------*/
//延时25000+3us 函数定义
void delay25ms(void)
{
    unsigned char i, j;
    for(i = 58; i > 0; i--)
    for(j = 214; j > 0; j--);
}



/*--------------------------------------------------------------*/
//延时2000000+1us 函数定义
void delay2s(void)
{
    unsigned char i,j,k;
    for(i=254;i>0;i--)
    for(j=17;j>0;j--)
    for(k=230;k>0;k--);
}



/*--------------------------------------------------------------*/
//画点演示函数
void demo_pixel(void)
{
 unsigned int i, j;
 unsigned char n;
 lcd_init();
 n = 10;
 for(j = 1; j < 121; j += n)
 {
  for(i = j-n; i < 240-j; i++) show_pixel(j, i, 0);   //"| "
  for(i = j+1; i < 240-j; i++) show_pixel(i, 239-j, 0);  //"_"
  for(i = j+1; i < 240-j; i++) show_pixel(239-j, 239-i, 0); //" |"
  for(i = j+1; i < 240-n-j; i++) show_pixel(239-i, j, 0);  //"ˉ
 }


 for(j = 5; j < 121; j += n)
 { 
  for(i = j-n; i < 240-j; i++) {show_pixel(j, i, i&0x02); delay25ms(); }  //"| "
  for(i = j+1; i < 240-j; i++) {show_pixel(i, 239-j, i&0x02);delay25ms(); }  //"_"
  for(i = j+1; i < 240-j; i++){ show_pixel(239-j, 239-i, i&0x02);delay25ms();} //" |"
  for(i = j+1; i < 240-n-j; i++) {show_pixel(239-i, j, i&0x02); delay25ms();} //"ˉ"
 }
}



/*--------------------------------------------------------------*/
//画线演示函数
void demo_line(void)
{
 lcd_init();


 show_line(0,0,319,239, 0); //"\"
 show_line(0,239,319,0, 0); //"_"
 show_line(0,0,319,0, 0); //"-"
 show_line(0,0,0,239, 0); //"|"
 show_line(0,239,319,239, 0);//"/"
 show_line(319,0,319,239, 0);//"|"
 show_line(0,0,239,239, 0);
 show_line(0,239,239,0, 0);
 show_line(239,0,239,239, 0);


 delay2s();
}



/*--------------------------------------------------------------*/
//画方形演示函数
void demo_rectangle(void)
{
 unsigned char i;
 lcd_init();
 
 for(i = 0; i < 119; i += 2)
 {
  show_rectangle(i, i, 319-i, 239-i, 0);
 }
 for(i = 0; i < 119; i += 2)
 {
  show_rectangle(i, i, 319-i, 239-i, 1);
 }
 delay100ms();
}



/*--------------------------------------------------------------*/
//画圆演示函数
void demo_circle(void)
{
 unsigned char i, j;


 lcd_init();


 show_circle(4,4,3, 0);
 show_circle(315,4,3, 0);
 show_circle(315,235,3, 0);
 show_circle(4,235,3, 0);


 for(i = 1; i< 118; i+=3) 
 { 
  show_circle(159,119,i, 0);
  delay100ms();
 }
 j = 5;
 while(j--)
 {
  for(i = 1; i< 118; i+=3) 
  { 
   show_circle(159,119,i, 1);
   delay100ms();
  }
  for(i = 118; i > 2; i-=3) 
  { 
   show_circle(159,119,i, 0);
   delay100ms(); 
  }
 }
}



/*--------------------------------------------------------------*/
//图片演示函数
void demo_picture(void)
{
 lcd_init();
 show_char(2, 0, "Hi! I am glad to see you again. Now I'll show some picture below in layer two.");
 show_pic(0, 16, tab1, 1);
 show_pic(0, 31, tab2, 1);
 show_char(0, 6, "Don't you think it is beautiful? very nice~ !*^_^*! ");
 delay2s();
 delay2s();
}



/*--------------------------------------------------------------*/
//正弦演示函数
void demo_sine(void)
{
 unsigned char i;
 lcd_init();
 i = 5;
 while(i--)
 { 
  show_sine(119, 80, 5, 0);
  delay100ms();
  show_sine(119, 80, 5, 1);
  delay100ms();
 }
}



/*--------------------------------------------------------------*/
//滚动演示函数
void demo_roll(void)
{
 lcd_init();


 show_char(0, 0, "In this Program, I'll print some string like this in the screen below. ");
 show_char(3, 3, "!*^_^*!  very beautiful, do you think so?");
 show_char(0, 29, "X");
 show_char(39, 29, "Y");
 show_char(19, 17, "Z");


 roll_h(5,0,0);
 roll_h(5,1,0);
 roll_v(10,0,0);
 roll_v(10,1,0);
 show_char(16, 15, "!*^_^*!");
 delay2s();
}



/*--------------------------------------------------------------*/
//汉字演示函数
void demo_hz(void)
{
 lcd_init();


 show_hzg(0, 0,  tab, 0);
 show_hzg(0, 30, tab, 1);
 load_cgram(4,1);
 show_hzt(0,2,0x80);
 show_hzt(2,2,0x84);
 show_hzt(4,2,0x88);
 show_hzt(6,2,0x8c);
 delay2s();
}



/*--------------------------------------------------------------*/
//弹球
void demo_game(void)
{
 unsigned char r = 20;    //半径
 unsigned char i = 3;    //步进变量
 int  x = 30,y = 30;     //起始位置
 int  dx = i,  dy = i;    //步进
 int  x1, y1;      //保存上次位置


 lcd_init();
 while(1)
 {
  show_circle(x, y, r, 0);
  x1 = x, y1 = y;     //保存位置
  if((x-r) < 0) dx = i;
  if((x+r) > 319) dx = -i;
  if((y-r) < 0) dy = i;
  if((y+r) > 239) dy = -i;
  x += dx;
  y += dy;
  delay100ms();     //延迟时间
  show_circle(x1, y1, r, 1);  //消掉前一个圆
  show_pixel(x1, y1, x&0x01);  //轨迹
 }
}



/*--------------------------------------------------------------*/
//主函数
void main(void)
{
 demo_pixel();   //画点演示函数
 demo_line();   //画线演示函数
 demo_rectangle();  //画方形演示函数
 demo_circle();   //画圆演示函数
 demo_sine();   //正弦演示函数
 demo_picture();   //图片演示函数
 demo_hz();    //汉字演示函数
 demo_roll();   //滚动演示函数
 demo_game();
}


//over!


 

文章评论11条评论)

登录后参与讨论

用户80988 2011-9-12 22:50

那位大侠能否告诉小弟演示文件是基于那个开发软件运行的,本人刚入门,tgp6188@hotmail.com 谢谢!

用户149863 2011-3-3 17:01

sbit LCD320_CD = P1^2; //高:选择指令寄存器;低:选择数据寄存器 cd不是指cs片选信号。 片选信号一直选中(硬件拉高或者拉低),不过我忘记是高有效还是低有效,呵呵,快两年了,忘记了。你可以查看器件手册。 CD是 Command/Data 的缩写 CS是 Chip Select 的缩写

用户305114 2011-3-1 09:57

sbit LCD320_CD = P1^2; //高:选择指令寄存器;低:选择数据寄存器 cd是指的cs片选信号吗

用户1579220 2011-2-25 11:32

佩服佩服!!!

用户286866 2010-12-1 09:45

楼主,我真诚的要顶一下,看到你的笔记,我深深的折服,感谢你做的工作。

用户144668 2010-9-23 13:40

太感谢了,很好,很全,很强大。。。谢谢楼主。。。

用户230481 2009-10-27 20:37

很好,很强大

用户1713248 2009-9-7 20:35

程序下载后看了一下,有些不明白的地方请教下楼主,取指针地址的函数: addr =(unsigned int)(y) * AP + x; 这个公式是怎么得到的?的确是这么用的,但在PDF文档里我没有找到这个公式。不明白这个公式。 还有在程序 locate_xy1 中写高8位为: write_dat((unsigned char)(addr >> 8)); //后写高八位 而在程序 locate_xy2 中写高8位为:write_dat((unsigned char)(addr >> 8) + basepart2); //后写高八位 多了一个basepart2,为每显示一行需要的字节数。 楼主能不能讲讲,,谢谢了。

用户1713248 2009-9-7 15:49

非常感谢楼主,,,

用户1410217 2009-8-21 08:47

太谢谢了,正需要呢!!!
相关推荐阅读
用户149863 2010-05-22 22:40
LCD简单菜单显示
LCD简单菜单显示显示器件为图形型LCD12864(主控芯片KS0108)什么都不带!包含以下文件:LCD菜单(测试)LCD菜单(简单)LCD菜单(界面)LCD菜单(遥控器)希望对大家有用^_^感兴趣...
用户149863 2010-05-22 14:33
LCD12864(KS0108)液晶演示程序
LCD12864(KS0108)液晶演示程序LCD12864(KS0108)液晶演示程序视频: LCD12864演示程序(什么都不带的液晶) 视频演示网址:http://v.youku.com/v_s...
用户149863 2009-10-22 18:27
AVR代码
AVR单片机程序代码集,给需要的朋友们参考呵呵,都是自己一边学一边写的,一个一个字符从键盘敲出来的^_^希望对大家有用:-)呵呵,编译软件为:  ICCAVR V6.31A版本一共七个压缩包,呵呵,分...
用户149863 2009-10-22 15:18
VGA相关资料
VGA相关资料呵呵^_^如果你想玩的就请下载,有很多东西,都是花了我好几个夜晚才搜到的都是网上的资料:-)有兴趣的可以做做哦 包含以下文件夹:├─VGA+2051│  │  共享-----国外优秀电子...
用户149863 2009-10-10 14:46
PS/2 键盘与单片机
程序打包PS/2 键盘与单片机接口用LCD1602显示调试成功所以拿出来给大家分享,希望对大家有用,呵呵^_^用PS/2键盘做系统输入部分蛮方便的哦!可以使用Backspace/Esc/Tab/Cap...
用户149863 2009-08-17 19:54
AVR端口操作宏定义,便于移植
AVR端口操作宏定义头文件(ICCAVRIO.H),便于移植(ICCAVR编译环境) 压缩包里面有网上的相关资料,把它看完,相信你会更加了解红宏定义的^_^还有头文件在ICCAVRIO.H在Inclu...
我要评论
11
7
关闭 站长推荐上一条 /2 下一条