한백전자의 EMPOS II 보드에서 TextLCD를 제어하는 소스 입니다.
광운대 07년 여름방학중 임베디드 세미나에서 받은 소스로 작성되었으며...
저작권은 RTA랩실과 저에게 있습니다.
상업적 이용및 제출용 이용을 불허합니다.
왜냐면... 느리니까;;; 이건 가치가... 떨어져서;;;
다음에 다시 코딩해봐야할듯 하네요;;;
Makefile
Code Type : bash
CC = arm-linux-gcc
INCLUDE = .
lcd_test : main.o txtlcd_driver.o
$(CC) -o lcd_test main.o txtlcd_driver.o
main.o : main.c
$(CC) -I$(INCLUDE) -c main.c
txtlcd_driver.o : txtlcd_driver.c
$(CC) -I$(INCLUDE) -c txtlcd_driver.c
clean :
rm -f lcd_test main.o txtlcd_driver.o *.bak
닫기 textlcd_driver.c
Code Type : C
#include < stdio.h>
#include < unistd.h>
#include < stdlib.h>
#include < fcntl.h>
#include < sys/mman.h>
#define DEV_NAME "/dev/mem" //MEMORY DEVICE
#define ADDROFLCD 0x10700000 //PHYSICAL ADDRESS OF CHARACTER LCD
#define BYTE_LEN 2 //SIZE OF BYTE for MEMORY
static int txtlcd_fd; //device description
static unsigned int *lcd; //pointer for LCD ADDRESS
void set_command (unsigned short cmd)
{
cmd=cmd&0x00ff;
*lcd=cmd|0x0000;
*lcd=cmd|0x0400;
//*lcd=cmd&0xFDFF;
*lcd=cmd&0x0000;
usleep(50);
}
void write_byte (char ch)
{
unsigned char data;
data = ch &0x00ff;
*lcd=data|0x100;
*lcd=data|0x500;
*lcd=data|0x100;
usleep(50);
}
void set_func()
{
unsigned short cmd = 0x30; //00110000 data length : 8-bit
cmd |= 0x08; //set rows : 2-line
set_command (cmd);
}
void ctrl_display ()
{
unsigned short cmd = 0x08;
cmd |= 0x04; //display enable
set_command(cmd);
}
void shift_cursor (int set_scr , int set_rshift)
{
unsigned short cmd = 0x10;
cmd = set_scr ? cmd | 0x08 : cmd;
cmd = set_rshift ? cmd | 0x04 : cmd;
set_command ( cmd );
}
void set_entrymode ()
{
unsigned short cmd = 0x04;
cmd |= 0x2; //increment , do not shift
set_command ( cmd );
}
void ret_home ()
{
unsigned short cmd = 0x02;
set_command (cmd);
//usleep(2000);
}
void clr_display()
{
unsigned short cmd = 0x01;
set_command (cmd);
usleep(2000);
}
void set_ddr_addr(unsigned char pos)
{
unsigned short cmd = 0x80; //set D7
cmd |= (pos & 127); // 7-bit
set_command ( cmd );
}
void init_lcd(unsigned char *addr)
{
txtlcd_fd = open(DEV_NAME , O_RDWR | O_SYNC);
if (!txtlcd_fd)
{
printf ("device open failed\n");
exit(-1);
}
addr = mmap(NULL,BYTE_LEN , PROT_WRITE , MAP_SHARED , txtlcd_fd , ADDROFLCD);
if (addr == NULL)
{
close(txtlcd_fd);
printf ("memory map error\n");
exit(-1);
}
lcd = (unsigned int*)addr; //pointer fowarding
set_func();
ctrl_display();
clr_display ();
ret_home();
set_entrymode(); //fix : increment /do not shift
//usleep(2000);
}
void close_lcd(unsigned char *addr)
{
lcd = NULL;
munmap(addr , BYTE_LEN);
close(txtlcd_fd);
}
닫기
닫기 main.c
Code Type : C
#include < stdio.h>
#include < stdlib.h>
int main( void )
{
unsigned char *p_lcd;
char buf1[100] = "Hello Embeded World";
char buf2[100] = "RTA LAB with Ohyung";
int i;
int len1,len2;
len1 = strlen(buf1);
len2 = strlen(buf2);
init_lcd(p_lcd);
if(p_lcd == NULL)
{
printf("lcd init error!\n");
exit(-1);
}
for(i=0;i < len1;i++)
write_byte (buf1[i]);
set_ddr_addr(0x40);
for(i=0;i < len2;i++)
write_byte (buf2[i]);
/**
* Insert your own code
*/
close_lcd(p_lcd);
}
닫기
| main.c (531 Byte) |
| | txtlcd_driver.c (2.2 KB) |
|