📄 lcdtest.c
字号:
#include <stdio.h>#include <string.h>#include <malloc.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <unistd.h>#include <signal.h>#include <sys/ioctl.h>#include <linux/delay.h>/* * Function command codes for io_ctl. */#define LCD_On 1#define LCD_Off 2#define LCD_Clear 3#define LCD_Reset 4#define LCD_Cursor_Left 5#define LCD_Cursor_Right 6#define LCD_Disp_Left 7#define LCD_Disp_Right 8#define LCD_Get_Cursor 9#define LCD_Set_Cursor 10#define LCD_Home 11#define LCD_Read 12#define LCD_Write 13#define LCD_Cursor_Off 14#define LCD_Cursor_On 15#define LCD_Get_Cursor_Pos 16#define LCD_Set_Cursor_Pos 17#define LCD_Blink_Off 18#define FUNCTION_SET 19#define MAX_LEN_MESSAGE 64#define LCDDATA 0x002012A0#define LCDDATADIR 0x002012A4#define LCDCTL 0x002012B0#define LCDDATAIN 0#define LCDDATAOUT 0xff#define DELAY 80000unsigned char lcd_c=0x18;#define LCD_E(d) if (d>0)lcd_c|=0x04;else lcd_c&=~0x04;(*(volatile unsigned *)(LCDCTL))=lcd_c;#define LCD_RW(d) if (d>0)lcd_c|=0x01;else lcd_c&=~0x01;(*(volatile unsigned *)(LCDCTL))=lcd_c;#define LCD_RS(d) if (d>0)lcd_c|=0x02;else lcd_c&=~0x02;(*(volatile unsigned *)(LCDCTL))=lcd_c;#define LCD_RST(d) if (d>0)lcd_c|=0x08;else lcd_c&=~0x08;(*(volatile unsigned *)(LCDCTL))=lcd_c;#define LCD_PSW(d) if (d>0)lcd_c|=0x10;else lcd_c&=~0x10;(*(volatile unsigned *)(LCDCTL))=lcd_c;void Delay(unsigned int j){ int k,i; for (k=0;k<j;k++) for(i=1000;i>0;i--) ;}void Lcd_Write_Cmd(char instru){ int i; //for (i=DELAY;i>0;i--); /*clr RS low */ LCD_RS(0); /*clr R/w for write*/ LCD_RW(0); /*Set enable*/ LCD_E(1); (*(volatile unsigned *)(LCDDATADIR))=0xffffffff; (*(volatile unsigned *)(LCDDATA))=instru; Delay(100) ; LCD_E(0); Delay(150) ; } void Lcd_Write_Data(char lcddata){ int i; //for (i=DELAY;i>0;i--); /*clr RS low */ LCD_RS(1); /*clr R/w for write*/ LCD_RW(0); /*Set enable*/ LCD_E(1); (*(volatile unsigned *)(LCDDATADIR))=0xffffffff; (*(volatile unsigned *)(LCDDATA))=lcddata; Delay(100) ; LCD_E(0); Delay(150) ;}void Lcd_init(){ //Delay(100); LCD_RST(0); Delay(100); LCD_RST(1); Lcd_Write_Cmd(0x30); Delay(100); Lcd_Write_Cmd(0x30); Delay(50); Lcd_Write_Cmd(0x0c); Delay(100); Lcd_Write_Cmd(0x01); Delay(10000); Lcd_Write_Cmd(0x06); Delay(10);}void hzkdis(unsigned char *s){ while(*s>0) { Lcd_Write_Data(*s); s++; Delay(1); }}void test(){ Lcd_Write_Cmd(0x01); Delay(10);usleep(100); Lcd_Write_Cmd(0x82); hzkdis("8A205"); Lcd_Write_Cmd(0x88); hzkdis("123456789我");}int mai000n(void){ int i,j,k,o,d,da; da = 0; printf("LCD测试程序!\n"); Lcd_init(); printf("LCD8\n"); test(); printf("LCD test end.\n");return 0;}#define LCD_X 19#define LCD_Y 20#define LCD_D 21int main(void){ int fd,fd1,count,i,tmp; unsigned long rgcon; char title1[]="hello 8a205 1"; char title2[]="hello 8a205 2"; char title3[]="hello 8a205 3"; int *spinfo=(int *)malloc(4); int x,y; unsigned char key_buf[100]; printf("entered main\n"); if((fd=open("/dev/lcddrv",O_RDWR))==-1) { perror("open eror"); exit(1); } printf("open ok\n"); sleep(1); for (y=0;y<4;y++) for (x=0;x<4;x++) { ioctl(fd,LCD_X,&x); ioctl(fd,LCD_Y,&y); i='a'; ioctl(fd,LCD_D,&i); sleep(1); //printf("%d\n",x); } if((fd1=open("/dev/button",O_RDWR))==-1) { perror("open button eror"); exit(1); } ioctl(fd,LCD_Clear); while(1) { x = 0; y = 0; count = read(fd1,key_buf,1); if (count>0) { for (i=0;i<count;i++) { if (key_buf[i]>10) { tmp = key_buf[i] / 10; if (key_buf[i]==10) tmp =1; ioctl(fd,LCD_X,&x); ioctl(fd,LCD_Y,&y); tmp +='0'; ioctl(fd,LCD_D,&tmp); tmp -='0'; tmp = key_buf[i] - tmp *10; x++; ioctl(fd,LCD_X,&x); ioctl(fd,LCD_Y,&y); tmp +='0'; ioctl(fd,LCD_D,&tmp); }else { ioctl(fd,LCD_X,&x); ioctl(fd,LCD_Y,&y); tmp = key_buf[i] + '0'; ioctl(fd,LCD_D,&tmp); } sleep(1); x =0;y=0; ioctl(fd,LCD_X,&x); ioctl(fd,LCD_Y,&y); tmp =' '; ioctl(fd,LCD_D,&tmp); x++; ioctl(fd,LCD_X,&x); ioctl(fd,LCD_Y,&y); ioctl(fd,LCD_D,&tmp); } } } // sleep(2); printf("spinfo=%d\n",*spinfo); close(fd); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -