Book: Programming the SX Microcontroller - stumped on the first tutorial :cry:
doggiedoc
Posts: 2,246
Hi again!
Well, I just pop up with problems all over don't I? Sorry to be such a problem child, but I really do enjoy this (I think <grin>).
Ok, so I maybe I have bitten off more than I can chew this time. I wanted to get my feet wet with assembly language and what better way than with the SX? So here I am with a head-ache from trying to get TUT001.src to work. I have checked and double checked the code and I have it typed in EXACTLY as in the book (even matched the case on every letter - even thought that shouldn't matter.) I am running XP with SX-Key v3.10 and the SX is plugged in to the SX Tech board powered by 7.5v 1000mAh AC/DC converter. The SX-Key is oriented correctly.
When I run the code the LED comes on very dimly. If I reverse the LED to a pull-down resistor instead of a pull-up then run the code the LED will come on (I am comfortable that I am reading the schematic correctly). When I run debug - it won't STEP - it doesn't react as expected and the D window says SLEEPING and the buttons are dimmed out (not active).
I don't know what I am doing wrong. Is the code too "dated" for the version of software I have or are there settings I don't understand?
Any help greatly appreciated, especially at this late hour (maybe some of you left coast guys are still at it <grin>).
Cheers,
Doc
PS: here's the code-
Well, I just pop up with problems all over don't I? Sorry to be such a problem child, but I really do enjoy this (I think <grin>).
Ok, so I maybe I have bitten off more than I can chew this time. I wanted to get my feet wet with assembly language and what better way than with the SX? So here I am with a head-ache from trying to get TUT001.src to work. I have checked and double checked the code and I have it typed in EXACTLY as in the book (even matched the case on every letter - even thought that shouldn't matter.) I am running XP with SX-Key v3.10 and the SX is plugged in to the SX Tech board powered by 7.5v 1000mAh AC/DC converter. The SX-Key is oriented correctly.
When I run the code the LED comes on very dimly. If I reverse the LED to a pull-down resistor instead of a pull-up then run the code the LED will come on (I am comfortable that I am reading the schematic correctly). When I run debug - it won't STEP - it doesn't react as expected and the D window says SLEEPING and the buttons are dimmed out (not active).
I don't know what I am doing wrong. Is the code too "dated" for the version of software I have or are there settings I don't understand?
Any help greatly appreciated, especially at this late hour (maybe some of you left coast guys are still at it <grin>).
Cheers,
Doc
PS: here's the code-
; ================================================= ; Programming the SX Microcontroller ; TUT001.src ; ================================================= LIST Q = 37 DEVICE SX28L, TURBO, STACKX, OSCHS2 IRC_CAL IRC_FAST FREQ 50_000_000 RESET 0 mov !rb, #%11111110 Loop clrb rb.0 setb rb.0 jmp Loop
Comments
this code is actually not designed to be run at full speed as the LED is toggled way too fast. This is why it comes on very dimly - I have described that later in the tutorial. I have included this very simple code so that the readers have something they can single-step with the debugger.
Well now, by some reason, with your setup, the debugger displays the sleep mode which does not allow you to single-step the code. Please make sure that there is no resonator plugged into the 3-pin socket on the SX-Tech board. The SX-Key won't debug as long as there is another resonator because the SX-Key supplies the clock to the SX for debugging.
I hope this helps to get the system up and running. If it does, please continue reading the first chapter. You will soon learn how to "slow down" the SX to nicely blink the LED.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Greetings from Germany,
G
It is now perfectly clear!
Thank you, thank you, thank you!
Doc
SX-Keys conflicting with on-board resonators has been topic in the forum more than once. Obviously because none of the existing manuals clearly point that out. You can find some more information on it in the FAQ document (see the "sticky" post at the beginning of the topic list). This document contains more information that might be handy when just starting with the SX.
I promise that the next edition of the SX-Key manual will cover such pitfalls in more detail.
Good luck and happy programming!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Greetings from Germany,
G
I know people who use books for killing flies but I never heard of people using books as chair cushions. So what else did you do with the book at your soccer game?
Besides this I'm glad to hear that you like it. I always suggest to "drink from more sources", so you should also have a look at the other fine material available from the Parallax web site, like "Beginning Assembly Language for the SX Microcontroller".
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Greetings from Germany,
G
before answering your message, I must say that I'm shocked about the latest breaking news I just watched at TV about the new terrorist attack in Bali. When will this bombing ever end !!!
Good to hear that you could watch an exciting soccer game - sorry that "you" lost. Sometimes, it is a good idea to take an "out time", like watching a soccer game, when concentrating on learning something new.
I'm glad that you like the tutorial. I suggest that you work through it to get "warmed up" a bit, but then think about a larger project you want to do with an SX, and try go get it done. To my own experience, this is the best way to "boost up" your learning curve. I was working on a project that I planned to build around PIC controllers when I first learned about the SXes. I decided to switch to SXes to get that project done. I can tell you, this was hard work. But in the end, I made it, and I learned a lot about the SX controllers (please don't ask me to publish the code I wrote at that time), just by "fighting" through this project.
This is similar to learning C or any other programming language. It's quite easy to print out "Hello world" (similar to blinking an LED with the SX) - but to really dive into C, do a "real" project.
Having said that, I wish you much success in mastering the SX. I'd be glad to give you a helping hand if I can.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Greetings from Germany,
G
I've experienced similar frustrations trying to learn the SX microcongroller.· To be fair I started reading through "Beginning assembly language for the sx microcontroller" rathor than gunthers book.... mostly because its a lot smaller.· There seems to be a lot it isn't saying yet, and thats giving me some gripe.· things like what a w register is, and why we need one..· I dunno..
I'm·a MechE by trade.. so·I would typically do my programming with cams and linkages.. or just pass the buck to the EE guys..· so I have a lot to understand yet.·
the W register (the "W" stands for "working") is similar to the accumulator register used in other microcontrollers/processors. You can think of it as the "master temporary storage". For example, when you want to copy the contents of any register into another one using a MOV instruction, you can't directly do the copy from the source to the target because all SX basic instructions consist of one word (12 bits), and thus, there are not bits enough to specify the addresses of two registers in a single instruction. So, to copy the contents of FR1 to FR2, you would code
mov w, FR1
mov FR2, w
When you look at the list of instructions supported by the SASM assembler, you will also find the instruction format
mov FR2, FR1
When SASM translates this into instruction code, it replaces it by exactly the sequence of two instrucions, I have shown above. This is why such instructions are called "compound", or "multi-word" instructions.
The W register can also hold one operand of an arithmetic instruction, and possibly its result. For example,
add FR, w
adds the contents of FR and w, and places the result in FR, where
add w, FR
also adds the contents of FR and w, but places the result in w without changing the contents of FR.
Again, SASM also "understands" the
add FR1, FR2
instruction which will be replaced by
mov w, FR2
add FR1, w
It is important to keep in mind that such multi-word instructions use w as temporary storage in most cases. So you should never make an assumpotion on the contents of w, like in the following example:
mov w, #123
mov FR1, FR2
Although you have stored 123 to w, you can't assume that w still holds this value after the mov FR1, FR2 has been executed. This becomes clear when you replace the multi-word instruction by the single-word instructions:
mov w, #123
mov w, FR2
mov FR1, w
Now you see that w is overwritten by the contents of FR2, and the initial value of 123 is lost.
Happy programming!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Greetings from Germany,
G
Being a MechE myself, I feel Duckie's pain.· For example, reading the SX data sheet, I understand about ten percent of it.· It's mostly·a language barrier.· I don't know what a lot of the terms mean.
Chris I.
I quickly scanned through the SX28 data sheet, and collected terms like
ADC, Analog comparator, Bank, Brown-out-detection, Bus, CMOS, CMOS level, Comparator, CPU, Debugging, DTMF generation/detection, EE/Flash Program Memory, File register, FSK, FSR , Fuse registers, High-Z, etc, etc...
Are these terms you would like to see in a glossary? In this case, I think the SX FAQ document I have published (see the "sticky" post on top of this section) might be a good place to host such a glossary.
I wish I had more spare time to prepare a new edition of the FAQ document but I'm too busy with another important SX-related project right now. Therefore, I ask for some patience but I promise to maintain and update the FAQ document in the future.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Greetings from Germany,
G
I kept trying to figure out why the values I was writing to register B were not reflected properly in the debugger window.
I eventually figured out that a pin has to be configured as an output before you can write to it, but that certainly is not obvious if you read the book from front to back..
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I wonder if this wire is hot...
Yes.· All those terms are good candidates.· And the SX FAQ is a great place for them.· Perhaps extending the name to "SX FAQ and Glossary" in in order.·
I will read the data sheet again with a highlighter.· It will be a few days before I get to it.· I'm buried right now.
Thanks,
Chris I.
This is exactly the case - as long as a pin is not configured as an output, the debugger displays what it "sees" at the input pin, and not what you write into the output register.
Chris,
yes, please read the data sheet with a highlighter - it is most likely that you'll find more terms to be explained if I would do it. Don't hurry - as mentioned before, I've got a couple of other things to do as well.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Greetings from Germany,
G