FlyingBlindOnARocketCycle Posted March 30, 2019 Share Posted March 30, 2019 hi Im trying to do a simple hello world by turning on the LED's. It appears that I can not assert two bits in a single register if calling them by name. The below WILL light all four LEDs as it cycles through them faster than the human flicker fusion rate. while(1){ PORTGbits.RG15 = 1; PORTGbits.RG6 = 1; PORTBbits.RB11 = 1; PORTDbits.RD4 = 1; } If I do this PORTGbits.RG15 = 1; PORTGbits.RG6 = 1; PORTBbits.RB11 = 1; PORTDbits.RD4 = 1 while(1) The only RG# led that stays lit is the last one. Can I not write to the bits of a register individually? Link to comment Share on other sites More sharing options...
FlyingBlindOnARocketCycle Posted March 30, 2019 Author Share Posted March 30, 2019 Well geees. In typical fashion as soon as I expose my ignorance, I answer my own question. What I should have been using is the "Latch". This works like I had expected assigning a port would have. LATGbits.LATG6 = 1; LATGbits.LATG15 = 1; Link to comment Share on other sites More sharing options...
Larry Standage Posted March 31, 2019 Share Posted March 31, 2019 If you want to set both pins at the same time, rather than in two separate statements, you could also do this: LATGSET = (1 << 15) | (1 << 6); // or 0b1000000001000000 These parts have registers that can do an atomic set/clear/invert, so that you don't have to do a read/modify/write of the register. Link to comment Share on other sites More sharing options...
jpeyron Posted April 1, 2019 Share Posted April 1, 2019 Hi @FlyingBlindOnARocketCycle, Glad to hear you figured out a solution. Thank you for sharing what you did to overcome this issue. best regards, Jon Link to comment Share on other sites More sharing options...
Question
FlyingBlindOnARocketCycle
hi
Im trying to do a simple hello world by turning on the LED's. It appears that I can not assert two bits in a single register if calling them by name.
The below WILL light all four LEDs as it cycles through them faster than the human flicker fusion rate.
while(1){
PORTGbits.RG15 = 1;
PORTGbits.RG6 = 1;
PORTBbits.RB11 = 1;
PORTDbits.RD4 = 1;
}
If I do this
PORTGbits.RG15 = 1;
PORTGbits.RG6 = 1;
PORTBbits.RB11 = 1;
PORTDbits.RD4 = 1
while(1)
The only RG# led that stays lit is the last one. Can I not write to the bits of a register individually?
Link to comment
Share on other sites
3 answers to this question
Recommended Posts
Archived
This topic is now archived and is closed to further replies.