jhd-12232d使用总结(与大多数12232相同)

来源:互联网 发布:毒萝脸型数据当战 编辑:程序博客网 时间:2024/05/17 05:18
概述:
JHD12232D与另外两款LCD,MG-12232与TG12232B,极为相似,他们使用的都是SED1520芯片,都是有18个接口,只是在个别的接口是高电平有效还是低电平有效上有一些区别。
 
参考文档(这些文档放在项目备份盘中)
JHD(晶汉达)公司网站上下载的三份相关PDF(接口以英文版为准)
MCU123.NET文件夹中的TG12232B.PDF与示例程序
SED1520.PDF中文版:这应该是某个公司为自己的产品写的文档,不是SED1520芯片的官方文档,但里面关于程序编写的流程很是实用
SED1520官方参考,官方参考一定是有用的
 
点阵的分布
JHD12232D的点阵布局
JHD12232D的两个SED芯片是左右分布的(好像有些别的型号的LCD是上下分布的),左右两个芯片各有一个指针指向当前要读写的显示RAM。所以要对某个显示RAM操作时,应设定其芯片的当前指针,具体要指定:设定在哪个芯片的哪页,设定在哪个芯片的哪列,在读写显示RAM时,要指定写到哪个芯片里去。如要将0XF3写到右边芯片的第二页的写40列,则应设置右边芯片的页为2,设置右边芯片的列为40,再把0XF3写到右边芯片中去。
 
引脚连线的问题
引脚的连线一定要参照LCD的官方文档,不同LCD的工作电压、接口都有可能是不同的。
RES : 当RES为高电平时,LCD正常工作,当其为低电平时,复位
Vo : 对比度调节,一般可以接低电平,如果需要调节对比度的话,可以将此接口接在滑动变阻器的滑动脚上,变阻器的另外两个脚分别接+5伏和-5伏,不过在调节时注意其电压,对于JHD12232D,其最小值为-5.5V。
LED+:应该连一个250欧电阻之后再接5V
 
程序的编写
SED1520.pdf中有程序流程图
当E1、E2为高电平时,数据被发送到总线上,当其在下降沿时,数据被锁存在SED1520中。
 
注意事项:
LCD要在程序初始化之后才能使用。
如果不改变页和列,不停地向一个芯片中写数据,当当前指针超出范围,之后的写操作不会引起LCD显示的改变。
 
 程序
//defs.h
#define LCD_DATA    P1

#define D0    P1_0
#define D1    P1_1
#define D2    P1_2
#define D3    P1_3
#define D4    P1_4
#define D5    P1_5
#define D6    P1_6
#define D7    P1_7

#define E1    P3_5
#define E2    P3_4
#define RW    P3_3
#define A0    P3_7    

#define LOW     0
#define HIGH    1

#define uchar     unsigned char
#define uint    unsigned int
#define byte    unsigned char

#define LONGDELAY    for( i_loop = 0 ; i_loop < 300 ; ++i_loop )delay2(100);
#define LONGLONGDELAY    for( i_loop = 0 ; i_loop < 10000 ; ++i_loop )delay2(100);

#define CMD_DISPLAY_ON    0xAF
#define CMD_DISPLAY_OFF    0xAE
#define CMD_DISPLAY_START_LINE    0xC0    // | ,when use it
#define CMD_PAGE_ADDR_SET    0xB8        // | ,when use it
#define CMD_COLUMN_ADDR_SET    0x00        // |, when use it
#define CMD_RESET    0xE2    

#define LCD_Reset(); LCD_Write_Cmd( CMD_RESET,1 );
#define LCD_Display_ON();    LCD_Write_Cmd( CMD_DISPLAY_ON,1 );LCD_Write_Cmd( CMD_DISPLAY_ON,2 );    
#define LCD_Display_OFF();    LCD_Write_Cmd( CMD_DISPLAY_OFF,1 );LCD_Write_Cmd( CMD_DISPLAY_OFF,2 );

 

//func.h
#include "defs.h"
void delay(uint n);
void delay2(uint n);
void LCD_Init(void);
void LCD_Write_Cmd( byte cmd ,uchar E_Select);
void LCD_Write_Data( byte cmd ,uchar E_Select);
void LCD_Set_Page( uchar pnum, uchar E_Select );
void LCD_Set_Col( uchar colnum, uchar E_Select );
void LCD_Show_Char( uchar chNum, uchar row, uchar big_col );
void LCD_Show_Str( uchar * pstr    );
void LCD_Show_One_Char( uchar chnum , uchar SED );
void LCD_Fill( uchar m_data);
void LCD_Fill_Page( uchar * p_data , uchar page);
uchar LCD_Get_Char_Index( uchar szText );
void LCD_Show_Str_2( uchar * pstr    );

 

 

//func.c
#include "defs.h"
#include 
"func.h"
#include 
"at89x51.h"

/*ASCII字体,大小6X8,上到下D0~D7,左到右*/
unsigned 
char code ASCII[][6]={{0x00,0x00,0x00,0x00,0x00,0x00},/*SPACE*/
                               
{
0x00,0x7e,0x21,0x21,0x21,0x7e},/*A*/
                               
{
0x00,0x7f,0x49,0x49,0x49,0x36},/*B*/
                               
{
0x00,0x3e,0x41,0x41,0x41,0x22},/*C*/
                               
{
0x00,0x7f,0x41,0x41,0x22,0x1c},/*D*/
                               
{
0x00,0x7f,0x49,0x49,0x49,0x49},/*E*/
                               
{
0x00,0x7f,0x09,0x09,0x09,0x01},/*F*/
                               
{
0x00,0x3e,0x41,0x49,0x49,0x7a},/*G*/
                               
{
0x00,0x7f,0x08,0x08,0x08,0x7f},/*H*/
                               
{
0x00,0x41,0x7f,0x41,0x00,0x00},/*I*/
                               
{
0x00,0x20,0x40,0x41,0x3f,0x01},/*J*/
                               
{
0x00,0x7f,0x08,0x14,0x22,0x41},/*K*/
                               
{
0x00,0x7f,0x40,0x40,0x40,0x40},/*L*/
                               
{
0x00,0x7f,0x02,0x0c,0x02,0x7f},/*M*/
                               
{
0x00,0x7f,0x04,0x08,0x10,0x7f},/*N*/
                               
{
0x00,0x3e,0x41,0x41,0x41,0x3e},/*O*/
                               
{
0x00,0x7f,0x09,0x09,0x09,0x06},/*P*/
                               
{
0x00,0x3e,0x41,0x41,0x41,0x3e},/*Q*/
                               
{
0x00,0x7f,0x09,0x19,0x29,0x46},/*R*/
                               
{
0x00,0x46,0x49,0x49,0x49,0x31},/*S*/
                               
{
0x00,0x01,0x01,0x7f,0x01,0x01},/*T*/
                               
{
0x00,0x3f,0x40,0x40,0x40,0x3f},/*U*/
                               
{
0x00,0x1f,0x20,0x40,0x20,0x1f},/*V*/
                               
{
0x00,0x3f,0x40,0x38,0x40,0x3f},/*W*/
                               
{
0x00,0x63,0x14,0x08,0x14,0x63},/*X*/
                               
{
0x00,0x07,0x08,0x70,0x08,0x07},/*Y*/
                               
{
0x00,0x61,0x51,0x49,0x45,0x43},/*Z*/
                               
{
0x00,0x20,0x54,0x54,0x54,0x7c},/*a*/
                               
{
0x00,0x7f,0x48,0x44,0x44,0x38},/*b*/
                               
{
0x00,0x38,0x44,0x44,0x44,0x20},/*c*/
                               
{
0x00,0x38,0x44,0x44,0x48,0x7f},/*d*/
                               
{
0x00,0x38,0x54,0x54,0x54,0x18},/*e*/
                               
{
0x00,0x08,0x7e,0x09,0x01,0x02},/*f*/
                               
{
0x00,0x0c,0x52,0x52,0x52,0x3e},/*g*/
                               
{
0x00,0x7f,0x08,0x04,0x04,0x78},/*h*/
                               
{
0x00,0x00,0x44,0x7d,0x40,0x00},/*i*/
                               
{
0x00,0x40,0x40,0x44,0x3d,0x00},/*j*/
                               
{
0x00,0x7f,0x10,0x28,0x44,0x00},/*k*/
                                 
{
0x00,0x00,0x41,0x7e,0x40,0x00},/*l*/
                               
{
0x00,0x7c,0x04,0x18,0x04,0x78},/*m*/
                               
{
0x00,0x7c,0x08,0x04,0x04,0x78},/*n*/
                               
{
0x00,0x38,0x44,0x44,0x44,0x38},/*o*/
                               
{
0x00,0x7c,0x14,0x14,0x14,0x08},/*p*/
                               
{
0x00,0x08,0x14,0x14,0x14,0x7c},/*q*/
                               
{
0x00,0x7c,0x08,0x04,0x04,0x08},/*r*/
                               
{
0x00,0x48,0x54,0x54,0x54,0x20},/*s*/
                                
{
0x00,0x04,0x3f,0x44,0x44,0x24},/*t*/
                               
{
0x00,0x3c,0x40,0x40,0x20,0x7e},/*u*/
                               
{
0x00,0x1d,0x20,0x40,0x20,0x1c},/*v*/
                               
{
0x00,0x3c,0x40,0x30,0x40,0x3c},/*w*/
                               
{
0x00,0x44,0x28,0x10,0x28,0x44},/*x*/
                               
{
0x00,0x06,0x48,0x48,0x48,0x3e},/*y*/
                               
{
0x00,0x44,0x64,0x54,0x4c,0x44},/*z*/
                               
{
0x00,0x00,0x01,0x02,0x04,0x00},/*`*/
                               
{
0x00,0x00,0x42,0x7f,0x40,0x40},/*1*/
                               
{
0x00,0x62,0x51,0x51,0x49,0x46},/*2*/
                               
{
0x00,0x21,0x41,0x45,0x4b,0x31},/*3*/
                               
{
0x00,0x18,0x14,0x12,0x7f,0x10},/*4*/
                               
{
0x00,0x27,0x45,0x45,0x45,0x39},/*5*/
                               
{
0x00,0x3c,0x4a,0x49,0x49,0x30},/*6*/
                               
{
0x00,0x01,0x71,0x09,0x05,0x03},/*7*/
                               
{
0x00,0x36,0x49,0x49,0x49,0x36},/*8*/
                               
{
0x00,0x06,0x49,0x49,0x29,0x1e},/*9*/
                               
{
0x00,0x3e,0x51,0x49,0x45,0x3e},/*0*/
                               
{
0x00,0x08,0x08,0x08,0x08,0x08},/*-*/
                               
{
0x00,0x14,0x14,0x14,0x14,0x14},/*=*/
                               
{
0x00,0x01,0x02,0x08,0x10,0x20},/**/
                               
{
0x00,0x04,0x08,0x04,0x08,0x04},/*~*/
                               
{
0x00,0x00,0x00,0x4f,0x00,0x00},/*!*/
                               
{
0x00,0x3e,0x59,0x55,0x79,0x3e},/*@*/
                               
{
0x00,0x14,0x7f,0x14,0x7f,0x14},/*#*/
                               
{
0x00,0x24,0x2a,0x7f,0x2a,0x12},/*$*/
                               
{
0x00,0x23,0x13,0x08,0x62,0x61},/*%*/
                               
{
0x00,0x04,0x02,0x01,0x02,0x04},/*^*/
                               
{
0x00,0x36,0x49,0x55,0x22,0x50},/*&*/
                               
{
0x00,0x14,0x08,0x3e,0x08,0x14},/***/
                               
{
0x00,0x00,0x1c,0x22,0x41,0x00},/*(*/
                               
{
0x00,0x00,0x41,0x22,0x1c,0x00},/*)*/
                               
{
0x00,0x40,0x40,0x40,0x40,0x40},/*_*/
                               
{
0x00,0x08,0x08,0x3e,0x08,0x08},/*+*/
                               
{
0x00,0x00,0x00,0x7e,0x00,0x00},/*|*/
                               
{
0x00,0x00,0x7f,0x41,0x41,0x00},/*[*/
                               
{
0x00,0x00,0x41,0x41,0x7f,0x00},/*]*/
                               
{
0x00,0x00,0x56,0x36,0x00,0x00},/*;*/
                               
{
0x00,0x00,0x00,0x05,0x03,0x00},/**/
                               
{
0x00,0x00,0x00,0x28,0x18,0x00},/*,*/
                               
{
0x00,0x00,0x00,0x60,0x60,0x00},/*.*/
                               
{
0x00,0x20,0x10,0x08,0x04,0x02},/*//*/
                               
{
0x00,0x00,0x08,0x36,0x41,0x00},/*{*/
                               
{
0x00,0x00,0x41,0x36,0x08,0x00},/*}*/
                               
{
0x00,0x00,0x36,0x36,0x00,0x00},/*:*/
                               
{
0x00,0x00,0x00,0x07,0x00,0x07},/*"*/
                               
{
0x00,0x08,0x14,0x22,0x41,0x00},/*<*/
                               
{
0x00,0x00,0x41,0x22,0x14,0x08},/*>*/
                               
{
0x00,0x02,0x01,0x51,0x09,0x06}/*?*/
                               };


void delay(uint n){
    
//while(--n);
}
void delay2(uint n){
    
while(--n);
}

/************************************************ 
 * Initial the LCD
 * Written by Manio
 * 
http://www.manio.cn http://blog.csdn.net
 ***********************************************
*/
void LCD_Init(void){
    E1 
= 0;
    E2 
= 0;
    LCD_Write_Cmd( 
0xE21 );
    LCD_Write_Cmd( 
0xA41 );
    LCD_Write_Cmd( 
0xA91 );
    LCD_Write_Cmd( 
0xA01 );
    LCD_Write_Cmd( 
0xAF1 );
    LCD_Write_Cmd( 
0xC01 );

    LCD_Write_Cmd( 
0xE22 );
    LCD_Write_Cmd( 
0xA42 );
    LCD_Write_Cmd( 
0xA92 );
    LCD_Write_Cmd( 
0xA02 );
    LCD_Write_Cmd( 
0xAF2 );
    LCD_Write_Cmd( 
0xC02 );

    LCD_Fill(
0); //clear the screen
}


/************************************************ 
 * Write Command to the LCD
 * Written by Manio
 * 
http://www.manio.cn http://blog.csdn.net
 ***********************************************
*/
void LCD_Write_Cmd( byte cmd ,uchar E_Select){
    
if( E_Select == 1)
        E1 
= LOW;
    
else
        E2 
= LOW;
    RW 
= LOW;
    A0 
= LOW;
    LCD_DATA 
= cmd;
    delay(
400);
    
if( E_Select == 1)
        E1 
= HIGH;
    
else
        E2 
= HIGH;
    delay(
4);
    
if( E_Select == 1)
        E1 
= LOW;
    
else
        E2 
= LOW;
    delay(
100);        
}

/************************************************ 
 * Write Data to the LCD
 * Written by Manio
 * 
http://www.manio.cn http://blog.csdn.net
 ***********************************************
*/
void LCD_Write_Data( byte cmd ,uchar E_Select){
    
if( E_Select == 1)
        E1 
= LOW;
    
else
        E2 
= LOW;
    RW 
= LOW;
    A0 
= HIGH;
    LCD_DATA 
= cmd;
    delay(
400);
    
if( E_Select == 1)
        E1 
= HIGH;
    
else
        E2 
= HIGH;
    delay(
4);
    
if( E_Select == 1)
        E1 
= LOW;
    
else
        E2 
= LOW;
    delay(
100);        
}

/************************************************ 
 * Set the current page
 * Written by Manio
 * 
http://www.manio.cn http://blog.csdn.net
 ***********************************************
*/
void LCD_Set_Page( uchar pnum, uchar E_Select ){
    LCD_Write_Cmd( CMD_PAGE_ADDR_SET 
| pnum, E_Select );    
}

/************************************************ 
 * Set the current column to the position
 * Written by Manio
 * 
http://www.manio.cn http://blog.csdn.net
 ***********************************************
*/
void LCD_Set_Col( uchar colnum, uchar E_Select ){
    LCD_Write_Cmd( CMD_COLUMN_ADDR_SET 
| colnum, E_Select );
}

/************************************************ 
 * Shw one char in the current position
 * Written by Manio
 * 
http://www.manio.cn http://blog.csdn.net
 ***********************************************
*/
void LCD_Show_One_Char( uchar chnum , uchar SED ){
    uchar i 
= 0;

    
for( i = 0 ; i < 6 ; ++i){
        LCD_Write_Data( ASCII[ LCD_Get_Char_Index(chnum) ][i] ,SED );
        
    }    
}

/************************************************ 
 * Show strings in one screen,if it is too long ,the part out of range won't show.
 * Written by Manio
 * 
http://www.manio.cn http://blog.csdn.net
 ***********************************************
*/
void LCD_Show_Str( uchar * pstr    ){
    uchar i 
= 0 ,SED = 1, pageL = 0, pageR = -1;
    LCD_Fill(
0);
    LCD_Set_Page(
0,1);
    LCD_Set_Page(
0,2);
    LCD_Set_Col( 
11 ); //start at 1px
 while( pstr[i] != '/0' ){
  
  if( i % 10 == 0 && i != 0 ){
   if( SED == 1 ){
    SED = 2;
    ++pageR;
    LCD_Set_Page(pageR,SED);
    LCD_Set_Col( 0, SED );       
   }else{
    SED = 1;
    ++pageL;
    if( pageL == 4 ) break;
    LCD_Set_Page(pageL,SED);
    LCD_Set_Col( 1, SED );//start at 1px   
   }             
  }
  LCD_Show_One_Char(pstr[i],SED);
  ++i;
 }
}
/************************************************
 * Show long strings in divided screens
 * Written by Manio
 * http://www.manio.cn http://blog.csdn.net
 ************************************************/
void LCD_Show_Str_2( uchar * pstr ){
 uint i, strlength=0;
 uchar k;
 while( pstr[strlength++] != '/0' );
 --strlength;
 for( i = 0 ; i < strlength ; i += 80 ){
  LCD_Show_Str( &pstr[i] );
  for( k = 0; k < 100 ; ++k )delay2(20000);  
 }
 
  
}
/************************************************
 * Fill the whole LCD
 * Written by Manio
 * http://www.manio.cn http://blog.csdn.net
 ************************************************/
void LCD_Fill( uchar m_data){
 uchar j,k;
 for( j = 0 ; j < 4 ; ++j ){ 
  LCD_Set_Page( j , 1 );
  LCD_Set_Page( j , 2 );
  LCD_Set_Col( 0, 1 );
  LCD_Set_Col( 0, 2 ); 
  for( k = 0 ; k < 61 ; ++k ){
   LCD_Write_Data( m_data, 1);
   LCD_Write_Data( m_data, 2);   
  }
 }
}
/************************************************
 * Fill one page
 * Written by Manio
 * http://www.manio.cn http://blog.csdn.net
 ************************************************/
void LCD_Fill_Page( uchar * p_data , uchar page){
 uchar i=0,k;
 LCD_Set_Page( page, 1 );
 LCD_Set_Page( page, 2 );
 LCD_Set_Col( 0, 1 );
 LCD_Set_Col( 0, 2 );
 
 for( k = 0 ; k < 61 ; ++k )
  LCD_Write_Data( p_data[i++], 1 );
 for( k = 0 ; k < 61 ; ++k )
  LCD_Write_Data( p_data[i++], 1 );
}
uchar LCD_Get_Char_Index( uchar szText ){
    unsigned char code TAB[]={' ',
                       
      'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q'
,'R','S','T','U','V','W','X','Y','Z',
                       
      'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q'
,'r','s','t','u','v','w','x','y','z',
                       
      '`','1','2','3','4','5','6','7','8','9','0','-','=','//',
                       
      '~','!','@','#','$','%','^','&','*','(',')','_','+','|',
                       
      '[',']',';','/'',',','.','/',
                       
      '{','}',':','"','<','>','?'
                            
    };
 uchar i;
 for( i = 0 ; i < 95 ; ++i ){
  if( szText == TAB[i] )return i;
 }
 return 0;

}
/************************************************
 * Show one char in some position
 * Written by Manio
 * http://www.manio.cn http://blog.csdn.net
 ************************************************/
void LCD_Show_Char( uchar chnum, uchar row, uchar big_col ){
 uchar SED;
 
 //translate col to SED and col in SED
 if( big_col > 10 ){
  big_col = big_col%10 ;
  SED = 2;
  big_col = (big_col-1)*6;
 }else{
  SED = 1;
  big_col = (big_col-1)*6+1;
 }     
 //big_col = (big_col-1)*8;
 LCD_Set_Page( row, SED );
 LCD_Set_Col( big_col, SED);
 LCD_Show_One_Char( chnum, SED );       

}

 

//main.c
#include "at89x51.h"
#include 
"func.h"



int main()
{

    
uint i, i_loop;
    uchar j,k;
    code uchar copyright[]
="All Rights Reseverd! This is a product designed by Manio.@_@ *_* -_-| $_$ ^_^ #_# ()_() On another foreign policy topic, Biden said he would send 2,500 U.S. troops to Darfur to try to end the civil war there. It took three tries to get Clinton to answer the same questions. She finally said U.S. ground troops don't belong in the fight because they are overextended in Iraq. ";

    LCD_Init();


LOOP2:
    LCD_Fill(
0);
    i 
= 'a';
    
for( j = 0 ; j < 4 ; ++j )
        
for( k = 1 ; k <= 20 ; ++k ){
            LCD_Show_Char( i
++, j, k  );
            
if( i == 'z'+1 ) i = 'A';
            
if( i == 'Z'+1 ) goto myend;
        }

myend:
LONGLONGDELAY
LONGLONGDELAY

LCD_Show_Str_2(copyright);

LONGLONGDELAY
LONGLONGDELAY    
goto LOOP2;        
}
原创粉丝点击