|
|
Exercise 1 : Count of the number of times of opening the door / Realization of display function | |||||
| ■ Exercise 1 2. Creation of the "counter" variable for the count of the number of times 3. TMR1 internal timer / Interrupt handling routine 4. State of opening and closing of the door (RB0) → Output to LED#4 (RB4) with positive logic 5. Count module of the number of times of opening the door: test4 6. Display of the counter to the web control screen
→Click here if you have some questions and comments. ←Back to the table of contents
Updated May 4, 2005 20:40
|
●Goal of Exercise 1As Exercise 1, submit the exercise of "Count of the number of times of opening the door / Realization of display function". →Click here for the submission of exercise. The basic implementation policy is as follows. ・Creating a variable (8bit) for the count of the number of times. ●Creation of the "counter" variable for the count of the number of times (2003/10/12 updated)Create the "counter" variable for the count of the number of times to the BANK#3 register. <Implementation example>
Create 4 counters together with the future in mind. ※2003/10/12 Changes: Initially, 4 bytes from 1B0 were gotten as the counter variable. However, it was found that a value of some kind was entered in the general register near 1B0 somewhere when frequently switching RB5 from the web control screen or mounting continuous attacks from the web browser. Because the variable is not actually defined in this area by EQU, the original v12.asm general register operation (RP0 and RP1) might have a bug (BANK#3 instead of BANK#1 is changed) or PIC16F877 itself might have a problem. To avoid these problems, we changed to get 4 bytes from 1E0 as the counter variable. Because BANK#3 remains the same anyway, the following description is the same as before. In addition, the counter variable should be initialized at the end of the start module. ●TMR1 internal timer / Interrupt handling routineReminders:In Exercise 0, we added four steps for the call processing of the test module immediately after the main0 label and confirmed the operation. (Refer to this part of Exercise 0.) However, from Exercise 1 on, because the module to be implemented is called out by jumping from the timer interrupt routine , make sure to comment out or delete the callout processing which was added immediately after the main0 label. (2005/5/3 added) ※Click here to see the current description related to the internal timer/ interrupt handling routine in PIC16F877+PICNIC firmware,v12.asm.
It is virtually difficult to increase the number of codes within the interrupt routine (The program memory, PAGE#0, is full). From the interrupt routine, it is easy to PCLATH to an external module which resides in program memory PAGE#3 and go back to the return tag in the interrupt routine using a goto jump, so we will use this method.
The above example is executed in the following order from the interrupt handling routine; int_tmr1→jump to test4→(count processing)→back to int_tmr9→int_tmr2 ●State of opening and closing of the door (RB0) -> Output to LED#4 (RB4) with positive logicRefer to Experiment 4 (test2 module) in the tutorial (Execise 0). 【Experiment 4】RB0 (door sensor)→Output to RB4 (LED#4); Creation of the test2 module
●Count module of the number of times of opening the door: test4It should be called out at 13.1-msec intervals from the interrupt handling routine. Because of the callout from the interrupt routine, it is dangerous to save the STATUS and W register's values by wk2 and wk1 as the tutorial (Exercise 0) described. ・Do not conserve the STATUS value.
・Is the door open? (Check of RB0) In the test4 module
●Display of the counter to the web control screenDisplay the value (8bit) of the counter variable counted to the web control screen. Change the callout from the control code '$9' in ctrl_code1. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ <After changing>
<Example of the processing procedure>
●Practical example・Immediately after power-on → After the door is opened and closed once → .... → Ten times Depending on the state of the door, LED#4(RB4) is lighted or unlighted. ●Submission of Exercise 1
(1) Create each module for the realization of the function of counting the number of times of opening the door and the function of displaying it. (2) Using the changes of the state of door sensor, the web control screen and the counter value, confirm to work as required. (3) Change the version number of the assembled source file to (4) Save the assembled source file under the name of v1206e1.asm. (English one byte characters/ Lower-case alphabets/ Do not use one-byte katakana and double-byte characters as file name.) (5) From the following report submission system, upload v1206e1.asm. We will mark your report after receiving it. <How to submit> We will judge submission or completion after checking the operation of the file you submitted. You have to resubmit if there are any defects in the operation. You can finish if the operation is OK. Click here to submit the report of Exercise 1 (Exercise number: picnic-exp01). (6) You have to "wait our judgement". Send an e-mail to here if you do not receive the result of judgement for a long time. (7) If you received the judgement of submission, correct the defects indicated, change the filename to the name of v1206e1a.asm and so on and submit it. (8) Without (7) (that is, the judgement of completion), your report was accepted and you can finish.
●Point of considerationPoint of consideration on this time's specification and implementation is as follows. You do not have to answer it as a report, but make sure to arrange your thoughts before you finish the program and submit your report.
[1] Because the 8-bit counter is used, the number of times returns to 0 because the variable overflows when the door is opened and closed 256 times. What should be done to avoid that? [2] If a 16-bit counter is used as the number of times of opening and closing the door, the variable will not overflow in actual use. Which part should be changed to do that? [3] If a door switch with extremely long chattering time (about three times as long as TMR1 timer interrupt interval) is entered, there is a possibility that the count-up is mistaken more than once in a single operation of opening and closing. What should be improved to avoid that? [4] The counter should be set the default value to 0 somewhere after reset. Where should that be implemented exactly?
|
|||||
|
wasaki@cs.shinshu-u.ac.jp |