搜索
bottom↓
回复: 3

lpc1768 操作LCD12864 不成功 请指教

[复制链接]

出0入0汤圆

发表于 2013-5-28 16:12:31 | 显示全部楼层 |阅读模式
#include "stdint.h"
#include "lpc17xx_gpio.h"
#include "lcd12864.h"
#include "mytimer.h"

#define LCD_RST        (1<<18)//P1.18
#define LCD_CS1        (1<<25)//P1.25
#define LCD_CS2        (1<<26)//P1.26
#define LCD_RS        (1<<27)//P1.27
#define LCD_RW        (1<<28)//P1.28
#define LCD_EN        (1<<29)//P1.29
#define LCD_CTR_PORT        1
#define LCD_BUS_PORT        0
#define LCD_BUS        (0XFF)

volatile timer timer_12864;

static void write_cmd( uint8_t cmd );
static void write_data( uint8_t dat );


/*
static void delay( uint16_t ms )
{
        while( ms--);
}
*/
void delay( uint16_t ms )
{
        timer_12864.cnt = 0;
        timer_12864.dly = ms;
        timer_12864.stat = MY_ENABLE;
        timer_12864.mode = MY_ONE;
        timer_12864.alarm = NOALARM;
        while( timer_12864.alarm == NOALARM );
}

void lcd12864_init( void )
{       
        delay( 100 );       
        LPC_GPIO0->FIODIR0 |= 0XFF;       
        LPC_GPIO1->FIODIR |= (LCD_RST | LCD_CS1 | LCD_RS | LCD_RW | LCD_RS);       
       
        LPC_GPIO1->FIOCLR = LCD_RST;
        delay( 50 );       
        LPC_GPIO1->FIOSET = LCD_RST;       
        delay( 50 );       
        LPC_GPIO1->FIOSET = LCD_CS1;               
       
        write_cmd( 0x30 );
        delay( 50 );       
        write_cmd( 0x30 );
        delay( 50 );       
        write_cmd( 0x30 );
        delay( 50 );       
       
        write_cmd( 0x30 );       
        delay( 50 );       
        write_cmd( 0x08 );
        delay( 50 );       
        write_cmd( 0x01 );
        delay( 50 );       
        write_cmd( 0x06 );
        delay( 50 );       
        write_cmd( 0x0f );//显示开       
        delay( 50 );       
}

void lcd12864_clr()
{
        write_cmd( 0x01 );       
        write_cmd( 0x34 );       
        write_cmd( 0x30 );       
}

void set_cursor( uint8_t x, uint8_t y )
{
    unsigned char i;
    switch(x)//确定行号
    {
        case 0x00: i=0x80; break;//第一行
        case 0x01: i=0x90; break;//第二行
        case 0x02: i=0x88; break;//第三行
        case 0x03: i=0x98; break;//第四行
        default : break;
    }
    i = y+i;//确定列号
        write_cmd( 0x30 );
    write_cmd( i );//写地址
}



/***********************************************
val 为所要发送的数据
ctrl 取值范围为 CMD 表示发送命令 或 DATA 表示发送数据
************************************************/
static void write_cmd( uint8_t cmd )
{
        delay( 10 );
        GPIO_ClearValue( LCD_CTR_PORT, LCD_RW );
        GPIO_ClearValue( LCD_CTR_PORT, LCD_RS );                       
       
        LPC_GPIO0->FIOMASK0 = 0X00;
        LPC_GPIO0->FIOPIN0 = cmd;
        LPC_GPIO0->FIOMASK0 = 0XFF;
       
        delay( 1 );
        GPIO_SetValue( LCD_CTR_PORT, LCD_EN );
        delay( 1 );       
        GPIO_ClearValue( LCD_CTR_PORT, LCD_EN );       
        delay( 1 );       
}

static void write_data( uint8_t dat )
{
        delay( 10 );
        GPIO_ClearValue( LCD_CTR_PORT, LCD_RW );       
        GPIO_SetValue( LCD_CTR_PORT, LCD_RS );       
       
        LPC_GPIO0->FIOMASK0 = 0X00;
        LPC_GPIO0->FIOPIN0 = dat;
        LPC_GPIO0->FIOMASK0 = 0XFF;
        delay( 1 );
        GPIO_SetValue( LCD_CTR_PORT, LCD_EN );
        delay( 1 );       
        GPIO_ClearValue( LCD_CTR_PORT, LCD_EN );       
        delay( 1 );       
}

void lcd_show_string( uint8_t x, uint8_t y, uint8_t *str )
{
        set_cursor( x, y );
        while( *str != '\0' ) {
                write_data( *str );               
                str++;
        }       
}

/*
void lcd_show_chinese( uint8_t x, uint8_t y, uint8_t *chinese )
{
        set_cursor( x, y );
        while( *str != '\0' ) {
                write_data( *str );               
                str++;
        }       
}
*/

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

知道什么是神吗?其实神本来也是人,只不过神做了人做不到的事情 所以才成了神。 (头文字D, 杜汶泽)

出0入0汤圆

发表于 2013-5-28 17:22:42 | 显示全部楼层
1768是3.3v的,模块是5v的,电平转换了没啊

出0入0汤圆

 楼主| 发表于 2013-6-9 08:53:20 | 显示全部楼层
12864 VO 需要直接从 VCC串电阻引入即可,无须再接地

出0入0汤圆

发表于 2013-6-9 17:08:27 | 显示全部楼层
这片子初始化比较麻烦,又是时钟又是功率配置什么的,看看有没有初始化正常。
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片。注意:要连续压缩2次才能满足要求!!】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

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

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

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