📄 ocmj15x20d.c
字号:
#include "config.h"
const uint8 LCD_REG_ADDR[] =
{
0x00,0x01,0x02,0x03,0X10,0X11,0X12,0X21,0X31,0X41,0X51,0X20,0X30,0X40,0X50,0X60,
0X61,0X70,0X71,0X72,0X80,0X81,0X91,0X90,0XA0,0XA1,0XA2,0XA3,0XB0,0XB1,0XC0,0XC1,
0XC8,0XC9,0XCA,0XD0,0XE0,0XF0,0XF1,0
};
const uint8 LCD_REG_PARAS[]=
{
0XCD,0XF2,0X10,0X80,0X6B,0X00,0X91,0X27,0XEF,0X00,0X00,0X27,0XEF,0X00,0X00,0X00,
0X00,0X00,0X00,0XEF,0XAA,0X00,0X00,0X06,0X11,0X00,0X00,0X00,0X27,0XEF,0X00,0X0A,
0X80,0X80,0X00,0X80,0X00,0XA0,0X0F,0
};
void delay(uint32 delay)
{
volatile uint32 i ;
volatile uint32 j ;
for(i = 0; i<delay ;i++)
for(j = 0; j<(uint32)100 ;j++);
}
void lcd_regwr(uint8 regnada)
{
/*
lcd_regnada = regnada;
lcd_cs1 =0; // chip enable.
lcd_rd = 1; //
lcd_rs = 0; // rs = 0;
lcd_wr = 0; // wr = 0;
;
lcd_wr = 1; // wr = 1;
lcd_rs = 1; // rs = 1;
lcd_cs1 =1; // chip disable.
*/
uint32 dataset,dataclr ;
dataset = regnada & 0xFF ;
dataclr = ( ~dataset ) & 0xFF ;
dataset = dataset << PDB0 ;
dataclr = dataclr << PDB0 ;
LCD_DB_SET = LCD_DB_SET | dataset ;
LCD_DB_CLR = LCD_DB_CLR | dataclr ;
LCD_nCS1_CLR = LCD_nCS1;
LCD_RS_CLR = LCD_RS;
//delay(1) ;
LCD_nRD_SET = LCD_nRD;
LCD_nWR_CLR = LCD_nWR;
delay(1) ;
LCD_nWR_SET = LCD_nWR;
//delay(1) ;
LCD_RS_SET = LCD_RS;
LCD_nCS1_SET = LCD_nCS1;
}
void lcd_regwrite(uint8 regname,uint8 regdata)
{
lcd_regwr(regname);
delay(10);
lcd_regwr(regdata);
}
//.............................................
void lcd_datawrite(uint8 wrdata)
{
/*
while(lcd_busy == 1);
lcd_data = wrdata;
lcd_cs1 =0; // chip enable.
lcd_rd = 1; //
lcd_rs = 1; // rs = 1;
lcd_wr = 0; // wr = 0;
;
lcd_wr = 1; // wr = 1;
lcd_rs = 1; // rs = 1;
lcd_cs1 =1; // chip disable.
*/
uint32 dataset,dataclr ;
uint32 read;
LCD_BUSY_SET = ( LCD_BUSY ) ;
read = LCD_BUSY_PIN ;
read = read & LCD_BUSY ;
while (read)
{
//LCD_BUSY_SET = ( LCD_BUSY ) ;
read = LCD_BUSY_PIN ;
read = read & LCD_BUSY ;
}
//delay(50) ;
dataset = wrdata & 0xFF ;
dataclr = ( ~dataset ) & 0xFF ;
dataset = dataset << PDB0 ;
dataclr = dataclr << PDB0 ;
LCD_DB_SET = LCD_DB_SET | dataset ;
LCD_DB_CLR = LCD_DB_CLR | dataclr ;
LCD_nCS1_CLR = LCD_nCS1;
LCD_RS_SET = LCD_RS;
//delay(1) ;
LCD_nRD_SET = LCD_nRD;
LCD_nWR_CLR = LCD_nWR;
delay(1) ;
LCD_nWR_SET = LCD_nWR;
//delay(1) ;
LCD_RS_SET = LCD_RS;
LCD_nCS1_SET = LCD_nCS1;
}
void lcd_character(uint8 * cha,int count)
{ //显示中文或字符
int i;
for(i=0;i<count;i++)
{
lcd_datawrite(*cha);
++cha;
}
}
//.............................................
void lcd_character1(int count)
{ //显示中文或字符
lcd_datawrite(count);
}
//.............................................
extern void gotoxy(uint8 x,uint8 y)
{ //定坐标
lcd_regwrite(0x60,x); // active window top register(awtr)
lcd_regwrite(0x70,y); // active window top register(awtr)
}
uint8 tab5[]={
"0123456789"
};
//.............................................
uint8 lcd_regread(uint8 regname)
{ //读缓存器
uint8 reg_rddata;
lcd_regwr(regname);
/*
lcd_data = 0xff;
lcd_cs1 =0; // chip enable.
lcd_wr = 1; // wr = 1;
lcd_rs = 0; // rs = 0;
lcd_rd = 0; // rd = 0;
;
reg_rddata = lcd_data;
lcd_rd = 1; // rd = 1;
lcd_rs = 1; // rs = 1;
lcd_cs1 =1; // chip disable.
*/
return(reg_rddata);
}
//=============================================
//.............................................
void lcd_clear(void)
{ //清屏
uint8 reg_rddata;
lcd_regwrite(0xe0,0x00);
//reg_rddata = lcd_regread(0xf0);
reg_rddata = 0xA8;
lcd_regwrite(0xf0,reg_rddata);
}
//.............................................
void lcd_photo(uint8 *pho)
{ //显示图形
uint8 i,j,k;
uint8 *pp;
for(k=0;k<4;k++)
{
pp=pho;
for(j=0;j<60;j++)
{
for(i=0;i<40;i++)
{
lcd_datawrite(*pp);
++pp;
}
}
}
}
//.............................................
void lcd_lattice(uint8 data1,uint8 data2)
{ //显示点阵
uint8 i,j;
for(j=0;j<60;j++)
{
for(i=0;i<80;i++)
{
lcd_datawrite(data1);
}
for(i=0;i<80;i++)
{
lcd_datawrite(data2);
}
}
}
//.............................................
//.............................................
void lcd_reset(void)
{ //上电复位
delay(1200); // delay 120ms 等待上电复位
LCD_RS_SET = LCD_RS;
LCD_nWR_SET = LCD_nWR;
LCD_CS2_SET = LCD_CS2;
LCD_nRD_SET = LCD_nRD;
LCD_RS_SET = LCD_RS;
LCD_nCS1_SET = LCD_nCS1;
LCD_nRST_CLR = LCD_nRST_CLR | LCD_nRST ;
delay(1000) ;
LCD_nRST_SET = LCD_nRST_SET | LCD_nRST ;
delay(2000) ;
// lcd_control = 0xff; // lcd_rs/wr/rd/cs1/cs2 normal - skeep high.
}
void LCDInit(void)
{
volatile uint8 i ;
volatile uint16 j ;
volatile uint32 tmp32 ;
/*
#define PDB7 26 //P1.26
#define PDB6 25 //P1.25
#define PDB5 24 //P1.24
#define PDB4 23 //P1.23
#define PDB3 22 //P1.22
#define PDB2 21 //P1.21
#define PDB1 20 //P1.20
#define PDB0 19 //P1.19
#define PnRST 09 //P0.9
#define PCS2 08 //P0.8
#define PnCS1 07 //P0.7
#define PnRD 06 //P0.6
#define PnWR 07 //P2.7
#define PRS 06 //P2.6
#define PINT 25 //P3.25
#define PBUSY 26 //P3.26
*/
/*
设置管脚功能
*/
PINSEL3 = PINSEL3 & (~ ( (1 << ((PDB0 - 16) * 2)) + (1<<((PDB0 - 16) * 2 + 1)) +
(1 << ((PDB1 - 16) * 2)) + (1<<((PDB1 - 16) * 2 + 1)) +
(1 << ((PDB2 - 16) * 2)) + (1<<((PDB2 - 16) * 2 + 1)) +
(1 << ((PDB3 - 16) * 2)) + (1<<((PDB3 - 16) * 2 + 1)) +
(1 << ((PDB4 - 16) * 2)) + (1<<((PDB4 - 16) * 2 + 1)) +
(1 << ((PDB5 - 16) * 2)) + (1<<((PDB5 - 16) * 2 + 1)) +
(1 << ((PDB6 - 16) * 2)) + (1<<((PDB6 - 16) * 2 + 1)) +
(1 << ((PDB7 - 16) * 2)) + (1<<((PDB7 - 16) * 2 + 1))
) ) ;
PINSEL0 = PINSEL0 & (~ ( (1<<(PnRST *2)) + (1<<(PnRST *2 + 1)) +
(1<<(PCS2 *2)) + (1<<(PCS2 *2 + 1)) +
(1<<(PnCS1 *2)) + (1<<(PnCS1 *2 + 1)) +
(1<<(PnRD *2)) + (1<<(PnRD *2 + 1))
) ) ;
PINSEL4 = PINSEL4 & ( ~ ( (1<<(PnWR *2)) + (1<<(PnWR *2 + 1)) +
(1<<(PRS *2)) + (1<<(PRS *2 + 1))
)) ;
PINSEL7 = PINSEL7 & ( ~ ( (1<<((PINT - 16) *2)) + (1<<((PINT - 16) *2 + 1)) +
(1<<((PBUSY - 16) *2)) + (1<<((PBUSY - 16) *2 + 1))
)) ;
LCD_nWR_MASK = LCD_nWR_MASK &(~( ( 1<<PnWR ))) ; //GPIO_OUTPUT
LCD_RS_MASK = LCD_RS_MASK &(~( ( 1<<PRS ))) ; //GPIO_OUTPUT
LCD_INT_MASK = LCD_INT_MASK &(~( ( 1<<PINT ))) ; //GPIO_OUTPUT
LCD_BUSY_MASK = LCD_BUSY_MASK &(~( ( 1<<PBUSY ))) ; //GPIO_OUTPUT
/*
设置GPIO 方向
*/
LCD_DB_DIR = LCD_DB_DIR | ( ( 1<<PDB7 ) +
( 1<<PDB6 ) +
( 1<<PDB5 ) +
( 1<<PDB4 ) +
( 1<<PDB3 ) +
( 1<<PDB2 ) +
( 1<<PDB1 ) +
( 1<<PDB0 )
) ;
LCD_nRST_DIR = LCD_nRST_DIR | (( 1<<PnRST )) ; //GPIO_OUTPUT
LCD_CS2_DIR = LCD_CS2_DIR | (( 1<<PCS2 )) ; //GPIO_OUTPUT
LCD_nCS1_DIR = LCD_nCS1_DIR | (( 1<<PnCS1 )) ; //GPIO_OUTPUT
LCD_nRD_DIR = LCD_nRD_DIR | (( 1<<PnRD )) ; //GPIO_OUTPUT
LCD_nWR_DIR = LCD_nWR_DIR | (( 1<<PnWR )) ; //GPIO_OUTPUT
LCD_RS_DIR = LCD_RS_DIR | (( 1<<PRS )) ; //GPIO_OUTPUT
//LCD_INT_DIR = LCD_INT_DIR & (~( 1<<PINT )) ; //GPIO_INTPUT
//LCD_BUSY_DIR = LCD_BUSY_DIR & (~( 1<<PBUSY )) ; //GPIO_INPUT
LCD_INT_DIR = LCD_INT_DIR & (~( 1<<PINT )) ; //GPIO_INTPUT
LCD_BUSY_DIR = LCD_BUSY_DIR & (~( 1<<PBUSY )) ; //GPIO_INPUT
LCD_BUSY_SET = ( LCD_BUSY ) ;
LCD_INT_SET = ( LCD_INT ) ;
/*
设置低电平
*/
LCD_nRST_CLR = ( 1<<PnRST ) ;
LCD_CS2_CLR = ( 1<<PCS2 ) ;
LCD_nCS1_CLR = ( 1<<PnCS1 ) ;
LCD_nRD_CLR = ( 1<<PnRD ) ;
LCD_nWR_CLR = ( 1<<PnWR ) ;
LCD_RS_CLR = ( 1<<PRS ) ;
LCD_DB_CLR = ( 1<<PDB7 ) + //P1.26
( 1<<PDB6 ) + //P1.25
( 1<<PDB5 ) + //P1.24
( 1<<PDB4 ) + //P1.23
( 1<<PDB3 ) + //P1.22
( 1<<PDB2 ) + //P1.21
( 1<<PDB1 ) + //P1.20
( 1<<PDB0 ) ; //P1.19
/*
设置高电平
*/
LCD_nRST_SET = ( 1<<PnRST ) ;
LCD_CS2_SET = ( 1<<PCS2 ) ;
LCD_nCS1_SET = ( 1<<PnCS1 ) ;
LCD_nRD_SET = ( 1<<PnRD ) ;
LCD_nWR_SET = ( 1<<PnWR ) ;
LCD_RS_SET = ( 1<<PRS ) ;
LCD_DB_SET = ( 1<<PDB7 ) + //P1.26
( 1<<PDB6 ) + //P1.25
( 1<<PDB5 ) + //P1.24
( 1<<PDB4 ) + //P1.23
( 1<<PDB3 ) + //P1.22
( 1<<PDB2 ) + //P1.21
( 1<<PDB1 ) + //P1.20
( 1<<PDB0 ) ; //P1.19
/*
设置低电平
*/
LCD_nRST_CLR = ( 1<<PnRST ) ;
LCD_CS2_CLR = ( 1<<PCS2 ) ;
LCD_nCS1_CLR = ( 1<<PnCS1 ) ;
LCD_nRD_CLR = ( 1<<PnRD ) ;
LCD_nWR_CLR = ( 1<<PnWR ) ;
LCD_RS_CLR = ( 1<<PRS ) ;
LCD_DB_CLR = ( 1<<PDB7 ) + //P1.26
( 1<<PDB6 ) + //P1.25
( 1<<PDB5 ) + //P1.24
( 1<<PDB4 ) + //P1.23
( 1<<PDB3 ) + //P1.22
( 1<<PDB2 ) + //P1.21
( 1<<PDB1 ) + //P1.20
( 1<<PDB0 ) ; //P1.19
LCD_BUSY_SET = ( LCD_BUSY ) ;
LCD_DB_PIN = 0xFFFFFFFF ;
LCD_DB_PIN = 0 ;
LCD_DB_PIN = 0xFFFFFFFF ;
lcd_reset();
for(i=0;i<39;i++)
lcd_regwrite(LCD_REG_ADDR[i],LCD_REG_PARAS[i]); // lcd control register(lcr)
lcd_clear();
//LCD_RegWrite(LCD_REG_ADDR[i],LCD_REG_PARAS[i]);
//lcd_character(tab4,160);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -