?? lcd_tri_1602.c
字號:
#include "alt_types.h"
#include "lcd_tri_1602.h"
#include "lcd_tri_1602_regs.h"
#include "system.h"
#include <string.h>
#include <stdio.h>
#include <unistd.h>
static alt_u8 busy;
static unsigned char LcdChkBusy(unsigned int base)
{
alt_u32 i = 1000000;
while (IORD_LCD_STATUS(base) & 0x80)//_8DIRECT(LCD_12864_0_BASE,0x1) & 0x80)
if (--i == 0)
{
busy=1;
return 1;
}
busy=0;
return 0;
}
static void lcd_write_cmd(unsigned int base, unsigned char command)
{
// if(LcdChkBusy(base))
if(busy)
return;
usleep(200);
IOWR_LCD_COMMAND(base,command);
}
static void lcd_write_data(unsigned int base, unsigned char data)
{
//if(LcdChkBusy(base))
if(busy)
return;
usleep(200);
IOWR_LCD_DATA(base, data);
}
void LCD1602_Init(LCD_TRI_1602_dev *dev)
{
unsigned int base = dev->base;
LcdChkBusy(base);
lcd_write_cmd(base,0x38);
usleep(2000);
lcd_write_cmd(base,0x0C);
usleep(2000);
lcd_write_cmd(base,0x01);
usleep(2000);
lcd_write_cmd(base,0x06);
usleep(2000);
lcd_write_cmd(base,0x80);
usleep(2000);
alt_dev_reg (&dev->dev);
}
int LCD1602_writestring(unsigned int base, unsigned char* ptr, unsigned char line)
{
int i;
if(line==1)
lcd_write_cmd(base,0x80);
else if(line==2)
lcd_write_cmd(base,0xC0);
usleep(2000);
for(i=0;i<strlen(ptr);i++)
{
lcd_write_data(base,ptr[i]);
usleep(200);
}
return 1;
}
int LCD1602_write(alt_fd* fd, const char* ptr, int len)
{
LCD_TRI_1602_dev * dev = (LCD_TRI_1602_dev*) fd->dev;
const char * end = ptr + len;
unsigned int base = dev->base;
if(*(end-1) == '1')
lcd_write_cmd(base,0x80);
else if(*(end-1) == '2')
lcd_write_cmd(base,0xc0);
for ( ; ptr < end-1 ; ptr++)
{
usleep(200);
lcd_write_data(base,*ptr);
usleep(200);
}
return len;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -