⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ledtest.c

📁 Linux Device Driver 3 的例子程序
💻 C
字号:

#include <stdio.h>
#include <stdlib.h>

#include <sys/types.h>
#include <fcntl.h>
#include <string.h>

#include <unistd.h>
#include <sys/stat.h>
#include <sys/ioctl.h>


#include <sys/mman.h>

#define LED_SIZE 0x200
//#define LED_PORT (*(volatile unsigned*)0x80000000)
#define LED_PORT	0x80000000

unsigned int *led_ptr;
int fd;

int main(int argc, char *argv[])
{
	fd=open("/dev/mem",O_RDWR);
//	led_ptr= mmap(NULL, LED_SIZE, PROT_WRITE, MAP_SHARED, fd, LED_PORT);

	led_ptr= mmap(NULL, LED_SIZE, PROT_WRITE, MAP_SHARED, fd, LED_PORT);
	printf("buffer address 0x%x \n",led_ptr+0x100);                                
     //printf("buffer data <%s> \n",p); 
//	close(fd);

//	*((volatile unsigned *)(led_ptr+0x100)) = 0xff;
	write(0xaa,led_ptr+0x100,1);
    	printf("buffer data <%x> \n",*(led_ptr+0x100)); 
	close(fd);
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -