Abstract: Take Atmel Corporation’s AT89S52 monolithic micro controller as an object, introduced that based on RTOS (multi-duty real-time operating system) and ISP (in system programmable) function digital instrument system’s software and hardware design, simultaneously gives hardware system’s composition and the correlation software programming realizes the code. Indicated after some armament system’s debugging experiment that this instrument system has the demonstration intuitively, accurate, the reliable merit.
Key word: RTOS; ISP; Monolithic micro controller; Liquid crystal display module
Introduction
The Atmel Corporation’s controller take its integration rate high, characteristics and so on online debugging convenience widely applies in the project practice domain, in the article by some armament system’s preliminary advanced research as a background, discussed the digital instrument system’s software and hardware to realize the process, its major function included: Real-time gathering distributing box system’s 6 group positive and negative analogue voltage value and operational environment temperature, and through MSl2232B liquid crystal module dynamic formula demonstration.
1 software characteristic
Along with the C language in embedded system’s widespread utilization, software system’s timeliness, the complexity design requirements is also getting higher and higher, coordinates the programming thought with the usual single duty infinite loop structure and the interrupt servicing subroutine to complete the related software design with difficulty or to realize is more difficult, RTOS (multi-duty real-time operating system) is the present stage more popular processing mode.
The RTOS basic design thought is many kinds of system inputs and the processing request, makes the different duty function body according to the function, and assigns the suitable priority, refers to the Windows system’s multi-thread processing mechanism, divides certain sectors the CPU execution time, each duty function body corresponds a time fragment. Carries out after the stipulation time allows to cut another duty, because various time section is short, what displays is the multi-duty real-time processing characteristic. Because the duty simultaneously carries out by no means that and has the skipping characteristic, therefore in the entire project management document may have many infinite loop structures, and has abbreviated the main entrance function, this is the RTOS biggest characteristic. In the article take the Keil integrated development environment as the platform, edition completes the entire software design process using RTX5l the Tiny.
ISP (in system programmable) is one kind suits Atmel the series component’s Flash technology, through the PC LPT standard parallel interface, can real-time download the Intel form source program code to the micro controller’s corresponding memory region. The ISP most major characteristic simplified the debugging process, enhanced software system’s maintainability, caused it to have the online promotion characteristic. Moreover the entire performance history omitted inserted repeatedly pulls out electric circuit’s operation.
2 system hardware constitutions
This system hardware mainly includes the following several modules: At89S52 master-control unit, the ADC0809 mold/number transforms, the MSl2232B liquid-crystal display, the temperature sensor and the pronunciation warning and so on. And at89S52 microprocessor mainly completes the periphery component’s hardware control and correlation data resolving, ADC0809 gathers 6 group simulated signals and inputs the master-control unit, MSl2232B completes digital and the related marking character demonstration, electrical power distribution system’s voltage hunting surpasses when the determined indicator gives the corresponding alarm message by the pronunciation module.
2.1 master-control unit modules
The master-control unit is at89S52 monolithic micro controller which Atmel Corporation produces, compares with the conventional C51 series, its prominent characteristic has 8KB to dodge the fast -like memory (to reduce expanded memory’s request, 256B the RAM memory (to be possible outward) to hold more local variables), 8 interrupt sources and the ISP online programmable characteristics.
2.2 liquid crystal display module
MSl2232B belongs to the graph lattice series display device, has the two row demonstration function, its lattice structure for 122×32, gives the essential data and the instruction through AT89s52 operates MSl2232B main, the auxiliary controller, thus completes the graph, the character and so on related information demonstration. This liquid crystal display module also has the strong versatility. The user may constitute a complete LCD system with the few parts. Electric circuit connection as shown in Figure 1.
2.3 A/D data acquisition module
Because this system involves the multi-channel simulated signals, therefore has chosen AD (20809 general mold/number switch, it uses approaches the way to complete a/D switching process gradually, it internal has 8 group analog switches, can lock saves the signal, the input voltage scope is 0V~ 5V automatically, because this component’s output has the 1TrL three states of matter lock to save the buffer structure, therefore may link the person monolithic micro controller’s I/O mouth directly. Related connection connection as shown in Figure 2.
What needs to explain, only then a group negative supply signal conforms to the ADC0809 0V~5v input characteristic in this system 6 group power source signals, must therefore provide the corresponding phase inverter circuit, completes through the LM358 operational amplifier. May also expand the monitor scope using LM358 (take to reduce measuring accuracy as premise), this regarding the accuracy requirement not too high situation is feasible. Figure 2 PC817 light pair uses in examining the negative voltage signal, when IN4 is the low level signal corresponds the negative voltage signal, this time ought to do the position in MSl2232B to give “-” the symbol, not only this has solved the compatible problem which the positive and negative voltage colleague demonstrated that moreover reduced the software design quantity (by 6 groups simplifications is 3 groups), simultaneously causes the system timeliness to promote correspondingly.
2.4 temperature sensor module
DSl8820 is the l-Wire type digit temperature sensor which Dallas Corporation promotes, it can the real-time gathering scene environment temperature data, and the corresponding value will transform into the digital quantity output. This temperature sensor and AT89S52 connection as shown in Figure 3.
2.5 pronunciation warning module
This module mainly realizes in the unusual circumstance to report an emergency the information output, so long as the distributing box voltage signal’s undulating quantity surpasses certain scope, the audio frequency alarm device namely gives the different frequency code to cause the buzzer sound production, prompts the related operators to pay attention.
3 system software designs
According to the RTOS system’s program structure request, the software engineering is mainly composed of the following 4 parts: The initialization, the data acquisition and A/D transform, the demonstration subroutine, the temperature monitoring and the warning module.
If the initialization will establish as the duty 0, then besides must complete the corresponding hardware disposition and the variable bestows on the starting value, but must start possesses other duties, moreover, because the initialization process only need carry on one time, therefore Task 0 must delete its oneself. The concrete procedure code as follows shows:
void Init(void)_task_Intial
{
variable=0;
LcdInitialO;
ClrScreenO;
0s_create_task(AI)C0809I) ata);
os_create_task(DSl8820Temperate);
0s_create_task(LCMI)isplay);
0s_delete_task(Intial);
}
And the related great definition variable value is:
#define Intial O
#define ADC0809Data 1
#define DSl 8820Temperate 2
#define LCMDisplay 3
Debugs this procedure when the Keil integrated development environment, besides must include the corresponding head document (rtx51tny.h), but must establish the good corresponding environment parameter value.
3.1 digital-analog conversion subroutine
The data acquisition and A/I) transform the subroutine mainly the simulated signal which transmits to the distributing box to carry on the sampling, the quantification and returns value processing. The software programs when the electrical succession and correlation technique request as shown in Figure 4.
In the succession chart, rises along the clear spatial quantification result register’s in value, drops along the start, a/D transformation; The sampling tripping pulse’s high level condition should maintain at least 100μs; EOC becomes the low level to express that the switching process is carrying on, and start signal’s hardware sluggish effect time should at least for 10μs; MSB corresponds AT89S52 and the mouth: P0.7, LSB corresponds P0.0.
The essential part’s procedure source code and the annotation are as follows:
unsigned int AI) C0809(void)
{
unsigned int wait=3;
ChannelChooseA=1;
ChannelChooseB=0;
ChannelChooseC=0;
ADStartPulse=0;
ADStartPulse=1; // produces the tripping pulse which A/D transforms
(rise along part)
delay(); // guarantee tripping pulse high level width
Is bigger than at least 100μs
ADStartPulse=0; // produces the tripping pulse which A/D transforms
(drop along part)
wait–;
wait–; // instruction time delay guarantees achieves: EOC
Becomes hardware sluggish request which the low level needs.
`whilefADConvertEOC==0):
return(Result); after/returns to A/[) transformation's quantification value
Returns to the main function.
}
3.2 liquid crystal display module
MSl2232B about the graph lattice liquid crystal display (LCM) module divides into Master and the Slave controller, high and low is divided 4 pages, left side a row address is 0-61, right side a row address is 0-61, is disposes the good host, the auxiliary controller's active status correctly to this component's operation key according to the succession chart. Visits when LCM using AT89S52 has two commonly used methods, namely the memory mapping register addressing and the analogue interface succession, this system uses the latter method. Main function module source code analysis:
void MasterWriteD (unsigned char Ramdata)
// writes the data to the Master controller
{
ReadOrWrite=0;
InstructionOrData=1;
MasterEl=1;
P0=Ramdata;
MasterEl:0;
}
void MasterWriteI (unsigned char Ramdata)
// writes the instruction to the Master controller
{
ReadOrWrite=0;
InstructionOrData=0;
MasterEl=1;
P0=Ramdata;
MasterE1=O;
}
void the ReadState(void) // examines main, the auxiliary controller active status
{
ReadOrWrite=1;
InstructionOrData=0;
MasterEl=1:
SlaveE2=1;
PO=0xff;
while(BusStateBusy==1);
}
void SetPage (unsigned char page0, unsigned char pagel)
{
MasterWriteI (0xb8 | pagel);
SlaveWriteI (0xb8 | page0);
}
void SetColumn (unsigned char address0, unsigned char addressl)
{
MasterWriteI (0x3f & addressl);
SlaveWfiteI (0x3f & address0);
}
// in the master-control unit operates on the left side LCM screen demonstrates a row information (by 8 picture element constitution)
void MasterPutChar (unsigned char masterchar)
{
ReadState();
MasterWriteD(masterchar);
}
In general. At89S52 RAM storage space is limited, but the graph or the character lattice code (may download related application plug-in unit, by the .bmp document or character automatic production), if is too big, lays aside warning prompt which presents memory insufficient to the RAM district conference, for this reason may according to the following way processing:
unsigned char code Dotn[]=lOxOO, Ox00,0×30,
0×00,0×30, Ox00, Ox00,0×00};
Soon the lattice code after the code key words defined puts in the ROM region.
3.3 DSl8820 1-Wire subroutines
The DSl8820 prominent merit is the scene gathering ambient temperature directly by the digital form output, like this may omit the following signal enlargement and the mold/number conversion fraction, constructs peripheral circuit’s part to be few, and relatively simple, the system cost is inexpensive; the 1-Wire connection and at89S52 correspondence, its structure is advantageous for the multi-spot survey, and easy to expand; Temperature measurement scope wide (- 550℃~1250℃), and the precision is high.
To the l-Wire operation key is software succession processing, regarding the different crystal oscillator its time delay parameter is different, this system as the example gives the following main program code take 12MHz:
bit DallassReset(void)
{
unsigned char presence=0;
DallassDataout=1; before // sends out the reset pulse, to release first
Puts the main line
delay(10);
DallassDataout=0;
delay(240); // guarantee time delay in 4801μs~9601μs between
DaUassDataout=1;
delay(35);
Dresence=DallassDataout;
delay(60);
return(presence);
}
// writes the succession to pull from the master-control unit the main line is low time starts
void writeCommand (unsigned char command)
{
unsigned char count;
for (count=O; count<8; count )
{
DallassDataout=0;
if(command&0×01==1)
{
DallassDataout=1;
// writes “1″ the succession after pulls lowly the main line, at89S52 master-control unit must in 15μs in release the main line, before therefore this sentence, cannot have the long time time delay sentence
}
delay(35); // regardless of writes “1″ writes “0″ the succession to have at least 601as low level DallassDataout=1; // main line restores process
command=command>>1;
}
}
// reads the succession pulls lowly the main line at least 1μs to release after the master-control unit main line’s time start
unsigned char readdata(void)
{
unsigned char value;
unsigned char midtemp=0;
for (value=0; value<8; Value )
{
I DallassDataout=0;
midtemp=midtemp>>1;
- nop_O;
_nop_O;
DallassDataout=1;
when // reads the succession, the controller must in 15μs in release the main line, then sampling main line condition, before therefore this sentence, cannot the time delay too long time time delay sentence
if(DallassDataout==1)
{
midtemp=midtemp | 0×80;
// because midtemp initial by the evaluation is 0, if therefore the sampling main line condition is 0 pieces does not need to process, 0 will be returned automatically
}
delay(35);
// time delay 70μs completes this Bit
The position reads the succession process, for next time reads prepares
}
return(midtemp);
}
void delay (unsigned char out)
{
unsigned char in;
for (in=out; in>O; in–);
}
4 ISP structure principles
Integrates the formation the ISP function on PCB to be possible to realize the procedure real-time renewal and the promotion operation, its structure principle as shown in Figure 5, this regarding the complex engineering system design is obviously very convenient, is also practical and feasible.
5 conclusions
Along with the smart instrument measuring appliance technology’s development, display module’s fluid crystallizes has become one more popular tendency. This article gives the software and hardware design proposal obtained correctly, reliable, the stable movement in some armament system’s debugging process. Its not only gram NT mold resembles the measuring appliance volume to be big, failure rate high flaw, moreover, because has utilized the RTOS technology, enables the data detection agile to obtain the large promotion. Moreover, the ISP function’s online integration has also reserved the space for system function’s expansion.