|
|
Tutorial (Exercise 0) | |||||||||||||||||
| Tutorial (Exercise 0) 2. Memory Use Status and Jumps between Pages 4. call/return with a dummy module 5. Door sensor -> LED relay outputs 6. Introduction of In/Out mode
→Click here if you have some questions and comments. ←Back to the table of contents
Updated May 4, 2005 20:33
|
Tutorial ObjectiveNow we will begin the tutorial using the PICNIC+peripheral extension option kit. In this tutorial, we will show the programming for the following implementation examples: *call/return with a dummy module (Experiments 1, 2) Finally, for Exercise 0 (Experiment 8), we will implement * Memory Use Status and Jumps between PagesNow, I can understand wanting to take the code up to Exercise 0 and placing it directly in the main loop main0-main99, but let's not rush and wait a minute here. If you think OK and merrily go about adding code right after main0, after a while, you will start noticing things like lack of response from the web control screen, partial displays of the HTML control screen, the browser receiving icon never moving on from "receiving" mode, etc. and from the symptoms it would appear that the system is "unstable". < Cause of Problems > With the current implementation of firmware, PAGE#0 of program memory is used right up to the limit. Memory Use Status
For example, on PAGE#1, the put_socket_stat module (for sending socket status to the Web browser (i.e., netstat -n)) is commented out because PAGE#1 is already full and unless we delete this portion, the other modules will not fit in the memory. In firmware development, we need to treat one word of memory like a single drop of blood and use the limited memory space to the fullest. < How to solve the problem > About the only other place to put additional modules
while preserving the current functions is in:
This is right after Bank#4 for web messages, so here also we need to be careful not to let the Bank#4 messages exceed 256 words. In the remainder of the tutorial, we will implement the experimental module from 1E00h and to check its operation we will write code for calling "across pages" to call the experimental module right after the main0 label. OK, let us proceed with the actual implementation. * On Firmware ver1.2.0.4(b) (updated 2004/10/30)In Section 4. Firmware Updating Procedure, we started with the original ver1.2.0.0 (v12.asm) and made the following changes: Update of the firmware version number to update the firmware to ver1.2.0.1. ver1.2.0.0 * original distribution After that, a number of small modifications were made to update the firmware to Version ver1.2.0.4(b), the "starting point" for this tutorial. ver1.2.0.2 update history 0.1->0.2 View the web control screen for the latest version The remainder of the tutorial makes changes to this latest version of the firmware ver1.2.0.4(b). Of course, you can make the changes to the original firmware (v12.asm) and still get it to work in the same way. Click here to download the latest version of the firmware (v1204org.asm, modified Oct. 30, 2004) * Notes of Caution * IP address: 192.168.1.200 (not 0.200) To use this form of the firmware, set the network segment of the operation PC to: * IP address: 192.168.1.10 (If you don't understand what this means, go back and review) * Oct. 12, 2003 modification(a): * Oct. 30, 2004 modification(b): * call/return using a dummy module[Experiment 1] Construction of a dummy module e0.4.1 [Experiment 1] Construction of a dummy moduleLet us construct and experiment with a dummy module. < Specification > < Operation > < Outline of Processing > * figure out the page position
(#0-#3) of the module to be called
< Implementation >
[ Calling side of dummy call ] Note of caution:Be sure the four lines to be added for calling the dummy module are positioned just after the existing main0 label. In this position, the calls will be sure to be made periodically from the main loop. (Added May 3, 2005)
[ Placement of the dummy module ] Web browser messages up to here [ver0.4] because it will be a suitable place to do an org 1E00h. The processing of the dummy module will be to perform only a nop command (do nothing) and then return.
e0.4.2 [ Experiment 2 ] Construction of dummy2 module version for saving STATUS register valuesOnce Experiment 1 has been completed correctly, let us next construct a dummy2 module version which saves the values of the STATUS register. < Specification > < Operation > < Outline of Processing > wk2 is convenient because
it looks the same from any of the
register banks BANK#0-#3. In interrupt routines where wk2 is used without initialization, processing for first storing the value of wk2 is performed before it is used, creating a vicious cycle of saves in the implementation. However, in the current firmware, wk2 is not used when dummy2 is called so we will use it to store the values of the STATUS register, but not add processing for storing wk2 itself (<- complicated, but be sure you understand what that means). Of course, since wk2 holds the values of the STATUS register, it cannot be changed until the STATUS register has been restored. < Implementation >
Now, while the STATUS register is being stored (at the point where nop is being executed), we can change the STATUS RP0,RP1 bits as much as we like. With this, the base for the experimental form below is completed. :-)
Door sensor -> LED relay output[ Experiment 3 ]
Fixed value output ("H") on RB4 (LED#4) Construction of test1 module e0.5.1 [ Experiment 3 ] Fixed value output ("H") on RB4 (LED#4) Construction of test1 moduleTo practice outputting values on PORTB, let us create a test1 module which will output a fixed value ("H") on RB4 (LED#4). < Specification > < Operation > < Outline of Processing > We can switch to register bank BANK#0 and #2 by clearing the RP0 bit of the STATUS register. To set PORTB[bit4] high, we can first read PORTB with movf, do an OR operation on bit4 to force it high, and then write the result back to PORTB. < Implementation > Below, we will omit changes to the main0 side and the save/restore processing at the beginning and end of the module. The four lines below will replace the nop in dummy2. Of course, the module entry label should be test1, not dummy2.
Now, even if we command RB4=L, it
will hold at H.
e0.5.2 [ Experiment 4 ] Output RB0 (door sensor) -> RB4 (LED#4) Construction of test2 moduleNext, to review conditional branching commands, let us construct a test2 module for outputting the value of RB0 (door sensor) to RB4 (LED#4). < Specification > Output RB0・door sensor) -> RB4・LED#4) (normal logic) < Operation > < Outline of Processing > To switch to register bank BANK#0 or #2, we can clear RP0 of the STATUS register as in Experiment 3.
To check the status of PORTB[bit0], we first read PORTB with movf and copy it to working memory wk1. We then check the bit (e.g., using the btfsc command) (since we do not want to destroy the W register). To save the W register,
we use the common variable wk1 (wk1 07EH). * To set PORTB[bit4] H, we
do the same as Experiment 3 (force bit4 to H with OR logic). < Implementation >
Now the value of RB0 (door sensor) is output as is to RB4 (LED#4). (In other words, LED#4 is on when the door is closed.)
e0.5.3 [ Experiment 5 ] Reverse logic output RB0 (door sensor) -> RB4 (LED#4) Construction of test2a moduleConstruct a test2a module by modifying the test2 module to output the reverse logic value of RB0 (door sensor) to RB4 (LED#4). In other words, in the security system we want to use the opposite meaning from test2 and assume the lamp goes on (=door open alarm) when the door has been opened (danger situation) < Specification > < Operation >
< Hint > (Before modification) (After modification)
e0.5.4 [ Experiment 6 ] Reverse logic output RB0 (door sensor) -> RB7 (Relay#2) Construction of test2b module< Specification > < Processing >
< Hint > Before modification After modification
e0.5.5 [ Experiment 7 ] Normal logic output RB0 (door sensor) -> RB4 and reverse logic output RB0 (door sensor) -> RB7 Construction of test2c module< Specification > RB0・door sensor) < Processing >
< Hint > (Before modification) (Before modification)
* Introduction of the in/out mode[ Experiment 8 ] (Exercise 0)
Alarm operation switching based on in/out mode Construction
of test3 module e0.6.1 [ Experiment 8 ] Alarm operation switching based on in/out mode Construction of test3 module< Specification > During Low: out mode (initial value on reset) Based on this in/out mode we want to do the following RB0・door sensor) < Operation > Based on the in/out mode, we can do the following * check the door status from LED#4 during in mode
* Note of caution during programming Be sure to always add a short comment describing the action being taken on every line of assembly code. Even the person writing the program can forget the contents after 2-3 days and since the names of many branching commands in particular have confusing names (e.g., btfsc, btfss), be sure to add comments carefully to branching conditions in the code. Writing comments might seem useless at first, but it is an important element in the process of developing programs (->refer to Javadoc samples) e0.6.2 Considerations for setting "out mode" on reset initialization (RB5==Low)(A) Case of assuming "in mode" during the initial value (Low) If a soft reset is done or a power outage occurs while you are out, the initial Low value on restart would be taken as "in mode" and the door open warning function would stop working. (B) Case of assuming "out mode" during the initial value (Low) As opposed to case (A), restarting from a soft reset or power outage would set the initial value Low and be taken as "out mode", so the door open alarm function would continue working. (C)Battery backup during power outages If you use an AC adapter and provide power to your system from an outlet, the door alarm "will not work" during a power outage. For this reason, you should prepare an uninterruptible power supply (UPS) for your PICNIC+peripheral extension options kit+network connecting environment. * Submission of Exercise 0(2) Verify that it works according to the specifications by using the door sensor status and the RB5 state change functions from the web control screen. (3) Change the assembly source
file version number to (4) Save the completed assembly source file as v1205e0.asm (use only one-byte English alphabet characters and numerals, alphabet characters should be lowercase, do not use one-byte katakana or two-byte characters in the file name.) (5) Using the report submission system below, upload v1205e0.asm. Reports will be scored upon receipt. < Method of submission > We will check the submitted programs and post a COMPLETED mark if the operation is OK and a RESUBMIT mark if there are any problems with the program operation. Submit Report Exercise 0 (Exercise number: picnic-exp00) here (6) The report status will be WAITING FOR MARK. Please wait while we check your report. If the waiting status does not change for an extended period of time, please send mail here. (7) If a report has been marked as RESUBMIT, correct the problems indicated and submit under a different name such as v1205e0a.asm. (8) If (7) does not occur (COMPLETED mark), Report Exercise 0 has been received and marked as completed.
|
|||||||||||||||||
|
wasaki@cs.shinshu-u.ac.jp |