spirit-ii lab manual

Upload: kunal-khandelwal

Post on 03-Jun-2018

226 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/12/2019 Spirit-II Lab Manual

    1/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in1

    SPIRIT - II LAB MANUAL

    VERSION - 2

  • 8/12/2019 Spirit-II Lab Manual

    2/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in2

    INDEX

    CHAPTER 1 .................................................................................................................................. 3Project Creation / Compilation / Downloading STEPS.............................................................. 3

    CHAPTER 2 ................................................................................................................................... 5

    1.Assembly Language Programming.......................................................................................... 5

    2 LED and DIP SWITCH .......................................................................................................... 83. BUZZER............................................................................................................................... 13

    4.RELAY................................................................................................................................... 16

    5.STEPPER MOTOR ............................................................................................................... 196. TIME DELAY....................................................................................................................... 23

    7.External Interrupt ................................................................................................................... 26

    8. 7- Segment ............................................................................................................................ 309.Keypad ................................................................................................................................... 34

    10.Multi Digit 7 Segment ......................................................................................................... 3811.Text LCD (TLCD)................................................................................................................ 42

    12 ADC and Temperature display............................................................................................. 4613 I2C Serial EEPROM......................................................................................................... 49

    14 Generation of PWM Signal.................................................................................................. 56

    CHAPTER -3................................................................................................................................ 601.LED........................................................................................................................................ 60

    2 Display of Message on LCD.................................................................................................. 64

    3.MailBox ................................................................................................................................. 684.Messages to PC through Serial Port....................................................................................... 72

  • 8/12/2019 Spirit-II Lab Manual

    3/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in3

    CHAPTER 1

    Project Creation / Compilation / Downloading STEPS

    Double click on the icon Triton available on your Desktop.

    Select the workspace by creating a folder or also can select the defaultworkspace.

    Create C or C++ project by clicking ProjectNewC Project /C++Project .

    Enter a name for the project. In the Project name field, type the name of

    project. Do not use spaces or special characters in the project name (forexample, "ABC").

    Select appropriate Target i.e ARM.

    Select appropriate Variant LPC2138 /LPC2148 /LPC2129 from list as requiredfor building project.

    Select appropriate Operating System, here we would select none as theoperating system.

    Select Port from list as per your target board i.e COM1.

    Select Baud Rate from dropdown list i.e 38400.

    And let the rest of the options be default, and then click Next.

    Select the type of project that you want to build. By defaultProject Type isExecutable (Gnu).

    Debug- Project can be debugged on target board using Serial, Odyssey JTAGand Ethernet

    Release- Project is run on Target board without debugging.

    ClickFinish when you are done.

    You should now see the new project (ABC) in the C/C++ Projects view.

    In Triton IDE new project created will have template files. for eg ABC_main.cand ABC_start.s

  • 8/12/2019 Spirit-II Lab Manual

    4/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in4

    Properties file is also created which shows properties of project.

    Enter the code in the ABC_main .c file. You can double click the ABC_main.ctab in the Editorview to expand the view.

    You will notice an asterisk in front of the file name on the tab in theEditorview.The asterisk indicates that the file has changed but has not been saved.

    Now save the ABC_main .c file by clicking FileSave.

    In Triton IDE you can build project in two modes :--

    1. Debugmode - Builds project with debugging

    2. Releasemode - Builds project without debugging

    To build project in release mode:

    Select release mode by right clicking on project and clickActive Build ConfigurationRelease.

    Right click on the project folder, and select the option BUILD.

    Navigate to the C/C++ Projectsview and expand the Release folder created when youbuild project in Release mode.

    Here, ABC.hex file is created which is to be downloaded on target board and executed.

    Connect the Hardware Board with the serial connector and power supplyprovided.

    Switch on the Hardware Board, and put the switch in ISP Mode for the programto be downloaded.

    Right click on the ABC.hex file and download the executable code on to the

    Board.

    Once, the program is downloaded, shift the mode from ISP to RUN and resetthe Board to verify the output.

  • 8/12/2019 Spirit-II Lab Manual

    5/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in5

    CHAPTER 21.Assembly Language Programming

    Programs in Assembly Language for the following:-

    a) Addition

    #include #include #include

    int j,i;char k=0;char rem,ch[4]={'0','0','0','0'};

    int L1(int);

    int main(void){

    q_lcdinit(SPIRIT); // initialise the LCDk=L1(j); // return from assemblyq_printf("%d \r\n", k); // print on hyperterminal

    for(i=0;i=0;j--)q_displaylcd(&ch[j],1); // display on LCDreturn 0;

    }

    b) Subtraction

    #include #include #include

    int j,i;char k=0;

  • 8/12/2019 Spirit-II Lab Manual

    6/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in6

    char rem,ch[4]={'0','0','0','0'};

    int L1(int);

    int main(void){

    q_lcdinit(SPIRIT); // initialise the LCDk=L1(j); // return from assemblyq_printf("%d \r\n", k); // print on hyperterminal

    for(i=0;i=0;j--)q_displaylcd(&ch[j],1); // display on LCD

    return 0;}

    c) Multiplication

    #include #include #include

    int j,i;char k=0;char rem,ch[4]={'0','0','0','0'};

    int L1(int);

    int main(void){

    q_lcdinit(SPIRIT); // initialise the LCDk=L1(j); // return from assemblyq_printf("%d \r\n", k); // print on hyperterminal

    for(i=0;i=0;j--)q_displaylcd(&ch[j],1); // display on LCDreturn 0;

  • 8/12/2019 Spirit-II Lab Manual

    7/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in7

    }

    d) Division

    #include #include #include int j,i;char k=0;char rem,ch[4]={'0','0','0','0'};

    int L1(int);

    int main(void){

    q_lcdinit(SPIRIT); // initialise the LCD

    k=L1(j); // return from assemblyq_printf("%d \r\n", k); // print on hyperterminal

    for(i=0;i=0;j--)q_displaylcd(&ch[j],1); // display on LCD

    return 0;}

  • 8/12/2019 Spirit-II Lab Manual

    8/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in8

    2 LED and DIP SWITCH

    Objective:

    To display the status of DIP Switches on LED s .

    Theory of Operation:

    This experiment is to glow the Light Emitting Diode (LED). LED is a special diode thatemits light upon application of a potential difference greater than its forward biasvoltage across its terminals. A LED can be forward biased as per following diagram.

    The voyager board has LED connections as shown in the following diagram

    H44H48

    H36H40

    H12H16

    H4H8

    SMD

    W16U2

    W14U2

    W12U2

    VCC5V_LED

    1 2

    R40

    W9U2

    1 2

    R47

    1 2

    R41

    1 2

    R46

    1 2R42

    1 2

    R43

    1 2

    R45

    1 2

    R44

    1 2

    LD1

    1 2

    LD2

    1 2

    LD4

    1 2LD3

    1 2

    LD6

    1 2

    LD5

    W7U2

    1 2

    LD7

    W18U2

    W5U2

    W3U2

    1 2

    LD8

    C1

    1A12

    1A24

    1A36

    1A48

    2A111

    2A213

    2A315

    2A417

    1G 1

    2G 19

    1Y1 18

    1Y2 16

    1Y3 14

    1Y4 12

    2Y1 9

    2Y2 7

    2Y3 5

    2Y4 3

    VCC20

    GND10

    U6

    74AHCT244

    WR2

    WR4

    WR3

    WR6

    WR5

    WR10

    WR8

    WR7

    The ARM LPC controller pins numbered H16, H12, H8, H4, H48, H44, H40 and H36are used to drive the buffer 74HC244. Buffer is just used as a temporary data storage

  • 8/12/2019 Spirit-II Lab Manual

    9/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in9

    device that strengthens the signal. Using this mechanism prevents the controller fromdamage. Otherwise when all the LEDs are ON too much current will be sourced fromthe controller which may damage the port permanently. This happens because the

    input and output sections of the buffer are electrically isolated. Resistors R40~R47 areresistors in order to limit the current to avoid any damage to the LEDs.

    On selection of the pin register we can configure all the peripheral pins to be generalpurpose input output (GPIO) pins. The GPIO pins are controlled by four registers, asshown below:-

    RegisterName

    Functionality ExpectedOperation*

    IODIR Controls the GPIO direction Write Only

    IOSET Sets the GPIO to be 1(sets theLed in ON state)

    Write Only

    IOCLR Sets the GPIO to be 0(sets theLed in OFF State)

    Write Only

    IOPIN Reflects the current state Read Only

    * Unexpected operations on registers are undefined

    Here, on the Voyager - LED add on board we have 8 LEDs connected .This LED pinsare connected to the port pin 0.15 to port pin 0.22, henceforth the same are selectedvia PINSEL register through value 0x007f8000 .

  • 8/12/2019 Spirit-II Lab Manual

    10/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in10

    As, all the header files related to ARM are present in the LPC21xx.h .Hence, weinclude the Header File.

    DIP SWITCH :A DIP switchis a set of manual electric switches that are packaged in a groupin a standard dual in-line package (DIP) (the whole package unit may also be referred to as aDIP switch in the singular). This type of switch is designed to be used on a printed circuit boardalong with other electronic components and is commonly used to customize the behavior of anelectronic device for specific situations.

    DIP switches are an alternative to jumper blocks. Their main advantages are that they arequicker to change and there are no parts to lose.

    Procedural Algorithm :

    LED No. Signal (LPC21xx) Description

    1 Pin 45 (P0.15) LED 1

    2 Pin 46 (P0.16) LED 2

    3 Pin 47 (P0.17) LED 3

    4 Pin 53 (P0.18) LED 4

    5 Pin 54 (P0.19) LED 5

    6 Pin 55 (P0.20) LED 6

    7 Pin 1 (P0.21) LED 7

    8 Pin 2 (P0.22) LED 8

  • 8/12/2019 Spirit-II Lab Manual

    11/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in11

    S.No Signal (LPC21xx) Description

    1 Pin 22 (P0.2) Switch 1

    2 Pin 26 (P0.3) Switch 2

    3 Pin 27 (P0.4) Switch 3

    4 Pin 29 (P0.5) Switch 4

    5 Pin 30 (P0.6) Switch 5

    6 Pin 33 (P0.8) Switch 6

    7 Pin 34 (P0.9) Switch 7

    8 Pin 35 (P0.10) Switch 8

    Set the Direction Pins from P0.15- P0.22 withIODIR Register for LED s .

    Extract the status PORT0 (P0.2 P0.10) using IOPIN0 Register .

    Display the status on LED s .

    Source Code :

    #include

    int main(void){

    int i;while(1)

    {*IODIR0 =*IODIR0 | 0x007f8000; //Set Direction of LED*IOCLR0 = 0x007f8000; //Clear all LED's

    *IOSET0 = ((*IOPIN0 & 0X000000F7C)

  • 8/12/2019 Spirit-II Lab Manual

    12/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in12

    Conclusion:

    Hence , display of the status of DIP Switches on LED s is been done .

  • 8/12/2019 Spirit-II Lab Manual

    13/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in13

    3. BUZZER

    Objective :

    To program Buzzer using ARM Technology .

    Theory of operation :

    One end of the electromagnet wire is connected directly to one end of the electrical circuit. Theother end of the wire connects to ametal contact, which is adjacent to a moving contact arm.

    The contact arm is a thin piece of light, conductive metal, with a thin iron bar soldered onto it.The anchored end of the contact arm is wired to the electrical circuit. When the electromagnet isturned off, the free end of the arm rests against the contact point. This forms a connectionbetween that end of the wire and the electrical circuit. In other words, electricity can flow throughthe electromagnet when the circuit is closed.

    Closing the circuit (by pressing the button) puts this mechanism in motion. Initially, theelectromagnetic field attracts the iron bar, which pulls the contact arm off the stationary metal

  • 8/12/2019 Spirit-II Lab Manual

    14/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in14

    contact. This breaks the connection between the circuit and electromagnet, so theelectromagnet shuts off.

    Without a magnetic field pulling it back, the contact arm snaps back into position against thestationary contact. This reestablishes the connection between the electromagnet and the circuit,and the current can flow through it again. The magnetic field draws the contact arm up, and theprocess repeats itself as long as you hold down the buzzer button. In this way, theelectromagnet keeps shutting itself on and off.

    The buzzing noiseyou hear is the sound of the rapidly moving arm hitting the magnet and thestationary contact dozens of times a second.

    Procedural Algorithm :

    S.No Port.No Description

    4 P0.7 Buzzer

    Set the Direction pin for P0.7 as shown in the in schematic Diagram .

    Select the Pin with IOSET Register and give Delay .

    Clear the Pin with IOCLR Register and give Delay

    Connect the Jumper JP8 .

    Source Code :

    #include #include

    int main(void)

    {

    int i;*IODIR0=*IODIR0 | 0X0000080; // As shown in the Pin Connection Diagram P0.7 is connected

    to the Buzzer , hence 8 th pin is selected .while(1){

    *IOSET0= 0X0000080; //Sets the Pin No 7for (i=0;i

  • 8/12/2019 Spirit-II Lab Manual

    15/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in15

    for (i=0;i

  • 8/12/2019 Spirit-II Lab Manual

    16/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in16

    4.RELAY

    Objective :

    To program Relay using ARM Technology .

    Theory of operation :

    Relays are amazingly simple devices. There are four parts in every relay:

    Electromagnet Armaturethat can be attracted by the electromagnet. Spring Set of electrical contacts

    The following figure shows these four parts in action:

    In this figure, you can see that a relay consists of two separate and completely independentcircuits. The first is at the bottom and drives the electromagnet. In this circuit, a switch iscontrolling power to the electromagnet. When the switch is on, the electromagnet is on, and itattracts the armature (blue). The armature is acting as a switch in the second circuit. When theelectromagnet is energized, the armature completes the second circuit and the light is on. Whenthe electromagnet is not energized, the spring pulls the armature away and the circuit is notcomplete. In that case, the light is dark.

  • 8/12/2019 Spirit-II Lab Manual

    17/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in17

    When you purchase relays, you generally have control over several variables:

    The voltage and current that is needed to activate the armature The maximum voltage and current that can run through the armature and the armature

    contacts The number of armatures (generally one or two) The number of contacts for the armature (generally one or two -- the relay shown here

    has two, one of which is unused) Whether the contact (if only one contact is provided) isnormally open (NO) or normally

    closed (NC)

    Procedural Algorithm:

    Sr. No. Signal (LPC22xx) Description

    1 Pin 24 (P1.26) Relay On/Off

    Set the Direction pin for pin.no 26 as shown in the in schematic Diagram.

    Select the Pin with IOSET Register and give Delay.

    Clear the Pin with IOCLR Register and give Delay.

    Source Code :

    #include #include

    int main(void){

    int i;

    *IODIR1 = *IODIR1 | 0X04000000; //As shown in the pin connection diagram P1.26is connected,hence Pin 26is been selected .

    while (1){

    *IOSET1 = 0X04000000; // Sets the Pin 26for(i=0;i

  • 8/12/2019 Spirit-II Lab Manual

    18/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in18

    Conclusion:

    Thus, the RELAY is been Programmed using ARM.

  • 8/12/2019 Spirit-II Lab Manual

    19/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in19

    5.STEPPER MOTOR

    Objective :

    To program the Stepper Motorusing ARM Controller.

    Theory of Operation :

    A Stepper Motor is an Electromechanical device which converts electrical pulses in todiscrete mechanical movements .Every stepper motor has a permanent magnet rotoralso called shaft surrounded by a stator .The shafts or spindle of a stepper motorrotates in a fixed repeatable step and it increments when electrical command pulsesare applied to it in the proper sequence .This is possible as a result of electromagneticinduction theory.

    The motors rotation has several direct relationships to these applied inputpulses.

    The sequence of the applied pulses is in direct correlation to the direction ofmotor shafts rotation.

    The speed of the motor shafts is in direct co relation to the frequency of theinput pulses.

    And, the angle of rotation is in direct correlation to the number of input pulses

  • 8/12/2019 Spirit-II Lab Manual

    20/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in20

    applied.

    Based, on this A and B value as shown in figure the stepper motor rotates.

    As , shown in the schematic diagram as well in the pin connection table the ports pinsconnected are from P0.11 to P0.14.

    Procedural Algorithm :

    Sr. No. Signal (LPC21xx) Description

    1 Pin 37 (P0.11) Data 0

    2 Pin 38 (P0.12) Data 1

    3 Pin 39 (P0.13) Data 2

    4 Pin 41 (P0.14) Data 3

    5 5.0V/12.0V VCC(5)

    6 GND GND

    H31H29

    H30H27 MOSI

    SCK0SSEL0MISO

    VCC5V

    STEPPER MOTOR

    13579

    246810

    J3

    H5_CAN1H3_CAN1RD2 TD2

  • 8/12/2019 Spirit-II Lab Manual

    21/77

  • 8/12/2019 Spirit-II Lab Manual

    22/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in22

    }

    return 0;

    }

    Conclusion:

    Hence, the Stepper Motor is been operated using ARM Controller.

  • 8/12/2019 Spirit-II Lab Manual

    23/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in23

    6. TIME DELAYObjective :

    To program for Time Delay using TIMER.

    Theory of operation :

    The timers are based around a 32-bit timercounter with a 32-bit prescaler. The clock sourcefor all of the timers is the VLSI peripheral clockPCLK

    Each timer also has up to four match channels.Each match channel has a match register whichstores a 32-bit number. The current value of thetimer counter is compared against the matchregister. When the values match an event is

    triggered. This event can perform an action to the timer (reset, stop or generate interrupt) andalso affect an external pin (set clear , toggle).To configure the timer for a match event, load the match register with the desired value. Theinternal match event can now be configured through the Match Control Register.

  • 8/12/2019 Spirit-II Lab Manual

    24/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in24

    In this register each channel has a group of bits which can be used to enable the followingactions on a match event: generate a timer interrupt, reset the timer or stop the timer. Anycombination of these events may be enabled. In addition, each match channel has an associatedmatch pin which can be modified when a match event occurs. The match pins are then controlledby the first four bits in the external match register

    Procedural Algorithm :

    Initialize VIC Block for TIMER0

    Write ISR for TIMER0

    Start the TIMER, and put main function in infinite loop.

    Source Code :

    #include#includevoid TIMER_ISR (void) __attribute__ ((interrupt ("IRQ")));#define TIMER 4;

    int main(void){

    *T0MCR=0x03;*T0MR0=0x650000;*T0TCR=0x01;

    *VICIntEnable=0x10;*VICVectCntl0=0x20 |TIMER;

  • 8/12/2019 Spirit-II Lab Manual

    25/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in25

    *VICVectAddr0=(unsigned int)TIMER_ISR;

    return 0;

    }

    void TIMER_ISR(){

    *IODIR0=0x007F8000;static int flag=1;if(flag){

    *IOCLR0=0x007F8000;flag=0;

    }else{

    *IOSET0=0x007F8000;flag=1;}*VICVectAddr=0X00;*T0IR=0X01;

    }

    Conclusion:

    Thus , the program for Time Delay is been programmed using TIMER

  • 8/12/2019 Spirit-II Lab Manual

    26/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in26

    7.External Interrupt

    Objective :

    To program for External InterruptUsing ARM Technology .

    Theory of operation :

    If one interrupt source defined as an FIQ interrupt all the remaining interrupt sources must beconnected to the remaining IRQ line. To ensure efficient and timely processing of theseinterrupts, the VIC provides a programmable hardware lookup table which delivers the address ofthe C function to run for a given interrupt source. The VIC contains 16 slots for vectoredaddressing. Each slot contains a vector address register and a vector control register.

    The Vector Control Register contains two fields: a channel field and an enable bit. By

    programming the channel field, any interrupt channel may be connected to any given slot and

    then activated using the enable bit.

    The priority of a vectored interrupt is given by its slotnumber, the lower the slot number, the more importantthe interrupt.

    The other register in the VIC slot is the Vector AddressRegister its register is initialized with the address of theappropriate C function to run when the interrupt

    associated with the slot occurs. In practice, when avectored interrupt is generated the interrupt channel isrouted to a specific slot and the address of the ISR inthe slots Vector Address Register is loaded into a newregister called the Vector Address Register. Sowhenever an interrupt configured as a vectored ,interrupt is generated, the address of its ISR will be

    loaded into a fixed memory location called the Vector Address Register.

  • 8/12/2019 Spirit-II Lab Manual

    27/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in27

    Procedural Algorithm :

    Initialising , VIC Block for External Interrupt .

    Initializing, VIC Block for TIMER Interrupt.

    Writing an ISR for Timer and External Interrupt.

    The priority for TIMER ISR is low and for External Interrupt is high.

    Source Code :

    #define VIC_WELLKNOWN (unsigned int *) 0xFFFFF030

    #define VIC_VECADDR0 (unsigned int *) 0xFFFFF100#define VIC_VECCNTL0 (unsigned int *) 0xFFFFF200

    #define VIC_VECADDR1 (unsigned int *) 0xFFFFF104#define VIC_VECCNTL1 (unsigned int *) 0xFFFFF204#define VIC_INTENB (unsigned int *) 0xFFFFF010

    #define TMR_IR (unsigned int *) 0xE0004000

    #define TMR_MR0 (unsigned int *) 0xE0004018#define TMR_MR1 (unsigned int *) 0xE000401C#define TMR_MR2 (unsigned int *) 0xE0004020#define TMR_MR3 (unsigned int *) 0xE0004024

    #define TMR_MCR0 (unsigned int *) 0xE0004014

    #define TMR_TCR0 (unsigned int *) 0xE0004004

    #define EXT_INT3 (unsigned int *) 0xE01FC140#define EXT_INT3MODE (unsigned int *) 0xE01FC148#define EXT_INT3POL (unsigned int *) 0xE01FC14C#define EXT_PINSEL (unsigned int *) 0xE002C004

    #define IODIR (unsigned int *) 0xE0028008#define IOSET (unsigned int *) 0xE0028004#define IOCLR (unsigned int *) 0xE002800C

    int i = 0x00008000, count =0;

    void Timer(void) __attribute__ ((interrupt("IRQ")));void ExtInt(void) __attribute__ ((interrupt("IRQ")));

  • 8/12/2019 Spirit-II Lab Manual

    28/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in28

    int main(void){

    *IODIR = *IODIR | 0x007F8000;

    *VIC_VECADDR0 = (unsigned int *) ExtInt;*VIC_VECCNTL0 = 0x20 | 17;

    *VIC_VECADDR1 = (unsigned int *) Timer;*VIC_VECCNTL1 = 0x20 | 4;

    *VIC_INTENB = 0x20010;

    *EXT_PINSEL = 0x20000000;*EXT_INT3MODE = 0x0;

    *EXT_INT3POL = 0x0;

    *TMR_MR0 = 15000000;*TMR_MR1 = (*TMR_MR0) * 2;*TMR_MR2 = (*TMR_MR0) * 3;*TMR_MR3 = (*TMR_MR0) * 4;

    *TMR_MCR0 = 0x649;

    *TMR_TCR0 = 0x1;while(1);

    return 0;}

    void Timer( ){

    int j;*TMR_IR = 0xF;if (count == 8){

    count = 0;i = 0x00008000;

    }

    *IOSET = i;for (j=0;j

  • 8/12/2019 Spirit-II Lab Manual

    29/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in29

    *EXT_INT3 = 0x8;*IOSET = 0x7F8000;

    for (j=0;j

  • 8/12/2019 Spirit-II Lab Manual

    30/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in30

    8. 7- Segment

    Objective :

    To display 7 segment using ARM Technology .

    Theory of operation :

    A seven-segment displayis a form of electronic display device for displaying decimalnumerals. These are commonly used in digital clocks .., electronic meters..Etc.,

    There are two types of displays available,

    common anode and common cathode as shownin following figures:

    Common Anode Common Cathode

    As shown in the schematic diagrams above, the LEDs in a seven-segment display arenot isolated from each other.

    In Common Cathode, all the cathodes are connected together while the anodes areconnected individually .In this we need to give 1 as an input for all Leds to glow.

    In Common Anode, all the anodes are connected together while the cathodes areconnected individually .In this we need to give 0 as an input for all the leds to be

    glown.

    LCD is configured as per the following diagram.

  • 8/12/2019 Spirit-II Lab Manual

    31/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in31

    Procedural Algorithm :

    Sr. No. Signal (LPC21xx) Description

    1 Pin 16 (P1.16) 'a'

    2 Pin 12 (P1.17) 'b'

    3 Pin 8 (P1.18) 'c'

    4 Pin 4 (P1.19) 'd'

    5 Pin 48 (P1.20) 'e'

    6 Pin 44 (P1.21) 'f'

    7 Pin 40 (P1.22) 'g'

    8 Pin 36 (P1.23) '.'

    10 Vcc + 5 V

    11 Pin 14 (P0.29) RS

    12 GND WR

    Configure the port pins as GPIO for pinselect2.

    Select the Port 1, 16 to 23 Pins.

    .Clear all the Pins, and give Delay.

  • 8/12/2019 Spirit-II Lab Manual

    32/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in32

    Set and clear the Pins by using IOSET and IOCLR Register for different Hexvalues by enabling the respective pins and give Delay.

    Source Code :

    #include

    void delay(void);

    int main(void){

    *PINSEL2= *PINSEL2 & 0xFFFFFFF3;*IODIR1 = 0X017F0000;*IODIR0 = 0x12000800;

    *IOSET0 = 0x00000800; //select Seven Segment S1 ,S3,S4// *IOSET0 = 0x12000800; //select Seven Segment S1 ,S3,S4

    //*IOSET1 = 0X01000000; //Select Seven Segment S2

    *IOCLR1 = 0X007F0000; //Clear Data Bit

    while(1){

    *IOCLR1 = 0Xff000;delay();

    *IOSET1 = 0x3F0000; //Display 0delay();*IOCLR1 = 0Xff0000;*IOSET1 = 0x060000; //Display 1delay();*IOCLR1 = 0Xff0000;*IOSET1 = 0x5b0000; //Display 2delay();*IOCLR1 = 0Xff0000;*IOSET1 = 0x4f0000; //Display 3delay();*IOCLR1 = 0Xff0000;*IOSET1 = 0x660000; //Display 4

    delay();*IOCLR1 = 0Xff0000;*IOSET1 = 0x6d0000; //Display 5delay();*IOCLR1 = 0Xff0000;*IOSET1 = 0x7d0000; //Display 6delay();*IOCLR1 = 0Xff0000;*IOSET1 = 0x070000; //Display 7delay();

  • 8/12/2019 Spirit-II Lab Manual

    33/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in33

    *IOCLR1 = 0Xff0000;*IOSET1 = 0x7f0000; //Display 8delay();

    *IOCLR1 = 0Xff0000;*IOSET1 = 0x6f0000; //Display 9delay();*IOCLR1 = 0Xff0000;*IOSET1 = 0x770000; //Display Adelay();*IOCLR1 = 0xff0000;*IOSET1 = 0x7c0000; //Display Bdelay();*IOCLR1 = 0xff0000;*IOSET1 = 0x390000; //Display Cdelay();*IOCLR1 = 0xff0000;

    *IOSET1 = 0x5e0000; //Display Ddelay();*IOCLR1 = 0xff0000;*IOSET1 = 0x790000; //Display Edelay();*IOCLR1 = 0xff0000;*IOSET1 = 0x710000; //Display Fdelay();*IOCLR1 = 0xff0000;*IOSET1 = 0x860000;delay();*IOCLR1 = 0xff0000;*IOSET1 = 0x800000;delay();*IOSET1 = 0x000000;delay();

    }

    }

    void delay(void){

    int j;for (j=0;j

  • 8/12/2019 Spirit-II Lab Manual

    34/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in34

    9.Keypad

    Objective :

    To program keypad using ARM Technology .

    Theory of operation :

    The following figure is a 4 x 4 matrix connected to two ports .The rows are connectedto an output port and the columns are connected to an input port .If no key has beenpressed ,reading the input port will yield 1s for all columns since they are allconnected to high (Vcc) .If all the rows are grounded and a key is pressed , one of the columns will have 0 sincethe key pressed provides the path to ground .

    Procedural Algorithm :

    Sr. No. Signal (LPC21xx) Description

    1 Pin 22 (P0.2) ROW1

    2 Pin 26 (P0.3) ROW2

    3 Pin 27 (P0.4) ROW3

  • 8/12/2019 Spirit-II Lab Manual

    35/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in35

    4 Pin 29 (P0.5) ROW4

    5 Pin 30 (P0.6) COL1

    6 Pin 31 (P0.7) COL2

    7 Pin 33 (P0.8) COL3

    8 Pin 34 (P0.9) COL4

    Ground all rows.

    Read for all the columns

    Wait for Debounce .

    Read for all the columns

    Ground next row, and read for the column.

    Display the key on to LCD which is been pressed on the keypad.

    Source Code :

    #include#include/*#include*/#define KEYPORTDIR *IODIR0#define KEYPORTSET *IOSET0#define KEYPORTCLR *IOCLR0#define rowpattern 0x04#define colpattern 0x40

    unsigned char numarray[]={0x2d,0x3f,0x3b,0x79,0x66,0x6d,0x7d,0x07,0x7f,0x6f};static char num[4][4]={

    {0,4,7,0},

    {2,5,8,0},{3,6,9,0},{0,0,0,0}};

    void delay(long y){

    long x=0;while(x!=y)

  • 8/12/2019 Spirit-II Lab Manual

    36/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in36

    x++;}

    // to print given number on 7-segment displayvoid putnum_7seg(unsigned char n){

    *IODIR1 = 0xff0000; // segment pins as output*IOPIN1 = (unsigned int) (numarray[n]>2;if(x == 0x01){

    row = 0;q_printf("\n Key from %d th row and %d column",col+1, row+1);return num[row][col];

    }if(x == 0x02){

    row=1;q_printf("\n Key from %d th row and %d column",col+1,row+1);return num[row][col];

    }if(x == 0x04){

    row = 2;q_printf("\n Key from %d th row and %d column",col+1,row+1);

    return num[row][col];}if(x == 0x08){

    row = 3;q_printf("\n Key from %d th row and %d column",col+1,row+1);return num[row][col];

    }}

  • 8/12/2019 Spirit-II Lab Manual

    37/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in37

    goto xyz;}

    void debounce(){

    unsigned int i=10000;while(i

  • 8/12/2019 Spirit-II Lab Manual

    38/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in38

    10.Multi Digit 7 Segment

    Objective :

    To display Multi Digit 7 segment using ARM Technology .

    Theory of operation :

    A seven-segment displayis a form of electronic display device for displaying decimalnumerals. These are commonly used in digital clocks .., electronic meters..Etc.,

    There are two types of displays available,

    common anode and common cathode as shownin following figures:

    Common Anode Common Cathode

    As shown in the schematic diagrams above, the LEDs in a seven-segment display arenot isolated from each other.

    In Common Cathode, all the cathodes are connected together while the anodes areconnected individually .In this we need to give 1 as an input for all Leds to glow.

    In Common Anode, all the anodes are connected together while the cathodes areconnected individually .In this we need to give 0 as an input for all the leds to be

    glown.

    LCD is configured as per the following diagram.

  • 8/12/2019 Spirit-II Lab Manual

    39/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in39

    Procedural Algorithm :

    Sr. No. Signal (LPC21xx) Description

    1 Pin 16 (P1.16) 'a'

    2 Pin 12 (P1.17) 'b'

    3 Pin 8 (P1.18) 'c'4 Pin 4 (P1.19) 'd'

    5 Pin 48 (P1.20) 'e'

    6 Pin 44 (P1.21) 'f'

    7 Pin 40 (P1.22) 'g'

    8 Pin 36 (P1.23) '.'

    10 Vcc + 5V

    11 Pin 14 (P0.29) RS

    12 GND WR

    Configure the port pins as GPIO for pinselect2 .

    Select the Port 1 , 16 to 23 Pins.

    LCD Enable Pin numbers are as follows :For LCD1P0.11 , LCD2P1.24,LCD3P0.28 ,LCD4P0.25

  • 8/12/2019 Spirit-II Lab Manual

    40/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in40

    Clear all the Pins ,and give Delay .

    Set and clear the Pins by using IOSET and IOCLR Register for different Hexvalues by enabling the respective pins and give Delay .

    Source Code :

    #include

    void delay(void);

    int main(void){

    *PINSEL2= *PINSEL2 & 0xFFFFFFF3;*IODIR1 = 0X017F0000;*IODIR0 = 0x12000800;

    *IOSET0 = 0x12000800; //select Seven Segment S1 ,S3,S4*IOSET1 = 0X01000000; //Select Seven Segment S2

    *IOCLR1 = 0X007F0000; //Clear Data Bitwhile(1){

    *IOCLR1 = 0Xff0000;delay();*IOSET1 = 0x3f0000;

    delay();*IOCLR1 = 0Xff0000;*IOSET1 = 0x060000;delay();*IOCLR1 = 0Xff0000;*IOSET1 = 0x5b0000;delay();*IOCLR1 = 0Xff0000;*IOSET1 = 0x4f0000;delay();*IOCLR1 = 0Xff0000;*IOSET1 = 0x660000;delay();*IOCLR1 = 0Xff0000;

    *IOSET1 = 0x6d0000;delay();*IOCLR1 = 0Xff0000;*IOSET1 = 0x7d0000;delay();*IOCLR1 = 0Xff0000;*IOSET1 = 0x070000;delay();*IOCLR1 = 0Xff0000;

  • 8/12/2019 Spirit-II Lab Manual

    41/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in41

    *IOSET1 = 0x7f0000;delay();*IOCLR1 = 0Xff0000;

    *IOSET1 = 0x6f0000;delay();*IOCLR1 = 0Xff0000;*IOSET1 = 0x770000;delay();*IOCLR1 = 0xff0000;*IOSET1 = 0x7c0000;delay();*IOCLR1 = 0xff0000;*IOSET1 = 0x390000;delay();*IOCLR1 = 0xff0000;*IOSET1 = 0x5e0000;

    delay();*IOCLR1 = 0xff0000;*IOSET1 = 0x790000;delay();*IOCLR1 = 0xff0000;*IOSET1 = 0x710000;delay();*IOCLR1 = 0xff0000;*IOSET1 = 0x860000;delay();*IOCLR1 = 0xff0000;*IOSET1 = 0x800000;delay();*IOSET1 = 0x000000;delay();

    }

    }

    void delay(void){

    int j;for (j=0;j

  • 8/12/2019 Spirit-II Lab Manual

    42/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in42

    11.Text LCD (TLCD)

    Objective :

    To program Text LCDusing ARM Technology .

    Theory of operation :

    TLCD stands for Text Liquid Crystal Display.

    LCD technology has been around for a long time but it is now becoming very popular for flat-screen computer monitors and televisions. It can provide a much better, brighter image than theold CRT (Cathode Ray Tube) monitors.

    Its low electrical power consumption enables it to be used in battery-powered electronic

    equipment. It is an electronically-modulated optical device made up of any number of pixelsfilled with liquid crystals and arrayed in front of a light source (backlight) or reflector to produceimages in color or monochrome.

  • 8/12/2019 Spirit-II Lab Manual

    43/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in43

    The two transparent panels are polarised, which means they will only pass lightwaves in one plane.

    These two polarised panels at 90 degrees to each other so that light filteredfrom one plane cannot get through the other panel because it only lets lightthrough in a plane at 90 degrees to the first plane.

    So the panel appears to be "black" (or at least very dark). However, whenelectricity is applied to one of the segments of liquid crystals (segments areswitched on and off to form the images you see on the screen).

    The crystals line up in such a way as to make the light turn through 90 degrees

    in between the two panels. So now the light "TWISTS" through the panels andis visible on the other side.

    Procedural Algorithm :

    Sr. No. Signal (LPC21xx) Description

    1 Pin 16 (P1.16) Data 0

    2 Pin 12 (P1.17) Data 1

    3 Pin 8 (P1.18) Data 24 Pin 4 (P1.19) Data 3

    5 Pin 48 (P1.20) Data 4

    6 Pin 44 (P1.21) Data 5

    7 Pin 40 (P1.22) Data 6

    8 Pin 36 (P1.23) Data 7

    10 Pin 13 (P0.28) EN

    11 Pin 14 (P0.29) RS

    12 GND WR

    Select the pins as per the schematic diagram with IODIR1 and IODIR0 register.

    Send the command with lcdcmd subroutine .Here, in lcdcmd subroutinecommand is sent through IOSET1 register and select the RS pin =0. Give delayand clear the register with IOCLR1 register.

    Send the data with lcddata subroutine .Here, in lcddata subroutine data is sentthrough IOSET1 register and select the pin RS=1 .give delay and clear the

  • 8/12/2019 Spirit-II Lab Manual

    44/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in44

    register.

    Source Code :

    #include #include

    void lcdcmd(unsigned int);void lcddata(unsigned int);void delay_lcd(void);void DisplayLCD(char *str, int len);

    int main(void){*PINSEL2 = *PINSEL2 & 0xFFFFFFF7;*IODIR1=0X00FF0000;*IODIR0=0x00001800;

    lcdcmd(0x38); //2 lines and 5x7 matrixlcdcmd(0x0e); //Display On, Cursor Blinkinglcdcmd(0x01); //Clear Display screenlcdcmd(0x06); //Increment cursorlcdcmd(0x80); //1st Line starting from 4th position.DisplayLCD("OASIS TECHNOLOGY", 16);while(1);}

    void lcdcmd(unsigned int cmddata){*IOCLR1=0X00FF0000; //set direction for P1.16 to P1.23*IOCLR0=0x00000800; // clear RS to select command register

    cmddata = cmddata

  • 8/12/2019 Spirit-II Lab Manual

    45/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in45

    *IOSET0=0x00001000;delay_lcd();*IOCLR0=0x00001000;

    delay_lcd();}

    void delay_lcd(void){int j;for (j=0;j

  • 8/12/2019 Spirit-II Lab Manual

    46/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in46

    12 ADC and Temperature display

    Objective :

    To program for ADC and Temperature Sensor Interface using ARM Technology .

    Theory of operation :

    An analog-to-digital converteris a device which converts continuous signals to discrete digitalnumbers.

    It means the conversion of an input analog voltage to a digital number which is proportional tothe magnitude of the voltage or current.

    TheResolutionof the converter indicates the number of discrete values it can produce over therange of analog values.

    The values are usually stored in binary form, so the resolution is usually expressed in bits . The

  • 8/12/2019 Spirit-II Lab Manual

    47/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in47

    discrete values available, is usually a power of two i.e an ADC with a resolution of 8 bits can

    encode an analog input to one in 256 different levels, since 28= 256.

    The values can represent the ranges from 0 to 255 (i.e. unsigned integer) or from -128 to 127(i.e. signed integer), depending on the application.

    Here ,in the schematic as well as in the pin connection diagram the ADC pin is connected toPort P0.28 .

    ADCR Register is used for configuring ADC to start theconversion .

    ADDR Register is an OUTPUT register which is usedto collect the converted digital Data.

    Procedural Algorithm :

    S.No Pin.No Port.No Description

    1) Pin 13 P0.28 Adc Input

    Select the GPIO for ADC conversion .

    Set the ADCR Register with Channel 2, Clock 4Mhz, Burst Mode, 11 clocks per10 bit and start conversion .

    While the data bit is 1 , data is been received in ADDR and is collected inadcdata .(6-16 ) bits .

    This data is been moved to the first 10 bits .

    Convert this data in to temperature by scaling ,and print the output onhyperterminal .

    Source Code :

  • 8/12/2019 Spirit-II Lab Manual

    48/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in48

    #include #include

    int main(void){unsigned int adcdata;unsigned int temp;

    *PINSEL1 = *PINSEL1 & 0XFCFFFFFF;*PINSEL1 = *PINSEL1 | 0X01000000;//*ADCR = 0X01210301; // Channel 0 , Clock 4Mhz, Burst Mode, 11 clocks per 10 bit ,

    //AD conversion is operational, start conversion*ADCR = 0X01210302; // Channel 1 , Clock 4Mhz, Burst Mode, 11 clocks per 10 bit ,

    //AD conversion is operational, start conversion

    while(1)

    { if(*ADDR&0X80000000){

    adcdata = (*ADDR&0X0000FFC0);adcdata = adcdata >> 6;temp = ((adcdata*100)1023); //Scaling of adc value with actual temperatureq_printf ("Current Temperature is = %d \n", temp);

    }}

    return 0;}

    Conclusion :

    Thus ADC is been programmed using ARM Technology.

  • 8/12/2019 Spirit-II Lab Manual

    49/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in49

    13 I2C Serial EEPROM

    Objective :

    To program I2C Interface Serial EEPROMusing ARM Technology .

    Theory of operation :

    The reference design, asmentioned below , is a bus witha clock (SCL) and data (SDA)lines with 7-bit addressing. Thebus has two roles for nodes:

    master and slave :

    Master node nodethat issues the clockand addresses slaves

    Slave node node thatreceives the clock line

    and address.

    The bus is a multi master which means any number of master nodes can be present.Additionally, master and slave roles may be changed between messages (after a STOP is sent).

    There are four potential modes of operation for a given bus device, although most devices onlyuse a single role and its two modes:

    master transmit master node is sending data to a slave master receive master node is receiving data from a slave slave transmit slave node is sending data to a master slave receive slave node is receiving data from the master

    The master is initially in master transmit mode by sending a start bit followed by the 7-bitaddress of the slave it wishes to communicate with, which is finally followed by a single bitrepresenting whether it wishes to write(0) to or read(1) from the slave.

    If the slave exists on the bus then it will respond with an ACK bit (active low for acknowledged)for that address. The master then continues in either transmit or receive mode (according to theread/write bit it sent), and the slave continues in its complementary mode (receive or transmit,respectively).

    The address and the data bytes are sent most significant bit first. The start bit is indicated by ahigh-to-low transition of SDA with SCL high; the stop bit is indicated by a low-to-high transitionof SDA with SCL high.

  • 8/12/2019 Spirit-II Lab Manual

    50/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in50

    If the master wishes to write to the slave then it repeatedly sends a byte with the slave sendingan ACK bit. (In this situation, the master is in master transmit mode and the slave is in slavereceive mode.)

    If the master wishes to read from the slave then it repeatedly receives a byte from the slave, themaster sending an ACK bit after every byte but the last one. (In this situation, the master is inmaster receive mode and the slave is in slave transmit mode.)

    The master then ends transmission with a stop bit , or it may send another START bit if itwishes to retain control of the bus for another transfer (a "combined message").

    Procedural Algorithm :

    Connector

    Pin No.

    Pin.No Port.No Description

    1 Pin22 P0.2 SCL0

    2 Pin26 P0.3 SDA0

    Once, the START condition is successful with the code 0x08, the applicationsoftware will write the Slave Address and R/W bit in to the I2C data Register.

    This is been acknowledge by the Slave, and an Interrupt is generated with acode 0x18 in status register that the transfer was successful.

    Every time, a byte is been transmitted, it is acknowledged and an interrupt isgenerated 0x28 in status register, that the transfer was successful.

    If it is failed, an NACK signal is generated and 0x20 and the byte must be sentagain.

    Once, all the bytes are been transferred a STOP bit is generated sayingtransaction is been finished.

    Source Code :

    #include "address_c.h"#include "functions.h"#include

    /*@@@@@@@@@ delay @@@@@*/

  • 8/12/2019 Spirit-II Lab Manual

    51/77

  • 8/12/2019 Spirit-II Lab Manual

    52/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in52

    while(1){

    q_printf("ERROR \n");

    }}

    }}

    }

    /*@@ time date write function @@@@@@@*/

    void i2c_rtc_set( u8 *txbuf ){

    int i;*I2CONSET = ENABLE;delay(1000);

    // ---------------------transmit a START and address with write---------------------*I2CONSET = START;wait_for_ack(0x08);

    *I2DAT = (RTC_ADDR); // transmit slave address with write bit*I2CONCLR = SI_CLR;*I2CONCLR = START_CLR; // clear the START bit to avoid retransmit of STARTwait_for_ack(0x18);

    *I2DAT = 0x00;*I2CONCLR = SI_CLR;wait_for_ack(0x28);

    for(i=0;i

  • 8/12/2019 Spirit-II Lab Manual

    53/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in53

    // ---------------------transmit a START ---------------------

    *I2CONSET = START;

    wait_for_ack(0x08);

    *I2DAT = (RTC_ADDR|0X01); // transmit slave address with write bit*I2CONCLR = SI_CLR;*I2CONCLR = START_CLR; // clear the START bit to avoid

    retransmit of STARTwait_for_ack(0x40);

    *I2DAT = 0x00;for(i = 0x00;i < 0x7;i++){

    rxbuf[i]=i2c_read(ack);}

    rxbuf[i]=i2c_read(nack);

    //-------------------transmit a STOP---------------------------------

    *I2CONSET =STOP ;delay(1000);*I2CONCLR = DISABLE | START_CLR | STOP_CLR | SI_CLR | AA_CLR;

    }

    /*@@@@@ register write function @@@@@*/

    void rtc_reg_wr(u8 reg,u8 data){

    *I2CONSET = ENABLE;delay(1000);

    *I2CONSET = START;wait_for_ack(0x08);

    *I2DAT = (RTC_ADDR); // transmit slave address with write bit*I2CONCLR = SI_CLR;*I2CONCLR = START_CLR; // clear the START bit to avoid retransmit of STARTwait_for_ack(0x18);

    *I2DAT = reg;

    *I2CONCLR = SI_CLR;wait_for_ack(0x28);

    *I2DAT = data;*I2CONCLR = SI_CLR;wait_for_ack(0x28);

    *I2CONSET =STOP ;delay(1000);

  • 8/12/2019 Spirit-II Lab Manual

    54/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in54

    *I2CONCLR = DISABLE | START_CLR | STOP_CLR | SI_CLR | AA_CLR;}

    /*@@@@ register read function @@@@*/

    u8 rtc_reg_rd(u8 reg){u8 data;

    *I2CONSET = ENABLE | AA ;delay(1000);

    *I2CONSET = START;wait_for_ack(0x8);

    *I2DAT = (RTC_ADDR|0X01); // transmit slave address with write bit*I2CONCLR = SI_CLR;

    *I2CONCLR = START_CLR; // clear the START bit to avoidretransmit of STARTwait_for_ack(0x40);

    *I2DAT = reg;*I2CONCLR = SI_CLR;wait_for_ack(0x50);

    data = (*I2DAT);*I2CONCLR = SI_CLR;wait_for_ack(0x50);

    *I2CONCLR = AA_CLR;*I2CONCLR = SI_CLR;wait_for_ack(0x58);

    /*-------------------transmit a STOP---------------------------------*/

    *I2CONSET =STOP ;*I2CONCLR = DISABLE | START_CLR | STOP_CLR | SI_CLR | AA_CLR;q_printf("%x", data);

    return(data);}

    /*@@@@@@@@ i2c write @@@@@@@@@@*/

    void i2c_write(u8 data){

    *I2DAT = data;*I2CONCLR = SI_CLR;wait_for_ack(0x28);

    }

    /*@@@@@@ i2c read @@@@@@*/

    u8 i2c_read(u8 stat){

  • 8/12/2019 Spirit-II Lab Manual

    55/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in55

    u8 retvalue=0;if(stat){

    retvalue = (*I2DAT);*I2CONCLR = SI_CLR;wait_for_ack(0x50);

    }

    else{

    retvalue=(*I2DAT);*I2CONCLR = SI_CLR;wait_for_ack(0x50);

    *I2CONCLR = AA_CLR;*I2CONCLR = SI_CLR;

    wait_for_ack(0x58);

    }return(retvalue);}

    void rtc_set_addr(u8 address){

    *I2CONSET = ENABLE ;delay(1000);

    // ---------------------transmit a START ---------------------*I2CONSET = START;wait_for_ack(0x08);

    *I2DAT = (RTC_ADDR); // transmit slave address with write bit*I2CONCLR = SI_CLR;*I2CONCLR = START_CLR; // clear the START bit to avoid retransmit of STARTwait_for_ack(0x18);

    *I2DAT = address;*I2CONCLR = SI_CLR;wait_for_ack(0x28);

    *I2CONSET =STOP ;delay(1000);*I2CONCLR = DISABLE | START_CLR | STOP_CLR | SI_CLR | AA_CLR;

    }

    Conclusion:

    Thus, I2C is been Programmed.

  • 8/12/2019 Spirit-II Lab Manual

    56/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in56

    14 Generation of PWM Signal

    Objective :

    To program for generation of PWM Signal using ARM Technology .

    Theory of operation :

    Pulse-width modulation(PWM) is a very efficient way of providing intermediateamounts of electrical power between fully on and fully off. A simple power switch with atypical power source provides full power only, when switched on. PWM is acomparatively-recent technique, made practical by modern electronic power switches.It is a device that may be used as an efficient light dimmer or DC motor speedcontroller. The circuit described here is for a general purpose device that can controlDC devices which draw up to a few amps of current.

    In ARM , PWM modulator is capable of producing six channels of single edge controlled PWM

    Procedural Algorithm :

    lnitialise , for ADC .

    Initialise VIC Block for PWM

    Initialise PWM .

    Continuously read ADC values .

    Modulate PWM using ADC value

    Source Code :

    #include

    #include /* LPC21xx definitions */void PWM0_isr(void) __attribute__ ((interrupt("IRQ")));

  • 8/12/2019 Spirit-II Lab Manual

    57/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in57

    void poll_ADC (void){ /* Get ADC Value and set PWM */

    unsigned int val;static unsigned int oldval;*ADCR |= 0x01000000; /* Start A/D Conversion */

    do{

    val = ADDR; /* Read A/D Data Register */}while((val & 0x80000000) == 0); /* Wait for end of A/D Conversion */

    *ADCR &= ~0x01000000; /* Stop A/D Conversion */val = (val >> 6) & 0x03FF; /* Extract AIN0 Value */

    if ((val != oldval))

    { *PWMMR2 = val;*PWMLER = 0x4; /* Enable Shadow latch */oldval = val;

    }}

    void init_PWM (void){

    *VICVectAddr8 = (unsigned)PWM0_isr; /* Set the PWM ISR vector address */*VICVectCntl8 = 0x00000028; /* Set channel */*VICIntEnable = 0x00000100; /* Enable the interrupt */*PINSEL0 |= 0x00028008; /* Enable P0.7 and P0.1 as PWM output */*PWMPR = 0x00000000; /* Load prescaler */

    *PWMPCR = 0x00000C0C; /* PWM channel 2 & 3 double edge control,output enabled */

    *PWMMCR = 0x00000003; /* On match with timer reset the counter */*PWMMR0 = 0x400; /* set cycle rate to sixteen ticks */*PWMMR1 = 0; /* set rising edge of PWM2 to 100 ticks */*PWMMR2 = 0x200; /* set falling edge of PWM2 to 200 ticks */*PWMMR3 = 0x400; /* set rising edge of PWM3 to 100 ticks */*PWMLER = 0xF; /* enable shadow latch for match 1 - 3 */*PWMTCR = 0x00000002; /* Reset counter and prescaler */*PWMTCR = 0x00000009; /* enable counter and PWM, release counter

    from reset */

    }

    int main (void){

    *IODIR1 = 0x00FF0000; /* P1.16..23 defined as Outputs */*ADCR = 0x01200401; /* Setup A/D: 10-bit AIN0 @ 3MHz */init_PWM();

  • 8/12/2019 Spirit-II Lab Manual

    58/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in58

    while (1){ /* Loop forever */

    poll_ADC();}

    }

    void PWM0_isr(void){*PWMIR |= 0x00000001; /* Clear match0 interrupt */*VICVectAddr = 0x00000000;

    }

    Conclusion :

    Thus , the program for generation of PWM signal is been done .

  • 8/12/2019 Spirit-II Lab Manual

    59/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in59

  • 8/12/2019 Spirit-II Lab Manual

    60/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in60

    CHAPTER -3

    1.LEDObjective :

    To program for blinking of LEDs using RTOS Technology.

    Theory of operation :

    Multitasking is the process of scheduling and switching the CPU (Central Processing Unit)between several tasks; a single CPU switches its attention between several sequential tasks.Multitasking is like foreground/background with multiple backgrounds. Multitasking maximizesthe utilization of the CPU and also provides for modular construction of applications.One of the most important aspects of multitasking is that it allows the application programmer tomanage complexity inherent in real-time applications. Application programs are typically easierto design and maintain if multitasking is used.

    A task, also called a thread, is a simple program that thinks it has the CPU all to itself. Thedesign process for a real-time application involves splitting the work to be done into tasks whichare responsible for a portion of the problem. Each task is assigned a p riority, its own set of CPUregisters, and its own stack area.

  • 8/12/2019 Spirit-II Lab Manual

    61/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in61

    Each task typically is an infinite loop that can be in any one of five states: DORMANT, READY,RUNNING, WAITING FOR AN EVENT, or INTERRUPTED). The DORMANT state corresponds

    to a task which resides in memory but has not been made available to the multitasking kernel. Atask is READY when it can execute but its priority is less than the currently running task. A taskis RUNNING when it has control of the CPU. A task is WAITING FOR AN EVENT when itrequires the occurrence of an event (waiting for an I/O operation to complete, a shared resourceto be available, a timing pulse to occur, time to expire etc.). Finally, a task is INTERRUPTEDwhen an interrupt has occurred and the CPU is in the process of servicing the interrupt.

    Procedural Algorithm :

    Initializing uC/OS-II,number of Tasks and Stack size for each Task

    Creating 2 tasks .

    Blink the LED 1,2,3,4 ON and OFF in Task1

    Blink the LED 5,6,7,8 ON and OFF in Task2

    Start Multitasking.

    Source Code :

    #include /* LPC21xx definitions */#include #include

  • 8/12/2019 Spirit-II Lab Manual

    62/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in62

    #define TASK_STK_SIZE 100 /* Size of each task's stacks (# of WORDs) */#define NO_TASKS 3 /* Number of identical tasks */

    char TaskData[NO_TASKS];OS_STK TaskStk[NO_TASKS][TASK_STK_SIZE]; /* Tasks stacks */OS_STK TaskStartStk[TASK_STK_SIZE];

    extern void init_timer (void);

    void Task2 (void *data){

    int n, i;data = data; // avoid compiler warning

    while(1){for (n = 0x00080000; n

  • 8/12/2019 Spirit-II Lab Manual

    63/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in63

    i++;}

    }

    }

    void startTask(void *data){

    init_timer();

    TaskCreate(Task1, (void *)&TaskData[0], "HiPrioTsk", 1);TaskCreate(Task2, (void *)&TaskData[1], "LoPrioTsk", 2);

    while (1){

    OSTimeDly(1000);

    }}

    int main (void){

    *IODIR0 = 0x007F8000;

    OSInit(); /* Initialize uC/OS-II */

    init_timer();

    TaskCreate(startTask, (void *)0, "VHiPrioTsk", 0);

    OSStart(); /* Start multitasking */

    return 0; // Actually we should never come here}

    Conclusion:

    Thus , the program for Led Blinking is been done .

  • 8/12/2019 Spirit-II Lab Manual

    64/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in64

    2 Display of Message on LCD

    Objective :

    To program for displaying 2 different messages on LCD using RTOS Technology.

    Theory of operation :

    Multitasking is the process of scheduling and switching the CPU (Central Processing Unit)between several tasks; a single CPU switches its attention between several sequential tasks.Multitasking is like foreground/background with multiple backgrounds. Multitasking maximizesthe utilization of the CPU and also provides for modular construction of applications.One of the most important aspects of multitasking is that it allows the application programmer tomanage complexity inherent in real-time applications. Application programs are typically easierto design and maintain if multitasking is used.

    A task, also called a thread, is a simple program that thinks it has the CPU all to itself. Thedesign process for a real-time application involves splitting the work to be done into tasks whichare responsible for a portion of the problem. Each task is assigned a priority, its own set of CPUregisters, and its own stack area.

  • 8/12/2019 Spirit-II Lab Manual

    65/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in65

    Each task typically is an infinite loop that can be in any one of five states: DORMANT, READY,RUNNING, WAITING FOR AN EVENT, or INTERRUPTED). The DORMANT state correspondsto a task which resides in memory but has not been made available to the multitasking kernel. A

    task is READY when it can execute but its priority is less than the currently running task. A taskis RUNNING when it has control of the CPU. A task is WAITING FOR AN EVENT when itrequires the occurrence of an event (waiting for an I/O operation to complete, a shared resourceto be available, a timing pulse to occur, time to expire etc.). Finally, a task is INTERRUPTEDwhen an interrupt has occurred and the CPU is in the process of servicing the interrupt.

    Procedural Algorithm :

    Initializing uC/OS-II, number of Tasks and Stack size for each Task

    Initializing direction register for 16x2 LCD display .

    Initialise function for giving cmd to LCD display.

    Initialise function for giving data to LCD Display

    Create a task, and send the data .

    Start Multitasking.

    Source Code :

  • 8/12/2019 Spirit-II Lab Manual

    66/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in66

    #include #include#include

    void lcdcmd(unsigned int);void lcddata(unsigned int);void delay_lcd(void);void DisplayLCD(char *str, int len);

    #define TASK_STK_SIZE 100 /* Size of each task's stacks (# of WORDs) */#define NO_TASKS 2 /* Number of identical tasks */

    OS_STK TaskStk[NO_TASKS][TASK_STK_SIZE]; /* Tasks stacks */OS_STK TaskStartStk[TASK_STK_SIZE];char TaskData[NO_TASKS]; /* Parameters to pass to each task */

    int main(void){*IODIR1=0X00FF0000;*IODIR0=0x30000000;lcdcmd(0x38);lcdcmd(0x0e);lcdcmd(0x01);lcdcmd(0x06);lcdcmd(0x84);

    OSInit(); /* Initialize uC/OS-II */init_timer(); /*initilize timer tick for RTOS */TaskCreate(Task1, (void *)&TaskData[1], "Task1",0);OSStart(); /* Start multitasking */

    while(1);}void Task1 (void *data){

    while(1){

    DisplayLCD("RAM", 3);DisplayLCD("Lakhan",6);

    }}

    void lcdcmd(unsigned int cmddata){

    *IOCLR1=0X00FF0000;*IOCLR0=0x10000000;cmddata = cmddata

  • 8/12/2019 Spirit-II Lab Manual

    67/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in67

    *IOSET0=0x20000000;delay_lcd();return;

    }void DisplayLCD(char *str, int len){

    while(len-- != 0){

    lcddata(*str);str++;

    }}void lcddata(unsigned int outdata){

    *IOCLR1=0x00FF0000;

    *IOSET0=0x10000000;outdata = outdata

  • 8/12/2019 Spirit-II Lab Manual

    68/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in68

    3.MailBox

    Objective :

    To program for sending and receiving messages between different TASK throughMailbox using RTOS Technology.

    Theory of operation :

    Messages can be sent to a task through kernel services. A Message Mailbox, also called amessage exchange, is typically a pointer size variable. Through a service provided by thekernel, a task or an ISR can deposit a message (the pointer) into this mailbox. Similarly, one ormore tasks can receive messages through a service provided by the kernel.

    Both the sending task and receiving task will agree as to what the pointer is actually pointing to.

    A waiting list is associated with each mailbox in case more than one task desires to receivemessages through the mailbox. A task desiring to receive a message from an empty mailboxwill be suspended and placed on the waiting list until a message is received. Typically, thekernel will allow the task waiting for a message to specify a timeout. If a message is notreceived before the timeout expires, the requesting task is made ready-to-run and an error code(indicating that a timeout has occurred) is returned to it.When a message is deposited into the mailbox, either the highest priority task waiting for themessage is given the message (calledpriority-based) or the first task to request a message isgiven the message (calledFirst-In-First-Out, or FIFO). The following figure shows a taskdepositing a message into a mailbox. Note that the mailbox is represented graphically by an I-beam and the timeout is represented by an hourglass. The number next to the hourglassrepresents the number of c lock ticks (described later) that the task will wait for a message to

    arrive.

    Kernel services are typically provided to:

    a) Initialize the contents of a mailbox. The mailbox may or may not initially contain a message.

    b) Deposit a message into the mailbox (POST).c) Wait for a message to be deposited into the mailbox (PEND).d) Get a message from a mailbox; if one is present, but not suspend the caller if the mailbox isempty (ACCEPT). If the mailbox contains a message, the message is extracted from themailbox. A return code is used to notify the caller about the outcome of the call.Message mailboxes can also be used to simulate binary semaphores. A message in themailbox indicates that the resource is available while an empty mailbox indicates that theresource is already in use by another task.

  • 8/12/2019 Spirit-II Lab Manual

    69/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in69

    Procedural Algorithm :

    Initializing uC/OS-II,number of Tasks and Stack size for each Task

    Creating 2 tasks .

    Task1 waits for a message , until it finds a message in message queue it doesnot proceeds and jumps to another Task because OSDelay().

    Task2 creates a Message Queue ,and posts the messages in it.

    Once,the Task1 finds a message in a Message Queue ,it is executed .

    Start Multitasking

    Source Code :

    #include /* LPC21xx definitions */#include

    #define TASK_STK_SIZE 100 /* Size of each task's stacks (# of WORDs) */#define NO_TASKS 5 /* Number of identical tasks */

    OS_STK TaskStk[NO_TASKS][TASK_STK_SIZE]; /* Tasks stacks */

    OS_STK TaskStartStk[TASK_STK_SIZE];char TaskData[NO_TASKS]; /* Parameters to pass to each task */

    OS_EVENT *MQue; /* Message Queue pointer */void *MQueTable[20]; /* array to store Messages */

    extern void init_timer (void);

    /* ******************************************************************** *//* Task functions

    *//* ******************************************************************** */

    void Task2 (void *data){

    char tx1msg[] = "Hello T1\n";char tx2msg[] = "This is msg from T2\n";

    data = data; /* Prevent compiler warning */while(1){

    q_printf("Task2 \n");OSQPost(MQue, (void *)&tx1msg); /* Send message to MQ */

  • 8/12/2019 Spirit-II Lab Manual

    70/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in70

    OSQPost(MQue, (void *)&tx2msg);OSTimeDly(100);

    }

    q_printf("Task should not have come here");}void Task1 (void *data){

    U8 err;char *rxmsg;

    data = data; /* Prevent compiler warning */q_printf("Task1 \n");

    while(1){

    rxmsg = (char *)OSQPend(MQue, 0, &err); /* Wait for message in MQ */q_printf(rxmsg);

    }

    q_printf("Task should not have come here");}

    void TaskStart (void *data){

    data = data; /* Prevent compiler warning */

    init_timer();

    MQue = (OS_EVENT *) OSQCreate(&MQueTable,20); /* Create a message queue */

    q_printf("uC/OS-II, The Real-Time Kernel ARM Ported version\n");

    // TaskData[1] = 1; /* Each task will display its own letter */TaskCreate(Task1, (void *)&TaskData[1], "Task1", 3);

    // TaskData[2] = 1; /* Each task will display its own letter */TaskCreate(Task2, (void *)&TaskData[2], "Task2", 2);

    while(1){

    OSTimeDly(1500); /* Wait one second */}

    }

    int main (void){

    OSInit(); /* Initialize uC/OS-II */init_timer();TaskCreate(TaskStart, (void *)0, "Task Start", 0);OSStart(); /* Start multitasking */

    return 0;}

  • 8/12/2019 Spirit-II Lab Manual

    71/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in71

    Conclusion:

    Thus, program for sending and receiving messages between different TASK throughMailbox is been done .

  • 8/12/2019 Spirit-II Lab Manual

    72/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in72

    4.Messages to PC through Serial Port

    Objective :

    To program for sending messages to PC through Serial Port by different Tasks on prioritybasis using RTOS Technology.

    Theory of operation :

    Multitasking is the process of scheduling and switching the CPU (Central Processing Unit)between several tasks; a single CPU switches its attention between several sequential tasks.Multitasking is like foreground/background with multiple backgrounds. Multitasking maximizesthe utilization of the CPU and also provides for modular construction of applications.One of the most important aspects of multitasking is that it allows the application programmer to

    manage complexity inherent in real-time applications. Application programs are typically easierto design and maintain if multitasking is used.

    A task, also called a thread, is a simple program that thinks it has the CPU all to itself. Thedesign process for a real-time application involves splitting the work to be done into tasks whichare responsible for a portion of the problem. Each task is assigned a priority, its own set of CPUregisters, and its own stack area.

  • 8/12/2019 Spirit-II Lab Manual

    73/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in73

    Each task typically is an infinite loop that can be in any one of five states: DORMANT, READY,RUNNING, WAITING FOR AN EVENT, or INTERRUPTED). The DORMANT state corresponds

    to a task which resides in memory but has not been made available to the multitasking kernel. Atask is READY when it can execute but its priority is less than the currently running task. A taskis RUNNING when it has control of the CPU. A task is WAITING FOR AN EVENT when itrequires the occurrence of an event (waiting for an I/O operation to complete, a shared resourceto be available, a timing pulse to occur, time to expire etc.). Finally, a task is INTERRUPTEDwhen an interrupt has occurred and the CPU is in the process of servicing the interrupt.

    Procedural Algorithm :

    Initializing uC/OS-II,number of Tasks and Stack size for each Task

    Initilaze UART through VIC Control Block .

    Creating 3 tasks with their Priorities assigned .

    Write in Task1 where it transmits and prints the Data on Hyperterminal.

    Write in Task2 where it transmits and prints the Data on Hyperterminal.

    Write in Task3 where it transmits and prints the Data on Hyperterminal.

    Start Multitasking .

  • 8/12/2019 Spirit-II Lab Manual

    74/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in74

    Source Code :

    /************************************************************************ Msg2PC_main.c************************************************************************/#include /* LPC21xx definitions */#include

    #define TASK_STK_SIZE 100 /* Size of each task's stacks (# of WORDs) */#define NO_TASKS 5 /* Number of identical tasks */

    OS_STK TaskStk[NO_TASKS][TASK_STK_SIZE]; /* Tasks stacks */

    OS_STK TaskStartStk[TASK_STK_SIZE];char TaskData[NO_TASKS]; /* Parameters to pass to each task */

    extern void init_timer (void);

    /* ******************************************************************** *//* Task functions

    *//* ******************************************************************** */

    void init_uart(void){

    *VICVectCntl0=0x20 |6;

    *PINSEL0=0x01; /* Programming 0.0th Pin - Transmit data Pin */*U0LCR=0x83; /* 8 -> Device lab = 1 , 3 -> 8 bit transmission*/*U0DLM=0x00; /* Device latch MSB = 0 */*U0DLL=0x18; /* Sets Baud rate */*U0LCR=0x03;*U0IER=0X02;

    }

    void Task3(void *data){

    char a[]="Task3==> Lakhan";int i;while(1){

    while(!(*U0LSR & 0x20));for(i=0;a[i]!='\0';i++)*U0THR= a[i];

    OSTimeDly(200);}

    }

  • 8/12/2019 Spirit-II Lab Manual

    75/77

    Oasis Technologies Pvt. Ltd.

    Copyrights 2009, All rights reserved.

    www.oasistech.co.in75

    void Task2 (void *data){

    char a[]="Task2 ==> Ram";

    int i;while(1){

    while(!(*U0LSR & 0x20));for(i=0;a[i]!='\0';i++)

    *U0THR= a[i];OSTimeDly(200);

    }

    }void Task1 (void *data)

    { char a[]="Task1==>Sita";int i;while(1){

    while(!(*U0LSR & 0x20));for(i=0;a[i]!='\0';i++)

    *U0THR= a[i];OSTimeDly(200);

    }

    }

    void TaskStart (void *data){

    data = data; /* Prevent compiler warning */init_timer();

    TaskCreate(Task2, (void *)&TaskData[2], "Task2", 2);TaskCreate(Task1, (void *)&TaskData[1], "Task1", 3);TaskCreate(Task3, (void *)&TaskData[2], "Task3", 4);while(1){

    OSTimeDly(15000); /* Wait one second */}

    }

    int main (void){

    init_uart();OSInit(); /* Initialize uC/OS-II */

    TaskCreate(TaskStart, (void *)0, "Task Start", 0);OSStart(); /* Start multitasking */

    return 0; // Actually we should never come here

  • 8/12/2019 Spirit-II Lab Manual

    76/77

  • 8/12/2019 Spirit-II Lab Manual

    77/77

    Oasis Technologies Pvt. Ltd.

    Can reach us @Oasis Technologies Private Limited

    Smt S.N Pasalkar Udyog Bhavan, 2nd Floor,

    Opp Sinchan Bhawan , Barne Road,

    409 B Mangalwar Peth. Pune - 411011

    Maharashtra , INDIA .

    Phone : +91-20- 65236642Telefax : +91-20- 25661715

    Email: [email protected]

    Website: www.oasistech.co.in