You are on page 1of 77

Oasis Technologies Pvt. Ltd.

SPIRIT - II LAB MANUAL


VERSION - 2

Copyrights 2009, All rights reserved. www.oasistech.co.in

Oasis Technologies Pvt. Ltd.


INDEX

CHAPTER 1 .................................................................................................................................. 3 Project Creation / Compilation / Downloading STEPS.............................................................. 3 CHAPTER 2 ................................................................................................................................... 5 1.Assembly Language Programming.......................................................................................... 5 2 LED and DIP SWITCH .......................................................................................................... 8 3. BUZZER ............................................................................................................................... 13 4.RELAY................................................................................................................................... 16 5.STEPPER MOTOR ............................................................................................................... 19 6. TIME DELAY....................................................................................................................... 23 7.External Interrupt ................................................................................................................... 26 8. 7- Segment ............................................................................................................................ 30 9.Keypad ................................................................................................................................... 34 10.Multi Digit 7 Segment ......................................................................................................... 38 11.Text LCD (TLCD)................................................................................................................ 42 12 ADC and Temperature display............................................................................................. 46 13 I2C Serial EEPROM ......................................................................................................... 49 14 Generation of PWM Signal.................................................................................................. 56 CHAPTER -3 ................................................................................................................................ 60 1.LED........................................................................................................................................ 60 2 Display of Message on LCD.................................................................................................. 64 3.MailBox ................................................................................................................................. 68 4.Messages to PC through Serial Port....................................................................................... 72

Copyrights 2009, All rights reserved. www.oasistech.co.in

Oasis Technologies Pvt. Ltd.

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 default workspace. Create C or C++ project by clicking Project New C 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 (for example, "ABC"). Select appropriate Target i.e ARM. Select appropriate Variant LPC2138 /LPC2148 /LPC2129 from list as required for building project. Select appropriate Operating System, here we would select none as the operating 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 default Project Type is Executable (Gnu). Debug - Project can be debugged on target board using Serial, Odyssey JTAG and Ethernet Release - Project is run on Target board without debugging. Click Finish 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.c and ABC_start.s

Copyrights 2009, All rights reserved. www.oasistech.co.in

Oasis Technologies Pvt. Ltd.


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.c tab in the Editor view to expand the view. You will notice an asterisk in front of the file name on the tab in the Editor view. The asterisk indicates that the file has changed but has not been saved. Now save the ABC_main .c file by clicking File In Triton IDE you can build project in two modes :-1. Debug mode - Builds project with debugging 2. Release mode - Builds project without debugging To build project in release mode: Select release mode by right clicking on project and click Active Build Configuration Release. Right click on the project folder, and select the option BUILD. Navigate to the C/C++ Projects view and expand the Release folder created when you build project in Release mode. Save.

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 supply provided. Switch on the Hardware Board, and put the switch in ISP Mode for the program to 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 reset the Board to verify the output.

Copyrights 2009, All rights reserved. www.oasistech.co.in

Oasis Technologies Pvt. Ltd.

CHAPTER 2
1.Assembly Language Programming
Programs in Assembly Language for the following:a) Addition
#include <board.h> #include <LPC21xx.h> #include <stdio.h> 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 assembly q_printf("%d \r\n", k); // print on hyperterminal for(i=0;i<=4;i++) { rem=k%10; rem = rem + 0x30; // to convert hex to char ch[i]=rem; k=k/10; } for(j=3;j>=0;j--) q_displaylcd(&ch[j],1); // display on LCD return 0; }

b) Subtraction
#include <board.h> #include <LPC21xx.h> #include <stdio.h>

int j,i; char k=0;

Copyrights 2009, All rights reserved. www.oasistech.co.in

Oasis Technologies Pvt. Ltd.


char rem,ch[4]={'0','0','0','0'}; int L1(int); int main(void) { q_lcdinit(SPIRIT); k=L1(j); q_printf("%d \r\n", k); for(i=0;i<=4;i++) { rem=k%10; rem = rem + 0x30; ch[i]=rem; k=k/10; } for(j=3;j>=0;j--) q_displaylcd(&ch[j],1); return 0; } // initialise the LCD // return from assembly // print on hyperterminal

// to convert hex to char

// display on LCD

c) Multiplication
#include <board.h> #include <LPC21xx.h> #include <stdio.h> 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 assembly q_printf("%d \r\n", k); // print on hyperterminal for(i=0;i<=4;i++) { rem=k%10; rem = rem + 0x30; // to convert hex to char ch[i]=rem; k=k/10; } for(j=3;j>=0;j--) q_displaylcd(&ch[j],1); // display on LCD return 0; Copyrights 2009, All rights reserved. www.oasistech.co.in 6

Oasis Technologies Pvt. Ltd.


}

d) Division
#include <board.h> #include <LPC21xx.h> #include <stdio.h> 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 assembly q_printf("%d \r\n", k); // print on hyperterminal for(i=0;i<=4;i++) { rem=k%10; rem = rem + 0x30; // to convert hex to char ch[i]=rem; k=k/10; } for(j=3;j>=0;j--) q_displaylcd(&ch[j],1); // display on LCD return 0; }

Copyrights 2009, All rights reserved. www.oasistech.co.in

Oasis Technologies Pvt. Ltd. 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 that emits light upon application of a potential difference greater than its forward bias voltage 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
R40 W18U2 1 R41 W16U2 1 2 R42 W14U2 1 W12U2 R43 1 W9U2 1 W7U2 1 R46 W5U2 W3U2 1 1 R47 2 WR10 1 2 WR8 1 LD8 2 R45 2 WR7 1 LD7 2 R44 2 WR6 1 LD6 2 2 WR5 1 LD5 2 2 WR4 1 LD4 2 WR3 1 LD3 2 2 WR2 1 LD2 2 LD1 2

SMD
U6 H16 H12 H8 H4 H48 H44 H40 H36 2 4 6 8 11 13 15 17 20 10 C1 VCC5V_LED 1A1 1A2 1A3 1A4 2A1 2A2 2A3 2A4 VCC GND 74AHCT244 1Y1 1Y2 1Y3 1Y4 2Y1 2Y2 2Y3 2Y4 1G 2G 18 16 14 12 9 7 5 3 1 19

The ARM LPC controller pins numbered H16, H12, H8, H4, H48, H44, H40 and H36 are used to drive the buffer 74HC244. Buffer is just used as a temporary data storage
Copyrights 2009, All rights reserved. www.oasistech.co.in 8

Oasis Technologies Pvt. Ltd.


device that strengthens the signal. Using this mechanism prevents the controller from damage. Otherwise when all the LEDs are ON too much current will be sourced from the controller which may damage the port permanently. This happens because the input and output sections of the buffer are electrically isolated. Resistors R40~R47 are resistors 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 general purpose input output (GPIO) pins. The GPIO pins are controlled by four registers, as shown below:-

Register Name IODIR IOSET IOCLR IOPIN

Functionality

Expected Operation* Write Only Write Only Write Only Read Only

Controls the GPIO direction Sets the GPIO to be 1(sets the Led in ON state) Sets the GPIO to be 0(sets the Led in OFF State) Reflects the current state

* Unexpected operations on registers are undefined

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

Copyrights 2009, All rights reserved. www.oasistech.co.in

Oasis Technologies Pvt. Ltd.


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

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

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

Procedural Algorithm : LED No. 1 2 3 4 5 6 7 8 Signal (LPC21xx) Pin 45 (P0.15) Pin 46 (P0.16) Pin 47 (P0.17) Pin 53 (P0.18) Pin 54 (P0.19) Pin 55 (P0.20) Pin 1 Pin 2 (P0.21) (P0.22) Description LED 1 LED 2 LED 3 LED 4 LED 5 LED 6 LED 7 LED 8

Copyrights 2009, All rights reserved. www.oasistech.co.in

10

Oasis Technologies Pvt. Ltd.


S.No 1 2 3 4 5 6 7 8 Signal (LPC21xx) Pin 22 (P0.2) Pin 26 (P0.3) Pin 27 (P0.4) Pin 29 (P0.5) Pin 30 (P0.6) Pin 33 (P0.8) Pin 34 (P0.9) Pin 35 (P0.10) Description Switch 1 Switch 2 Switch 3 Switch 4 Switch 5 Switch 6 Switch 7 Switch 8

Set the Direction Pins from P0.15- P0.22 with IODIR Register for LED s . Extract the status PORT0 (P0.2 P0.10) using IOPIN0 Register . Display the status on LED s .

Source Code :
#include <lpc21xx.h> int main(void) { int i; while(1) { *IODIR0 =*IODIR0 | 0x007f8000; //Set Direction of LED *IOCLR0 = 0x007f8000; //Clear all LED's *IOSET0 = ((*IOPIN0 & 0X000000F7C) << 12); for(i=0;i<200000;i++); } return 0; } Copyrights 2009, All rights reserved. www.oasistech.co.in 11

Oasis Technologies Pvt. Ltd.


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

Copyrights 2009, All rights reserved. www.oasistech.co.in

12

Oasis Technologies Pvt. Ltd. 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. The other end of the wire connects to a metal 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 is turned off, the free end of the arm rests against the contact point. This forms a connection between that end of the wire and the electrical circuit. In other words, electricity can flow through the electromagnet when the circuit is closed. Closing the circuit (by pressing the button) puts this mechanism in motion. Initially, the electromagnetic field attracts the iron bar, which pulls the contact arm off the stationary metal

Copyrights 2009, All rights reserved. www.oasistech.co.in

13

Oasis Technologies Pvt. Ltd.


contact. This breaks the connection between the circuit and electromagnet, so the electromagnet shuts off. Without a magnetic field pulling it back, the contact arm snaps back into position against the stationary 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 the process repeats itself as long as you hold down the buzzer button. In this way, the electromagnet keeps shutting itself on and off. The buzzing noise you hear is the sound of the rapidly moving arm hitting the magnet and the stationary contact dozens of times a second.

Procedural Algorithm :

S.No 4

Port.No P0.7

Description 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 <lpc21xx.h> #include <BOARD.H>

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 7 for (i=0;i<90000;i++); *IOCLR0= 0X0000080; //Clears the Pin No 7 Copyrights 2009, All rights reserved. www.oasistech.co.in 14

Oasis Technologies Pvt. Ltd.


for (i=0;i<90000;i++); } return 0; }

Conclusion:
Thus, BUZZER is been Programmed using ARM.

Copyrights 2009, All rights reserved. www.oasistech.co.in

15

Oasis Technologies Pvt. Ltd. 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 Armature that 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 independent circuits. The first is at the bottom and drives the electromagnet. In this circuit, a switch is controlling power to the electromagnet. When the switch is on, the electromagnet is on, and it attracts the armature (blue). The armature is acting as a switch in the second circuit. When the electromagnet is energized, the armature completes the second circuit and the light is on. When the electromagnet is not energized, the spring pulls the armature away and the circuit is not complete. In that case, the light is dark.
Copyrights 2009, All rights reserved. www.oasistech.co.in 16

Oasis Technologies Pvt. Ltd.


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) is normally open (NO) or normally closed (NC)

Procedural Algorithm:

Sr. No. 1

Signal (LPC22xx) Pin 24 (P1.26)

Description 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 <lpc21xx.h> #include <BOARD.H> int main(void) { int i; *IODIR1 = *IODIR1 | 0X04000000; //As shown in the pin connection diagram P1. ,hence Pin 26is been selected . while (1) { *IOSET1 = 0X04000000; // Sets the Pin 26 for(i=0;i<900000;i++); *IOCLR1 = 0X04000000; //Clears the Pin 26 for(i=0;i<900000;i++); } return 0; } Copyrights 2009, All rights reserved. www.oasistech.co.in

26is connected

17

Oasis Technologies Pvt. Ltd.

Conclusion:
Thus, the RELAY is been Programmed using ARM.

Copyrights 2009, All rights reserved. www.oasistech.co.in

18

Oasis Technologies Pvt. Ltd. 5.STEPPER MOTOR


Objective :
To program the Stepper Motor using ARM Controller.

Theory of Operation :

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

The motors rotation has several direct relationships to these applied input pulses. The sequence of the applied pulses is in direct correlation to the direction of motor shafts rotation. The speed of the motor shafts is in direct co relation to the frequency of the input pulses. And, the angle of rotation is in direct correlation to the number of input pulses
Copyrights 2009, All rights reserved. www.oasistech.co.in 19

Oasis Technologies Pvt. Ltd.


applied.

J3
H27 H30 H3_CAN1
SCK0 MOSI RD2 1 3 5 7 9 2 4 6 8 10 MISO SSEL0 TD2

H29 H31 H5_CAN1

VCC5V

STEPPER MOTOR

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 pins connected are from P0.11 to P0.14.

Procedural Algorithm : Sr. No. 1 2 3 4 5 6 Signal (LPC21xx) Pin 37 (P0.11) Pin 38 (P0.12) Pin 39 (P0.13) Pin 41 (P0.14) 5.0V/12.0V GND Description Data 0 Data 1 Data 2 Data 3 VCC(5) GND

Copyrights 2009, All rights reserved. www.oasistech.co.in

20

Oasis Technologies Pvt. Ltd.

Select the pins for Port no 11 14 in IODIR as given from the Schematic Diagram. Set the Pins with IOSET Register to feed 6, and then give Delay. Clear the Pins with IOCLR Register, and then give Delay. Set the Pins with IOSET Register to feed 5, and then give Delay. Clear the Pins with IOCLR Register, and then give Delay. Set the Pins with IOSET Register to feed 9, and then give Delay. Clear the Pins with IOCLR Register, and then give Delay. Set the Pins with IOSET Register to feed A, and then give Delay. Clear the Pins with IOCLR Register, and then give Delay.

Source Code :
#include <LPC21xx.h> int main(void) { unsigned long int i; *PINSEL0 = *PINSEL0 & (0XFFFF87FF); *IODIR0 = *IODIR0 | (0X00007800); //Stepper Motor is connected to pin P0.11 to P0.14 while(1) { *IOSET0 = 0x00002800; for(i=0;i<2500;i++); *IOCLR0 = 0x00002800; for(i=0;i<2500;i++); *IOSET0= 0x00003000; for(i=0;i<2500;i++); *IOCLR0 = 0x00003000; for(i=0;i<2500;i++); *IOSET0 = 0x00005000; for(i=0;i<2500;i++); *IOCLR0 = 0x00005000; for(i=0;i<2500;i++); *IOSET0 = 0x00004800; for(i=0;i<2500;i++); *IOCLR0 = 0x00004800; for(i=0;i<2500;i++); //Feeding 6

//Feeding 5

//Feeding 9

//Feeding A

Copyrights 2009, All rights reserved. www.oasistech.co.in

21

Oasis Technologies Pvt. Ltd.


} return 0; }

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

Copyrights 2009, All rights reserved. www.oasistech.co.in

22

Oasis Technologies Pvt. Ltd.

6. TIME DELAY
Objective :
To program for Time Delay using TIMER .

Theory of operation :
The timers are based around a 32-bit timer counter with a 32-bit prescaler. The clock source for all of the timers is the VLSI peripheral clock PCLK

Each timer also has up to four match channels. Each match channel has a match register which stores a 32-bit number. The current value of the timer counter is compared against the match register. When the values match an event is triggered. This event can perform an action to the timer (reset, stop or generate interrupt) and also affect an external pin (set clear , toggle). To configure the timer for a match event, load the match register with the desired value. The internal match event can now be configured through the Match Control Register.

Copyrights 2009, All rights reserved. www.oasistech.co.in

23

Oasis Technologies Pvt. Ltd.

In this register each channel has a group of bits which can be used to enable the following actions on a match event: generate a timer interrupt, reset the timer or stop the timer. Any combination of these events may be enabled. In addition, each match channel has an associated match pin which can be modified when a match event occurs. The match pins are then controlled by 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<LPC21xx.h> #include<board.h> void TIMER_ISR (void) __attribute__ ((interrupt ("IRQ"))); #define TIMER 4; int main(void) { *T0MCR=0x03; *T0MR0=0x650000; *T0TCR=0x01; *VICIntEnable=0x10; *VICVectCntl0=0x20 |TIMER;

Copyrights 2009, All rights reserved. www.oasistech.co.in

24

Oasis Technologies Pvt. Ltd.


*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

Copyrights 2009, All rights reserved. www.oasistech.co.in

25

Oasis Technologies Pvt. Ltd. 7.External Interrupt


Objective :
To program for External Interrupt Using ARM Technology .

Theory of operation :
If one interrupt source defined as an FIQ interrupt all the remaining interrupt sources must be connected to the remaining IRQ line. To ensure efficient and timely processing of these interrupts, the VIC provides a programmable hardware lookup table which delivers the address of the C function to run for a given interrupt source. The VIC contains 16 slots for vectored addressing. 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 slot number, the lower the slot number, the more important the interrupt. The other register in the VIC slot is the Vector Address Register its register is initialized with the address of the appropriate C function to run when the interrupt associated with the slot occurs. In practice, when a vectored interrupt is generated the interrupt channel is routed to a specific slot and the address of the ISR in the slots Vector Address Register is loaded into a new register called the Vector Address Register. So whenever 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.
Copyrights 2009, All rights reserved. www.oasistech.co.in 26

Oasis Technologies Pvt. Ltd.

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 #define VIC_VECADDR0 #define VIC_VECCNTL0 (unsigned int *) (unsigned int *) (unsigned int *) 0xFFFFF030 0xFFFFF100 0xFFFFF200

#define VIC_VECADDR1 #define VIC_VECCNTL1 #define VIC_INTENB #define TMR_IR #define TMR_MR0 #define TMR_MR1 #define TMR_MR2 #define TMR_MR3 #define TMR_MCR0 #define TMR_TCR0 #define EXT_INT3 #define EXT_INT3MODE #define EXT_INT3POL #define EXT_PINSEL #define IODIR #define IOSET #define IOCLR int i = 0x00008000, count =0;

(unsigned int *) 0xFFFFF104 (unsigned int *) 0xFFFFF204 (unsigned int *) 0xFFFFF010 (unsigned int *) (unsigned int *) (unsigned int *) (unsigned int *) (unsigned int *) (unsigned int *) (unsigned int *) 0xE0004000 0xE0004018 0xE000401C 0xE0004020 0xE0004024 0xE0004014 0xE0004004

(unsigned int *) 0xE01FC140 (unsigned int *) 0xE01FC148 (unsigned int *) 0xE01FC14C (unsigned int *) 0xE002C004 (unsigned int *) (unsigned int *) (unsigned int *) 0xE0028008 0xE0028004 0xE002800C

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

Copyrights 2009, All rights reserved. www.oasistech.co.in

27

Oasis Technologies Pvt. Ltd.


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<=100000;j++); *IOCLR = i; count += 1; i <<= 1; *VIC_WELLKNOWN = 0; } void ExtInt( ) { int j;

Copyrights 2009, All rights reserved. www.oasistech.co.in

28

Oasis Technologies Pvt. Ltd.


*EXT_INT3 = 0x8; *IOSET = 0x7F8000; for (j=0;j<=100000;j++); *IOCLR = 0x7F8000; *VIC_WELLKNOWN = 0; }

Conclusion:
Thus, the External Interrupt is been programmed using VIC Block with TIMER Interrupt.

Copyrights 2009, All rights reserved. www.oasistech.co.in

29

Oasis Technologies Pvt. Ltd. 8. 7- Segment


Objective :
To display 7 segment using ARM Technology .

Theory of operation :
A seven-segment display is a form of electronic display device for displaying decimal numerals. These are commonly used in digital clocks .., electronic meters..Etc., There are two types of displays available,

common anode and common cathode as shown in following figures:

Common Anode

Common Cathode

As shown in the schematic diagrams above, the LEDs in a seven-segment display are not isolated from each other. In Common Cathode, all the cathodes are connected together while the anodes are connected 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 are connected 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.

Copyrights 2009, All rights reserved. www.oasistech.co.in

30

Oasis Technologies Pvt. Ltd.

Procedural Algorithm :

Sr. No. 1 2 3 4 5 6 7 8 10 11 12

Signal (LPC21xx) Pin 16 (P1.16) Pin 12 (P1.17) Pin 8 (P1.18) Pin 4 (P1.19) Pin 48 (P1.20) Pin 44 (P1.21) Pin 40 (P1.22) Pin 36 (P1.23) Vcc Pin 14 (P0.29) GND

Description 'a' 'b' 'c' 'd' 'e' 'f' 'g' '.' +5V RS WR

Configure the port pins as GPIO for pinselect2. Select the Port 1, 16 to 23 Pins. .Clear all the Pins, and give Delay.
Copyrights 2009, All rights reserved. www.oasistech.co.in 31

Oasis Technologies Pvt. Ltd.


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

Source Code :
#include <LPC21xx.H> 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; 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();

//Display 0

//Display 1

//Display 2

//Display 3

//Display 4

//Display 5

//Display 6

//Display 7

Copyrights 2009, All rights reserved. www.oasistech.co.in

32

Oasis Technologies Pvt. Ltd.


*IOCLR1 = 0Xff0000; *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(); } } //Display 8

//Display 9

//Display A

//Display B

//Display C

//Display D

//Display E

//Display F

void delay(void) { int j; for (j=0;j<100000;j++); for (j=0;j<100000;j++); for (j=0;j<100000;j++); for (j=0;j<100000;j++); for (j=0;j<100000;j++); }

Conclusion:
Hence , 7 segment displays all the 16 hex digits .
Copyrights 2009, All rights reserved. www.oasistech.co.in 33

Oasis Technologies Pvt. Ltd. 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 connected to an output port and the columns are connected to an input port .If no key has been pressed ,reading the input port will yield 1s for all columns since they are all connected to high (Vcc) . If all the rows are grounded and a key is pressed , one of the columns will have 0 since the key pressed provides the path to ground .

Procedural Algorithm : Sr. No. 1 2 3 Signal (LPC21xx) Pin 22 (P0.2) Pin 26 (P0.3) Pin 27 (P0.4) Description ROW1 ROW2 ROW3

Copyrights 2009, All rights reserved. www.oasistech.co.in

34

Oasis Technologies Pvt. Ltd.


4 5 6 7 8 Pin 29 (P0.5) Pin 30 (P0.6) Pin 31 (P0.7) Pin 33 (P0.8) Pin 34 (P0.9) ROW4 COL1 COL2 COL3 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<LPC21xx.h> #include<ucos.h> /*#include<lcd1.h>*/ #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) Copyrights 2009, All rights reserved. www.oasistech.co.in 35

Oasis Technologies Pvt. Ltd.


x++; } // to print given number on 7-segment display void putnum_7seg(unsigned char n) { *IODIR1 = 0xff0000; // segment pins as output *IOPIN1 = (unsigned int) (numarray[n]<<16) ; } // clear 7 segment display void clear_7seg() { *IODIR1 = 0xff0000; // segment pins as output *IOPIN1 = (unsigned int) (0x00<<16) ; } unsigned char detectkey() { int col=0,row=0,x; *IODIR0 = *IODIR0 | 0x03fc; xyz: for(col=0;col<4;col++) { *IOCLR0 = *IOCLR0 | (~(0x0200>>col)); *IOSET0 = *IOSET0 | (0x0200>>col); x= (*IOPIN0 & 0x3c)>>2; if(x == 0x01) { row = 0; q_printf("\n Key from return num[row][col]; } if(x == 0x02) { row=1; q_printf("\n Key from return num[row][col]; } if(x == 0x04) { row = 2; q_printf("\n Key from return num[row][col]; } if(x == 0x08) { row = 3; q_printf("\n Key from return num[row][col]; } }

%d th row and %d column",col+1, row+1);

%d th row and %d column",col+1,row+1);

%d th row and %d column",col+1,row+1);

%d th row and %d column",col+1,row+1);

Copyrights 2009, All rights reserved. www.oasistech.co.in

36

Oasis Technologies Pvt. Ltd.


goto xyz; } void debounce() { unsigned int i=10000; while(i<=10000) i--; } unsigned int getch_keypadto7seg() { unsigned char temp,nexttemp; temp = detectkey(); debounce(); nexttemp = detectkey(); if( nexttemp == temp) return nexttemp; else return 0; } int main() { unsigned char ch; // write your program here while(1) { ch= getch_keypadto7seg(); clear_7seg(); putnum_7seg(ch); } return 0; }

Conclusion:
Hence , the Keypad works as per the Code .

Copyrights 2009, All rights reserved. www.oasistech.co.in

37

Oasis Technologies Pvt. Ltd. 10.Multi Digit 7 Segment


Objective :
To display Multi Digit 7 segment using ARM Technology .

Theory of operation :
A seven-segment display is a form of electronic display device for displaying decimal numerals. These are commonly used in digital clocks .., electronic meters..Etc., There are two types of displays available,

common anode and common cathode as shown in following figures:

Common Anode

Common Cathode

As shown in the schematic diagrams above, the LEDs in a seven-segment display are not isolated from each other. In Common Cathode, all the cathodes are connected together while the anodes are connected 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 are connected 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.

Copyrights 2009, All rights reserved. www.oasistech.co.in

38

Oasis Technologies Pvt. Ltd.

Procedural Algorithm : Sr. No. 1 2 3 4 5 6 7 8 10 11 12 Signal (LPC21xx) Pin 16 (P1.16) Pin 12 (P1.17) Pin 8 (P1.18) Pin 4 (P1.19) Pin 48 (P1.20) Pin 44 (P1.21) Pin 40 (P1.22) Pin 36 (P1.23) Vcc Pin 14 (P0.29) GND Description 'a' 'b' 'c' 'd' 'e' 'f' 'g' '.' + 5V RS 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 LCD1 LCD3 P0.28 ,LCD4 P0.25 P0.11 , LCD2 P1.24,

Copyrights 2009, All rights reserved. www.oasistech.co.in

39

Oasis Technologies Pvt. Ltd.

Clear all the Pins ,and give Delay . Set and clear the Pins by using IOSET and IOCLR Register for different Hex values by enabling the respective pins and give Delay .

Source Code :
#include <LPC21xx.H> 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; while(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; //Clear Data Bit

Copyrights 2009, All rights reserved. www.oasistech.co.in

40

Oasis Technologies Pvt. Ltd.


*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<100000;j++); for (j=0;j<100000;j++); for (j=0;j<100000;j++); for (j=0;j<100000;j++); for (j=0;j<100000;j++); }

Conclusion:
Hence , LCD 7 segment displays all the 16 hex digits .

Copyrights 2009, All rights reserved. www.oasistech.co.in

41

Oasis Technologies Pvt. Ltd. 11.Text LCD (TLCD)


Objective :
To program Text LCD using 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 flatscreen computer monitors and televisions. It can provide a much better, brighter image than the old 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 pixels filled with liquid crystals and arrayed in front of a light source (backlight) or reflector to produce images in color or monochrome.

Copyrights 2009, All rights reserved. www.oasistech.co.in

42

Oasis Technologies Pvt. Ltd.


The two transparent panels are polarised, which means they will only pass light waves in one plane. These two polarised panels at 90 degrees to each other so that light filtered from one plane cannot get through the other panel because it only lets light through in a plane at 90 degrees to the first plane.

So the panel appears to be "black" (or at least very dark). However, when electricity is applied to one of the segments of liquid crystals (segments are switched 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 and is visible on the other side.

Procedural Algorithm :

Sr. No. 1 2 3 4 5 6 7 8 10 11 12

Signal (LPC21xx) Pin 16 (P1.16) Pin 12 (P1.17) Pin 8 (P1.18) Pin 4 (P1.19) Pin 48 (P1.20) Pin 44 (P1.21) Pin 40 (P1.22) Pin 36 (P1.23) Pin 13 (P0.28) Pin 14 (P0.29) GND

Description Data 0 Data 1 Data 2 Data 3 Data 4 Data 5 Data 6 Data 7 EN RS WR

Select the pins as per the schematic diagram with IODIR1 and IODIR0 register. Send the command with lcdcmd subroutine .Here, in lcdcmd subroutine command is sent through IOSET1 register and select the RS pin =0. Give delay and clear the register with IOCLR1 register.

Send the data with lcddata subroutine .Here, in lcddata subroutine data is sent through IOSET1 register and select the pin RS=1 .give delay and clear the
Copyrights 2009, All rights reserved. www.oasistech.co.in 43

Oasis Technologies Pvt. Ltd.


register.

Source Code :
#include <LPC21xx.H> #include<board.h> 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 matrix lcdcmd(0x0e); //Display On, Cursor Blinking lcdcmd(0x01); //Clear Display screen lcdcmd(0x06); //Increment cursor lcdcmd(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 << 16; *IOSET1=cmddata; *IOSET0=0x00001000; delay_lcd(); *IOCLR0=0x00001000; delay_lcd(); } void DisplayLCD(char *str, int len) { while(len-- != 0) { lcddata(*str); str++; } } void lcddata(unsigned int outdata) { *IOCLR1=0x00FF0000; *IOSET0=0x00000800; outdata = outdata << 16; *IOSET1=outdata; Copyrights 2009, All rights reserved. www.oasistech.co.in 44

Oasis Technologies Pvt. Ltd.


*IOSET0=0x00001000; delay_lcd(); *IOCLR0=0x00001000; delay_lcd(); } void delay_lcd(void) { int j; for (j=0;j<600;j++); }

Conclusion: Hence, TLCD is been programmed using ARM Technology.

Copyrights 2009, All rights reserved. www.oasistech.co.in

45

Oasis Technologies Pvt. Ltd. 12 ADC and Temperature display


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

Theory of operation :

An analog-to-digital converter is a device which converts continuous signals to discrete digital numbers. It means the conversion of an input analog voltage to a digital number which is proportional to the magnitude of the voltage or current.

The Resolution of the converter indicates the number of discrete values it can produce over the range of analog values. The values are usually stored in binary form, so the resolution is usually expressed in bits . The
Copyrights 2009, All rights reserved. www.oasistech.co.in 46

Oasis Technologies Pvt. Ltd.


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 to Port P0.28 .

ADCR Register is used for configuring ADC to start the conversion .

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

Procedural Algorithm : S.No 1) Pin.No Pin 13 Port.No P0.28 Description Adc Input

Select the GPIO for ADC conversion . Set the ADCR Register with Channel 2, Clock 4Mhz, Burst Mode, 11 clocks per 10 bit and start conversion . While the data bit is 1 , data is been received in ADDR and is collected in adcdata .(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 on hyperterminal .

Source Code :

Copyrights 2009, All rights reserved. www.oasistech.co.in

47

Oasis Technologies Pvt. Ltd.


#include <LPC22xx.h> #include <board.h> 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 temperature q_printf ("Current Temperature is = %d \n", temp); } } return 0; }

Conclusion :
Thus ADC is been programmed using ARM Technology.

Copyrights 2009, All rights reserved. www.oasistech.co.in

48

Oasis Technologies Pvt. Ltd. 13 I2C Serial EEPROM


Objective :
To program I2C Interface Serial EEPROM using ARM Technology .

Theory of operation :

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

Master node node that issues the clock and addresses slaves Slave node node that receives 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 only use 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-bit address of the slave it wishes to communicate with, which is finally followed by a single bit representing 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 the read/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 a high-to-low transition of SDA with SCL high; the stop bit is indicated by a low-to-high transition of SDA with SCL high.
Copyrights 2009, All rights reserved. www.oasistech.co.in 49

Oasis Technologies Pvt. Ltd.


If the master wishes to write to the slave then it repeatedly sends a byte with the slave sending an ACK bit. (In this situation, the master is in master transmit mode and the slave is in slave receive mode.) If the master wishes to read from the slave then it repeatedly receives a byte from the slave, the master sending an ACK bit after every byte but the last one. (In this situation, the master is in master 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 it wishes to retain control of the bus for another transfer (a "combined message").

Procedural Algorithm : Connector Pin No. 1 2 Pin.No Pin22 Pin26 Port.No P0.2 P0.3 Description SCL0 SDA0

Once, the START condition is successful with the code 0x08, the application software 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 a code 0x18 in status register that the transfer was successful.

Every time, a byte is been transmitted, it is acknowledged and an interrupt is generated 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 sent again.

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

Source Code :
#include "address_c.h" #include "functions.h" #include <board.h> /*@@@@@@@@@ delay @@@@@*/

Copyrights 2009, All rights reserved. www.oasistech.co.in

50

Oasis Technologies Pvt. Ltd.


void delay(u32 val) { while(val--) { asm("nop"); } } /*@@@@@@ init function @@@@@@*/ void i2c_init() { *PINSEL0 = *PINSEL0 & 0XFFFFFF0F; // SELECT THE PIN for I2C *PINSEL0 = *PINSEL0 | 0X00000050; *I2CONCLR = DISABLE | START_CLR | STOP_CLR | SI_CLR | AA_CLR; *I2SCLH = 150; //set the bit frequency to 50 khz *I2SCLL = 150; } /*@@@@ rtc init function @@@@@*/ void rtc_init() { delay(100); rtc_reg_wr(SECONDS_REG,0x00); rtc_reg_wr(SQWAVE_REG,0x00|SQWE|OUT); }

/*@@@@@@@ wait @@@@@@@*/ void wait_for_ack(u32 status) { while(1) { if(*I2CONSET & SI) { if(*I2STAT == status) { break; } else { q_printf("\n ERROR STATUS RECEIVED = "); q_printf("%x", *I2STAT); *I2CONSET = STOP; *I2CONCLR = 0xFF;

Copyrights 2009, All rights reserved. www.oasistech.co.in

51

Oasis Technologies Pvt. Ltd.


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); *I2CONCLR = SI_CLR; *I2CONCLR = START_CLR; wait_for_ack(0x18); *I2DAT = 0x00; *I2CONCLR = SI_CLR; wait_for_ack(0x28); for(i=0;i<7;i++) { *I2DAT = txbuf[i]; *I2CONCLR = SI_CLR; wait_for_ack(0x28); } *I2CONSET =STOP ; delay(1000); *I2CONCLR = DISABLE | START_CLR | STOP_CLR | SI_CLR | AA_CLR; } /*@@@@ date time read function @@@@*/ void i2c_rtc_get(u8 *rxbuf) { u8 i=0; *I2CONSET = ENABLE |AA; delay(1000); // transmit slave address with write bit // clear the START bit to avoid retransmit of START

Copyrights 2009, All rights reserved. www.oasistech.co.in

52

Oasis Technologies Pvt. Ltd.


// ---------------------transmit a START --------------------*I2CONSET = START; wait_for_ack(0x08); *I2DAT = (RTC_ADDR|0X01); *I2CONCLR = SI_CLR; *I2CONCLR = START_CLR; retransmit of START wait_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; } // transmit slave address with write bit // clear the START bit to avoid

/*@@@@@ register write function @@@@@*/ void rtc_reg_wr(u8 reg,u8 data) { *I2CONSET = ENABLE; delay(1000); *I2CONSET = START; wait_for_ack(0x08); *I2DAT = (RTC_ADDR); *I2CONCLR = SI_CLR; *I2CONCLR = START_CLR; wait_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); // transmit slave address with write bit // clear the START bit to avoid retransmit of START

Copyrights 2009, All rights reserved. www.oasistech.co.in

53

Oasis Technologies Pvt. Ltd.


*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); *I2CONCLR = SI_CLR; *I2CONCLR = START_CLR; retransmit of START wait_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) { // transmit slave address with write bit // clear the START bit to avoid

Copyrights 2009, All rights reserved. www.oasistech.co.in

54

Oasis Technologies Pvt. Ltd.


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); *I2CONCLR = SI_CLR; *I2CONCLR = START_CLR; wait_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; } // transmit slave address with write bit // clear the START bit to avoid retransmit of START

Conclusion:
Thus, I2C is been Programmed.

Copyrights 2009, All rights reserved. www.oasistech.co.in

55

Oasis Technologies Pvt. Ltd. 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 intermediate amounts of electrical power between fully on and fully off. A simple power switch with a typical power source provides full power only, when switched on. PWM is a comparatively-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 speed controller. The circuit described here is for a general purpose device that can control DC 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 <LPC21xx.H>

#include <LPC21xx.H> /* LPC21xx definitions */ void PWM0_isr(void) __attribute__ ((interrupt("IRQ"))); Copyrights 2009, All rights reserved. www.oasistech.co.in 56

Oasis Technologies Pvt. Ltd.

void poll_ADC (void) { unsigned int val; static unsigned int oldval; *ADCR |= 0x01000000; do { val = ADDR; }while((val & 0x80000000) == 0); *ADCR &= ~0x01000000; val = (val >> 6) & 0x03FF; if ((val != oldval)) { *PWMMR2 = val; *PWMLER = 0x4; oldval = val; } }

/* Get ADC Value and set PWM */

/* Start A/D Conversion */

/* Read A/D Data Register */ /* Wait for end of A/D Conversion */ /* Stop A/D Conversion */ /* Extract AIN0 Value */

/* Enable Shadow latch */

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; output enabled */ *PWMMCR = 0x00000003; *PWMMR0 = 0x400; *PWMMR1 = 0; *PWMMR2 = 0x200; *PWMMR3 = 0x400; *PWMLER = 0xF; *PWMTCR = 0x00000002; *PWMTCR = 0x00000009; from reset */ } /* PWM channel 2 & 3 double edge control, /* On match with timer reset the counter */ /* set cycle rate to sixteen ticks */ /* set rising edge of PWM2 to 100 ticks */ /* set falling edge of PWM2 to 200 ticks */ /* set rising edge of PWM3 to 100 ticks */ /* enable shadow latch for match 1 - 3 */ /* Reset counter and prescaler */ /* enable counter and PWM, release counter

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

Copyrights 2009, All rights reserved. www.oasistech.co.in

57

Oasis Technologies Pvt. Ltd.


while (1) { /* Loop forever */ poll_ADC(); } } void PWM0_isr(void) { *PWMIR |= 0x00000001; *VICVectAddr = 0x00000000; }

/* Clear match0 interrupt */

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

Copyrights 2009, All rights reserved. www.oasistech.co.in

58

Oasis Technologies Pvt. Ltd.

Copyrights 2009, All rights reserved. www.oasistech.co.in

59

Oasis Technologies Pvt. Ltd.

CHAPTER -3
1.LED
Objective :
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 maximizes the 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 easier to 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. The design process for a real-time application involves splitting the work to be done into tasks which are responsible for a portion of the problem. Each task is assigned a p riority, its own set of CPU registers, and its own stack area.
Copyrights 2009, All rights reserved. www.oasistech.co.in 60

Oasis Technologies Pvt. Ltd.


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. A task is READY when it can execute but its priority is less than the currently running task. A task is RUNNING when it has control of the CPU. A task is WAITING FOR AN EVENT when it requires the occurrence of an event (waiting for an I/O operation to complete, a shared resource to be available, a timing pulse to occur, time to expire etc.). Finally, a task is INTERRUPTED when 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.H> #include <ucos.h> #include <board.h> /* LPC21xx definitions */

Copyrights 2009, All rights reserved. www.oasistech.co.in

61

Oasis Technologies Pvt. Ltd.


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

char TaskData[NO_TASKS]; OS_STK TaskStk[NO_TASKS][TASK_STK_SIZE]; OS_STK TaskStartStk[TASK_STK_SIZE]; extern void init_timer (void);

/* Tasks stacks */

void Task2 (void *data) { int n, i; data = data; // avoid compiler warning while(1) { for (n = 0x00080000; n <= 0x04000000; n <<= 1) { /* Blink LED 5, 6 ,7 ,8*/ *IOSET0 = n; /* Turn on LED */ OSTimeDly(10); /* Wait one second */ *IOCLR0 = n; /* Turn off LEDs */ OSTimeDly(10); /* Wait one second */ i++; q_printf("LoPrio "); } } } void Task1 (void *data) { int n, i; data = data; while(1) { for (n = 0x00008000; n <= 0x00040000; n <<= 1) { /* Blink LED 1,2, 3, 4 */ *IOSET0 = n; q_printf("Task1 LEDON "); /* Turn on LED */ OSTimeDly(10); /* Wait one second */ q_printf("Task1 LEDOFF "); *IOCLR0 = n; /* Turn off LEDs */ OSTimeDly(10); /* Wait one second */ q_printf("%s", "HiPrioTsk "); // avoid compiler warning

Copyrights 2009, All rights reserved. www.oasistech.co.in

62

Oasis Technologies Pvt. Ltd.


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(); init_timer(); TaskCreate(startTask, (void *)0, "VHiPrioTsk", 0); OSStart(); return 0; } /* Start multitasking */ /* Initialize uC/OS-II */

// Actually we should never come here

Conclusion:
Thus , the program for Led Blinking is been done .

Copyrights 2009, All rights reserved. www.oasistech.co.in

63

Oasis Technologies Pvt. Ltd. 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 maximizes the 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 easier to 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. The design process for a real-time application involves splitting the work to be done into tasks which are responsible for a portion of the problem. Each task is assigned a priority, its own set of CPU registers, and its own stack area.

Copyrights 2009, All rights reserved. www.oasistech.co.in

64

Oasis Technologies Pvt. Ltd.


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. A task is READY when it can execute but its priority is less than the currently running task. A task is RUNNING when it has control of the CPU. A task is WAITING FOR AN EVENT when it requires the occurrence of an event (waiting for an I/O operation to complete, a shared resource to be available, a timing pulse to occur, time to expire etc.). Finally, a task is INTERRUPTED when 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 :

Copyrights 2009, All rights reserved. www.oasistech.co.in

65

Oasis Technologies Pvt. Ltd.


#include <LPC21xx.H> #include<board.h> #include <ucos.h> void lcdcmd(unsigned int); void lcddata(unsigned int); void delay_lcd(void); void DisplayLCD(char *str, int len); #define TASK_STK_SIZE 100 #define NO_TASKS 2 /* Size of each task's stacks (# of WORDs) */ /* 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(); 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 << 16; *IOSET1=cmddata; *IOCLR0=0x20000000; delay_lcd();

*/ /*initilize timer tick for RTOS */ */

Copyrights 2009, All rights reserved. www.oasistech.co.in

66

Oasis Technologies Pvt. Ltd.


*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 << 16; *IOSET1=outdata; *IOSET0=0x20000000; delay_lcd(); *IOCLR0=0x20000000; delay_lcd(); return; } void delay_lcd(void) { int j; for (j=0;j<500;j++); return; }

Conclusion:
Thus , the program for display for different characters on LCD is been done .

Copyrights 2009, All rights reserved. www.oasistech.co.in

67

Oasis Technologies Pvt. Ltd. 3.MailBox


Objective :
To program for sending and receiving messages between different TASK through Mailbox using RTOS Technology.

Theory of operation :
Messages can be sent to a task through kernel services. A Message Mailbox, also called a message exchange, is typically a pointer size variable. Through a service provided by the kernel, a task or an ISR can deposit a message (the pointer) into this mailbox. Similarly, one or more 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 receive messages through the mailbox. A task desiring to receive a message from an empty mailbox will be suspended and placed on the waiting list until a message is received. Typically, the kernel will allow the task waiting for a message to specify a timeout. If a message is not received 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 the message is given the message (called priority-based) or the first task to request a message is given the message (called First-In-First-Out, or FIFO). The following figure shows a task depositing a message into a mailbox. Note that the mailbox is represented graphically by an Ibeam and the timeout is represented by an hourglass. The number next to the hourglass represents 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 is empty (ACCEPT). If the mailbox contains a message, the message is extracted from the mailbox. 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 the mailbox indicates that the resource is available while an empty mailbox indicates that the resource is already in use by another task.

Copyrights 2009, All rights reserved. www.oasistech.co.in

68

Oasis Technologies Pvt. Ltd.

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 does not 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.H> #include <ucos.h> #define TASK_STK_SIZE 100 #define NO_TASKS 5 /* LPC21xx definitions */

/* Size of each task's stacks (# of WORDs) */ /* 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; void *MQueTable[20]; extern void init_timer (void); /* ******************************************************************** */ /* Task functions */ /* ******************************************************************** */ /* Message Queue pointer */ /* array to store Messages */

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 */ Copyrights 2009, All rights reserved. www.oasistech.co.in 69

Oasis Technologies Pvt. Ltd.


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; init_timer(); MQue = (OS_EVENT *) OSQCreate(&MQueTable,20); /* Create a message queue */

/* Prevent compiler warning */

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); } } int main (void) { OSInit(); /* Initialize uC/OS-II init_timer(); TaskCreate(TaskStart, (void *)0, "Task Start", 0); OSStart(); /* Start multitasking return 0; } /* Wait one second */

//

*/

*/

Copyrights 2009, All rights reserved. www.oasistech.co.in

70

Oasis Technologies Pvt. Ltd.


Conclusion:
Thus, program for sending and receiving messages between different TASK through Mailbox is been done .

Copyrights 2009, All rights reserved. www.oasistech.co.in

71

Oasis Technologies Pvt. Ltd. 4.Messages to PC through Serial Port


Objective :
To program for sending messages to PC through Serial Port by different Tasks on priority basis 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 maximizes the 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 easier to 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. The design process for a real-time application involves splitting the work to be done into tasks which are responsible for a portion of the problem. Each task is assigned a priority, its own set of CPU registers, and its own stack area.
Copyrights 2009, All rights reserved. www.oasistech.co.in 72

Oasis Technologies Pvt. Ltd.


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. A task is READY when it can execute but its priority is less than the currently running task. A task is RUNNING when it has control of the CPU. A task is WAITING FOR AN EVENT when it requires the occurrence of an event (waiting for an I/O operation to complete, a shared resource to be available, a timing pulse to occur, time to expire etc.). Finally, a task is INTERRUPTED when 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 .

Copyrights 2009, All rights reserved. www.oasistech.co.in

73

Oasis Technologies Pvt. Ltd.

Source Code :
/*********************************************************************** * Msg2PC_main.c ************************************************************************/ #include <LPC21xx.H> /* LPC21xx definitions */ #include <ucos.h> #define TASK_STK_SIZE 100 #define NO_TASKS 5 /* Size of each task's stacks (# of WORDs) */ /* 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); }

} Copyrights 2009, All rights reserved. www.oasistech.co.in 74

Oasis Technologies Pvt. Ltd.


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; init_timer();

/* Prevent compiler warning */

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

*/

Copyrights 2009, All rights reserved. www.oasistech.co.in

75

Oasis Technologies Pvt. Ltd.


}

Conclusion:
Thus program for sending messages to PC through Serial Port by different Tasks on priority basis is been done .

Copyrights 2009, All rights reserved. www.oasistech.co.in

76

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- 65236642 Telefax : +91-20- 25661715 Email: contact@oasistech.co.in Website: www.oasistech.co.in

Copyrights 2009, All rights reserved. www.oasistech.co.in

77

You might also like