Expands unceasingly along with the micro controller application domain and thorough, also gradually enhances to its various aspects performance’s request. At present, more and more type’s micro controllers have ISP (In System Programrning) namely in the system programming function. When ISP programming does not need to emigrate the micro controller from the target system, and only needs the limited several pins and the outside is connected, maximum limit reduced the extra part expenses and the circuit wafer area, causes the micro controller product the development and the concrete application is quite convenient. This article will analyze P89LPC922 the preinstall ISP code the good and bad points, further unifies the application the actual situation, studies from arranges the ISP code the plan, and gives concretely realizes the method, regarding has the very strong use value by the Ps9LPC922 constitution’s micro controller system.
1 P89LPC922 preinstall ISP code functional analysis
P89LPC922 is one section the monolithic seal micro controller which produces by Philips Corporation. It uses the high performance the processor structure, integrated including the ISP function many system-level function, suits in many requests the high integration rate, the low cost situation, may satisfy various performance requirement.
P69LPC922 when leaving the plant, the user code space’s high 512 bytes have contained a serial ISP subroutine, allows the component to carry on the programming in the electric circuit through the serial port. When using the ISP function, needs to use the chip 5 pins (Vdd, Vss, TxD, RxD, RST), and needs a coupling and the computer serial port is connected.
In order to cause the component to enter the ISP condition, must when on electricity gives the replacement pin 3 accurate low level pulses fixed time. The pulse number can only be 3, is short in or is more than 3 pulses to be able to cause the component to be unable to enter the ISP pattern. Other one kind enters the ISP pattern the method is causes the chip replacement using the serial port gap measuring ability, and causes the component to force to enter the ISP pattern. But this method needs to carry on the corresponding function establishment in the user program, but P89LPC922 the preinstall ISP code does not support this way.
After entering the ISP pattern, although may dock the specific character which receives to carry on the baudrate the automatic hypothesis, but this baudrate’s setup parameter only then 1 byte, the baudrate scope receives certain limit. Moreover, ISP serial port work in pattern 1 condition, after baudrate hypothesis, only receives the Intel-Hex form the record.
May know by the above analysis, P89LPC922 preinstall ISP function, although is quite perfect, may satisfy the chip phase of exploitation the application, but if product design finalization, specially in makes it for the networking system in the lower position machine actual scene, must carry on the user program code renewal downloading very not to be convenient, some functions simply cannot even realize. This mainly manifests in the following several aspects:
◇ must when on electricity can enter the ISP pattern, does not suit the remote control;
◇ needs to use the replacement pin, and controls the succession to be strict correspondingly;
◇ the baudrate scope has certain limit;
◇ non-address option, support program networking;
◇ only supports the Intel-Hex form, the correspondence efficiency is low.
2 from arrange the ISP code plan
P89LPC922 has the very perfect hardware system, compiled own ISP code for the user to provide the quite great degree-of-freedom. Below take the P89LPC922 composition’s 485 main line networking system as an example, gives from arranges the ISP code the function request:
◇ on the hardware does not use the replacement pin, only uses the serial port to receive and dispatch two connections then;
◇ does not need the electricity, momentarily to be possible to cause the component up and down to enter the ISP pattern;
◇ the automatic judgment hypothesis correspondence baudrate, the baudrate should have ten kinds;
◇ the component has the address, and this address may momentarily inquire, the revision;
◇ may realize the user code cleaning, write, the verification, the encryption function.
And, 485 main line networking system’s superior machine is the computer, the lower position machine is P89LPC922.
In order to realize the above function, must solve the following several problems:
how ◇ does the code memory block assign;
◇ chip address plan and processing;
◇ enters the ISP method;
◇ automatic determination baudrate method;
◇ serial port working and communication protocol determination;
◇ISP code encryption and disposition character determination.
2.1 code memory block assignment
For does not affect the user the procedure code compilation, from arranges the ISP code to apply in the procedure memory block high-end. Certainly, different from arranges the ISP code to need the different size the storage space. Here stipulated from arranges the ISP code the address space is 1COOH~lFFFH, altogether l KB, namely 7th sector entirety. And the ISP entry point address is 1FOOH.
2.2 chip address plan and processing
Because the P89LPC922 procedure storage space may do for the data-carrier storage use, then imitates the 6th sector’s final 16 bytes is the data space which ISP and the user program uses in common, the address is 1BFOH~1BFFU. And, the address lBFAH depositing chip address, the address 1BFBH depositing chip address takes instead. For example, the chip address is 0lH, then (1BFAH)=01H,(1BFBH)=0FEH. After the address takes counter-, depositing is for again the user program read-out when judges the address validity use, thus increases the reliability.
2.3 enter the ISP method
Because the function request cannot enter the ISP pattern using the replacement pin way, therefore can only guide the condition to suppose is l, the guidance vector supposes is lFH. Thus, when on each time electricity replacement or other replacements, the procedure fixes from the lF00H address starts to carry out, after namely replacement, the chip first enters the ISP pattern, carries out the ISP code. Will carry out the ISP process or (for example 2s) in has not carried on any ISP operation in the stipulation time, the procedure will change to address O to carry out the user program code. Before changing to address O is the execution user program code, finished the serial port gap measuring ability establishment, like this, when execution user program code then through the serial port gap measuring ability, after causing the chip replacement, enters the ISP pattern. Below as serial port gap measuring ability establishment dependent program.
ANL SSTAT,#OFAH; Eliminates the BR position, SSTAT.2
MOV BRGCON,#00H; Closes the baud string generator
ORL AUXRl,#40H; Setting EBRR position, when examines UART ; When spacing wave namely carries on the replacement
MOV SCON,#50H; The establishment serial port for the working 1 (may also be; Way 2 or way 3), permission serial port receive
MOV BRGRl,#05H; The establishment serial port baudrate 4800 (may also be; Other values)
MOV BRGRO,#0fOH
MOV BRGCON,#03H; Opens and uses the serial port baudrate generator
May know by the above procedure, the ISP code does not affect the user program to the serial port use, the user program may carries on to the serial port working and the baudrate establishes, simultaneously the user program will not affect using the serial port complains about separates the measuring ability to enter the ISP pattern. In the actual use, superior machine transmission 0 signal 0.5s, then restores is 1 signal, then causes the serial port to examine the spacing wave, thus after causing the chip replacement, enters the ISP code procedure.
2.4 automatic determination baudrates
After the lower position machine (i.e. P89LPC922) repositions, in the stipulation time (for example in 2s, the superior machine according to the user hypothesis’s baud string to the lower position machine transmission l byte site frame, this address frame is 85 (hexadecimal system is 55H). The lower position machine basis this address frame determination establishes own baudrate.
First, establishes timer Tl is pattern l, establishes 16 counters and its reset. Then judgment receive pin RXD whether is the low level, if continues for the low level to judge waited for that RXD is the high level. The actual this process for the judgment superior machine transmission address frame’s outset position, simultaneously is also one kind of against disturbance measure. Then in RXD drop along start timer Tl, in RXD next drop along closure timer T1. By now the timer Tl 16 counter’s values namely to transmit 2 bit data by the current baudrate the time. Solid timer’s clock source for independent baudrate generator clock source two frequency divisions, thus this time timer Tl 16 counter’s values namely for baudrate generator speed register BRGRl, the BRGR0 value add on 16.
Certainly, 16 counter values which obtains according to this method the value existence small deviation which determined with the baudrate theoretically. In order to cause the baudrate which and the theoretical value establishes is completely same, may rely on according to the function request ten kind of waves plots together to figure out the theoretical value, carries on the comparison again with 16 counter’s values, then reads in the theoretical value register BRGR1 and BRGR0, thus causes the hypothesis the baudrate 100% accurate.
2.5 serial port working and communication protocol determination
Regarding the networking system, the serial port needs to suppose for the pattern 3 conditions. The superior machine and lower position machine each correspondence defers to “orders a response” the way to carry on, the superior machine issues “the order”, the lower position machine the way carries on the reply by “the response”.
The single data frame is composed of 11, the form is as follows:
1 outset position 8 data position 1 marking position 1 stop positions
And, marking position =l expressed that this is the address frame, marking position =0 expresses this frame for the data frame.
When the correspondence starts, the lower position machine is in the address frame receive pattern, the superior machine transmission l byte address frame does for a roll-call package of order, the roll-call address frame scope is the lower position machine address range is 1~255; The lower position machine receive mentions by name Bao Houyu their address carry on the comparison, if tallies, changes the address frame receive pattern the pattern which the address frame and the data frame may receive, and makes own address is 1 byte data frame reply transmission for the superior machine. After the superior machine receives, judges with the address which transmits is consistent, the superior machine starts by the data frame pattern to transmit each kind of order, carries on the correspondence with the lower position machine. After the lower position machine enters the ISP condition, if receives the address frame which does not tally with the address, moreover this address is not equal to 0, then changes to the address 0 to carry out the user program code. If the address is equal to 0, the lower position machine changes the address frame receive pattern the pattern which the address frame and the data frame may receive, and makes own current address is l byte data frame reply transmission for the superior machine, thus completes the lower position machine address inquiry function.
Attention, when superior machine transmission O address can only connect a lower position machine.
According to the function request, the superior machine transmission should have the address modification, the sector cleaning for the lower position machine order, to write the user program code, to read the user program code, the sector encryption and procedure downloading finishes six kinds. And, superior machine execution downloading finished the order, after lower position machine returns downloading finished the response, the lower position turning point to the address 0 carries out the user program code.
As for an order package of form, may compile by user. Here gives one kind of typical order package of form:
Package of marking package of address package of order packet length package of data package of verification. Moreover, the ISP code file recommendation for the binary form document, may reduce the corresponding procedure like the complex degree.
2.6 ISP code encryption and disposition character determination
After the ISP code compilation finished, needed to read in P89LPC922 by the programmer. Needs to carry on the related disposition character before the programming the hypothesis, including user disposition byte, user security byte, guidance vector and guidance condition.
And, the guidance vector is 1FH, the guidance condition is 01H. In order to prevent the user cleaning or rewrite the ISP code, the user security byte’s 7 sectors should be 07H, namely forbids to the ISP code to carry on the cleaning and the read-write operation. Other sector’s user security byte may be OOH, namely does not suppose the security condition, but by user through communication protocol sector encryption order free hypothesis. The user disposition byte is 0A3H, namely the watch-dog reset function enables, the power failure examination enables, the replacement pin does is the input pin, uses the internal RC oscillator.
In summary, definitely may use the P89LPC922 perfect hardware source, compiles suits the concrete application environment the ISP code procedure. This will give this model of chip the actual use to bring enormous convenient, especially when needs to renew the downloading user program will appear handy. Certainly, when concrete application, if and in the lower position machine course of communications joins some encryption processing in the superior machine, will then strengthen entire from arranges the ISP code procedure the reliability, the security, simultaneously also causes the concrete application system to be more perfect.