|
|
Programming Tips | |||||||||||||
| ■Programming Tips 0. About troubles with the PIC16F877A Version ←NEW
→Click here if you have some questions and comments. ←Back to the table of contents
Updated April 29, 2005 21:57
|
●About troubles with the PIC16F877A Version (Added on 2004/4/29)
<The cause why writing error occurs> <How to solve the troubles> <Conclusion> ●Information materials for programmingMicrochip PIC series/Peripheral LSI data sheet/Books, Other project sites and FAQ 6.1.1 Microchip PIC Series→Links to all related information are here Microchip site Microchip U.S 6.1.2 Peripheral LSI Data Sheet→Links to all related information are here Ethernet-NIC (Realtek
RTL-8019AS) 6.1.3 Books, Other project sites and FAQ→Links to all related information are here Books PIC microcomputer practical use handbook (Published by CQ) Other project sites and FAQ Eric's PIC Page ●PICNIC Firmware OutlineBuilt-in protocol stack/Download/Outline of each block/About operation/Initial setting sequence 6.2.1 Built-in Protocol StackThe protocol stacks mounted in the firmware of this PICNIC are as follows. - Ethernet frame transceiver processing 6.2.2 Download Please download the firmware (ver1.2) for MPASM assembler of PICNIC ver.2 from the following sites. Assembly source file (v12.asm) Assembled HEX file (v12.hex) Listing file (v12.lst) Error file (v12.err) ※Reference: Include header file for PIC16F877 P16F877.inc 6.2.3 Outline of Each Block In the whole firmware, there are 7380 lines of codes.
Line 21-37: Definition of various constants
Line 470: Starting point of the program (ORG 0) Line 820-889: Main loop
Line 902-1018: Ethernet frame reception processing (RTL8019AS buffer control)
Line 2328-2393: A/D conversion input processing
Line 2771-3032: About the initialization of RTL8019AS
Line 3352-3578: UDP → parallel I/O control, A/D conversion function
Line 3879-4024: Socket control
Line 4295-4369: About writing data to EEPROM
Line 4379-4548: URL specified CGI analysis processing
Line 4651-4919: Start-up routine (Related to setup at the time of power supply)
Line 5297-5404: Bootstrap mode and initialization routine Line 5952-6056: Notification processing of the present socket status (Now unused)
Line 6139-6266: Processing that displays the acquired IP address on the LCD panel
Line 6273-6424: Serial port → UDP transmission processing Line 7061-7258: Storing area for the response massage and its format that are in web browser HTML format 6.2.4 About the operation It is almost not necessary to change the already mounted various protocol stacks by the user side. The change in the page displayed on a web browser for control starts from line 7061. The portion of storing area for the response massage and its format that are in web browser HTML format will be changed. Since there is limitation of Ethernet frame length, all HTML format texts cannot be sent at a time. So text is sent by dividing it into four blocks(4 transition changes from ESTAB0 to ESTAB9). This sending processing is mounted as the sequencer of TCP packet processing which starts from the 1690th line. In the timer interruption routine, automatic reset function is mounted for recovery from disconnection of an Ethernet cable, network disruption, and the freezing state of various protocol processing. For example, after freezing about 15 seconds it is designed so that it will return to the LISTEN state of TCP compulsorily. Only the GET method of HTTP protocol is mounted. <Reference> 6.2.5 Initial Setting Sequence Start-up routine of the firmware, i.e. the sequence of start: (Related to setup at the time of power supply, from line 4651 ~ ) is as follows. (1) Copy the required data (IP address setup etc.) to RAM for initial setting from the built-in EEPROM (2) Initialize the LCD liquid crystal display panel (3) Initialize EthernetNIC (RTL8019AS) and load CONFIG register to NIC (4) Acquire the MAC Address from the exterior serial EEPROM 93C46 (5) The MAC Address acquired in (4) is written to the PAR register of NIC (6) Check the operation mode (usual or bootstrap) by checking the state of jumper SW. Then, it enters the main routine of the selected mode. (7) If the acquisition of IP address (IP=0.0.0.0) from the DHCP server is required, send the DISCOVER message of the DHCP protocol by broadcast. ※After the above-mentioned processing is completed, it will be in the state waiting for frame receiving.
●Programming Tips1. The Available Program Memory 5. Message Creation of Web Control Screen 9. Display the Value of Room Temperature Sensor (RA5) 11. Internal Timer & Interruption 13. CGI ? Parameter Command Perth and Writing in EEPROM 16. Processing Related to Internal Timer and Interruption of v12.Asm 6.3.1 The Available Program MemoryIn total, 8192 bytes of program memory are available. For v12.asm(ver1.2.0.0), the status of memory use of the machine language after assembling is as follows.
We understand that there is almost no vacant domain. While adding other functions, some of the existing following functions should be deleted and then we get empty memory space (bank). The code of an additional function is put into the empty program memory space. Line 1441-1565: UDP protocol processing (parallel port output control) 6.3.2 Correspondence with Program Module on Firmware, and Memory Use Domain (V1.2.0.0) <Program memory>
<EEPROM memory>
6.3.3 Present Storage Value of EEPROM Data Domain Example of EEPROM data for IP:192.168.0.200, PORT:80 : (256 bytes 0x0000 -- 0x00FF)
As a real memory address, 0x2100--0x21FF is supported. 6.3.4 The Processing of Rewriting "default" Value in EEPROM The value "for returning EEPROM data to the initial stage" is stored in 0x1F00-- 0x1F17 (18h bytes). (Refer to Section 6.3.3) To get its domain size, subtraction between the following labels, i.e. default_values_end - default_values_begin is done. For module: initial_values, only that part of the domain (subtracted result) is rewritten in EEPROM domain. The writing sequence to actual EEPROM is done by module:write_eeprom and it is carried out by operating register files of EEADR and EEDATA etc. <Notes> From the above description, (at this stage) of the program It is necessary to make the constant values of the following domain same. IP address 0x2100 (192.168.0.200) If the values are not same, when the "default" value is read from the web control screen a different value from the ROM write value will be loaded. (Inversely, is it also fun to make it reconfigurable by two or more contexts?) Now, about the HTTP_PORT, LCD_PORT, PARALLEL_PORT and SERIAL_PORT, since the constants are defined in the upper part, only changing that part will be OK. 6.3.5 Message Creation of Web Control Screen About the message creation of PICNIC web control screen, transmission processing of contents of every bank as well as about every branch indicator for embedding the values is written below. Reference URL: MPASM Users Guide with MPLINK and MPLIB ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ (1) I/O Ports assignment RA0--RA3 Analog input (RA0 and RA1 are terminal block CN4) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ (2) Response message domain It is divided into four parts from #1 to #4. PAGE 3 Relative specification of display domain for every 0x0300. The contents of each bank are as follows. #1: Content-type: text/html -- up to </TD> </TR> of I/O RA5 In xx Celsius DB 0,0 (0000h) is block terminating discernment data string.
(3) Transmission processing of the contents of each bank job_ESTAB → The state changes between each mode from 00 to 99 sequentially. goto ESTAB_00 ESTAB_00: Else MOVLW 014H ; Bank address = 14h fan ESTAB_01: ESTAB_02: ESTAB_03: ESTAB_99:
(4) Send message: send_mes module Start from around the 2017th line send_mes_head: TCP header creation Meta character && 0x7F : Branch indicators are as follows : In case of usual characters except the above, low-order 7 bits are transmitted to RTL8019 buffer. send_mes9: Data domain transmission escape point
(5) Correspondence between each branch indicators and processing ctrl_code5: SOCKET STATUS Socket status display ctrl_code4: TRIS Display of direction of input and output ctrl_code2: META CHARACTER To the control character output routine ctrl_code1: Replace the embedded $? in the message of network setting value. goto put_mac_address ; 0:MAC address ctrl_code: Tag to ctrl_code1? 6.3.6Acquisition of Short Messages as "In", "Out", "High" "Low" etc. About acquisition of a short message as "In", "Out", "High", "Low", etc. message bank is from 0x1F00. org 1F00h Message display module The processing is done by ctrl_out, ctrl_in, ctrl_high and ctrl_low respectively. Actual writing is done by put_short_mes10. <Hint>Therefore, by adding the following character string definition in the message bank mes_open DT " Open ",0 If these are called instead of _low, _high Input: Output : The display can be change in the above ways. (Here _low <--> _Open and _high <--> _Close corresponds respectively) 6.3.7 Escape Sequence Embedding to DA and Word Alignment Reference URL : ASCII code table : MPASM Users Guide with MPLINK and MPLIB Escape sequence code ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ※The 7-bit segment store(Packed-8bit value) of DB, DA PIC16F877 has a data width of 1 word = 14 bits. If we think this 14bit data as two 7-bit width "bytes" lying together (Packed-8bit value), the store result of DB,DA described later is easy-to-understand. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ (1) DB (Declare Data of One Byte) For PIC16F877, constants described in DB (Declare Data of One Byte) are sequentially stored in 6 bits + 8 bits from higher order of 14 bits bit width. Example 1-1:If DB 0xFF, 0xFF, etc. are indicated forcibly, The following warning will be displayed. In fact, 0x3FFF is generated. Message[303]: Program word too large. Truncated to core size. (FFFF)
Example 1-2:In case of DB 0x3F etc., 0x3F00 will be generated.
Example 1-3:If DB is 0x06, 0x8A, 0x068A will be generated. 0x068A = 00.0110.1000.1010b → [000.1101]:[000.1010]b → [0x0D] : [0x0A]
That is, the code of "a new line" for CR+LF text file is generated.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ DA (Store Strings in Program Memory) For example, in case of the direction DA "HTTP", the ASCII codes of non-meta characters "H","T","P" are in range of low-order 7 bits. After putting this [x6 ... x0], [y6 ... y0] one by one, it becomes xx.xxxx.xyyy.yyyyb and this is the value of 1 word stored in memory. Example 2-1:DA "HTTP" In case of DA "HTTP" Since, "H" = 0x48 → 0100.1000b Both "HT" and "TP" are packed as 1 word. So the following will be generated. [100.1000]:[101.0100] → 10.0100.0101.0100b = 0x2454
Example 2-2:In case of odd number characters like DA "K",、 Since, "K" = 0x4B → 0100.1011b It has been packed as "K" + 7bit(filled by 0) [100.1011]:[000.0000] → 10.0101.1000.0000b = 0x2580
DB 0x3F, 0xFF 0x3FFF is generated for all.
The following two mounting are equivalent. DA "test\r\n" 0x39F4 0x068A will be generated in both cases. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ (3) The embedding of escape sequence to DA and word alignment About the description of web response massage, (a) We want to embed CR+LF or LF, a "new-line" code at the last of transmitting message character string. So we want to satisfy above three conditions.
About the HTTP response and header transmission ---------------------------------------------------------------------- We want to transmit the above "character string". And if purpose (c) is ignored, by using escape sequence embedding to DA we can simply embed ---------------------------------------------------------------------- We want to mount as above. However, in some web browsers (Netscape7.1 etc.), the garbage(0x00) behind \r\n is interpreted accurately. So if the message type is text/html, there may arise some problems. Here we have decided not to adopt those browsers. (Correction on 2003/10/12)
Again, about HTTP response and header transmission, in the character string row for DA, if we divide suitably as every DA has even number character string, for example it becomes as follows. ---------------------------------------------------------------------- Mounting is as follows. ---------------------------------------------------------------------- In this case, the word row generated is as follows.
In the above example, when we line them up there is an even number of strings, so if we do not consider readability, we can put them all in one line with "" using DA ---------------------------------------------------------------------- Even in this form, the code generated will be the same as Example 3-2. <Problem> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ (4) After all, is the combination of DB and DA just a lot of trouble? In the end, implementations using combinations of DB and DA such as in the original assembly source file (v12.asm), for example ---------------------------------------------------------------- we see that the result is poor readability and there is no merit whatsoever. ;-< 6.3.8 Start value insertion commands from the top part of word alignments Value insertion commands (such as $8) must start from the top part of word alignment. If $* begins from the bottom part of alignment, "$" and "8" will be interpreted as characters and "displayed" as "$8". Example: In the (wrong) case below, the position of $ in (right) (wrong) 6.3.9 On the room temperature sensor value display (RA5) A temperature sensor IC (NS LM35DZ) is connected to RA5 and the A/D converter inside the PIC is used to convert its values to 10-bit binary numbers. LM35 datasheet: As noted in this datasheet, this IC can directly obtain linearly corrected outputs of temperature in degrees centrigrade (temperature coefficient + 10.0mV/degree C) (very convenient). (1) Insertion of RA5 binary value "degrees C" conversion value to web control screen message OK, the position for inserting the RA5 value is at the end of Bank#1 which begins from org 1400h. ; In other words, the value is inserted as control character "@"+0x04. During data output from the send_mes0 module, it jumps to "@"(40h):ctrl_code3 module and in the case of an analog input pin, A/D conversion processing by the ad_in:module begins. For 0-+5V inputs, the PIC16F877 has a 10-bit A/D converter and the output of this temperature sensor IC is stored in variable [val1:val] as the conversion result. In the case of RA5, we consider the temperature coefficient above, the connection to Vs=GND by R14(10KΩ), the A/D conversion range (0-5V), as well as the resolution (0 to 1023 (≒1000) in decimal). For input values of 0 to approximately 1000, we compute values (5x) to be able to display 0-50 degrees centrigrade linearly. For details, refer to the v12.asm assembly source file ad_in:module starting around line 2325. (2) What is the meaning of "DB 12,84"? As explained earlier in 6.3.7 On insertions of escape sequences for DA and "word alignment", this is an instruction for inserting the <input direction> "In" or "Out" in HTML messages. When a "%" is found in the top part of word alignment, the processing for message output is branched and the material indicated by the parameter in the following bottom part is carried out. In this implementation, the message "%"+0x04 is generated. <Explanation> The DB directive of the MPASM assembly language here means Declare Data of One Byte so an implementation of DB 0x12, 0x84 in the PIC16F877 which has a one word 14-bit core, the following machine code is generated. 0x1284 If we divide this into 7bit+7bit widths, 0x12=0001.0010b, 0x84=1000.0100b, so 0x1284 = 00.010.0101:000.0100b → [010.0101]:[000.0100]b → [0x25]:[0x04] In other words, the result is the generation of the message "%"+0x04. For details, refer to §6.3.7. (3) On the processing of the "%" meta-character ※ The message sending module send_mes begins near line 2017. ++++++++++++++++++++++++++++++++++++++++++++++++++++ meta-character && 0x7F : branch as shown below: Here, we have "%", so we jump to the ctrl_code4:module ++++++++++++++++++++++++++++++++++++++++++++++++++++ and divide the processing. Here, "%"+0x04 is specified so we jump to the module for the "display" of the input/output direction of RA5, namely the string "In" or "Out" (after this, we will do table lookup processing of the message bank. See §6.3.6.) Since RA5 is an "input" from the temperature sensor as described earlier, we check the PIC register file input/output direction bit and the "In" display is done as a result. <Hint> Example: The following is an equivalent implementation. DB 12,84 ⇔ DA "%¥x04" For details, see §6.3.7. 6.3.10 Display temperature in Fahrenheit (degrees F) instead of the current Celsius display (degrees centrigrade) There are two methods. (1) In place of the current Celsius (degrees centrigrade) sensor, install a Fahrenheit (degrees F) sensor In place of the Celsius direct reading NS LM35(DZ), use the Fahrenheit direct reading version LM34(DZ) and that will be it. LM34 datasheet: The temperature coefficients are also +10.0mV/℃ for LM35 and +10.0mV/F for LM34, so the portion for calculating temperature from the A/D conversion result will be the same. To avoid confusion, when you switch the ICs, it would be a good idea to change the web display, for example, from "Celsius" to "Fahrenheit". (2) Add a conversion formula for Celsius (degrees C) to Fahrenheit (degrees F) If you wish to display temperatures in Fahrenheit using the Celsius (degrees C) sensor as is, you will need to add the following Celsius (degrees C) to Fahrenheit (degrees F) conversion formula to the ad_in: module described earlier before the part for storing values for display (or replace the current "5x" calculation). ++++++++++++++++++++++++++++++++++++++++ The Celsius temperatures are non-negative so the Fahrenheit results will also be non-negative and treatment for negative values is not necessary. <Hint> ※ This will be a good exercise, so I will leave it for student practice, OK? :-) 6.3.11 On the internal timer and interrupts <URL references> PIC16F877 datasheet (Japanese) PICmicro PIC16F87x MID-RANGE Complete Reference Manual: (1) On the internal timer The PIC16F877 is equipped with three internal timers TMR0 to TMR2. PIC16F877 datasheet DS30292A-J page47-- 8bit timer/counter with prescaler 16bit timer/counter with prescaler 8bit timer/counter with prescaler/postscaler ※Current PICNIC Fosc=20MHz(50nsec) so Fosc/4 = 5MHz(200nsec) ++++++++++++++++++++++++++++++++++++++++++++++++++++++ Internal timer 0 TMR0(8bit) Block diagram Related registers TMR0 register:register BANK#1, 101h PSout := !TOCS && PSA && (Fosc/4) PSA bit clear --> prescaler assigned to timer 0 TMR0register:TMR0 interrupt occurs on the 0xFF --> 0x00 transition (overflow) Interrupt flag is T0IF(INTCON:2)(need to first set this bit to 0) ++++++++++++++++++++++++++++++++++++++++++++++++++++++ Internal timer 1 TMR1(16bit) Block diagram T1CON control register Related registers
PSout := !TMR1CS && (Fosc/4) or RC oscillator Prescale values:1:1 ~ 1:8 TMR1 register: TMR1 interrupt occurs on the 0xFFFF --> 0x0000 transition (overflow) Interrupt flag is TMR1IF(PIR1:0)(need to first set this bit to 0) ++++++++++++++++++++++++++++++++++++++++++++++++++++++ Internal timer 2 TMR2(8bit) Block diagram T2CON control register Related registers TMR2 register:register BANK#0, 11h PSout := TMR2ON && (Fosc/4) Prescale values:1:1 1:4 1:16 PR2 register:in a comparator with TMR2 register. FFh on reset. TMR2 register:0x00 --> if matching PR2, scaled by postscaler --> Interrupt flag is TMR2IF(PIR1:1)(need to first set this bit to 0) ++++++++++++++++++++++++++++++++++++++++++++++++++++++ (2) On interrupts PICmicro PIC16F87x MID-RANGE Complete Reference Manual page123-- PIC16F877 datasheet DS30292A-J page143-- Logic for interrupt types 14 interrupt types.
Peripheral interrupt flags:PIR1 PIR2 When an interrupt is performed, the GIE bit becomes 0 and any further interrupts are disabled. The return address is pushed to the stack and 0004h (the interrupt processing routine) is loaded to the PC. In the interrupt processing routine, the cause of the interrupt can be checked by looking at the interrupt flag bit. After the interrupt is processed, before enabling the interrupt again, the interrupt flag bit has to be cleared by software. (Otherwise, once we have returned from the interrupt processing routine, the interrupt will occur again and an infinite loop of requests will be made.) ※For more information on the details of implementation, refer to the article of the above datasheet.
6.3.12 On the real-time clock (1) The PIC16F877 is not equipped with a so-called "real time clock (RTC)". The only way to get date and time is to connect a real time clock IC to an external port (serial port, for example). Example: Ultra small serial I/O real time clock module manufactured by Ricoh (2) Wait modules in units of milliseconds msec and microseconds μsec are already implemented in the firmware. (3) An example different from the PICNIC firmware we use here was found in another project which gets date and time from an NTP server on the Internet. (4) In theory, it may be possible to implement a "current time" feature on this PIC by somehow making it possible to set the current time, embedding calendar calculations in the remaining program memory, and generating internal timer interrupts for counting up one second at a time. ※In (3) above, they are actually counting up using 100msec internal timer interrupts. However, in the attached v12.asm firmware, the program memory is used up for implementing the current functions and the above implementation would be very difficult in the current form without deleting certain functions. (5) In the implementation of (4), if the power is cut, the current time will be forgotten so some other method for setting the date and time externally will be necessary. This will turn out to be another vicious cycle so the method in (1) for attaching an external RTC with battery backup would probably be the best solution. 6.3.13 On the CGI ? parameter command parse and EEPROM write When we do a gateway address change from a web browser, the ? parameters in the URL are passed and the gateway address in the EEPROM is rewritten. Example:In the following URL:http://192.168.1.200:8080/submit.cgi?00b=192.168.1.200&04b=255.255.255.0&08b=0.0.0.0&10w=8080 this would be the 08b=0.0.0.0 part. (we write it in byte units 0,0,0,0) (1) Outline of parameter command parsing and EEPROM writing ++++++++++++++++++++++++++++++++++++++++ and if "?" is included in the URL, we treat the following parts as parameters and jump to the analysis module parse_cgi_tag. This is the tag for jumps between memory banks and the actual processing is the parse_cgi module. The outline of processing for parse_cgi which begins around line 4374 is as follows. ++++++++++++++++++++++++++++++++++++++++ parse_cgi0 parse_cgi2 parse9_tag So you can see that as soon as a gateway address change is instructed, the value in the EEPROM is immediately rewritten. (2) IP address and http port number use variable values in memory In the current version of firmware, the IP address and http port number are read from the EEPROM at startup after a reset and copies of these values are held in memory as this_ip, http_port. During packet header generation for example, the values copied to memory are used rather than the values in the EEPROM. Therefore, when the IP address and http port number are changed from the web screen, the values are only written to the EEPROM and the configuration will not actually change until the values are read into this_ip, http_port after a reset. The other settings such as netmask and gateway appear to be read directly from the EEPROM so any changes made will be reflected immediately. <Hint> For a local PC connected under the same router, the netmask and gateway values are not meaningful for ordinary HTTP responses (because they are in the same segment), so even if these values are changed, you can still "continue" to see the web control screen. 6.3.14 On the processing for getting IP addresses from DHCP (Notes of caution) In the instructions manual, it says At present, the following problems are known. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ (1) Operation of address retrieval from DHCP <DHCP protocol packet>
<Outline of processing of IP address retrieval from DHCP> dhcp: →Check in the timer interrupt routine and unset the dhcp_done flag ※In the main0 loop, check the dhcp_done flag. So, in the response from the DHCP server, only dhcp_user_ip-ip3 are used and the value for netmask dhcp_router_ip is not set. Therefore, the default values (2) Case in which accesses outside of the router become necessary The netmask and gateway values will need to be ・written to the EEPROM as initial values beforehand or (3) Can we make it possible to automatically get gateway address, etc.? In theory, it would be possible to change the firmware yourself to set the netmask value dhcp_router_ip and operate much like a Windows PC, obtaining the gateway address automatically, etc. You can save the values in variables in memory in the same way as this_ip, http_port and dynamically change the netmask, gateway values depending on whether you are using a fixed IP or DHCP. You could add this processing to the same place as the setting for this_ip, etc. when the DHCP response is received. The difficulty with implementing this in the current firmware is the fact that every reference to the netmask, gateway values is done by a read to the EEPROM. You will have to change all of these references to reads of variables in memory. ※It is quite difficult work, but if it works stably, many people might be happy to have that distribution as ver1.2.1.0. :-) (4) On the DHCP protocol standards (BOOTP) The details of the DHCP protocol standards can all be found from RFCs since it is an Internet working protocol. The DHCP standards draft is RFC2131.
RFC 951(BOOTP) RFC 2131 Dynamic Host Configuration Protocol, Draft Standard Protocol <Reference URLs> http://www.net.intap.or.jp/oiia/cont1/p0302.html%7B0recid=10342.html 6.3.15 Mechanism for the display of "Number of packets sent" For the display of number of packets sent, we use value insertion in Sent Packets $9. The actual processing is shown below. (1) Branched processing of send_mes module
※After $9 is '$'+0x3a(":"). (refer to the ASCII code table) In the case of $9, the put_send_packet: module is called. In this module processing, the IP packet sequence number:ident is referenced val1 <-- upper part of sequence number:ident After each of these variables is set, we call the 32bit->decimal conversion:put_decimal32 and display the number of packets sent. (2) Conversion of 32-bit binary to decimal routine : put_decimal32 module The 32-bit binary to decimal conversion routine put_decimal32() module reads 4 words (byte enabled) specified from the area holding the binary values (val3:val2:val1:val) as a parameter and displays 32-bit binary values as decimal (val_m). The related variable memory areas are as follows.
6.3.16 On the processing for v12.asm internal timer and interrupts <Outline> ・We use the internal timer TMR1 for processing timeouts of DHCP request completions.
(a) Configuration for option registers
Switch to register bank #1/3 (Reference) ※Why 86h is loaded to OPTION_REG is a mystery.
Set interrupts for Rx processing of the serial interface USART. PEIE(INTCON[bit6]) (Reference)
Clear DHCP request flag (dhcp_done) (BANK#1) Initialize timer TMR1 16bit([TMR1H]:[TMR1L]) to zero TMR1CS := 0, so use internal clock. !TISYNC : Timer1 External Clock Input Synchronization Select bit TMR1ON: Timer1 On bit T1CKPS1:T1CKPS0: Timer1 Input Clock Prescale Select bits
200nsec x 65535 = 13,107,000nsec (約13.1msec) (Reference)
PIE1[TMR1IE] set: timer TMR1 interrupts enabled ※It is not clear why they do GIE twice.
(2) On the main, main0 routine Following start, we jump to the main routine and after checking the conditional branch for DHCP, we enter the main loop: main0. In the main0 loop, the following processing is done in order ・Rx check from USART I/F(receive232c) After a goto to each part, the routine is designed to return to this main0 label with another goto.
(3) On the interrupt processing routine Check PIR1,TMR1IF and if it is a TMR1 interrupt, jump to int_tmr1. Processing for DHCP done: int_tmr1 Send DHCP retrieval requests at intervals of TMR1 all over intervals approximately 13.1msec * 80h Socket timeout check: int_tmr2 Return to → dec_tm9
6.3.17 On an implementation error concerning the ADCON0 control register in the ad_in module ・In the ad_in module where the ADCON0 register is modified to control the A/D converter, it appears that the actual firmware (v12.asm) is actually modifying the ADCON1 register. Implementation of ad_in module
All of the ADCON1 in the above need to be rewritten as ADCON0.
|
|||||||||||||
|
wasaki@cs.shinshu-u.ac.jp |