Shop OBEX P1 Docs P2 Docs Learn Events
C language — Parallax Forums

C language

RsadeikaRsadeika Posts: 3,837
edited 2008-09-17 17:44 in Propeller 1
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 */

}

Comments

  • LeonLeon Posts: 7,620
    edited 2008-08-26 13:53
    ^ is standard C for a bitwise XOR. You ought to get a good book on C like The C programming Language.

    Leon

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Amateur radio callsign: G1HSM
    Suzuki SV1000S motorcycle
  • jazzedjazzed Posts: 11,803
    edited 2008-08-26 14:35
    There is a default bit-banged ASIO serial module that ships with ICC, but it has limitations. I've uploaded an ICC version of FullDuplexSerial to OBEX. Look for "C FullDuplexSerial" in the protocol section.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --Steve

    Post Edited (jazzed) : 8/26/2008 2:45:33 PM GMT
  • hippyhippy Posts: 1,981
    edited 2008-08-26 17:46
    Rsadeika said...
    ... unless I can figure out how to take the existing Spin code objects and use them directly in the C program.

    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.
  • RsadeikaRsadeika Posts: 3,837
    edited 2008-08-26 18:33
    Thanks jazzed for the FullDuplexSerial contribution, I downloaded it, and I will be looking at it to see how it is used. To bad there isn't a way of converting the spin code object to an object file that could be understood by C. I guess, then you could create a lib that would contain all the functions that you would want to use. Sort of getting excited over this, but there is still a lot of missing stuff before C becomes workable for us beginners; will get bored blinking LEDs pretty soon.

    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
  • jazzedjazzed Posts: 11,803
    edited 2008-08-26 18:48
    Propeller internal memory is not big enough for a "real" operating system with kernel services and "N" tasks. The same will be true of PropII ... but at least there will be enough pins there to have "at speed" memory hardware expansion almost like any mainstream CPU. Today's Propeller memory is big enough for file operations and launching programs one at a time for spin; C would be too big. Spin uses byte-codes and is smaller than C by about 3.5 to 1.

    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
  • RsadeikaRsadeika Posts: 3,837
    edited 2008-08-27 12:58
    Well, I broke down and ordered a PPDB, I should be getting it sometime late next week. So, now I have to come up with some ideas as to what C programs I can test on the board. Getting a little bored with the blink LED, I guess I can check out the VGA aspect. Since it has the 6 LED display units, maybe a program that uses the DS1302, and displays the results on the LED units, so everytime I turn the PPDB on, I will have a clock running. But, I did not see any easy way of attaching the DS1302 to a battery, let alone the PPDB. Is there a freebee manual in the works called, C language experiments using the PPDB? Maybe that sounds to academic, how about, C working out the PPDB?

    Ray
  • AleAle Posts: 2,363
    edited 2008-08-27 13:10
    That board has 6 14 or 16 segment LED digits and VGA out and so on. So you can come up with some nice combinations. Driving those digits requires a bit more than what is needed for a led. A VGA object for C is already available so you can combina both and adding a sound driver should not be that difficult.
  • RsadeikaRsadeika Posts: 3,837
    edited 2008-08-30 12:30
    I received my PPDB yesterday, so, I had a couple of hours to check it out; somehow I got the impression that the components, at least some of them, were hard wired. Since they are not, I am surprised that Parallax does not have a set of ribbon cables to make the connection between the components, and the processor header. There are a couple of other short commings, which have been·noted in other threads, ·but they can't think of everything.

    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
  • RsadeikaRsadeika Posts: 3,837
    edited 2008-08-30 17:53
    So, I have been·looking at the schematic for the sixteen segment displays, and it is not becoming apparent as to how you are supposed to make this thing work. It has a 2 x 17, and a 2 x 6 header, does that mean I will have to use 23 pins to make this thing work? If that is the case I think a small LCD device would have been more functional, using maybe two pins to drive the thing.

    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
  • jazzedjazzed Posts: 11,803
    edited 2008-08-30 19:21
    Rsadeika,

    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
  • TimmooreTimmoore Posts: 1,031
    edited 2008-08-30 20:08
    Rsadeika,
    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
  • RsadeikaRsadeika Posts: 3,837
    edited 2008-08-31 15:37
    With the suggestions from the previous post, I have a good idea as to how to light up the segments in the LED display, now it is a matter of sitting down, and putting together a C program to do the job. I will probably start with just one segment, do not want to many wires floating around, and to many of the processor pins to deal with at the moment. If I get something done I will post the program.

    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);
    ·· }
    ·
    }
  • TimmooreTimmoore Posts: 1,031
    edited 2008-08-31 16:52
    Heres a spin program that drives the ppdb displays, supports scrolling. The character lookup propably has some bugs 0-9 is correct, A-E is correct, others iffy.
  • jazzedjazzed Posts: 11,803
    edited 2008-08-31 20:09
    Please note keyboard driver posted in separate thread.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --Steve
  • RsadeikaRsadeika Posts: 3,837
    edited 2008-09-01 12:48
    I have had my PPDB since Friday, and I think I may have made a mistake in purchasing the product, what I·really probably need is the Prop demo board. I will probably keep the PPDB, and just work with the cumbersome aspect of the board.

    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
  • RsadeikaRsadeika Posts: 3,837
    edited 2008-09-01 15:35
    Today I was looking at the schematic for the RS-232 DCE component, on the PPDB,·and I noticed that on the DB9 the Rx is pin 4, and the Tx is pin 3. I went online and checked some of the so called standards, and for, lets say, a DTE, Rx·is pin 2, and Tx·is pin 3. Is there a typo, if not, then is the DB9 actually wired that way. It seems if I wanted to hook to my computer, I need the Rx, and Tx to be pins 2, and 3. I guess I need an explanation, before I start writing some C code.

    Ray
  • jazzedjazzed Posts: 11,803
    edited 2008-09-01 18:21
    Ray, looking at the schematic and the RS-232C DB9 standard it appears as though the connector might be reversed. Messing this up would be a pretty big guffaw, and knowing Parallax the product should function. The thing to watchout for of course is whether or not you have a correctly defined Null-Modem conversion between 2 DTE connections.

    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 SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-09-02 21:23
    Ray, the schematic has the DB-9 connector mirrored. All the pins are in reverse order on the diagram but it is wired correctly. Pin 5 is ground for example, not pin 1.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
  • jazzedjazzed Posts: 11,803
    edited 2008-09-03 05:43
    Looks like the PPBD schematic has been updated today. Can't ask for much better response than that.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --Steve
  • RsadeikaRsadeika Posts: 3,837
    edited 2008-09-16 13:07
    I started to play around with the·16 segement·display on my PPDB, and I am running into a problem with trying to get it to work with a C program. I have tried the spin program, and it works:

    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
  • Ron SutcliffeRon Sutcliffe Posts: 420
    edited 2008-09-16 13:57
    Ray

    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
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2008-09-16 14:16
    Ray,

    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
  • RsadeikaRsadeika Posts: 3,837
    edited 2008-09-16 14:51
    I attached a picture of the cable that I am using, picked it up at an electronics flea market, very cheap. I like the colored wires, simplifies trying to figure out what is what, and it is 16" length. For the PPDB, I think, it is about the right length, if to long I just coil the cable. For the PPDB, you need, four, three, and two wire cable sets, that way you can deal with the 17&6 pin requirement of the 16 segment display fairly easily. So, you should make sure you have a wiring strategy worked out before you start dealing with the components on the board.

    Ray
  • RsadeikaRsadeika Posts: 3,837
    edited 2008-09-17 15:51
    For the last couple of days, I have been trying to come up with a minimal C prog to light up one segment on the 16 segment display, on the PPDB, with no success. I have p0 connected to the first digit, and p1 connected to A1, to simplify things. The snippet that, by my understanding, should light up the segment:

    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
  • RsadeikaRsadeika Posts: 3,837
    edited 2008-09-17 17:23
    Has anybody purchased the ICCV7 For Propeller Manual? Just wondering what is contained in the manual, or is it just a hard copy of the help.pdf that comes with the system. Would be nice if ICC would give an indication as to what you get for the $26.00.

    Ray
  • Roy ElthamRoy Eltham Posts: 2,999
    edited 2008-09-17 17:30
    I am pretty sure it's just a printed version of the PDF that comes with the download.
  • ImageCraftImageCraft Posts: 348
    edited 2008-09-17 17:44
    I'm sure we said somewhere that the HTML Help is the same as the included .PDF file and the printed manual. Hence it's optional.

    I will check our website.
Sign In or Register to comment.