CubieBoard中文论坛

 找回密码
 立即注册
搜索
热搜: unable
查看: 4768|回复: 4

有辦法透過C語言控制A80的紅綠LED嗎?

[复制链接]
发表于 2015-10-31 22:38:57 | 显示全部楼层 |阅读模式
想請教各位
有辦法透過C語言控制A80的紅綠LED嗎?
像是寫一個 變數 = 1時,紅燈亮
變數 = 0時,紅滅綠亮

因為現在好像CPU執行時紅綠LED是閃爍的
不曉得該從哪裡下手
謝謝各位。
回复

使用道具 举报

发表于 2015-11-1 13:26:41 | 显示全部楼层
可以啊,最基本的,你会linux 文件操作即可,给你一个思路:

int fd = open("pin_name", O_WR);
write(fd, 1,1);
close(fd);

注意使用root 权限,否则你应该是写不成功的。
回复 支持 反对

使用道具 举报

发表于 2015-11-1 13:28:53 | 显示全部楼层
本身这个问题,在2013年的时候,就已经玩过了,当时有的是使用了python库,有的是直接使用的 open() unix系列函数来操作的,分别对应写0和1就可以了。

你不妨试着在论坛搜一下。
回复 支持 反对

使用道具 举报

发表于 2015-11-1 13:31:13 | 显示全部楼层
回复 支持 反对

使用道具 举报

发表于 2015-11-2 09:51:49 | 显示全部楼层
  1. #include <ctype.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. #include <math.h>
  6. #include <time.h>
  7. #include <signal.h>
  8. #include <sys/types.h>
  9. #include <sys/stat.h>
  10. #include <fcntl.h>
  11. #include <sys/mman.h>
  12. #include <sys/select.h>
  13. #include <pthread.h>
  14. #include <unistd.h>
  15. #include <sched.h>
  16. #include <errno.h>


  17. #define SW_PORTC_IO_BASE  0x06000800

  18. int main() {
  19.         unsigned int * pc;
  20.         int fd, i;
  21.         char * ptr;
  22.         unsigned int addr_start, addr_offset, PageSize, PageMask, data;
  23.        
  24.         PageSize = sysconf(_SC_PAGESIZE);
  25.         PageMask = (~(PageSize-1));
  26.         addr_start = SW_PORTC_IO_BASE & PageMask;
  27.         addr_offset = SW_PORTC_IO_BASE & ~PageMask;
  28.        
  29.         fd = open("/dev/mem", O_RDWR);
  30.         if(fd < 0) {
  31.            perror("Unable to open /dev/mem");
  32.            return(-1);
  33.         }
  34.        
  35.         pc = mmap(0, PageSize*2, PROT_READ|PROT_WRITE, MAP_SHARED, fd, addr_start);
  36.        
  37.         if(pc == MAP_FAILED) {
  38.            perror("Unable to mmap file");
  39.            printf("pc:%lx\n", (unsigned long)pc);
  40.            return(-1);
  41.         }
  42.         printf("PageSize:%8.8x\tPageMask:%8.8x\naddr_start:%8.8x\taddr_offset:%8.8x\n",PageSize,PageMask,addr_start,addr_offset);
  43.         printf("pc:%8.8x\n", *(unsigned int *)pc);
  44.         ptr = (char *)pc + addr_offset;

  45.         //the PG12 is UART4-TX in the board ,set it as output port
  46.         data = *(unsigned int *)(ptr+0xdc);
  47.         data &= ~(7<<16);                        
  48.         data |= 1<<16;                        
  49.         *(unsigned int *)(ptr+0xdc) = data;

  50.         //set it high level .If set low , data &= 0<<12 replace  data |= 1<<12
  51.         data = *(unsigned int *)(ptr+0xe8);
  52.         data |= 1<<12;                        
  53.         *(unsigned int *)(ptr+0xe8) = data;
  54.        
  55.        
  56.         return 0;
  57.     }
复制代码
通过I/O映射的方式,控制寄存器。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|粤ICP备13051116号|cubie.cc---深刻的嵌入式技术讨论社区

GMT+8, 2024-5-3 12:15 , Processed in 0.021790 second(s), 15 queries .

Powered by Discuz! X3.4

© 2001-2012 Comsenz Inc. | Style by Coxxs

返回顶部