You might find things less confusing if you use this program:
http://www.pitstock.com/robonz/news/bitometer.html
Leon
You might find things less confusing if you use this program:
http://www.pitstock.com/robonz/news/bitometer.html
Leon
leon_heller:
You might find things less confusing if you use this program:http://www.pitstock.com/robonz/news/bitometer.html
Leon
Tnx leon for the app. I’ve made a sheet which contains all the ports and adresses for future use
Yes, same thing. They do it in decimal. You'll work mostly in hex and binary because it's a natural way to think in computers.KidE:
Reminds me of calculating netmasks for networking
All correct.going back to “IOPIN0 ^= 0x000000800;”
This makes 0x000000800 bit number 11
and
This makes 0x000000400 bit number 10
Any correction needed so far?
They're all laid out the exact same way. Think of IOPIN0 as the actual Port0. Anything you do to it happens to the Port too, at least on GPIO pins. Read it and you're reading the port.So where do the registers come in?
IODIR sets whether pins are inputs or outputs. IOCLR clears bits and IOSET sets bits. All are the same 32-bit layout and correspond to the same 32 bits of the port.
Good. Some people get stupidly snitty when you "talk down to them". But I have to assume you don't understand hex/binary when you can't figure out the register/port connection. :mrgreen:BTW i’m absolutely not offended in any way! getting things explained in a simple way make life much more easy sometimes
Oops! Typo. The compiler will ignore the highest zero. Wonder why it worked?KidE:
In the 1st i see “0x00008000” which has 8 characters after the 0xIn the 2nd i see “0x000000400” which has 9 characters after the 0x :?:
Yes. You turned P0.21 on. That makes the pin high. High == 3.3V. Measure between the pin and ground.KidE:
i’ve put ```
IOPIN0 ^= 0x00200000;in the code right below the ``` IOPIN0 ^= 0x00000400; ``` so if LED1 is on this should turn P0.21 ON because its a normal GPIO pin right? If i measure between P0.21 and 3.3V i do not see anything here Did i forgot anything?
Also, if the pin was already on and you exclusive ORed it like that, it turned off, or was cleared, or went low. It’s at ground potential at that point. Exclusive OR is only for when you want to reverse a bit’s current value. If you want to just set a bit, use IOSET.
What’s probably throwing you is that the LEDs are connected so the 2148’s pins are open drain, meaning they go low and conduct current to ground through the LEDs to turn the LEDs on. So to turn the LEDs on this board ON, you set the pin LOW.
That might seem backward to you at this point, but that’s the way it’s done on many many chips. They can sink current better than they can source it. Some can’t source it at all - they can only sink it. Get it? Sink - Open Drain?
futz:
But I have to assume you don’t understand hex/binary when you can’t figure out the register/port connection.
Not be offended is one thing but rubbing it in is a totally different matter :mrgreen:
futz:
Yes. You turned P0.21 on. That makes the pin high. High == 3.3V. Measure between the pin and ground.
Did so but nut nothing happens. I measure a constant +0.36V if i push the button or not.
futz:
Also, if the pin was already on and you exclusive ORed it like that, it turned off, or was cleared, or went low. It’s at ground potential at that point. Exclusive OR is only for when you want to reverse a bit’s current value. If you want to just set a bit, use IOSET.
So making a pin high you need to use IOSET and making a pin low you need to use IOCLR right?
So to do it in a clean way i 1st need to set pin P0.21 as output.
But how do i use IODIR0 = 0x00200000 = 1 and then IOCLR0 = 0x00200000
Nevermind you 1st set IODIR0 = 0x00200000 so its configured as an output
And then you can select if you want the pin high or low (if i read the manual correct)
But still nothing is happening
Nehh this can be right. please so me!
Ok got it working
First i had to define the P.21 as an output port with: IODIR0 |= 0x00200000;
After that needed to be set low so it did not poweron directly at startup with: IOCLR0 = 0x00200000;
Then it is possible to toggle the status with: IOPIN0 ^= 0x00200000;
[/code]
He's starting to scratch the surface! :mrgreen: It's nice to get your first LED blinking, isn't it? Feels good.KidE:
Ok got it workingFirst i had to define the P.21 as an output port with: IODIR0 |= 0x00200000;
After that needed to be set low so it did not poweron directly at startup with: IOCLR0 = 0x00200000;
Then it is possible to toggle the status with: IOPIN0 ^= 0x00200000;
futz:
It’s nice to get your first LED blinking, isn’t it? Feels good.
Yes indeed it’s always nice to get things working special when something is so new.
Another question
I’m now trying to power 4 leds for making a walkinglight but when i only define the bits they are put LOW even as a dant tell them to do so?? wierd
the definitions:
IODIR0 |= 0x00200000; //sets P0.21 as output
IODIR0 |= 0x00400000; //sets P0.22 as output
IODIR0 |= 0x10000000; //sets P0.28 as output
IODIR0 |= 0x20000000; //sets P0.29 as output
IOSET0 = 0x00003c00;
IOSET0 = 0x00200000; //sets P0.21 HIGH
IOSET0 = 0x00400000; //sets P0.22 HIGH
IOSET0 = 0x10000000; //sets P0.28 HIGH
IOSET0 = 0x20000000; //sets P0.29 HIGH
The button part
while(1){
if((IOPIN0 & 0x00008000) == 0){ //button 1 pressed?
IOPIN0 ^= 0x00000400; //LED 1 ON
IOPIN0 ^= 0x00200000; //Toggle status of port P0.21 HIGH/LOW
//IOPIN0 ^= 0x00400000; //Toggle status of port P0.22 HIGH/LOW
//IOPIN0 ^= 0x10000000; //Toggle status of port P0.28 HIGH/LOW
//IOPIN0 ^= 0x20000000; //Toggle status of port P0.29 HIGH/LOW
As i look at it i dint request the status of the pins being changed here though?
leon_heller:
You might find things less confusing if you use this program:http://www.pitstock.com/robonz/news/bitometer.html
Leon
Sorry i was a bit sinical but now i realized why this tool is so handy
IODIR0 |= 0x30600000; //Does the same as 4 lines below
//IODIR0 |= 0x00200000; //sets P0.21 as output
//IODIR0 |= 0x00400000; //sets P0.22 as output
//IODIR0 |= 0x10000000; //sets P0.28 as output
//IODIR0 |= 0x20000000; //sets P0.29 as output
The part uphere is pretty straight forward but when hex is comming in its handy to double check it
Tnx for the tip
ok my fault i wired the stuff wrong so :oops:
anyway i got the stuff running in a loop but not 1 by 1
On this link http://www.8051projects.net/forum-t4128.html i found some code of a running light but there is a code line i cannot apply:
for (j = 0x010000; j < 0x800000; j <<= 1)
This should do a run counting down from 0x80 to 0x01. This can only be done when you have pins that follow up on eahother right?
Is there a way to do this more simple?
Don't forget current limiting resistors on your LEDs. :wink:KidE:
ok my fault i wired the stuff wrong so :oops:
Hard to say without seeing what you've done. Either post a quicky schematic or a few nice clear macro photos of your circuit. Distant third choice - a well written description.anyway i got the stuff running in a loop but not 1 by 1
Is there a way to do this more simple?
Yes. He's shifting a set bit left by one bit position each time through the loop. Your LEDs would have to be on consecutive pins.On this link http://www.8051projects.net/forum-t4128.html i found some code of a running light but there is a code line i cannot apply:
for (j = 0x010000; j < 0x800000; j <<= 1)
This should do a run counting down from 0x80 to 0x01. This can only be done when you have pins that follow up on each other right?
EDIT: You could put some if statements or a switch statement inside the loop that skips over the un-used pins.
If they’re non-consecutive then you’ll either have to figure out an algorithm to light them in sequence (impossible if they’re not in some pattern), or just write non-elegant brute force code to turn each one on and off in sequence, or use some kind of lookup table (quite easy, but lots of extra code).
futz:
You could put some if statements or a switch inside the loop that skips over the un-used pins.
What do you exactly mean by a “switch inside a loop”? can you give an example?
In a shell script i would do it like
for i in 21 22 28 29
do
echo $i
done
But i have no idea to how to do this in C
Do you know C? Do you have a book that you're learning C from? If not, you're going to have to get your C "learnin from the interweb" (say that with a big Texas drawl :grin: ).KidE:
What do you exactly mean by a “switch inside a loop”? can you give an example?
http://msdn.microsoft.com/en-us/library/66k51h7a.aspx
http://en.wikipedia.org/wiki/Switch_statement
http://cprogramminglanguage.net/c-switch-statement.aspx
Well, C is a fairly far cry from shell scripting. Of course there are some similarities, as in all programming languages. You need a reference book if you're new to the language. Get a C book though - not a C++ book. Most C++ books assume you already know C and skim over it. C++ is a superset of C. It's C with object oriented (OO) stuff added on.In a shell script i would do it like…
futz:
Do you know C? Do you have a book that you’re learning C from? If not, you’re going to have to get your C “learnin from the interweb” (say that with a big Texas drawl).
I know C enough for my work but i realize that it’s not enough to get around in this world. Anyway nice of you rubbing that one in
And i was just so pleased with myself that i had a LED burning :lol: