简体   繁体   English

关闭ARM9(LPC3141)上的单个GPIO引脚

[英]Turning off a single GPIO pin on ARM9 (LPC3141)

I am currently studying on a LPC3141 development board. 我目前正在LPC3141开发板上学习。 I am trying to turn off a single GPIO pin while leaving the others in the same states as they were. 我试图关闭一个GPIO引脚,同时使其他GPIO保持相同的状态。 My problem is that I can turn them on individually but when i want to turn off just one pit it makes a "bus reset" and turns them all off. 我的问题是我可以单独打开它们,但是当我只想关闭一个坑时,它会进行“总线复位”并全部关闭。 I cannot figure out why does it reset all of them when I use bit shifting. 我无法弄清楚为什么在使用移位功能时会重置所有设置。 Here is an example of my code that does this: 这是我的代码执行此操作的示例:

#define PINS (*((volatile unsigned int *)0x130031C0))
#define MODE0 (*((volatile unsigned int *)0x130031D0)) 
#define MODE0_SET (*((volatile unsigned int *)0x130031D4))
#define MODE0_RESET (*((volatile unsigned int *)0x130031D8))

#define MODE1 (*((volatile unsigned int *)0x130031E0))
#define MODE1_SET (*((volatile unsigned int *)0x130031E4))
#define MODE1_RESET (*((volatile unsigned int *)0x130031E8))

void delay (void);

void c_entry(void){

    //Prg gpio pins (glej user manual str 312-318
    //Bit manipulation (spremenim samo 1 bit v registru inne celega)
    MODE1 = MODE1 | (0x1 << 6); 
    MODE1 = MODE1 | (0x1 << 8);

    while(1){
        MODE0 = MODE0 | (0x1 << 6);
        MODE0 = MODE0 | (0x1 << 8);
        delay();
        MODE1 = MODE1 | (0x1 << 6);
        MODE1 = MODE1 | (0x1 << 8);
        MODE0 = MODE0 & !(0b1000000);
        delay();
    }
}

void delay (void){
    volatile int stej = 1000000;
    while(stej){
    stej = stej - 1;
}

You're using the wrong operator when you want to clear a bit - you want the bitwise complement operator ~ , not the logical NOT operator ! 当您想清除一位时,您使用的是错误的运算符-您需要按位补码运算符~ ,而不是逻辑 NOT运算符! .

Note: bitwise operators, as their name implies, operate on individual bits within a value, whereas logical operators treat a value as a single true/false quantity (0 = false, everything else = true). 注意:顾名思义, 按位运算符对值中的各个位进行运算,而逻辑运算符将值视为单个true / false数量(0 = false,其他所有值= true)。 Bitwise operators: & , | 按位运算符: &| , ^ , ~ . ^~ Logical operators: && , || 逻辑运算符: &&|| , ! ! .

So for example your line: 因此,例如您的行:

MODE0 = MODE0 & !(0b1000000);

should be: 应该:

MODE0 = MODE0 & ~(0b1000000);

or more succinctly/consistently: 或更简洁/一致地:

MODE0 &= ~(0x1 << 6);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM