This lesson gives you an example that holds a lot of the new instructions from the previous lessons.
The Program |
The example program that we will give you in this lesson works as follows: You will see 00 on your calculator screen when you start the program for the first time.
By pressing the up and down keys, you will be able to increase or decrease that number. The number is hexadecimal which means that you can go up to FF.
Pressing CLEAR or MODE will exit the program, but will also save the number currently on the screen somewhere inside the program.
The next time you start the program, the start number on the screen will be the number that was on the screen when you quit the last time.
Well, here it comes! It is an ASH 3.0 program, but it will also run on CrASH 1.x.
.db "Hex Program",0
CurrentValue = TEXT_MEM
; ShowHex routine
; input: a = number to display
; output: number displayed in hex
.db "Press Up/Down",0
.db "CLEAR to exit",0
.db "Last time :",0
As you can see, the first thing that's done is clearing the LCD and putting the titles.
Then, the old number(from when you last ran the program) is 'restored' and put on the screen also, using the ShowHex function.
If you run the program for the first time, the starting number will be 00, because Data_LastTime is initialised on $00.
The ShowHex function is also used elsewhere in the program to display the CurrentValue of the number.
The program enters a first loop where the screen is updated and continues in a keyloop.
This loop is only exited when up, down, clear or mode is pressed. Up and down will update CurrentValue and jump back to the first loop.
Clear and Mode will save the CurrentValue to the LastTime byte and return to the assembly shell (Ash or Crash).
About the ShowHex routine:
The first thing that's done is moving the upper nibble of A to the lower nibble by shifting (after masking out the upper nibble with AND $F0)
Then, the value for TX_CHARPUT is calculated. According to the value of A (0-15) this is '0'+A or 'A'+A-10.
This value is put on the screen with TX_CHARPUT and then the lower nibble of A is also taken care of.
Previous lesson |