C language
Rsadeika
Posts: 3,837
I thought I would give the ImageCraft C a try; below is the smallest amount of code that I could come up with to blink an LED. Awhile back I tried to do the same thing using Propeller asm, using asm was a much steeper learning curve, just to produce a simple blink program.
For those of you that have not tried C yet, so far, for me, it has been a pleasant experience, no hair pulling yet. Everything, in the IDE,·seems to be pretty intuitive, and that is the way I like it. If you are going to use the snippet below, once you make it a .c file, create a project with it. After you have the project or the file, in the File dropdown, use Compile File to create the Output file. Then goto Tools, and use the Propellant Downloader to get the project that you created onto the chip. This all seems very straight forward, and very simple. What I described here, took me about an hour last night.
A couple of things that would make life easier, is maybe a downloadable pdf file that would be a programmers manual. The Help file, I find it to be somewhat cumbersome to use. Also, I could not find things like what has to be in upper caps, for instance like DIRA, and OUTA. I also could not find an explanation for ^=, which I figured out to be a toggle, I think. So, there are some minor problems, as I perceive it, but in general it looks like a solid product.
Since I plan to convert one of my Spin programs to C, I think that I may have a problem with the following parts, I use serial comms, and·some IR·SIRC code in the program. In the object exchange I did not see any C equivelants, so that is a problem from the get go, unless I can figure out how to take the existing Spin code objects and use them directly in the C program.
The next little program that I may try is to have four cogs blink there own LED. Sounds trivial, but should be a good learning experience.
Ray
#include <propeller.h>
void main()
{
·/* The LED is connected to pin 9. */
· DIRA = 1 << 9;·· /* Not sure what this is doing */
· OUTA = DIRA;···· /* OUTA, DIRA, have to be upper caps */
· sleep(1);······· /* Sleep for one second */
· OUTA ^= DIRA;··· /* ^= , a toggle, in this case
·················· toggles off */
}
For those of you that have not tried C yet, so far, for me, it has been a pleasant experience, no hair pulling yet. Everything, in the IDE,·seems to be pretty intuitive, and that is the way I like it. If you are going to use the snippet below, once you make it a .c file, create a project with it. After you have the project or the file, in the File dropdown, use Compile File to create the Output file. Then goto Tools, and use the Propellant Downloader to get the project that you created onto the chip. This all seems very straight forward, and very simple. What I described here, took me about an hour last night.
A couple of things that would make life easier, is maybe a downloadable pdf file that would be a programmers manual. The Help file, I find it to be somewhat cumbersome to use. Also, I could not find things like what has to be in upper caps, for instance like DIRA, and OUTA. I also could not find an explanation for ^=, which I figured out to be a toggle, I think. So, there are some minor problems, as I perceive it, but in general it looks like a solid product.
Since I plan to convert one of my Spin programs to C, I think that I may have a problem with the following parts, I use serial comms, and·some IR·SIRC code in the program. In the object exchange I did not see any C equivelants, so that is a problem from the get go, unless I can figure out how to take the existing Spin code objects and use them directly in the C program.
The next little program that I may try is to have four cogs blink there own LED. Sounds trivial, but should be a good learning experience.
Ray
#include <propeller.h>
void main()
{
·/* The LED is connected to pin 9. */
· DIRA = 1 << 9;·· /* Not sure what this is doing */
· OUTA = DIRA;···· /* OUTA, DIRA, have to be upper caps */
· sleep(1);······· /* Sleep for one second */
· OUTA ^= DIRA;··· /* ^= , a toggle, in this case
·················· toggles off */
}
Comments
Leon
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Amateur radio callsign: G1HSM
Suzuki SV1000S motorcycle
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
--Steve
Post Edited (jazzed) : 8/26/2008 2:45:33 PM GMT
That's not possible at the present time. It might be one day but don't hold your breath waiting. It could be quite a challenge to inter-mix C and Spin.
I am also thinking·about the possibilities of creating PropOS that would be written in C; sort of a test run prior to the release of Prop II, where a PropOS would make a lot more sense. Doing a lot of daydreaming today LOL.
Thanks
Ray
Now, that being said one can use EEPROM or some other device to store the "text code segment" (SD card is possible, but the code would eat too much memory space to be practical). Then the program can use internal memory (or external for the adventurous) for variables and the interpreter kernel that C uses. I'll be working on that project in the near future, but I have something else to finish first.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
--Steve
Ray
I just got through looking at the object exchange, pretty thin for C progs, again, I want to thank jazzed for the contributions that he has made. I am wondering if some of the asm progs could be easily packaged in a function, and used that way. The one function that could be usefull is a keyboard, I noticed that there is an asm prog, just wondering what would be the format for packaging it within a function, and would it work correctly? I·hope some of the programmers, that are just developing asm programs, could keep in mind the portability issue, of using it within a C program.
Ray
I looked in the object exchange and did not see any code that would even give me a hint. I guess I am choosing one of the harder modules to start with, so, does anybody have any idea what so ever as to how to begin building the driver for this thing. I would like to build the driver in C, but I am open to trying in spin first.
Ray
You should look at spin at least to understand the environment and interfaces to the PASM ascii-byte array code. Spin is very C-like (and lisp-like as in "repeat var from" instead of for(...)) once you get past the intentional mis-use of curly braces and using := instead of = for assignments (among a few others).
One good item to start with is the keyboard code since you are interested in that. Basically, create a keyboard.[noparse][[/noparse]ch] module similar to the spin PUB methods. You can get a feel of spin PUB APIs from the "Documentation" view in the spin editor. The start method will be the hardest to translate, but if you look at some of the OBEX examples like TV_Text or Mouse, it will become clear what needs to happen (I hope). I'm including a windows command line binary that will automatically decode a spin binary and create an ascii-byte array if you want to use it to try and create a keyboard module. I might work on keyboard code tomorrow.
I've never given thought to using 7 segment LEDs with Propeller though I did with the SX chip, so I don't know where to point for that.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
--Steve
The way to look at the led digits is the segment pins select whihc segments to light for all of the digits and the digit pins select which digits to light. I think you take the digit pins low and the segments high. So if you take segments b,c high and digit L digit 1 low, then you see a 1 on the left hand display. To show something on all displays you have to keep cycling round selecting the right segments for each display.
If you want to do a driver, then you proably need a routine that copies an input string to a buffer. Then a separate cog will read the buffer and display in on the displays continously, i.e. start at the first byte of the buffer, work out the segments for that byte (say 0-9 for numbers), set the segments on the output pins, select digit L1, then get the 2nd byte, select segments and select R1, repeat for each byte in buffer/display. Then you need to decide what to do if buffer is bigger than 6, do you stop and not display or do you scroll the display.
Two resources to look at
http://obex.parallax.com/objects/360/·is on object for a led display, it has less segments then the ppdb, it also is't interfaces in the same way - you done drive the segments directly but it has scrolling support.
The thread by obc on the ppdb has some spin code for the ppdb display, again its in spin but you can see what it takes to drive the display
Post Edited (Timmoore) : 8/30/2008 8:14:39 PM GMT
I also played around with the sixteen LEDs, below is the program that I had used, it is from the ICC help file, so it is not pure code developed by me, but, never the less it works. The one thing that I noticed when working with PPDB LEDs, when you attach a wire from lets say p0, and connect it to 0 on the LED header, the LED starts to blink. Now, if you attach it to a power source, the LED stays on all the time, I wonder, what is going on, what causes it to blink when connected to a processor pin? ·There is no program in the EEPROM, and I did not have a program in RAM.
Below is the most straight forward example of what a C program would look like, you have to have the function prototype declared before you can use the function, and it has to be outside of main(). The innards of the function itself, I discussed the important parts in a previous post. Couple of things to look out for, the use of brackets, and the use of the semicolon, miss any of those in a longer program, and you will be tied up with a debugging nightmare.
Now that·I have tried Spin and C, I sort of like the structured style of C, I wonder what C++ would have to offer? OOP, and how would that help when it is applied to the Propeller?·I am probably going to leave inline assembly to the very last thing that I would be doing. Now I have to see if I can get some large programs built before my ICC Demo copy reverts to 4K.
#include <propeller.h>
void BlinkLED(void);
void main()
{
BlinkLED();
}
void BlinkLED()
{
· int i;
·
· while (1)
·
··· for (i=0; i <=15; i++)
·· {
····· DIRA = 1 << i;
····· OUTA ^= DIRA;
····· msleep(1000/2);
······OUTA ^= DIRA;
····· msleep(1000/2);
·· }
·
}
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
--Steve
The reason for the change of heart is simple, there is no quick and easy way of wiring the board so you can quickly check out some of the programs that jazzed has provided. Meaning, his latest contribution, the keyboard program, first you have to wire up the TV·component, then the keyboard component, then you have to make sure you get it right with the pin connections,· ..., so on, and so on. With the Demo board it would be matter of plugging the cables in, and·starting up the program. ·So, for those of you that are thinking about purchasing a PPDB as your only board, you better make sure that you have defined exactly what you will be doing with it.
Ray
Ray
BTW: I bought 5 Protoboards, a Prop-Plug, and a VGA accessory kit for about the same price of the PPDB, but that did not come with an RTC or LED segments, etc... Then again, I don't mind using a soldering iron.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
--Steve
Post Edited (jazzed) : 9/1/2008 6:26:22 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
--Steve
PUB display
·
· repeat
··· DIRA[noparse][[/noparse]0..3]~~
··· DIRA[noparse][[/noparse]4..7]~~
··· DIRA[noparse][[/noparse]0..3] := %1111
··· OUTA[noparse][[/noparse]4..7] := %1111
··· waitcnt(10_000_000 + cnt)
··· DIRA[noparse][[/noparse]4..7] := %0000
··· waitcnt(10_000_000 + cnt)
This works, and it blinks a 7 on the first four 16 segment·display. Now when I tried to convert this to a C program, I am not getting anything:
#include <propeller.h>
void (main)
{
·· DIRA = 1;
·· OUTA =· 0;
·· OUTA =· 4;
·· sleep(1);
}
Here I am trying to select the first digit, and the A1 segment, I am not getting anything. Now, when I tried to use the same strategy on an LED, I could get it to light up. In this particular case, I cannot get the segment to light up. Any ideas as to what the problem might be? I wish ICC would have a simple explanation as to how, and what can be done with DIRA, OUTA, and some similar commands.
Thanks
Ray
Post Edited (Rsadeika) : 9/16/2008 2:26:56 PM GMT
You said that the Spin program worked. Now My guess is that you copied this program from an example somewhere.
Thats fine, but You can't expect to write a C program if you don't have a complete understanding of how the SPIN program works.
Ask yourself what·does DIRA[noparse][[/noparse]0..3]~~ actually mean and·how can I check that the instruction is excuted the way that I expected.
Don't worry too much about C at this stage that comes later.
Spend some time on the spin code and understand each line of the SPIN code and fiqure out how you can check that each line of
code executed·as you expected it to.
If I guessed wrong then I appologize and disregards my comments
Ron
Here's an easy way to deal with the video connection..
www.parallax.com/Store/Accessories/CablesConverters/tabid/166/CategoryID/73/List/0/Level/a/ProductID/385/Default.aspx?SortField=ProductName%2cProductName
You'll also want an extra one of these...
www.parallax.com/Store/Components/WireConnection/tabid/151/CategoryID/29/List/0/SortField/0/Level/a/ProductID/182/Default.aspx
I bought three of these for working with the PPDB. (should have bought a couple more)
They should take the pain out of connecting things like video, sensors, etc.
OBC
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
New to the Propeller?
Getting started with a Propeller Protoboard?
Check out: Introduction to the Proboard & Propeller Cookbook 1.4
Updates to the Cookbook are now posted to: Propeller.warrantyvoid.us
Got an SD card connected? - PropDOS
Ray
DIRA = 3;····· //This should be %11, direction is output for p0, and p1
OUTA = DIRA; //This should be %11, output is VDD for p0, and p1
sleep(1);······ //This should keep the A1 segment lit for one second
I guess I just do not see the error of my ways, anybody see a glaring mistake?
Thanks
Ray
Ray
I will check our website.