31
1 University of Belgrade Department of Electrical Engineering Diploma thesis Code generator for control of industrial processes Menthor: Candidate: Prof. Slobodan Vukosavić Ivan Rajković 176/97

Diploma thesisemp.etf.rs/radovi/Diplomski/rajkovic/ivan_rajkovic.pdf · 2007. 6. 3. · information available from (USING CCG.PDF). Generated C code is quit optimal in terms of C

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

  • 1

    University of Belgrade Department of Electrical Engineering

    Diploma thesis Code generator for control of industrial processes Menthor: Candidate: Prof. Slobodan Vukosavić Ivan Rajković 176/97

  • 2

    Basic information

    CCG version 1.0

    C code generator for control of industrial processes

    December, 2002 Belgrade

  • 3

    1. INTRODUCTION 4

    2. EXECUTIVE SUMMARY 6

    3. MORE ABOUT CCG… 7

    3.1 CCGs graphical programming language 8

    3.2 Generated code 8

    3.3 Limitations and future upgrades of CCG 12

    3.3 Conclusion 12

    4. ADDITIONAL INFORMATION 13

  • 4

    1. Introduction This document contains basic information about CASE (computer aided software engineering) tool CCG (C code generator). Aim of this document is to give short and clear explanation about all important aspects of C code generator. Upon reading this document you should be quit sure what is CCG., and what are benefits of using it. Detail information about using CCG together with illustrative example you can find in another document USING_CCG.pdf.

  • 5

    Figure 1.1 From an idea to final realization of control system

  • 6

    2. Executive summary Main purpose of CCG ( C code generator) is to make possible fast development of

    software for control of industrial processes. From an idea of the control system to final realization there is a lot things to be done. In Figure 1.1 it is shown where CCG fits in process of developing industrial automation control system. CCG is developed to correspond to needs of industrial automation control systems. So user can save a great amount of time by programming in CCGs graphical programming language and get C code automatically generated on base of scheme that he made. It is clear (from Figure 1.1) that user has to add hardware specific part of code to generated code. After this code can be used with any C compiler and linker for any specific digital controller. Benefits of this approach except time saving is that generated code is hardware independent and with little add-ins it can be used for any digital controller in wide range from microcontrollers to DSP. By this we give more freedom to user. He can choose hardware by his specific need or use CCG to generate code for already existing hardware. But it requires that user have knowledge of C programming language and have appropriate compiler and linker for his digital controller. Adding code is strictly defined activity and can be done easly. This means that anyone with basic knowledge of C language can without problem add code if he obeys some rules.

    In short terms CCG (C code generator) means next: 1. easy development of good software for control of industrial processes 2. great amount of saved time by programming in graphical language 3. generated code can be used with wide range of digital controller 4. more freedom to developers Additional requirements beside having CCG and knowing how to use it are: 1. user must have knowledge of C programming language 2. user must have C compiler and linker for specific controller CCG is not first code generator that generates C code on base of visual designs made

    in graphical language What distinguish CCG from another is that generated code is not tied to any digital controller and can be used with wide range of different digital controllers. On another side user must add some hardware dependent things to generated code. In exchange for a little additional effort from user side CCG gives great flexibility. CCG can be used with operating system Windows 95 or higher. Example of simple scheme made in CCG graphical language is given in Figure 2.1. We were aware that first version of CCG will have limitations so we developed CCG in that way so it will be easy to upgraded it. In next chapter we will give more information about CCG graphical programming language, generated code, limitations of this version and plans for future upgrades.

  • 7

    Figure 2.1 simple scheme made in CCG graphical language

    3. More about CCG… Before we give more information about CCG we will shortly describe important

    things about systems that control industrial processes. Control system in most of cases consists of one or more digital controllers and appropriate hardware. As it can be seen in Figure 1.1 digital controller read trough input interface values of some signals and make appropriate action trough output interface based on program logic and values of inputs. Except this digital controller should perform diagnostic check of system (for example is some current out of allowed range… ) . Also it is common that digital controller have possibility to communicate with PC in order to make possible on-site changes or supervision by operator. Digital controller represents heart of system and program is what gives life to it. We have wide range of control tasks in industry, from very simple to complex servo-positioning task, also we have need for low costs changes and upgrades of system preferably made in softwear. CCG should make possible fast, efficient way to generate code for wide range of control task in industry. CCG is possible to use as code generator for almost any control system becouse it doesn’t make any assumption about system and generates “hardware independent code”.

  • 8

    3.1 CCGs graphical programming language

    In CCG it is quite easy to make scheme in graphical programming language and get code automatically generated on base of it. To write that code manually in C would take much longer even for those who are experience and know what they are doing. This is what saves time and make software development easier. Well-developed graphical languages are easy to learn and easy to use. Simple example of scheme made in CCG is given in Figure 2.1. Scheme consists of blocks and connections. For example one of three blocks in Figure 2.1 is PID. Block set is for CCG as equally important as instruction set for any programming language. We come to number of 16 different blocks, which by our opinion are fundamental in industrial control tasks. We are aware that this block set should be improved in future. And first blocks that should be added to this set in future are trajectory generation blocks. In Table 3.1, Table 3.2 and Table 3.3 in from of table can be found blocks graphical symbol, functionality description, types of operands and C function name. About blocks and how to make schemes in CCG and use CCG you can get detail information from document (USING CCG.PDF).

    3.2 Generated code We have chosen to generate C language code mostly because a wide range of microcontrollers have tools that support C and by that we have already overcome a very big problem like differences among microcontrollers of different producers and left it to user to make his own choice by his specific needs. C code generated by CCG is adaptive and hardware independent as it is possible . In another words, we give possibilty to use generated code with any digital controller. But for that controller must exist tools that support C language (compiler,… ). In order to achieve HW independency we left to user to add some specific things to generated code. The way in which code should be added is strictly defined. It is simple activity with predefined steps and can be easly done. Detail information available from (USING CCG.PDF). Generated C code is quit optimal in terms of C language but final result depends of specific compiler that will be used. User has to debug only added part of code and that should be quit easy. Also it possible in short time and with little changes to make code correspond to needs of specific compiler (C for digital controllers usually isn’t strictly ANSI C). We assume that user has knowledge of C programming language and specific needs of compiler he use.

  • 9

    Table 3.1

  • 10

    Table 3.2

  • 11

    Table 3.3

  • 12

    3.3 Limitations and future upgrades of CCG Limitations for CCG version 1.0: It is not allowed to make feedbacks in schemes. Although schemes that user makes by CCG graphical language are checked for errors before CCG produce C code, diagnostic check for errors does not check for unconnected pins of blocks, or feedbacks. When you use CCG it is clear that this is not of great importance but we will solve this problems in next version. Apart limitations there is few idea that we have about upgrades of CCG and those are to add to block set blocks that will be for trajectory generation. CCG is mainly for those users that have some experience in programming with C but as we see it could be very easly become tool that could be used by those with little experience. Also our plan is to allow to user to define their custom blocks and add it to standard block set. And we hope that CCG will be friendlier user oriented in every next version. Custom blocks will make CCG be very flexible becouse user will be able to get custom block from another user and in that way block set can be easly improved in right direction.

    3.3 Conclusion Solution that we offer is automatic code generator for digital controllers of industrial processes. CCG is friendly user oriented CASE tool, can be used for wide ranges of control problems and with wide range of digital controllers from small controllers to DSP. In CCG (C code generator) we have combined mostly already existing popular methods with new approach, in aim to offer to user: easy to use uniform, manufacturer-independent language concepts within graphical programming language. We also take care that we develop CCG in that manner so it would be easy to upgrade it. When we designed graphical language we especially was aware that block set (this is for CCG equally important as instruction set for any programming language) should be easy for improving by adding new blocks. CCG is capable to generate C code that is hardware independent, as code can be, and left to user to add only specific things, as it is hardware initialization and some other things. We have shown in details what should be done and added to generated code to make it be functional for specific controller and make it correspond to needs of specific compilers in document (USING CCG.PDF) (this because C compilers for digital controllers are rarely strictly ANSI ). Main benefits of using CCG are that in short time user can for standard control problems get code and with little effort from his side to make that code be functional for any digital controller for which exist tools that support C programming language. We noticed that this version of CCG have some limitations that should be solved in future. Apart limitations there is few idea that we have about upgrades of CCG.

  • 13

    4. Additional information The demoCCG is version that can not generate code and you can get it for free. Still

    you can in demoCCG make schemes and see how it looks like. Example of how to use CCG is in document USING_CCG.pdf in that document can be found how to make schemes, how to generate code. And in one fully illustrating example is shown how and what to add to code to make it become fully executable for specific microcontroller. You can download demoCCG.exe and USING_CCG.pdf from www… If you have some questions, suggestion, or you are interested in something about CCG and you cannot find enough information in documentation you can get more information via e-mail mail. You can also get example of successfully used C code generated by CCG with microcontroller PIC16F873.

  • 14

    Our aim was to provide as good documentation as it is in our possibility. We are aware that we maybe have made few mistakes. So we will continue to improve documentation. And if you are unsatisfied by any part of this document or information contained herein Please send your e-mail to this mail.

    TO READER

  • 15

    1. Introduction In this document we give complete example how to use CCG. Before reader start with

    example we suggest to read next chapter 2.Before we begin because it gives essential

    information for understanding the way CCG should be used. Upon reding this

    document you should be able to use CCG in best manner. All that is expected from

    you is to have knowladge of C programming language, to read and understand this

    document and we assume that you know what are specific needs of C compiler and

    hardware that you use. Figure 1.1 describe procedure step by step from programming

    in graphical progarming language to downloading hex filke to appropriate chip.

  • 16

  • 17

    Figure 1.1 From an idea to raelisation of control sysytem

  • 18

    2. Before we begin Before we begin with example we must explain some things. These things are important for any user who attends to have good understanding of CCGs capabilities and how to use them...

    2.1 CCG short description CCG (C code generator) is software developmant tool for automaic C code generation for control of industrial processes. As it can be seen in Figure 1.1 CCG automatically generates code on base of schemes made in graphical programming language. Code that is generated can be used for any digital controller but first hardware dependent things must be added by user. Adding code is simple and striclly defined activity. CCG is user friendly oriented tool. In this first version you may not find all (user friendly oriented) possibilty that you exspect from one modern PC program but we attend to make a great number of improvments in next version. For this version 1.0 our main aim to give tool that has good graphical language and generates good C code.

  • 19

    3. Template for using CCG

    We will give one complete example of using CCG and it will be shown how to: 1. use graphical programming language and make scheme 2. add hardware dependent code to generated code

    3.1 Creating scheme in CCG graphical programming language

    Control system consist im most cases of one or more digital controller and appropiate

    hardware. As it can be seen in bottom of Figure 1.1 trough input interface digital

    controller read values of some input signals and then on base of program and input

    values produces results that goes to output interface. Instead to write program for

    digital controller in assembler or in C you can write program in CCG graphical

    programming language. Input or output signals for control systems usualy can be of

    ON/OFF type or analog. In CCG graphical programming language exist two types of

    inpute blocks and two type of output blocks. Closer information on block set of CCG

    you can get from Table 2.1, Table 2.2, Table 2.3. Schemes that you make in CCG

    consist of blocks and their connections. For making scheme only thing that we have to

    know about system is how many input and output signals we have and which type they

    are.

    It’s common case in industry that you have time dependent activity for example when system is on for 5 minutes it is one mode next 2,5 minutes in another and finally 1 minute in third mode after 5 cycles system goes off till it get command to start again. Now lets see how to make this in CCG graphical programming lnguage.

    First let see how block (part) can be added. In Figure 3.1 we see that as a manu

    choice exist add Part. And if we click on it we will see that it will appear four subitems and that are inputs, outputs, standard, advanced. If we put cursor over some of it for example inputs we get a pop-up menu in which we see bRD and 16bRD choices, this

  • 20

    can be seen in Figure 3.1. This menu choice corresponds to BITREAD and 16BITREAD blocks from Table 2.3 .

    Figure 3.1

    We will now click on bRD and dialog box like one in Figure 3.2 appears we need to enter a name and it should be descriptive. For example cmnd as short form of command . After we click on OK we will see that we get graphical symbol in upper left corner of window, under graphical symbol goes block instance name in our case it is IIRcmndA notice that except of cmnd CCG added IIR and A this will be explained later. In similar manner it can be added as many blocks as we want but before we continue let show how can we move block in the window .

    Figure 3.2

  • 21

    As we can see in Figure 3.4 BITREAD graphical symbol consist of two rectangles, one big blue with text in it and one little black, little black rectangle is pin and big rectangle we will by convention refer as MFrame (Main Frame). If user look at any graphical symbol of any block it can be noticed that they all have MFrame and pins. In toolbar we can see apart standard buttons one more button on Figure 3.3 we see short description that appears when we put cursor over it and hold it for some time. As we see from Figure 3.3 it is button for selecting tools mode if it is unchecked we can use mouse cursor for moving blocks or simply selecting blocks or connections . Moving blocks in CCG is same as in most graphical programs . When we want to move block we put cursor over MFrame area of block push left button down and while holding it we move mouse, block will follow cursor and when we want to stop we simply let left button go up. Now that we know how to add and move blocks let add some more. We will add timeron100 we first click to menu choice add Part than to standard then to timers and then to timeron100 and for it we will have to enter in dialog box preset time. If the user not sure what that means information are always available in Tables 2.1, 2.2, 2.3 under block functionality description and if we look there we will see that for our value 3000 it means (for our case where Tcycle=1mS) that output will go to 1 (after 3000*100mS = 5 min) if input goes to1 and stays 1, if input goes to 0 output also goes to 0. Now if we press OK in dialog box we will have two blocks. Now we can show how to make connections in CCG.

    Connections in CCG can be made only between pins of different kind. And it is

    done in next manner. Button tools mode must be checked and when it is checked it looks like in Figure 3.4. Then we put cursor in area of pin (top of cursor must be inside little black rectangle ) and press left button down as we move mouse we will notice that line goes from pin to cursor (if we move mouse and there is no line that means that top of cursor was not in pin area when we pressed left button down so we will have to try it again) we then simply move cursor to another pin and when we let left button go up connection will be made. In Figure 3.4 we see connection that we made between output pin of block with name IIRcmndA and input pin of block with name timeron100A Although CCG wont let user make connections between two output pins user can made some mistakes. So user must obey some rules.

  • 22

    Figure 3.3

    By making connections user can make next mistakes: 0. Make a feedback. This is forbidden in this version. 1. Connect more than one output pin to same input pin. Although CCG will not prevent user make this kind of mistake it will report this kind of error when user try to generate code .It is important that when user get message that he had more than one output connected to same input he must do next things in order to fix that. All connections that go to that input pin MUST be deleted and after that he makes 1 connection to that pin (right one). 2.Connect two pins of different data type. This kind of error is more dangerous because CCG wont report any errors and it will generate code. In order to avoid this kind of error user should before making the connections check in Tables 2.1, 2.2, 2.3 in column data type does the pins that will be connected of same data type. We hope that in future we add feature that prevents user of making this kind of mistakes. 3. Left unconnected pins. This may be error or may be not error but it is not recommended to do that. In either case if user left unconnected pins code that is generated may not perform as it is expected on base of scheme, why? we will explain later.

  • 23

    For now user should obey next rules when making connections: 0. making feedbacks is forbidden

    1. Connect only one output pin to same input pin. 2. Do not left any unconnected pins in scheme. 3. Before making the connections check in Tables 2.1, 2.2, 2.3 in column data type

    does the pins that will be connected of same data type and only if they are, make connection.

    We now know how to make connections add and move blocks ( notice that if you

    have made connection if you move block connection will stay attached and follow the block).

    Figure 3.4

    Now we will show how to delete blocks and/or connections. In order to delete item

    we have to select it first. For example if we put cursor over MFrame area of BITREAD block and click with left mouse button we have selected that block and if we press key delete from keypad it will disappear together with connection this is because when we delete block we also delete all connections that was attached to his pins. We also can delete only connection and this is done by putting top of cursor over black lines that represent connection click with left mouse button and then press key delete from keypad. In Figure 3.5 is scheme that we made and which we will use for generating code.

  • 24

    Figure 3.5

  • 25

    Before we generate code we can save scheme that we made simply as it is done in any Windows program by choosing menu choice File then Save As notice that it will be saved with extension *.gfc (graphical function chart). We will now generate code for Figure 3.5. This is done by clicking on menu choice Tools and on its subitem code generation. When we code generation is finished we will see Message Box as in Figure 3.6 which inform us about generation results.

    Figure 3.6

    And generated code is given in Listing 3.1. We will now show how this code should be used. First let see what user should add in order to make this code functional. We must perform next step in order to make generated code be functional for specific controller.

    3.2 Adding hardware dependent part of code

    After CCG have generated code on base of scheme we have to add some things . Up to now we didn’t care about which digital controller we will use and all hardware dependent things. For making scheme only thing that we have to know about system is how many input and output signals we have and which type they are. We have to connect code that is generated by CCG to physical resouces of our digital controller and system so we have to add some code.

    Very important thing is to choose Tscan. Digital controller read inputs and based on their values and program logic produce results this is repeative activity with constant period Tscan. So input values must carry correct information and digital controller must be able to produce results befor new samples are taken. Tscan must be chosen with great care.

    Things to be added to generated code are: 1.Definition of function init( ). In this function should be putted all initialization of hardware. 2.We must have one interrupt with constant period of repeating. Function driver( ) which definition is given in bottom of Listing 3.1. should be interrupt service routine that response to that interrupt. Apart all other specific things in driver( ) we must set variable pseudo on every n-th interrupt (n is number greater or equal to 1). -explanation for step 2. As we see in function main( ) we have endless loop and if pseudo is 1 next three function will be called writeIIR( ), scan( ) in which we clear variable pseudo and readIOR( ). By this we get that this three function are executed on every n-th interrupt. This is repetiteve activity with constant period. Choosing this period is of great importance becouse if Tscan is 1mS it will read inputs every mS so if input

  • 26

    values changes faster system will not be correct also Tscan should not be to small becouse digital controller have to be able to execute program and produce output before come time to take new input values. 3.On scheme we have some blocks of input type and some blocks of output type user should do next. In function writeIIR( ) he assigns value of some physical input to variable whose name is same to block instance name (of some block of input type). Then in function readIOR( ) reads value of variable whose name is same to block instance name (of some block of output type) and copy its value to some physical output or some special register. -explanation for step 3. By this we connected physical inputs and outputs to part of program that is in function scan( ) and this is the function where all we have on scheme is done. In other words scan ( ) on base of variables in which we wrote values by function writeIIR( ), produces results that writes to variables that we read with function readIOR( ). As it can be seen in code function writeIIR( ) will be called before function scan( ) and function readIOR( ) after function scan( ). So all variables will be correctly updated. Now we can explain why functions have names writeIIR( ), and readIOR( ). IIR stands for input image registers this name is because we in function writeIIR( ) simply copy values of some physical inputs to some variables and that variables represents image of physical inputs. OIR stands for output image registers That means that by function readIOR( ) we just read some variables and their values we copy to some physical outputs or special registers so this variables are images of physical output. We by this gain that function scan( ) don’t have any touch with physical inputs, outputs.

    4. This step is optional. In generated code we see that in endless loop exist call of function serman( ), user should give definition of this function to enable communication of controller with another devices or simply to delete this call if communications are not necessary. Also after this function call it can be also optionally added one more function call, which will perform, self test diagnostic for device.

    All this we will show in example that will be written for digital controller PIC16F873. We will see how this is done for each step and at the end we will compile program and present build results. 1. Here is simple example of function init() For example system have one input signal from pin RB3 and have three output signals on pins RB0, RB1, RB2 also we have need for interrupt with constant period of appearing (FOSC is 20MHz). void init(){ PCLATH=0; // ensure PCLATH is zero GIE=0; // disable all interrupts OPTION=0x81; // prescaler to tmr0 TRISA=0xff; // all pins of POTRA are input

  • 27

    TRISB=0xf8; // RB0, RB1, RB2 are outputs INTCON=0x20; // allow interupt from tmr0 TMR0=0; // reset timer GIE=1; // enable interrup} 2. Here is simple example of function driver() By function init() we made that interrupt from tmr0 of PIC16F873 have period of 200uS And we want that our program from scheme executes every 1mS so we will put variable pseudo to 1 on every 5 interrupt (5*200uS=1mS). Tscan=1ms void interrupt driver(){

    if(cyc==5) {pseudo=1;cyc=0;} ++cyc; } 3. In this step we will connect our scheme with physical resouces of device: As we said we have input on pin RB3 and if look at Figure 3.5 we see one block of input type which name is IIRcmndA as we said we simple add code to function writeIIR() writeIIR(){IIRcmndA=RB3;} as we see it is simple because we just assing value of RA0 which is pin value to variable IIRcmndA. We also have outputs RB0, RB1, RB2 readIOR(){RB0=OIRhalfA; RB1=OIRpauseB; RB2=OIRfullC;} In simmilar manner we see in Figure 3.5 output blocks with corresponding names so we assing their values to pins RB0, RB1, RB2. By this we finished with adding code to generated code. NOTE: you should check which type of data is allowed in compiler that you use and all rules about that becouse in this example we used HT-PIC and data types for RAx or RBx are bit and data type for BITREAD are RBOOL it can be seen in header file vstpic2.h that RBOOL is char, but HT-PIC allows this kind of data assigment. We also could put that RBOOL is bit about this you can get additional information. In any case you should see in vstpic2.h what means RBOOL, BOOL… 4. Becouse this step is optional and this should be simple example so we will not add code but only comment out function call

    /*serman();*/

  • 28

    we have made some examples where we make possible by serman() to communicate with PC truogh serial port. Also after this function it is place to write code for diagnostic check of system.

    #define BLOCKASPACE 1 #define BLOCKTIMERON 1 #define BLOCKTIMERON10 1

  • 29

    #define BLOCKTIMERON100 1 #define BLOCKLOGIC 1 #include "vstpic2.h" RBOOL pseudo=0,IIRcmndA0=0,timeron100C0=0,timeron100B0=0, timeron100A0=0,andC0=0,andB0=0,andA0=0,notC0=0,notB0=0,notA0=0, OIRfullC=0,OIRpauseB=0,OIRhalfA=0; BOOL IIRcmndA=0; USHORT timeron100Ccur=0,timeron100Bcur=0,timeron100Acur=0; char timeron100Ccon=0,timeron100Bcon=0,timeron100Acon=0;

    void scan(){pseudo=0; IIRcmndA0=ddi(IIRcmndA); timeron100A0=timeron100(IIRcmndA0,timeron100A0,&timeron100Acur,3000,

    &timeron100Acon); timeron100B0=timeron100(timeron100A0,timeron100B0,&timeron100Bcur,1500

    ,&timeron100Bcon); timeron100C0=timeron100(timeron100B0,timeron100C0,&timeron100Ccur,1200

    ,&timeron100Ccon); notA0=not(timeron100A0); notB0=not(timeron100B0); notC0=not(timeron100C0); andA0=and(notA0,IIRcmndA0); andB0=and(notB0,timeron100A0); andC0=and(notC0,timeron100B0); OIRfullC=_digo(andC0); OIRpauseB=_digo(andB0); OIRhalfA=_digo(andA0); } writeIIR(){/* add your code here */} readIOR(){/* add your code here */} main(){init(); while(1){if(pseudo){writeIIR(); scan(); readIOR();} serman();} } void interrupt driver(){/* add your code here */} Listing !! generated code #define BLOCKBITS 1 #define BLOCKASPACE 1 #define BLOCKTIMERON 1

  • 30

    #define BLOCKTIMERON10 1 #define BLOCKTIMERON100 1 #define BLOCKLOGIC 1 #include #include "vstanpic.h" #include "init.h" RBOOL

    pseudo=1,IIRcmndA0=0,timeron100C0=0,timeron100B0=0,timeron100A0=0,andC0=0,andB0=0, andA0=0,notC0=0,notB0=0,notA0=0,OIRfullC=0,OIRpauseB=0,OIRhalfA=0; BOOL IIRcmndA=0; USHORT timeron100Ccur=0,timeron100Bcur=0,timeron100Acur=0; char timeron100Ccon=0,timeron100Bcon=0,timeron100Acon=0; char cyc=0; void scan(){pseudo=0; IIRcmndA0=ddi(IIRcmndA); timeron100A0=timeron100(IIRcmndA0,timeron100A0,&timeron100Acur,3000, &timeron100Acon); timeron100B0=timeron100(timeron100A0,timeron100B0,&timeron100Bcur,1500, &timeron100Bcon); timeron100C0=timeron100(timeron100B0,timeron100C0,&timeron100Ccur,1200, &timeron100Ccon); notA0=not(timeron100A0); notB0=not(timeron100B0); notC0=not(timeron100C0); andA0=and(notA0,IIRcmndA0); andB0=and(notB0,timeron100A0); andC0=and(notC0,timeron100B0); OIRfullC=_digo(andC0); OIRpauseB=_digo(andB0); OIRhalfA=_digo(andA0); } writeIIR(){IIRcmndA=RB3;} readIOR(){RB0=OIRhalfA; RB1=OIRpauseB; RB2=OIRfullC;} main(){init(); while(1){if(pseudo){writeIIR(); scan(); readIOR();} /*serman();*/} } void interrupt driver(){ if(cyc==5) {pseudo=1;cyc=0;} ++cyc; } Listing

    void init(){ PCLATH=0; // ensure PCLATH is zero

  • 31

    GIE=0; // disable all interrupts OPTION=0x81; // prescaler to tmr0 TRISA=0xff; // all pins of POTRA are input TRISB=0xf8; // RB0, RB1, RB2 are outputs INTCON=0x20; // allow interupt from tmr0 TMR0=0; // reset timer GIE=1; // enable interrup}

    Listing This is what we get by this program if value on pin RB3 goes to 1 and stays 1

    value on pnis RBO,RB1,RB2 will be 1,0,0 for 5 minutes then will be 0,1,0 for 2 minutes and 30 seconds and then 0,0,1 for 2 minutes after that will be 0,0,0. If value on pin RB3 is 0 value of outputs are 0,0,0.