|
#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, 杜汶泽)
|