这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 综合技术 » 基础知识 » LPC2131,MS240128 那为高手在LPC2131上调试通过MS2401

共3条 1/1 1 跳转至

LPC2131,MS240128 那为高手在LPC2131上调试通过MS240128液晶屏?

院士
2006-09-17 18:14:16     打赏
LPC2131,MS240128 那为高手在LPC2131上调试通过MS240128液晶屏?



关键词: LPC2131     MS240128     高手     调试     通过    

院士
2006-12-22 22:43:00     打赏
2楼
问 OK? 1: 俺用的2132,自己做的板子//lcd.h
#ifndef __LCD_H
#define __LCD_H

extern void lcd_init(void);
extern void lcd_clr(void);
extern void lcd_clrscr(void);
extern void lcd_cursor_on(void);
extern void lcd_cursor_off(void);
extern void lcd_show_bmp(void);
extern void LCDShowIcon(unsigned char x, unsigned char y, unsigned char id);
extern void LCDShowIcon2(unsigned char x, unsigned char y, unsigned char id);
extern void lcd_print(unsigned char x, unsigned char y, unsigned char mode, char *p);
extern void lcd_puts(unsigned char x, unsigned char y, unsigned char *p);
extern void lcd_set_cursor_pos(unsigned char x, unsigned char y);

#endif


//lcd.c
#include "string.h"
#include "lpc213x.h"

#include "bus.h"
//#include "t1.h"
//#include "includes.h"
//#include "hz.inc"
#include "logo.inc"

#define BIT(x)  (1<<x)
#define SET_BIT(x, y)   (x|=(1<<y))
#define CLR_BIT(x, y)   (x&=~(1<<y))
#define GET_BIT(x, y)   (x&(1<<y))

// T6963C 端口定义
#define LCMDW        0x3E
#define LCMCW        0x3F

#define GraphAddrL       0x00          //图形首地址低8位
#define GraphAddrH       0x04          //图形首地址高8位
#define GraphicStartAddr 0x0400        //图形首地址
#define TextAddrL        0x00          //文本首地址低8位
#define TextAddrH        0x00          //文本首地址高8位
#define TextStartAddr    0x00          //文本首地址

#define LC_CUR_POS    0x21        // 光标位置设置
#define LC_CGR_POS    0x22        // CGRAM偏置地址设置
#define LC_ADD_POS    0x24        // 地址指针位置
#define LC_TXT_STP    0x40        // 文本区首址
#define LC_TXT_WID    0x41        // 文本区宽度
#define LC_GRH_STP    0x42        // 图形区首址
#define LC_GRH_WID    0x43        // 图形区宽度
#define LC_MOD_OR    0x80        // 显示方式:逻辑“或”
#define LC_MOD_XOR    0x81        // 显示方式:逻辑“异或”
#define LC_MOD_AND    0x82        // 显示方式:逻辑“与”
#define LC_MOD_TCH    0x83        // 显示方式:文本特征
#define LC_CUR_SHP    0xA0        // 光标形状选择:0xA0-0xA7表示光标占的行数
#define LC_AUT_WR    0xB0        // 自动写设置
#define LC_AUT_RD    0xB1        // 自动读设置
#define LC_AUT_OVR    0xB2        // 自动读/写结束
#define LC_INC_WR    0xC0        // 数据一次写,地址加1
#define LC_INC_RD    0xC1        // 数据一次读,地址加1
#define LC_DEC_WR    0xC2        // 数据一次写,地址减1
#define LC_DEC_RD    0xC3        // 数据一次读,地址减1
#define LC_NOC_WR    0xC4        // 数据一次写,地址不变
#define LC_NOC_RD    0xC5        // 数据一次读,地址不变
#define LC_SCN_RD    0xE0        // 屏读
#define LC_SCN_CP    0xE8        // 屏拷贝
#define LC_BIT_OP    0xF0        // 位操作:D0-D2:定义D0-D7位;D3:1置位;0:清除

//unsigned char LCDRamBuf[128][30];
volatile unsigned char cursor_x = 0;
volatile unsigned char cursor_y = 0;                            //光标的坐标
volatile unsigned char lcd_buf[16][32];

typedef struct typFNT_GB16    // 汉字字模显示数据结构
{
    unsigned char Index[3];
    unsigned char Msk[32];
} AAA;

#include "asc14.inc"
#include "hz14.inc"

unsigned char fnST01(void)        // 状态位STA1,STA0判断(读写指令和读写数据)
{
    unsigned char i;
    
    for(i=10;i>0;i--)
    {
        if((bus_inp(LCMCW) & 0x03) == 0x03)
            break;
    }
    return i;    // 若返回零,说明错误
}

unsigned char fnST3(void)        // 状态位ST3判断(数据自动写状态)
{
    unsigned char i;
    
    for(i=10;i>0;i--)
    {
        if((bus_inp(LCMCW) & 0x08) == 0x08)
            break;
    }
    return i;    // 若返回零,说明错误
}

unsigned char fnPR1(unsigned char uCmd,unsigned char uPar1,unsigned char uPar2)    // 写双参数的指令
{
    if(fnST01() == 0)
        return 1;
    bus_outp(LCMDW, uPar1);
    if(fnST01() == 0)
        return 2;
    bus_outp(LCMDW, uPar2);
    if(fnST01() == 0)
        return 3;
    bus_outp(LCMCW, uCmd);
    return 0;    // 返回0成功
}

unsigned char fnPR12(unsigned char uCmd)        // 写无参数的指令
{
    if(fnST01() == 0)
        return 1;
    bus_outp(LCMCW, uCmd);
    return 0;    // 返回0成功
}

unsigned char fnPR13(unsigned char uData)        // 写数据
{
    if(fnST3() == 0)
        return 1;
    bus_outp(LCMDW, uData);
    return 0;    // 返回0成功
}

void lcd_cursor_on(void)
{
    fnPR12(0x9F);
}    

void lcd_cursor_off(void)
{
    fnPR12(0x9C);
}  

void lcd_clr(void)
{
    unsigned short i, j;
    fnPR1(LC_ADD_POS,0x00,0x00);    // 置地址指针
    fnPR12(LC_AUT_WR);                // 自动写
    for (i=0; i<128; i++)
    {
        for (j=0; j<30; j++)
        {
            fnPR13(logo[i][j]);            // 写数据
        }
        //OSSched();
    }
    fnPR12(LC_AUT_OVR);                // 自动写结束
    fnPR1(LC_ADD_POS,0x00,0x00);    // 重置地址指针
}

void lcd_set_cursor_pos(unsigned char x,unsigned char y)
{
    cursor_x = x;
    cursor_y = y;
    fnPR1(LC_CUR_POS, x, y);         //X的取值范围0-29;Y的取值范围0-15;
}

void lcd_clr_screen(unsigned short ram)
{
    unsigned short i;
                                                                //清显示 RAM 区 0000h--2000h (8k)
    fnPR1(LC_ADD_POS, 0x00, 0x00);    // 置地址指针
    fnPR12(LC_AUT_WR);                // 自动写
    for (i=0; i<ram; i++)
    {
        if (i<0x1800)
        {
            fnPR13(0x00);            // 写数据
        }
        else
        {
            fnPR13(ASC_MSK[i-0x1800]);
        }
    }
    fnPR12(LC_AUT_OVR);                // 自动写结束
    fnPR1(LC_ADD_POS, 0x00, 0x00);    // 重置地址指针
}

void lcd_show_bmp(void)
{
    unsigned short i, j;
    fnPR1(LC_ADD_POS, GraphAddrL, GraphAddrH);    // 置地址指针
    fnPR12(LC_AUT_WR);                // 自动写
    for (i=0; i<128; i++)
    {
        for (j=0; j<30; j++)
        {
            fnPR13(logo[i][j]);            // 写数据
        }
    }
    fnPR12(LC_AUT_OVR);                // 自动写结束
    fnPR1(LC_ADD_POS,0x00,0x00);    // 重置地址指针
}

void lcd_init(void)
{
    fnPR1(LC_GRH_STP, GraphAddrL, GraphAddrH);    // 图形显示区首地址
//    T1_delay10ms();
    fnPR1(LC_GRH_STP, GraphAddrL, GraphAddrH);    // 图形显示区首地址
//    T1_delay10ms();
    fnPR1(LC_GRH_WID, 0x1E, 0x00);    // 图形显示区宽度
//    T1_delay10ms();
    fnPR1(LC_GRH_WID, 0x1E, 0x00);    // 图形显示区宽度
//    T1_delay10ms();
    fnPR1(LC_TXT_STP, 0x00, 0x00);    // 文本显示区首地址
//    T1_delay10ms();
    fnPR1(LC_TXT_STP, 0x00, 0x00);    // 文本显示区首地址
//    T1_delay10ms();
    fnPR1(LC_TXT_WID, 0x1E, 0x00);    // 文本显示区宽度
//    T1_delay10ms();
    fnPR1(LC_TXT_WID, 0x1E, 0x00);    // 文本显示区宽度
//    T1_delay10ms();
    fnPR12(LC_CUR_SHP | 0x07);        // 光标形状
//    T1_delay10ms();
    fnPR12(LC_CUR_SHP | 0x07);        // 光标形状
//    T1_delay10ms();
    fnPR1(0x22, 0x03, 0x00);         //偏址地址设在0x02
//    T1_delay10ms();
    fnPR1(0x22, 0x03, 0x00);         //偏址地址设在0x02
//    T1_delay10ms();
    lcd_clr_screen(0x2000);
//    T1_delay10ms();
    fnPR12(0x88);                // 显示方式设置
//    T1_delay10ms();
    fnPR12(0x88);                // 显示方式设置
//    T1_delay10ms();
    fnPR12(0x9C);        // 显示开关设置
//    T1_delay10ms();
    fnPR12(0x9C);        // 显示开关设置
//    T1_delay10ms();
    lcd_set_cursor_pos(0, 0);
//    T1_delay10ms();
}

void lcd_clrscr(void)
{
    unsigned short i, j;
    fnPR1(LC_ADD_POS, 0x00, 0x00);    // 置地址指针
    fnPR12(LC_AUT_WR);                // 自动写
    for (i=0; i<40; i++)
    {
        for (j=0; j<128; j++)
        {
            fnPR13(0x00);            // 写数据
        }
    }
    fnPR12(LC_AUT_OVR);                // 自动写结束
    fnPR1(LC_ADD_POS,0x00,0x00);    // 重置地址指针
}

void lcd_set_pos(unsigned char urow, unsigned char ucol)
{
    unsigned short iPos = GraphicStartAddr;
    iPos += urow * 30 + ucol;
    fnPR1(LC_ADD_POS,iPos & 0xFF,iPos / 256);
    //gCurRow = urow;
    //gCurCol = ucol;
}

void lcd_set_pos2(unsigned char x, unsigned char y)
{
    unsigned short iPos = GraphicStartAddr;
    iPos += y * 30 + x;
    fnPR1(LC_ADD_POS,iPos & 0xFF,iPos / 256);
    //gCurRow = urow;
    //gCurCol = ucol;
}

void LCDShowIcon(unsigned char x, unsigned char y, unsigned char id)
{   
    unsigned char i, j;

    for (i=0; i<32; i++)
    {
           lcd_set_pos(y+i, x);
           fnPR12(LC_AUT_WR);
        for(j=0;j<4;j++)
        {

            fnPR13(icon[id][i][j]);
        }
        fnPR12(LC_AUT_OVR);
    }                            
}

void LCDShowIcon2(unsigned char x, unsigned char y, unsigned char id)
{   
    unsigned char i, j;

    for (i=0; i<32; i++)
    {
           lcd_set_pos(y+i, x);
           fnPR12(LC_AUT_WR);
        for(j=0;j<4;j++)
        {

            fnPR13(~icon[id][i][j]);
        }
        fnPR12(LC_AUT_OVR);
    }                                            
}

void lcd_print(unsigned char x, unsigned char y, unsigned char mode, char *p)
{   
    unsigned char c1, c2;
    unsigned char i, j, len;
    unsigned char col;    
    unsigned short k;

    i = 0;
    col = 0;
    len = strlen((char*)p);
  
    if (mode == 0)
    {
        while (i < len)
        {
            c1 = p[i];
            c2 = p[i+1];
            if(c1 < 0x80)
            {    
                // ASCII
                for(j=0;j<16;j++)
                {
                    lcd_buf[j][col] = ASC_MSK[c1*16+j];
                }                            
                col++;
            }
            else
            {    // 中文
                for(j=0;j<sizeof(GB_16)/sizeof(GB_16[0]);j++)
                {
                    if(c1 == GB_16[j].Index[0] && c2 == GB_16[j].Index[1])
                        break;
                }
                for(k=0;k<16;k++)
                {
                    lcd_buf[k][col] = GB_16[j].Msk[k*2];
                    lcd_buf[k][col+1] = GB_16[j].Msk[k*2+1];
                }
                col += 2;
                i++;
            }
            i++;
        }
    }
    else
    {
        while (i < len)
        {
            c1 = p[i];
            c2 = p[i+1];
            if(c1 < 0x80)
            {    
                // ASCII
                for(j=0;j<16;j++)
                {
                    lcd_buf[j][col] = ~ASC_MSK[c1*16+j];
                }                            
                col++;
            }
            else
            {    // 中文
                for(j=0;j<sizeof(GB_16)/sizeof(GB_16[0]);j++)
                {
                    if(c1 == GB_16[j].Index[0] && c2 == GB_16[j].Index[1])
                        break;
                }
                for(k=0;k<16;k++)
                {
                    lcd_buf[k][col] = ~GB_16[j].Msk[k*2];
                    lcd_buf[k][col+1] = ~GB_16[j].Msk[k*2+1];
                }
                col += 2;
                i++;
            }
            i++;
        }
    }
        

    for (i=0; i<16; i++)
    {
        lcd_set_pos2(x, y+i);
        fnPR12(LC_AUT_WR);
        for (j=0; j<len; j++)
        {
            fnPR13(lcd_buf[i][j]);
        }
        fnPR12(LC_AUT_OVR);
    }
    
}

void lcd_putchar(unsigned char x, unsigned char y, unsigned char c)
{
    unsigned short pos;
    
    pos = 60*y + x;
    fnPR1(LC_ADD_POS, (unsigned char)pos, pos>>8);
    fnPR12(LC_AUT_WR);
    fnPR13(c*2);
    fnPR12(LC_AUT_OVR);
    pos += 30;
    fnPR1(LC_ADD_POS, (unsigned char)pos, pos>>8);
    fnPR12(LC_AUT_WR);
    fnPR13(c*2+1);
    fnPR12(LC_AUT_OVR);
}

void lcd_puts(unsigned char x, unsigned char y, unsigned char *p)
{
    while(*p)
    {
        lcd_putchar(x, y, *p);
        x++;
        p++;
    }
}


//bus.h
#ifndef __BUS_H
#define __BUS_H

extern void bus_init(void);
extern void bus_outp(unsigned char port, unsigned char c);
extern unsigned char bus_inp(unsigned char port);

#endif

//bus.c
#include "lpc213x.h"

#define BIT(x)  (1<<x)
#define SET_BIT(x, y)   (x|=(1<<y))
#define CLR_BIT(x, y)   (x&=~(1<<y))
#define GET_BIT(x, y)   (x&(1<<y))

void bus_init(void)
{
    CLR_BIT(PINSEL2, 2);
    CLR_BIT(PINSEL2, 3);
    IODIR1 &= 0xFF00FFFF;
    //RD
    IOSET1 = BIT(30);
    //WR
    IOSET1 = BIT(31);
    IODIR1 |= 0xFF000000;
}

void bus_outp(unsigned char port, unsigned char c)
{
    unsigned int dat;
    
    //A0-A7
    dat = (port&0x03)|((port>>5)<<2);
    dat <<= 24;
    IOPIN1 = (IOPIN1&0xE0FFFFFF)|dat;
    //DIR
    IOCLR1 = BIT(29);
    //D0-D7
    IODIR1 |= 0x00FF0000;
    dat = c;
    dat <<= 16;
    IOPIN1 = (IOPIN1&0xFF00FFFF)|dat;
    //WR
    IOCLR1 = BIT(31);
    IOSET1 = BIT(31);
}

unsigned char bus_inp(unsigned char port)
{
    unsigned char c;
    unsigned int  dat;
    
    //A0-A7
    dat = (port&0x03)|((port>>5)<<2);
    dat <<= 24;
    IOPIN1 = (IOPIN1&0xE0FFFFFF)|dat;
    //DIR
    IOSET1 = BIT(29);
    //D0-D7
    IODIR1 &= 0xFF00FFFF;
    //RD
    IOCLR1 = BIT(30);
    dat = IOPIN1;
    c = (unsigned char)(dat>>16);
    IOSET1 = BIT(30);
    
    return c;
} 2: 感谢vcvcvcvcvcvcvcvc,您有Email或QQ吗?以便向您请教.
我在看你的程序.

谢谢 3: vcvcvcvcvcvcvcvc好:
你的下述LCMDW,LCMCW怎样定义的?
#define LCMDW        0x3E
#define LCMCW        0x3F
多谢 4: 是模拟总线的LCD地址A0为C/D
A6位CS 5: vcvcvcvcvcvcvcvc:
能否告知你的*.h文件.给张硬件连接图.你的程序,看了我莫名其妙.
我的Email:larryhai@163.com.
tks
6: 原理图已发 7: 谢谢.在Email中提了几个问题,请看看,回复. 8: 我也想学学vcvcvcvc:
能否告知你的*.h文件.给张硬件连接图.你的程序,
我的Email:szwjh98@sina.com.
9: 我也想学学vcvcvcvc:
能否告知你的*.h文件.给张硬件连接图.你的程序,
我的Email:fangli8437@126.com.  10: vcvcvcvc:你好vcvcvcvc:你好,我也想学,麻烦你告诉我你的*.h文件.顺便给张硬件连接图.谢谢!我的Email:dengni20012005@163.com

菜鸟
2011-04-15 13:59:57     打赏
3楼
我也想学学vcvcvcvc:
能否告知你的*.h文件.给张硬件连接图.你的程序,
我的Email:827746291@qq.com. 

共3条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]