// an example of how to use memory mapping. #include #include #include #include #include #include #include #include #include #define BUFSIZE 80 int main(int argc, char * argv[]) { int i, fd, len, tmp=0,j; char * mptr; size_t size = BUFSIZE; char buffer[BUFSIZE]; if((fd = open("/dev/lcd", O_RDWR)) < -1) { perror("file files\n"); return 0; } mptr = mmap(0, size, PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, fd, 0); if(mptr == MAP_FAILED) { printf("mmap() failed\n"); tmp = 1; exit(1); } memset(buffer,'\0', 80); sprintf(buffer," Hopefully it wont blow",34); memcpy(mptr,buffer,34); write(fd,"-mmapon",7); // memory mapping must be turned off. otherwise no other command // will be recognized. since it will read from memory mapping area write(fd,"-mmapof",7); munmap(mptr, size); close(fd); return 0; }