搜索
bottom↓
回复: 0

LPC2138驱动LCD12864画点线,初学者求助(TRULY的液晶屏)

[复制链接]

出0入0汤圆

发表于 2011-2-10 11:36:26 | 显示全部楼层 |阅读模式
#include <LPC213x.h>
#include "Inc/std.h"
#include "Inc/driver.h"
#define         ushort unsigned short
#define         uchar  unsigned char
#define         ulong unsigned long
#define         LED          23       
#define                LCDRS    26
#define                LCDRW         27
#define                LCDE         25
#define                LCDCSL         30
#define                LCDCSR         20       
void Delay_us(ushort n)
{
        ushort i;
        for(;n>0;n--)
                for        (i=0;i<5000;i++);
}

int main()
{       
        PINSEL0 = 0x00000000;
        PINSEL1 = 0x00000000;
        init();
        lcdOpen();
        lcdStartLine(0);
        lcdSetPage(0);
        lcdSetRow(0);
        pixel(30,20);
        pixel(100,50);
        pixel(15,40);
        pixel(53,57);
        pixel(90,36);
        pixel(65,19);
        while(1)
        {       
                IO0DIR = 1 << LED;
                 IO0CLR = 1 << LED;
                Delay_us(100);
                IO0SET = 1 << LED;
                Delay_us(100);
        }       
        return 0;
}
void Delay_ns(int n)
{       
        int i;
        for (i=0;i<n;i++);
}
void init()
{
        IO0DIR |= (ulong)1 << LCDRS;
        IO0DIR |= (ulong)1 << LCDE;
        IO0DIR |= (ulong)1 << LCDRW;
        IO0DIR |= (ulong)1 << LCDCSL;
        IO0DIR |= (ulong)1 << LCDCSR;
        IO0DIR |= (ulong)1 << LED;

}

uchar getState()
{
        IO0SET = 1 << LCDE;
        Delay_ns(5);
        IO0CLR = 1 << LCDE;
        Delay_ns(5);
        IO0CLR = 1 << LCDRS;
        IO0SET = 1 << LCDRW;
        IO0CLR = 1 << LCDCSL;
        IO0CLR = 1 << LCDCSR;       
        Delay_ns(5);
        IO0SET = 1 << LCDE;
        Delay_ns(10);
        return IO1PIN;
}
int lcdBusy()
{
        uchar state = 0;
        state = getState();
        if(state & (1 << 22))
        {
                return 1;
        }
        else
        {
                return 0;
        }
}
void lcdCommand(uchar command)
{
        IO1SET = 1 << LCDE;
        Delay_ns(5);
        IO0CLR = 1 << LCDE;       
        Delay_ns(5);
        IO0CLR = 1 << LCDCSL;
        IO0CLR = 1 << LCDCSR;
        IO0CLR = 1 << LCDRS;
        IO0CLR = 1 << LCDRW;
        Delay_ns(5);
        IO0SET = 1 << LCDE;
        Delay_ns(10);
        IO1PIN = (IO1PIN & 0xff00ffff) | (command << 16);       
}

void lcdOpen()
{
        while(lcdBusy());
        lcdCommand(0x3f);
}

void lcdStartLine(uchar lin)
{
        lin |= 0xc0;
        while(lcdBusy());
        lcdCommand(lin);
}

void lcdSetPage(uchar page)
{
        page &= 0x7;
        page |= 0xb8;
        while(lcdBusy());
        lcdCommand(page);       
}

void lcdSetRow(uchar row)
{
        row &= 0x3f;
        row |= 0x40;
        while(lcdBusy());
        lcdCommand(row);
}
void lcdWrite(uchar dat,uchar cs)
{
        while(lcdBusy());
        IO1DIR = 0x00000000;
        IO0SET = 1 <<  LCDE;
        Delay_ns(5);
        IO0CLR = 1 <<  LCDE;
        Delay_ns(5);
        if(cs == 1)
        {
                IO0CLR = 1 << LCDCSL;
                IO0SET = 1 << LCDCSR;
        }
        else
        {
                IO0CLR = 1 << LCDCSR;
                IO0SET = 1 << LCDCSL;
        }
        IO0SET = 1 << LCDRS;
        IO0CLR = 1 << LCDRW;
        Delay_ns(5);
        IO0SET = 1 <<  LCDE;
        Delay_ns(10);
        IO1PIN = (IO1PIN & 0xFF00FFFF) | (dat << 16);       
}

uchar lcdRead(uchar cs)
{
        uchar dat;
        while(lcdBusy());
        IO1PIN = 0xffffffff;
        IO0SET = 1 << LCDE;
        Delay_ns(5);
        IO0CLR = 1 << LCDE;
        Delay_ns(5);
        if(cs == 1)
        {
                IO0CLR = 1 << LCDCSL;
                Delay_ns(5);
                IO0SET = 1 << LCDCSR;
                Delay_ns(5);
        }
        else
        {
                IO0CLR = 1 << LCDCSR;
                Delay_ns(5);
                IO0SET = 1 << LCDCSL;
                Delay_ns(5);       
        }
        IO0SET = 1 << LCDRS;
        IO0SET = 1 << LCDRW;
        Delay_ns(2);
        IO0SET = 1 << LCDE;
        Delay_ns(10);
        dat = IO1PIN ;
        return dat >> 16;
}

void pixel(uchar x, uchar y)
{
        uchar page,dX,dY;
        uchar cs = 2;
        uchar dot = 0;
        if(x >= 64)
        {
                x -= 64;
        }
        else
        {
                cs = 1;
        }
        dX = x;
        page = y / 8;
        dY = y % 8;
        lcdSetPage(page);
        lcdSetRow(dX);
        dot = lcdRead(cs);
        dot ^= (1 << dY);
        lcdSetPage(page);
        lcdSetRow(dX);
        lcdWrite(dot,cs);         
}

屏完全就没有反应 屏是好的 各位高手们 救救我吧 快疯掉了

阿莫论坛20周年了!感谢大家的支持与爱护!!

知道什么是神吗?其实神本来也是人,只不过神做了人做不到的事情 所以才成了神。 (头文字D, 杜汶泽)
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片。注意:要连续压缩2次才能满足要求!!】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-7-24 01:22

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表