Professional Documents
Culture Documents
CONTENTS
1. 2. 3. 4. 5. 6. 7.
INTRODUCTION LPC 2148SB CPU DETAILS LPC2148 ARCHITECTURE HARDWARE DESCRIPTION SOFTWARE GETTING STARTED HARDWARE GETTING STARTED SOFTWARE EXAMPLE PROGRAMS
3 4 6 12 14 38 53
INTRODUCTION
First of all sales and R&D Team of MRR Embedded Systems Pvt Ltd thanking you for buying MRRs Embedded LPC214x Development KIT. The LPC214x Development KIT is a complete development platform for NXP ARM7 LPC214x series processors. It is a cost effective, flexible and highly integrated board, useful for develop custom embedded applications and evaluate all features of the new powerful ARM7 processor.
The LPC2148 Microcontroller is based on a 32/16 Bit ARM7TDMI-s CPU with real time Emulation and Embedded Trace support, That combines with the microcontroller with embedded high speed 512KB flash memory. It can work with 16-bit Thumb Mode. With Useful Implemented peripherals, plentiful practical code examples and a broad set of additional on board Peripherals MRRs ARM Development boards make fast and reliable tools that can satisfy the needs of experienced engineers and beginners alike. Modern SMD technology and Multilayer Design makes our board compact and of good quality. All Controller signals and ports extend from the controller to high density pitch Connectors of the board. MRR2148SB Hardware Manual Describes the boards design and functions. Precise Specifications for the NXP LPC2148 Microcontroller can be found in the enclosed Microcontroller Data sheet/Users Manual. In this hardware manual, schematic diagrams and Block Diagrams are attached.
The figure above shows the major parts of the LPC214x Development KIT. Diagrams and wiring descriptions for all connectors are provided in schematic. The board has the optional feature of Graphical LCD and USB Connector for developing these applications.
applications where miniaturization is a key requirement, such as access control and point-of-sale. A blend of serial communications interfaces ranging from a USB 2.0 Full Speed device, multiple UARTS, SPI, SSP to I2Cs and on-chip SRAM of 8 kB up to 40 kB, make these devices very well suited for communication gateways and protocol converters, soft modems, voice recognition and low end imaging, providing both large buffer size and high processing power. Various 32-bit timers, single or dual 10-bit ADC(s), 10-bit DAC, PWM channels and 45 fast GPIO lines with up to nine edge or level sensitive external interrupt pins make these microcontrollers particularly suitable for industrial control and medical systems.
Features:
6/32-bit ARM7TDMI-S microcontroller in a tiny LQFP64 package. 8 to 40 kB of on-chip static RAM and 32 to 512 kB of on-chip flash program memory. 28 bit wide interface/accelerator enables high speed 60 MHz operation. In-System/In-Application Programming (ISP/IAP) via on-chip bootloader software. Single flash sector or full chip erase in 400 ms & programming of 256 bytes in 1ms. Embedded ICE RT and Embedded Trace interfaces offer real-time debugging with the onchip Real Monitor software and high speed tracing of instruction execution. USB 2.0 Full Speed compliant Device Controller with 2 kB of endpoint RAM. In addition, the LPC2146/8 provide 8 kB of on-chip RAM accessible to USB by DMA. One or two (LPC2141/2 vs LPC2144/6/8) 10-bit A/D converters provide a total of 6/14 analog inputs, with conversion times as low as 2.44 s per channel. Single 10-bit D/A converter provides variable analog output. Two 32-bit timers/external event counters (with four capture and four compare channels each), PWM unit (six outputs) and watchdog. Low power real-time clock with independent power and dedicated32 kHz clock input. Multiple serial interfaces including two UARTs (16C550), two Fast I2C-bus (400 Kbit/s), SPI and SSP with buffering and variable data length capabilities. Vectored interrupt controller with configurable priorities and vector addresses. Up to nine edge or level sensitive external interrupt pins available. 60 MHz maximum CPU clock available from on-chip PLL with settling time of 100s. On-chip integrated oscillator operates with an external crystal range from 1 MHz to 30 MHz and with an external oscillator up to 50 MHz. Power saving modes include Idle and Power-down. Individual enable/disable of peripheral functions as well as peripheral clock scaling for additional power optimization.
MRR Embedded Systems Pvt Ltd | 5
Processor wake-up from Power-down mode via external interrupt, USB, Brown-Out Detect (BOD) or Real-Time Clock (RTC). Single power supply chip with Power-On Reset (POR) and BOD circuits: CPU operating voltage range of 3.0 V to 3.6 V (3.3 V 10 %) with 5 V tolerant I/O pads. Up to 45 of 5 V tolerant fast general purpose I/O pins in a tiny LQFP64 package.
Application
Industrial control Medical systems Access control Point-of-sale Communication gateway Embedded soft modem General purpose applications
UARTs:
The LPC2148 contains two UARTs. In addition to standard transmit and receive data lines, the LPC2148 UART1 also provide a full modem control handshake interface. Compared to previous LPC2000 microcontrollers, UARTs in LPC2148 introduce a fractional baud rate generator for both UARTs, enabling these microcontrollers to achieve standard baud rates such as 115200 with any crystal frequency above 2 MHz. In addition, auto-CTS/RTS flow-control functions are fully implemented in hardware (UART1). 16 Bit Receive and Transmit FIFO Register locations conform to 16C550 industry standard Receiver FIFO trigger points at 1 B, 4 B, 8 B, and 14 B Built-in fractional baud rate generator covering wide range of baud rates without a need for external crystals of particular values Transmission FIFO control enables implementation of software (XON/XOFF) flow control on both UARTs LPC2148 UART1 equipped with standard modem interface signals. This module also provides full support for hardware flow control (auto-CTS/RTS)
Serial clock synchronization can be used as a handshake mechanism to suspend and resume serial transfer The I2C-bus can be used for test and diagnostic purposes
10-bit ADC:
The LPC2148 contains two analog to digital converters. These converters are single 10-bit successive approximation analog to digital converters. While ADC0 has six channels, ADC1 has eight channels. Therefore, total numbers of available ADC inputs are 14. 10-bit successive approximation analog to digital converter Measurement range of 0 V to VREF (2.0 V ? VREF ? VDDA) Each converter capable of performing more than 400000 10-bit samples per second Every analog input has a dedicated result register to reduce interrupt overhead Burst conversion mode for single or multiple inputs Optional conversion on transition on input pin or timer match signal Global Start command for both converters
10-bit DAC:
The DAC enables the LPC2148 to generate a variable analog output. The maximum DAC output voltage is the VREF voltage. 10-bit DAC Buffered output Power-down mode available Selectable speed versus power
Real-time clock:
The RTC is designed to provide a set of counters to measure time when normal or idle operating mode is selected. The RTC has been designed to use little power, making it suitable for batterypowered systems where the CPU is not running continuously (Idle mode). Measures the passage of time to maintain a calendar and clock. Ultra-low power design to support battery powered systems. Provides Seconds, Minutes, Hours, Day of Month, Month, Year, Day of Week, and Day of Year. Can use either the RTC dedicated 32 kHz oscillator input or clock derived from the external crystal/oscillator input at XTAL1. Programmable reference clock divider allows fine adjustment of the RTC. Dedicated power supply pin can be connected to a battery or the main 3.3 V.
MRR Embedded Systems Pvt Ltd | 10
Crystal oscillator:
On-chip integrated oscillator operates with external crystal in range of 1 MHz to 25 MHz. The oscillator output frequency is called fosc and the ARM processor clock frequency is referred to as CCLK for purposes of rate equations, etc. fosc and CCLK are the same value unless the PLL is running and connected.
PLL:
The PLL accepts an input clock frequency in the range of 10 MHz to 25 MHz. The input frequency is multiplied up into the range of 10 MHz to 60 MHz with a Current Controlled Oscillator (CCO). The multiplier can be an integer value from 1 to 32 (in practice, the multiplier value cannot be higher than 6 on this family of microcontrollers due to the upper frequency limit of the CPU). The CCO operates in the range of 156 MHz to 320 MHz, so there is an additional divider in the loop to keep the CCO within its frequency range while the PLL is providing the desired output frequency. The output divider may be set to divide by 2, 4, 8, or 16 to produce the output clock. Since the minimum output divider value is 2, it is insured that the PLL output has a 50 % duty cycle. The PLL is turned off and bypassed following a chip reset and may be enabled by software. The program must configure and activate the PLL, wait for the PLL to Lock, then connect to the PLL as a clock source. The PLL settling time is 100 ms.
11
Hardware Description
MRR2148SB features a number of peripheral Devices. In order to enable these devices before programming, you need to check if appropriate jumpers have been properly set.
Board Features:
8 Nos. Digital Input 4x4 Matrix Keypad 8 Nos. Point LEDs 4 Nos. Analog Input 16*2 Character LCD with back light Temperature Sensor Stepper Motor Driver 2 Relays I2C - 6 Nos. 7-Segment Display I2C Real Time Clock with Battery-Backup I2C -EEPROM 2 Nos. UART (RS232)
MRR Embedded Systems Pvt Ltd | 12
Buzzer (Alarm) Interrupt Switches DAC Port out Power Supply connector out Relay terminal out External Analog input JTAG Debugger ISP programming through Serial port
Package Contents:
The box received when ordering LPC214x Development KIT includes: LPC214x Development Board. USB A-B cable. DB25 Parallel Cable for debugging Serial extension cable DB9-male DB9-femail for debugging and programming purpose. 12V DC SMPS Power Supply An optional Wiggler JTAG adapter for debugging. CD-ROM that includes datasheets, software examples, useful drive rs end etc.
13
14
Getting Started with Keil Once Keil is loaded, an empty workspace is displayed. If any project was opened previously, then the previously opened project will be displayed.
To create a New Project, goto Project. Drop down menu and select New Project
15
16
Once you select New Project, it asks you where to save the project. Specify the Path. Once you specify the Path, select the Chip to be programmed.
17
Once you select the chip, a message box will be displayed. It asks whether to load Startup code into the Project.
18
To write start writing code, select new file from file drop down menu. On Right Hand Side is the editor where the code can be written...
Once the code is written, it has to be added to the Project. To do that right click on the Source group and select .add files to source group. Option. Then select the file to be added. You can see the file added on Left Hand side in the Source group.
19
To Build the project, goto Project Drop Down menu and select Build.
20
Once the project is built, the result can be seen at the bottom. If any errors are present the list of errors will be displayed or if the project has no errors the build is said to be successful.
When the project is built, it only compiles and links all the files in project. If the same code is to be loaded onto the chip flash memory, we need the hex file. Hex file is the downloadable file which is used to load onto the flash memory of the chip. In order to generate the Hex file, right click on target folder in Project workspace (the first folder visible) and select .Options for Target .LPC 2100. Check the check box.
21
Create Hex file and press OK Once the option is selected to create Hex file, once again build the Project. This time the .Hex file is created. You can see the hex file in the folder where the Project is saved. If you want to check for the correctness of the code, then goto Debug Drop Down Menu and select .Start/Stop Debug Session.
22
Here you simulate the program in SIMULATOR mode here you can see Yellow arrow mark that will move step while pressing F11
23
24
Board Layout
The figure predicts the exact hardware features of the board which are clearly marked such as POWER, UART0ISP, UART1 etc.,
25
Power Supply
The kit is supplied with a 12V/1A SMPS Power Supply. The board contains two LM317 Regulators U1 and U2. U1 is tuned for 5V and U2 is tuned for 3.3V. The maximum output current of the voltage regulator is 1.5A. All elements of the board use the +3.3V power supply except relays and ULN2003 that uses +5V. Stepper Motor use +12V Power Supply. ULN2803 used for Stepper Motor uses +12V Power Supply that can be fed from the external Power source or the same power source used to power up the board. For using the same power source for the stepper motor jumper JP51 must be closed. Jumpers JP3 and JP4 must be closed to supply the board with proper power for errorless operation of the board.
Erase All flash Select the hex file using Browse Verify after programming Click Start to program the flash
HTAG Configuration
1.Open the H-Jag from Start Programs H-Tag
28
3. Once the Processor is deducted the Red color will change into Blue
H-Flasher Configuration Open H-Falsher.exe and follow the configuration steps as follows.
29
30
4. Select 2) Configuration
31
32
8. Select 5) Programming
33
34
Step-3 Select Src File: where your program has been saved
Step-4 Select Program to write the hex files into flash Memory
35
This will be the window which will be displayed when selected Debug Tab.
Now select RDI Interface Driver from the dropdown menu. Use on Right Hand Side of the window
36
Select the check box to select .Run to Main. And check box .Load Application at Startup.. Then click the Settings button
Now click utilities and deselect target driver. Select external tool and change the command option to link with H-Flasher. Delete contents in Arguments. Now start the keil debug mode and start debugging
37
HARDWARE GETTING STARTED LEDs: Therefore, when interfacing an LED to a TTL output, the maximum current through the LED is 16 mA. The features of LEDs are listed below Lower power consumption Require series resistors to limit the current Displaying decimal digits LED lighting is an emerging technology with many home applications such as LED Christmas lights, LED rope lights, LED spotlights, etc. LED bulbs last over 50,000 hours. For Running the LED applications you have to close the jumper JP6 to JP15. Remove Jumpers related to Stepper Motor and Relays for safe operation, but not mandatory.
SWITCHES: An electrical switch is any device used to interrupt the flow of electrons in a circuit. Switches are essentially binary devices: they are either completely on ("closed") or completely off ("open").. In the simplest case, a switch has two pieces of metal called contacts that touch to make a circuit, and separate to break the circuit. DIP switch is one of the mostly used type. The MRR2148SB Development Board has one 8-Way Dip Switch. When the switch is open, no
MRR Embedded Systems Pvt Ltd | 38
current flows through the resistor and therefore the voltage on the microcontroller pin is 3.3 V. When the switch is closed the pin is connected directly to ground. As before, when the TTL input is HIGH practically no current flows in the circuit and when the input is LOW there is a direct current for the 3mA that may flow from the pin. J12 and J7 must be closed to work with DIP Switch. A 10Pin FRC Connector is used to close these two connectors. Disconnect J7 from J9 and connect to J12.
J12 DSW1 DSW2 DSW3 DSW4 1 3 5 7 9 2 4 6 8 10 DSW5 DSW6 DSW7 DSW8 J7 P1.16 P1.17 P1.18 P1.19 1 3 5 7 9 2 4 6 8 10 P1.20 P1.21 P1.22 P1.23
CON_SW
CON_KEY /SW
SW18 1 2 3 4 5 6 7 8 SW DIP-8 16 15 14 13 12 11 10 9 DSW1 DSW2 DSW3 DSW4 DSW5 DSW6 DSW7 DSW8
Matrix KEY The Matrix keyboard is used to minimize the number of I/O lines. Normally it is possible to connect only one key or switch with a I/O line. If the number of keys in the system exceeds the more I/O lines are required. To reduce the number of I/O lines the keys are connected in the matrix circuit. Keyboards use a matrix with the rows and columns made up of wires. Each key act like a switch. When a key is pressed a column wire makes contact with row wire and completes a circuit. For example 16 keys arranged in a matrix circuit uses only 8 I/O lines. For using the Matrix keypad, the Connectors J7 and J9 has to be closed one to one using a 10Pin FRC Connector given as an accessory with the development kit. Disconnect J7 from J12 and connect to J9. The ports P1 of the Microcontroller are configured as port 1 input port in the software for using the matrix keypad. The Output can be viewed on the Serial port. The Software can be changed to view the output on LCD as well as per your wish.
J9 K1 K2 K3 K4 1 3 5 7 9 2 4 6 8 10 K5 K6 K7 K8 P1.16 P1.17 P1.18 P1.19 J7 1 3 5 7 9 2 4 6 8 10 P1.20 P1.21 P1.22 P1.23
CON_KEY
CON_KEY /SW
39
LCD (Liquid Crystal Display) Liquid crystals are a phase of matter whose order is intermediate between that of a liquid and that of a crystal. The molecules are typically rodshaped organic matters about 25 Angstroms in length and their ordering is a function of temperature. The molecular orientation can be controlled with applied electric fields. LCD is made up of two sheets of polarizing material with the liquid crystal solution between them. An electric current passed through the liquid causes the crystals to align so that light cannot pass through them, which results in display of character as per the applied voltage in its data lines. The driver is provided to drive the LCD. It stores the display data transferred from the microcontroller in the internal display RAM and generates dot matrix liquid crystal driving signals. Each bit data of display RAM corresponds to on/off state of a dot of a liquid crystal display. LCD is used in widespread applications due to the following reasons: 1. The declining prices of LCDs. 2. The ability to display numbers, characters, and graphics. 3. Incorporation of a refreshing controller into the LCD, thereby relieving the CPU of the task of refreshing the LCD. 4. Ease of programming for characters and graphics. Character Based LCD A standard character LCD is probably the most widely used data Visualization component. Character LCDs are available in various kinds of models. 1. No. Of characters and line 2. Color: Yellow, Green, Gray, Blue
MRR Embedded Systems Pvt Ltd | 40
The Character LCD communicates with the microcontroller via 8 bit data bus. The pin description for character LCD is given below. VCC, GND AND V0 - While VCC and VSS provide +5V and ground, respectively; V0 is used for controlling LCD contrast. RS (Register Select) - If RS = 0, the instruction command code register is selected, allowing the user to send a command such as clear display, cursor at home, etc. If RS = 1, the data register is selected, allowing the user to send data to be displayed on the LCD. RW (Read/Write) - RW allows the user to write information to the LCD or read information from it. RW=1 when reading; RW=0 when writing. EN (Enable) - The LCD to latch information presented to its data pins uses the enable pin. When data is supplied to data pins, a high to low pulse must be applied to this pin in order for the LCD to latch in the data present at the data pins. D0 D7 - The 8-bit data pins, are used to send information to the LCD or read the contents of the LCDs internal registers. To display letters and numbers, we send ASCII codes for the letters A-Z, a-z, and numbers 0-9 to these pins while making RS = 1. For working with the LCD, the jumpers JP44 has to be closed and the potentiometer R74 can be adjusted for contrast variation.
J15 LCD_CON
VCC_LCD
2 P1.20
P1.21
1 10K R74
VCC_LCD
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
R71 100E
41
RS-232 Communication
Serial port is a serial communication physical interface through which information transfers in or out one bit at a time (contrast parallel port). The name "serial" comes from the fact that a serial port "serializes" data. That is, it takes a byte of data and transmits the 8 bits in the byte one at a time. The advantage is that a serial port needs only one wire to transmit the 8 bits (while a parallel port needs 8). The disadvantage is that it takes 8 times longer to transmit the data than it would if there were 8 wires. Serial ports lower cable costs and make cables smaller. There are two basic types of serial communications, synchronous and asynchronous. With synchronous communications, the two devices initially synchronize themselves to each other, and then continually send characters to stay in sync. Even when data is not really being sent, a constant flow of bits allows each device to know where the other is at any given time. That is, each character that is sent is either actual data or an idle character. Synchronous communications allows faster data transfer rates than asynchronous methods, because additional bits to mark the beginning and end of each data byte are not required.
Synchronous Data Transfer Asynchronous means "no synchronization", and thus does not require sending and receiving idle characters. However, the beginning and end of each byte of data must be identified by start and stop bits. The start bit indicates when the data byte is about to begin and the stop bit signals when it ends. The requirement to send these additional two bits causes asynchronous communication to be slightly slower than synchronous however it has the advantage that the processor does not have to deal with the additional idle characters. An asynchronous line that is idle is identified with a value of 1 (also called a mark state). By using this value to indicate that no data is currently being sent, the devices are able to distinguish between an idle state and a disconnected line. When a character is about to be transmitted, a start bit is sent. A start bit has a value of 0 (also called a space state). Thus, when the line switches from a value of 1 to a value of 0, the receiver is alerted that a data character is about to be sent.
42
One of the LPC2148s many powerful features is its integrated UART, otherwise known as a serial port. The fact that the LPC2148 has an integrated serial port means that you may very easily read and write values to the serial port. If it were not for the integrated serial port, writing a byte to a serial line would be a rather tedious process-requiring turning on and off one of the I/O lines in rapid succession to properly "clock out" each individual bit, including start bits, stop bits, and parity bits. However, we do not have to do this. Instead, we simply need to configure the serial ports operation mode and baud rate. Once configured, all we have to do is write to an SFR to write a value to the serial port or read the same SFR to read a value from the serial port. The LPC2148 will automatically let us know when it has finished sending the character we wrote and will also let us know whenever it has received a byte so that we can process it. We do not have to worry about transmission at the bit level--which saves us quite a bit of coding and processing time. UART or Serial ports, also called communication (COM) ports, RS-232 ports are bi-directional. The LPC2148 contain two UARTs. In addition to standard transmit and receive data lines, the UART1 also provides a full modem control handshake interface. The hardware schematic of the RS232 conversion for UART1 is shown below. Fro Serial port working, o jumper selection is required. Mind it, Jumper selection is for only GPIOs.
43
Baud Rate Calculation The UART0 Divisor Latch is part of the UART0 Fractional Baud Rate Generator and holds the value used to divide the clock supplied by the fractional prescaler in order to produce the baud rate clock, which must be 16x the desired baud rate. The U0DLL and U0DLM registers together form a 16 bit divisor where U0DLL contains the lower 8 bits of the divisor and U0DLM contains the higher 8 bits of the divisor. The Divisor Latch Access Bit (DLAB) in U0LCR must be one in order to access the UART0 Divisor Latches. The UART0 Fractional Divider Register (U0FDR) controls the clock prescaler for the baud rate generation and can be read and written at users discretion. This presale takes the VPB clock and generates an output clock per specified fractional requirements.
All of the SFRs associated with UART0 most important SFRs are explainedin detail.
44
Where PCLK is the peripheral clock, U0DLM and U0DLL are the standard UART0 baud rate divider registers, and DIVADDVAL and MULVAL are UART0 fractional baud rate generator specific parameters. The value of MULVAL and DIVADDVAL should comply to the following Conditions: 1. 0 < MULVAL = 15 2. 0 = DIVADDVAL = 15 For more information refer to LPC2148 User Manual.
the Pin function Select register assigns them to port pins. A simple self-test of the ADC can be done by driving these pins as port outputs. While the ADC pins are specified as 5 V tolerant More than 3.3 V (VDDA) +10 % should not be applied to any pin that is selected as an ADC input, or the ADC reading will be incorrect. If for example AD0.0 and AD0.1 are used as the ADC0 inputs and voltage on AD0.0 = 4.5 V while AD0.1 = 2.5 V, an excessive voltage on the AD0.0 can cause an incorrect reading of the AD0.1, although the AD0.1 input voltage is within the right range. MRR2148 -SB has one potentiometers for working with A/D Converter. Potentiometer outputs are in the range of 0V to 3.3V.
Sensor Interfacing:
Interfacing computer systems to the outside world is an important issue in a large number of computer-related disciplines, from human computer interaction, to robotics, to interactive multimedia, to computer music. In order to do this, the computer systems require some form of sensors. A sensor is a device that measures a physical quantity and converts it into a signal, which can be read by an observer or by an instrument. Capturing the data from sensors is applied in industrial processes. Temperature sensor, Pressure sensor, Humidity sensor, Acceleration sensor, Flow sensor, level sensor, velocity sensor, Solar radiation sensor, Wind direction sensor, Fire/Smoke Sensor and proximity sensor are the types of Sensors used. Temperature Sensor LM35 A signal conditioner is a device that converts one type of electronic signal into another type of signal. Its primary use is to convert a signal that may be difficult to read by conventional instrumentation into a more easily read format. In performing this conversion a number of functions may take place.
Jumpers JP45 has to be closed for using the thermistor and JP42 has to be closed for using any external sensor. But JP45 and JP42 can be used alternately. Both should not be closed together.
46
Relay
A relay is an electrical switch that opens and closes under the control of another electrical circuit. In the original form, the switch is operated by an electromagnet to open or close one or many sets of contacts. When a current flows through the coil, the resulting magnetic field attracts an armature that is mechanically linked to a moving contact. The movement either makes or breaks a connection with a fixed contact. When the current to the coil is switched off, the armature is returned by a force approximately half as strong as the magnetic force to its relaxed position. Usually this is a spring, but gravity is also used commonly in industrial motor starters. Most relays are manufactured to operate quickly. In a low voltage application, this is to reduce noise. In a high voltage or high current application, this is to reduce arcing. If the coil is energized with DC, a diode is frequently installed across the coil, to dissipate the energy from the collapsing magnetic field at deactivation, which would otherwise generate a spike of voltage and might cause damage to circuit components. If the coil is designed to be energized with AC, a small copper ring can be crimped to the end of the solenoid. This "shading ring" creates a small out-of-phase current, which increases the minimum pull on the armature during the AC cycle. By analogy with the functions of the original electromagnetic device, a solid-state relay is made with a thyristor or other solid-state switching device. To achieve electrical isolation, a light-emitting diode (LED) is used with a photo transistor. For making the relay1 ON, P1.16 has to be made high and for making it off P1.16 has be made low. Similarly for relay2, P1.17 is used. Jumpers JP40 and JP43 has to be closed for the operation of onboard relays. If Relay is used make sure the input applications such as matrix keypad and digital inputs are not in use and the 10PIN FRC connectors are removed, because using the port as output and pressing the keypad may damage the ports pins and the processor. The relay connection diagram is shown in the figure below.
+5VDC RLY 1 5 R58 1K 3 +5VDC 4 8 P1.16 JP40 1 2 REL1_JP 1K R67 2 D4 3 Q4 1 BC547 1N4007 +5VDC 1 2 RELAY 1 LED R66 1K 7 6 L11 J14 1 2 3 RELAY 1_TM_B
I2C Peripherals I2C Stands for Inter Integrated Circuit Communications. This module is built into many arm Controllers. It allows I2C serial communication between two or more devices at a high speed. I2C is a synchronous protocol that allows a master device to initiate communication with a slave device.
MRR Embedded Systems Pvt Ltd | 47
Data is exchanged between these devices. I2C is also Bi-Directional. This is implemented by an Acknowledge System. In MRR2148-SB there are three I2C based Peripherals. 1. I2C Based Real Time Clock 2. I2C Based Serial EEPROM 3. I2C Based Seven Segment Display Real Time Clock Communication Protocol Hardware IC Application
: : : :
U6 is the real time clock used in the board, it can be used for storing the time and the time can be retrieved whenever required. The Time runs properly without failure and backed up by a 3V CMOS battery. For operation of the RTC, JP2 and JP5 jumpers has to be in closed condition. If RTC is not in use you can remove JP2 for saving the life of the battery. But the main feature of RTC is battery backup operation. You can use the jumper during demo and development time alone.
EEPROM Serial-interface EEPROMs are used in a broad spectrum of consumer, automotive, telecommunication, medical, industrial and PC related markets. Primarily used to store personal preference data and configuration/setup data, Serial EEPROMs are the most flexible type of nonvolatile memory utilized today. Compared to other NVM solutions, Serial EEPROM devices offer a lower pin count, smaller packages, lower voltages, as well as lower power consumption. U4 is the I2C based EEPROM available on the board which operates at 100 to 400 kHz. Jumper JP5 must be closed to write and read from the EEPROM device as the I2C Power supply will be flowing if and only if JP5 is closed. If Communication error is there between the Processor and the EEPROM make sure the JP5 jumper is closed. If error occurs reset the processor after the jumper is closed.
48
49
Jumpers JP30 to JP37 and Jumpers JP17 to JP22 has to be closed in order to work with Seven Segment. Also make sure that I2C jumper JP5 is closed previously. If not close it as well.
Buzzer
A buzzer or beeper is a signaling device, usually electronic, typically used in automobiles and handheld appliances. It most commonly consists of a number of switches or sensors connected to a control unit that determines if and which button was pushed or a preset time has lapsed, and usually illuminates a light on the appropriate button or control panel, and sounds a warning in the form of a continuous or intermittent buzzing or beeping sound. Initially this device was based on an electro mechanical system which was identical to an electric bell without the metal gong (which makes the ringing noise). Often these units were anchored to a wall or ceiling and used the ceiling or wall as a sounding board. Jumper JP23 has to be closed to work with Buzzer.
Stepper Motor Stepper motors operate differently from normal DC motors, which simply spin when voltage is applied to their terminals. Stepper motors, on the other hand, effectively have multiple "toothed" electromagnets arranged around a central metal gear, as shown at right. To make the motor shaft turn, first one electromagnet is given power, which makes the gear's teeth magnetically attracted to the electromagnet's teeth. When the gear's teeth are thus aligned to the first electromagnet, they are slightly offset from the next electromagnet. So when the next electromagnet is turned on and the first is turned off, the gear rotates slightly to align with the next one, and from there the process is repeated. Each of those slight rotations is called a "step." In that way, the motor can be turned a precise angle. There are two basic arrangements for the electromagnetic coils: bipolar and unipolar.
Jumper JP46, JP47, JP48, JP49 and JP51 has to be closed for the operation of Stepper motor.
50
The following figure shows the wiring diagram and the stepping sequence of the motor.
For More information on Stepper motor please refer to MRRs Stepper Motor User Manual in the CD.
External interrupt inputs: The LPC2148 include up to nine edge or level sensitive External Interrupt Inputs as selectable pin functions. When the pins are combined, external events can be processed as four independent interrupt signals. The External Interrupt Inputs can optionally be used to wake-up the processor from Power-down mode. Additionally capture input pins can also be used as external interrupts without the option to wake the device up from Power-down mode
MRR Embedded Systems Pvt Ltd | 51
Jumpers JP39 has to be closed for working with external Interrupt 0 and JP42 has to be closed to work with external interrupt 1.
SW20 JP39 EXINT0 R64 22K 1 2 R65 22K C27 EXINT0_SW 0.1MFD EXINT0 1 2 3 4
SW21 3 4
EXINT1_SW 0.1MFD
+3.3V
52
53
Exercise 1: AIM: Write a Program for ADDITION, SUBTRACTION, MULTIPLICATION AND DIVISION HARDWARE: OUTPUT: Connect RS2322 cable to UART1 and PC COM1 ANS: /************************************************************** /*ADDITION PROGRAM ASSEMBLY */ /************************************************************** #include <LPC21XX.h> NAME PUBLIC COMMON CODE32 B RSEG CODE32 main main INTVEC:CODE main ICODE:CODE
#include "uart.asm" main: LDR R0,=0X11111111 LDR R1,=0X12345678 //output value display in a serial window. ADD R8,R1,R0 //serial window language is hex. BL UART stop: B stop END main
54
/************************************************************** /*SUBTRACTION PROGRAM ASSEMBLY */ /************************************************************** #include <lpc21xx.h> NAME PUBLIC COMMON CODE32 B RSEG CODE32 main main INTVEC:CODE main ICODE:CODE
#include "uart.asm" main: LDR R1,=0X0000ffff LDR R0,=0X0000eeee SUB R8,R1,R0 BL UART B stop main
stop: END
55
/************************************************************** /*MULTIPLICATION PROGRAM ASSEMBLY */ /************************************************************** #include <lpc21xx.h> NAME PUBLIC COMMON CODE32 B RSEG CODE32 main main INTVEC:CODE main ICODE:CODE
#include "uart.asm" main: LDR R0,=0X00001000 LDR R1,=0X00000100 MOV R8,#0 CMP R1,#0 BEQ ERR CMP R0,R1 BLT DONE ADD R8,R8,#1 SUB R0,R0,R1 B loop MOV R8,#0XFFFFFFFF BL UART B stop main
loop:
56
/*************************************************************/ /*DIVISION PROGRAM ASSEMBLY */ /************************************************************/ #include <lpc21xx.h> NAME PUBLIC COMMON CODE32 B main main INTVEC:CODE main
RSEG ICODE:CODE CODE32 #include "uart.asm" main: LDR R0,=0X00000123 LDR R1,=0X00000234 MUL R8,R1,R0 BL UART B stop
stop:
END main
57
Exercise 2 (a): AIM: Write a Program for LED (8 Digital Output) Interface MRRs 2148 Syllabus Board has microcontrollers PORT P1.16 P1.23 HARDWARE CONFIGURATION: LED0-LED7 JUMPER CLOSE JUMPER OPEN SCHEMATIC: : P1.16 to P1.23 : JP6, JP7,JP8, JP9,JP10,JP11,JP12,JP13,JP14,JP15 : JP17-JP22, J40&JP43, and JP46 JP49 8 LEDs Connected to
ANS: /************************************************************** General Learning Program for GPIO configuration in LPC2100 /************************************************************** #include <LPC21xx.H> /* LPC21xx definitions */ /************************************************************** Wait function - LED Flashing Delay Routine /************************************************************** void wait (void) { unsigned long d; for (d = 0; d < 2000000; d++); }
58
/*************************************************************** LED Flashing Main Routine LED0 LED7 Connected to P1.16 P1.23 /*************************************************************** int main (void) { PINSEL2= 0x00000004; //Port1 Config - GPIO, Debug Enabled IODIR1 = 0x00FF0000; //P1.16..23 Configured as Outputs while (1){ IOSET1 = 0x00ff0000; wait (); IOCLR1 = 0x00ff0000; wait (); } } OUTPUT: You can find the Output as LED blinking from 1st LED to 8th LED one by one with the delay time defined in the wait function. CONCLUSION: For longer or reduced delay change the value of the variable d in the wait function. IOSET1 and IOCLR1 can be changed to play with the GPIOs. /* // // // // Loop Turn call Turn call forever*/ on LED wait function on LED wait function
59
Exercise 2 (b): AIM: Write a Program for 8 bit Switch Interface MRRs 2148 Syllabus Board has 8 microcontrollers PORT P1.16 P1.23 HARDWARE CONFIGURATION: DIP SWITCH SW18 JUMPER CLOSE JUMPER OPEN OUTPUT DEVICE SCHEMATIC:
J12 DSW1 DSW2 DSW3 DSW4 1 3 5 7 9 2 4 6 8 10
J7 P1.16 P1.17 P1.18 P1.19 1 3 5 7 9 2 4 6 8 10 P1.20 P1.21 P1.22 P1.23
Switches
Connected
to
: : : :
P1.16 to P1.23 J12 Connected to J7 using 10PIN FRC CONNECTOR JP6 JP15, JP17-JP22, J40&JP43, JP46 JP49 UART1 (Connect RS232 Cable to P1 and PC COM1)
CON_SW
CON_KEY /SW
SW18 1 2 3 4 5 6 7 8 SW DIP-8 16 15 14 13 12 11 10 9 DSW1 DSW2 DSW3 DSW4 DSW5 DSW6 DSW7 DSW8
ANS: /*************************************************************** /*General Learning Program for GPIO configuration in LPC2100 */ /*************************************************************** #include <LPC21xx.H> /* LPC21xx definitions */
#include <stdio.H> unsigned char digital_ip(void); extern int sendchar1 (int ch); // Standard IO Function // Routine to accept digital input // Sends a character in serial port1
/************************************************************** /*Digital input subroutine that reads a digital input and */ /*returns a value according to the given input */ /**************************************************************
unsigned char digital_ip(void) { // // Check if Port 1.16 through P1.23 is made low using Switch And return characters 1 through 8 respectively Return 0 if no switch is closed and so display nothing in the serial port if((IO1PIN & 0x000F0000)==0x000e0000) return '1'; else if((IO1PIN & 0x000F0000)==0x000d0000) return '2'; else if((IO1PIN & 0x000F0000)==0x000b0000) return '3'; else if((IO1PIN & 0x000F0000)==0x00070000)
61
return '4'; else if((IO1PIN & 0x00F00000)==0x00e00000) return '5'; else if((IO1PIN & 0x00F00000)==0x00d00000) return '6'; else if((IO1PIN & 0x00F00000)==0x00b00000) return '7'; else if((IO1PIN & 0x00F00000)==0x00700000) return '8'; else return '0'; } /**************************************************************************** /* SERIAL.C: Low Level Serial Routines /**************************************************************************** #include <LPC21xx.H> /* LPC21xx definitions */ #define CR 0x0D
/* implementation of putchar (also used by printf function to output data)*/ int sendchar1 (int ch) { /* Write character to Serial Port */
if (ch == '\n') { while (!(U1LSR & 0x20)); U1THR = CR; } while (!(U1LSR & 0x20)); return (U1THR = ch); }
/* output CR */
/***************************************************************************/ /* RETARGET.C: 'Retarget' layer for target-dependent low level functions */ /***************************************************************************/ #include <stdio.h> #include <rt_misc.h> #pragma import(__use_no_semihosting_swi) extern int sendchar1(int ch); /* in serial.c */ /* Add whatever you need here */
62
int fputc(int ch, FILE *f) { return (sendchar1(ch)); } int ferror(FILE *f) { return EOF; } void _ttywrch(int ch) { sendchar1(ch); } void _sys_exit(int return_code) { label: goto label; } /* Your implementation of ferror */
/* endless loop */
OUTPUT: You can find the Output in the serial port UART1 display the corresponding values for the 8 Switches closed using the DIP Switch. CONCLUSION: You can change the character returned in the digital_ip() function to see the displayed characters as you wish.
63
Exercise 3 (a): AIM: Write a Program for Beeping a Buzzer MRRs 2148 Syllabus Board has Onboard Buzzer Connected to P0.10 HARDWARE CONFIGURATION: Buzzer JUMPER CLOSE JUMPER OPEN OUTPUT DEVICE SCHEMATIC: : : : : 5V Buzzer Connected to P0.10 JP23 DONT CARE Buzzer Beeping with a delay
/**************************************************************/ /*Main Program to beep the buzzer */ /**************************************************************/ int main(void) { PINSEL0 = 0xffCfffff; // P0.10 GPIO Configured IODIR0 = 0x00000400; // P0.10 Output Configured
MRR Embedded Systems Pvt Ltd | 64
OUTPUT: You can find the Output as buzzer beeping with a delay specified. CONCLUSION: You can change the value of the variable i in the wait function to set the beep delay as your wish
65
Exercise 3 (b): AIM: Write a Program to ON and OFF Relays MRRs 2148 Syllabus Board has Onboard Relay Connected to P1.16 And P1.17 HARDWARE CONFIGURATION: Relay JUMPER CLOSE JUMPER OPEN OUTPUT SCHEMATIC:
+5VDC RLY1 5 R58 1K 3 +5VDC 4 8 P1.16 JP40 1 2 REL1_JP 1K R67 2 D4 3 Q4 1 BC547 1N4007 +5VDC 1 2 RELAY1 LED R66 1K 7 6 L11 J14 1 2 3 RELAY1_TM_B
: : : :
P1.16 & P1.17 J40 and JP 43 JP6 JP15, JP17-JP22 & JP46 JP49 TERMINAL BLOCKS J14 & J16
ANS: /**************************************************************/ /*Program to control relays connected to P1.16 & P1.17 */ /**************************************************************/ #include <LPC21xx.H> /* LPC21xx definitions */
/**************************************************************/ /*Delay Routine to make relays ON and OFF */ /*Reducing the delay may damage relays due to abrupt ON & OFF */ /**************************************************************/ void wait (void) { char i; unsigned long d; for(i=0;i<=2;i++) /* wait function */
66
for (d = 0; d < 2000000; d++); } /**************************************************************/ /*Main Routine to control relays */ /**************************************************************/ int main (void) { IODIR1 |= 0x00030000; while (1) { IOSET1 = wait(); IOCLR1 = wait (); } } OUTPUT: You can find the Output as the relays 1 and 2 connected to Port P1.16 & P1.17 are made ON and OFF with a delay specified. CONCLUSION: You can change the value function to set the ON/OFF Do not reduce the delay relays or external devices and OFF. of the variable i in the wait delay as your wish very low as it can damage the connected to it due to abrupt ON /* P1.16..23 defined as Outputs */ /* Loop forever */ // Making P1.16 & P1.17 High // Making P1.16 & P1.17 low
0x00030000; 0x00030000;
67
Exercise 3 (c): AIM: Write a Program to Rotate the Stepper Motor MRRs 2148 Syllabus Board has Onboard Stepper driver Connected to P1.16 to P1.19 ( 4 Bit interface) HARDWARE CONFIGURATION: Stepper Motor JUMPER CLOSE JUMPER OPEN OUTPUT SCHEMATIC: : : : : P1.16 to P1.19 J46 to JP 49, J51(Power Jumper) JP6 JP15, JP17-JP22, JP40 & JP43 Stepper Motor Rotation
ANS:
#include <LPC21xx.H> void void void void forward(void); reverse(void); motor_delay(void); motor_delay1(void); /* LPC21xx definitions */ // Function to rotate the motor forward // Function to rotate the motor reverse // Motor Delay Function
void wait (void) { /* wait function */ char i; unsigned long d; /* Motor delay for Forward and reverse Rotation*/ for (i = 0; i <=10; i++) for (d = 0; d < 2000000; d++); }
int main (void) { char rot; IODIR1 |= 0x00FF0000; while (1) { for(rot=0;rot<=25;rot++) forward(); wait(); for(rot=0;rot<=25;rot++) reverse(); wait(); } } /* P1.16..23 defined as Outputs */ /* Loop forever */
69
IOCLR1=0x000f0000; motor_delay1(); IOSET1=0x00f90000; motor_delay(); IOCLR1=0x000f0000; motor_delay1(); IOSET1=0x00f50000; motor_delay(); IOCLR1=0x000f0000; motor_delay1 (); IOSET1=0x00f60000; motor_delay (); IOCLR1=0x000f0000; motor_delay1(); }
OUTPUT: The stepper motor rotates in forward direction for a while and once again rotates in the reverse direction. CONCLUSION: You can change the value of the variable d in the motor_ delay() and motor_delay1() function to vary the spped of rotation of the stepper motor.
MRR Embedded Systems Pvt Ltd | 70
Exercise 5: AIM: Write a Program to execute external interrupt MRRs 2148 Syllabus Board has Onboard switches connected to P0.15 and P0.20 HARDWARE CONFIGURATION: External Int0 External Int1 JUMPER CLOSE JUMPER OPEN OUTPUT
SCHEMATIC:
SW20 JP39 EXINT0 R64 22K 1 2 R65 22K C27 EXINT0_SW 0.1MFD EXINT0 1 2 3 4
external
interrupt
: : : : :
P0.15 P0.20 J39 and JP 41 (Int0 and Int1 resp) Dont care UART1(PC Com1 port)
SW21 3 4
EXINT1_SW 0.1MFD
+3.3V
ANS:
/*************************************************************/ /*General Learning Program for External interrupt */ /* configuration in LPC2148 */ /************************************************************1*/
#include <LPC21xx.H> void FIQ_Handler (void) __fiq; void initFiq (void); //declare FIQ ISR
71
can
find
the
Output
as
LED
flashing
if
interrupt
CONCLUSION: You can change the LED flashing speed as you wish.
72
MRRs 2148 Syllabus Board has 6 Onboard Seven segment LEDs controlled by P1.16 to P1.21 and connected to I2C Io expander HARDWARE CONFIGURATION: PCF8574 CONTROL PINS JUMPER CLOSE JUMPER OPEN OUTPUT
SCHEMATIC:
: : : : :
P0.2(SCL) and P0.3(SDA) P1.16 to P1.21 (ULN2003 Darlington Array) JP5 (I2C Power), JP30 to JP37,JP17 to JP22 JP6 JP15, JP40, JP43 & JP51, JP46 to JP49 Seven segment 1
ANS:
73
#define #define #define #define #define #define #define #define #define #define
REP_START SLA_ACK SLA_NACK DATA_ACK DATA_NACK ARB_LOST SLA_READ_ACK SLA_READ_NACK DATA_READ_ACK DATA_READ_NACK
0x10 0x18 0x20 0x28 0x30 0x38 0x40 0x48 0x50 0x58
#define MAX_TRIES 10
// Set Pin 22 as SCL and Pin 26 as SDA //Enable the I2C interface
74
// FF for about 100 kHz I2C clock, High and Low time equal I2SCLL = 0x93; // Set count for SCL Low period // FF for about 100 kHz I2C clock }
75
You can change the value to be written to the PCf8574 in the main function to display some other number.
76
Exercise 7: AIM: Write a Program for 4*4 Matrix Interface MRRs 2148 Syllabus Board has matrix microcontrollers PORT P1.16 P1.23 HARDWARE CONFIGURATION: 4*4 Matrix JUMPER CLOSE JUMPER OPEN OUTPUT DEVICE SCHEMATIC: : : : : P1.16 to P1.23 J9 Connected to J7 using 10PIN FRC CONNECTOR JP6 JP15, JP17-JP22, J40&JP43, JP46 JP49 UART1 (Connect RS232 Cable to P1 and PC COM1) keypad Connected to
ANS:
MRR Embedded Systems Pvt Ltd | 77
/*************************************************************** /*General Learning Program for GPIO configuration in LPC2100 */ /*************************************************************** #include <LPC21xx.H> /* LPC21xx definitions */
#include <stdio.H> unsigned char digital_ip(void); extern int sendchar1 (int ch); // Standard IO Function // Routine to accept digital input // Sends a character in serial port1
/************************************************************** /* Main Program that reads a digital input and displays in */ /* the serial port 1 (UART1) */ /**************************************************************
int main(void) { unsigned char digi; PINSEL0 U1LCR = U1DLL = U1LCR = = 0x00050000; 0x83; 97; 0x03; /* /* /* // Enable RxD1 and TxD1 */ 8 bits, no Parity, 1 Stop bit */ 9600 Baud Rate */ DLAB = 0
/************************************************************** /*Digital input subroutine that reads a digital input and */ /*returns a value according to the given input */ /**************************************************************
unsigned char digital_ip(void) {
78
// //
Check if Port 1.16 through P1.23 is made low using Switch And return characters 1 through 8 respectively Return 0 if no switch is closed and so display nothing in the serial port if((IO1PIN & 0x000F0000)==0x000e0000) return '1'; else if((IO1PIN & 0x000F0000)==0x000d0000) return '2'; else if((IO1PIN & 0x000F0000)==0x000b0000) return '3'; else if((IO1PIN & 0x000F0000)==0x00070000) return '4'; else if((IO1PIN & 0x00F00000)==0x00e00000) return '5'; else if((IO1PIN & 0x00F00000)==0x00d00000) return '6'; else if((IO1PIN & 0x00F00000)==0x00b00000) return '7'; else if((IO1PIN & 0x00F00000)==0x00700000) return '8'; else return '0';
} /**************************************************************************** /* SERIAL.C: Low Level Serial Routines /**************************************************************************** #include <LPC21xx.H> /* LPC21xx definitions */ #define CR 0x0D
/* implementation of putchar (also used by printf function to output data)*/ int sendchar1 (int ch) { /* Write character to Serial Port */
if (ch == '\n') { while (!(U1LSR & 0x20)); U1THR = CR; } while (!(U1LSR & 0x20)); return (U1THR = ch); }
/* output CR */
/***************************************************************************/ /* RETARGET.C: 'Retarget' layer for target-dependent low level functions */ /***************************************************************************/ #include <stdio.h>
79
#include <rt_misc.h> #pragma import(__use_no_semihosting_swi) extern int sendchar1(int ch); /* in serial.c */ /* Add whatever you need here */
struct __FILE { int handle; }; FILE __stdout; int fputc(int ch, FILE *f) { return (sendchar1(ch)); } int ferror(FILE *f) { return EOF; } void _ttywrch(int ch) { sendchar1(ch); } void _sys_exit(int return_code) { label: goto label; }
/* endless loop */
OUTPUT: You can find the Output in the serial port UART1 display the corresponding values for the 8 Switches closed using the DIP Switch. CONCLUSION: You can change the character returned in the digital_ip() function to see the displayed characters as you wish.
80
Exercise 8: AIM: Write a Program to display a Multi digit in seven segment display MRRs 2148 Syllabus Board has 6 Onboard Seven segment LEDs controlled by P1.16 to P1.21 and connected to I2C Io expander HARDWARE CONFIGURATION: PCF8574 CONTROL PINS JUMPER CLOSE JUMPER OPEN OUTPUT
SCHEMATIC:
: : : : :
P0.2(SCL) and P0.3(SDA) P1.16 to P1.21 (ULN2003 Darlington Array) JP5 (I2C Power), JP30 to JP37,JP17 to JP22 JP6 JP15, JP40, JP43 & JP51, JP46 to JP49 Seven segment 1
ANS:
81
#define #define #define #define #define #define #define #define #define #define
REP_START SLA_ACK SLA_NACK DATA_ACK DATA_NACK ARB_LOST SLA_READ_ACK SLA_READ_NACK DATA_READ_ACK DATA_READ_NACK
0x10 0x18 0x20 0x28 0x30 0x38 0x40 0x48 0x50 0x58
#define MAX_TRIES 10
82
IOCLR1 = 0xfff7ffff; pcf8574_write_byte(0xab); delay(); pcf8574_write_byte(0x00); IOSET1 = 0x00100000; IOCLR1 = 0xffefffff; pcf8574_write_byte(0x8f); delay(); pcf8574_write_byte(0x00); IOSET1 = 0x00200000; IOCLR1 = 0xffdfffff; pcf8574_write_byte(0xc6); delay(); pcf8574_write_byte(0x00); } }
83
return -1; } I2DAT = 0x42; I2CONCLR = 0x28; // Clear interrupt Flag and Start Flag while (I2STAT!=0x18); if (I2STAT == SLA_NACK) goto restart; if (I2STAT == ARB_LOST) goto begin; if (I2STAT != SLA_ACK) goto errorfunc; // put byte into data register and start transmission I2DAT = buf; I2CONCLR=0x08; // Clear interrupt Flag while (I2STAT!= DATA_ACK); if (I2STAT == DATA_NACK) goto quit; if (I2STAT == ARB_LOST) goto begin; if (I2STAT != DATA_ACK) goto errorfunc; quit: // send stop condition I2CONSET=0x10; I2CONCLR=0x0c; return 1; errorfunc: // send stop condition I2CONSET=0x10; I2CONCLR=0x0c; return -1; }
84
OUTPUT: All the six seven segments displays digits at the same time. CONCLUSION:
You can change the value to be written to the PCf8574 in the main function to display some other number.
85
Exercise 9: AIM: Write a Program to display a message in the 2*16 Display LCD MRRs 2148 Syllabus Board has 2*16 Character connected to the P1.16 to P1.21 in 4 bit mode HARDWARE CONFIGURATION: LCD Interface JUMPER CLOSE JUMPER OPEN OUTPUT
SCHEMATIC:
J15 LCD_CON
LCD
Display
: : : :
P1.16 to P1.21(4 bit interface) JP44 JP6 JP15, JP40, JP43 & JP51, JP46 to JP49 Character LCD 2*16
VCC_LCD
2 P1.20
P1.21
1 10K R74
VCC_LCD
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
R71 100E
86
// R/W PIN IS CONNECTED TO GROUND /**************************************************************************/ #define #define #define #define RS_1 RS_0 EN_1 EN_0 IOSET1 IOCLR1 IOSET1 IOCLR1 | | | | 0x00100000 // RS=P0.11 0x00100000 0x00200000 //EN=P0.10 0x00200000
while(1) { lcdcmd(0x80); lcddata('A');lcddata('R');lcddata('M');lcddata('7');lcddata('T'); lcddata('D');lcddata('M');lcddata('I');lcddata(' '); lcddata('L');lcddata('P');lcddata('C');lcddata('2');lcddata('1'); lcddata('4');lcddata('8'); lcdcmd(0xC0); lcddata('D');lcddata('E');lcddata('V');lcddata(' );lcddata('B'); lcddata('O'); lcddata('A');lcddata('R');lcddata('D');lcddata(' ');lcddata(' '); lcddata(' ');lcddata(' '); } }
87
IOSET1=EN_1; delay(); IOCLR1=EN_0; data=copy; data=(data & 0x000F0000); IOSET1=IOSET1 | data; IOCLR1=IOCLR1 |~data; IOCLR1=RS_0; IOSET1=EN_1; delay(); IOCLR1=EN_0; }
//LCD TO LATCH THE DATA //lower nibble //Strobe 4-Bit Low -Nibble to LCD //COMMAND REGISTER //LCD TO LATCH THE DATA
88
OUTPUT: LCD displays a message ARM7TDMI LPC2148 in the first line and DEV BOARD in the second line CONCLUSION:
You can change the message to be displayed in the LCD by changing the lcddata() function in the the main program.
89
Exercise 10: AIM: Write a Program to use ADC and measure temperature sensor MRRs 2148 Syllabus Board has onboard ADC and LM35 Temperature sensor HARDWARE CONFIGURATION: ADC0 JUMPER CLOSE JUMPER OPEN OUTPUT
SCHEMATIC:
: : : :
ANS:
/***************************************************************************/ /* MEASURE.C: ADC and LM35 Temperature Sensor */ /***************************************************************************/ #include <stdio.h> /* standard I/O .h-file */ #include <LPC214x.H> /* LPC213x definitions */ #define ADCR AD0CR #define ADDR AD0DR #include "measure.h" /* global project definition */ struct mrec current; unsigned char lm35val; /* current measurements */
90
/***************************************************************************/ /*************************** MAIN PROGRAM ***************************/ /***************************************************************************/ int main (void) { /* main entry for program */
char i; unsigned int val; unsigned int crval; PINSEL1 = 0x15400000; ADCR = 0x002E0401; init_serial (); while (1) { for (i = 0; i != 4; i++) { crval = 0x01000000 | (1<<i); ADCR |= crval; do { val = ADDR; } while ((val & 0x80000000) == 0); ADCR &= ~crval; val = (val >> 8) & 0xFF; current.analog[i] = val; if(i==2) { lm35val = val; } } measure_display (current); } }
*/ */
/* initialite serial interface*/ /* loop forever */ /* loop for 4 A/D inputs /* Start A/D Conversion /* /* /* /* /* */ */
Read A/D Data Register */ Wait for end of A/D Convers.*/ Stop A/D Conversion */ Extract AIN Value */ result of A/D process */
/* display values
*/
/***************************************************************************/ /* Display measurements */ /***************************************************************************/ void measure_display (struct mrec display) { printf ("\rAnalog Measurements: "); /* display AD0 through AD3 */ printf (" A%d:%4.2fV", 1, (float) display.analog[1] * 3.3 / 256.0); LM35(lm35val+5); printf (" A%d:%4.2fV", 3, (float) display.analog[3] * 3.3 / 256.0); } /***************************************************************************/
91
/* LM35 Interface */ /**************************************************************************/ void LM35(unsigned char val1) { unsigned char i,j,k; i=val1/100; j=val1%100; k=val1%10; k=k+0x30; j=(j/10) + 0x30; i=i+0x30; printf(" Temp: "); sendchar(i); sendchar(j); sendchar(k); sendchar(' '); printf("C"); } /**************************************************************************** /* SERIAL.C: Low Level Serial Routines /**************************************************************************** #include <LPC21xx.H> /* LPC21xx definitions */ #define CR 0x0D int sendchar1 (int ch) { /* Write character to Serial Port */
if (ch == '\n') { while (!(U1LSR & 0x20)); U1THR = CR; } while (!(U1LSR & 0x20)); return (U1THR = ch); }
/* output CR */
OUTPUT: The value of the ADC Channels and the LM35 Temperature are displayed via the serial port UART1(COM1) of the PC CONCLUSION:
You can change the analog values by changing the Potentiometer R78 on the board and can notice the voltage changing in the serial port.
92
Exercise 11: AIM: Write a Program for I2C Interface Seven Segment Display MRRs 2148 Syllabus Board has 6 Onboard Seven segment LEDs controlled by P1.16 to P1.21 and connected to I2C Io expander HARDWARE CONFIGURATION: PCF8574 CONTROL PINS JUMPER CLOSE JUMPER OPEN OUTPUT
SCHEMATIC:
: : : : :
P0.2(SCL) and P0.3(SDA) P1.16 to P1.21 (ULN2003 Darlington Array) JP5 (I2C Power), JP30 to JP37,JP17 to JP22 JP6 JP15, JP40, JP43 & JP51, JP46 to JP49 Seven segment 1
ANS:
93
#define MAX_TRIES 10
94
pcf8574_write_byte(0xab); delay(); pcf8574_write_byte(0x00); IOSET1 = 0x00100000; IOCLR1 = 0xffefffff; pcf8574_write_byte(0x8f); delay(); pcf8574_write_byte(0x00); IOSET1 = 0x00200000; IOCLR1 = 0xffdfffff; pcf8574_write_byte(0xc6); delay(); pcf8574_write_byte(0x00); } } //Select Segment 5 i.e P0.20=1 //Other Segments deselect
95
} I2DAT = 0x42; I2CONCLR = 0x28; // Clear interrupt Flag and Start Flag while (I2STAT!=0x18); if (I2STAT == SLA_NACK) goto restart; if (I2STAT == ARB_LOST) goto begin; if (I2STAT != SLA_ACK) goto errorfunc; // put byte into data register and start transmission I2DAT = buf; I2CONCLR=0x08; // Clear interrupt Flag while (I2STAT!= DATA_ACK); if (I2STAT == DATA_NACK) goto quit; if (I2STAT == ARB_LOST) goto begin; if (I2STAT != DATA_ACK) goto errorfunc; quit: // send stop condition I2CONSET=0x10; I2CONCLR=0x0c; return 1; errorfunc: // send stop condition I2CONSET=0x10; I2CONCLR=0x0c; return -1; }
96
OUTPUT: All the six seven segments displays digits at the same time. CONCLUSION:
You can change the value to be written to the PCf8574 in the main function to display some other number.
97
Exercise 12: AIM: Write a Program for I2C Interface Serial EEPROM MRRs 2148 Syllabus Board has onboard I2c based AT24C04 EEPROM HARDWARE CONFIGURATION: AT24C04 JUMPER CLOSE JUMPER OPEN OUTPUT
SCHEMATIC:
: : : :
P0.2 (SCL) and P0.3 (SDA) JP5 (I2C Power) dont care UART1
ANS:
98
#define MAX_TRIES 10 void write_delay(void); void Init_I2C(void); void write_eeprom(unsigned char address, unsigned char dat); unsigned char read_eeprom(unsigned char address); extern int sendchar (int ch); extern void usart_init(void); int eeprom_read_byte(unsigned char eeaddr); int eeprom_write_byte(unsigned char eeaddr, char buf); void write_ee_string(unsigned char *s, unsigned char length); /*************************** MAIN ******************************************/ int main() { unsigned char eeval[8]; char i; usart_init(); Init_I2C(); write_ee_string("MRR'ARM7-LPC2148",16); while(1) { printf("I2C AT24C02: "); for(i=0;i<=15;i++) eeval[i]=eeprom_read_byte(i); for(i=0;i<=15;i++) sendchar(eeval[i]); printf("\n"); } }
// Set Pin 22 as SCL and Pin 26 as SDA //Enable the I2C interface
99
// Set count for SCL High period // FF for about 100 kHz I2C clock, High and Low time equal I2SCLL = 0x93; // Set count for SCL Low period // FF for about 100 kHz I2C clock }
*/
100
// send start cond. I2CONSET = 0x60; while (I2STAT!=REP_START); if (I2STAT == ARB_LOST) goto begin; if ( (I2STAT != REP_START) && (I2STAT != START)) { return -1; } I2DAT = 0xad; I2CONCLR = 0x2C; // Clear Interrup Flag and Start Flag while (I2STAT!=SLA_READ_ACK); if (I2STAT == SLA_READ_NACK) goto quit; if (I2STAT == ARB_LOST) goto begin; if (I2STAT != SLA_READ_ACK) goto errorfunc; // start read transmission I2CONCLR = 0x08; while (I2STAT!=0x58); buf=I2DAT; quit: //stop condition I2CONSET=0x10; I2CONCLR=0x0c; return buf; errorfunc: //stop condition I2CONSET=0x10; I2CONCLR=0x0c; return -1; }
101
I2CONCLR = 0x28; // Clear interrupt Flag and Start Flag while (I2STAT!=0x18); if (I2STAT == SLA_NACK) goto restart; if (I2STAT == ARB_LOST) goto begin; if (I2STAT != SLA_ACK) goto errorfunc; I2DAT = eeaddr; I2CONCLR=0x08; // Clear interrupt Flag while (I2STAT!= DATA_ACK); if (I2STAT == DATA_NACK) goto quit; if (I2STAT == ARB_LOST) goto begin; if (I2STAT != DATA_ACK) goto errorfunc; // put byte into data register and start transmission I2DAT = buf; I2CONCLR = 0x08; while (I2STAT!= DATA_ACK); //while(1){DISPHEX(I2STAT);} if (I2STAT != DATA_ACK) goto errorfunc; quit: // send stop condition I2CONSET=0x10; I2CONCLR=0x0c; return 1; errorfunc: // send stop condition I2CONSET=0x10; I2CONCLR=0x0c; return -1; }
102
OUTPUT: The Controller writes a string MRRs LPC2148BRD to the EEPROM via I2C bus, reads back and displays in the UART1 CONCLUSION:
You can change the string to be written to the EEPROM in the main function.
103
Exercise 13: AIM: Write a Program for Transmission and reception from the serial port MRRs 2148 Syllabus Board has serial port UART1 than can be connected to the COM port using Serial cable. HARDWARE CONFIGURATION: UART1 OUTPUT : MAX3232 : UART1
/***************************************************************************/ /* HELLO.C: Hello World Example /***************************************************************************/ #include <stdio.h> #include <LPC21xx.H> extern int sendchar (int ch); int main (void) { /* execution starts here */ */ */ */ */ /* prototype declarations for I/O functions */ /* LPC21xx definitions */
/* initialize the serial interface */ PINSEL0 = 0x00050005; /* Enable RxD1 and TxD1 U1LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit U1DLL = 97; /* 9600 Baud Rate @ 15MHz VPB Clock U1LCR = 0x03; /* DLAB = 0 while (1) {
104
*/
/***************************************************************************/ /* SERIAL.C: Low Level Serial Routines */ /***************************************************************************/ #include <LPC21xx.H> #define CR 0x0D { /* Write character to Serial Port */ /* LPC21xx definitions */
if (ch == '\n') { while (!(U1LSR & 0x20)); U1THR = CR; } while (!(U1LSR & 0x20)); return (U1THR = ch); } int getkey (void) {
/* output CR */
*/
while (!(U1LSR & 0x01)); return (U1RBR); } /***************************************************************************/ /* RETARGET.C: 'Retarget' layer for target-dependent low level functions */ /**************************************************************************/ #include <stdio.h> #include <rt_misc.h> #pragma import(__use_no_semihosting_swi) extern int sendchar(int ch); /* in serial.c */
struct __FILE { int handle; /* Add whatever you need here */ }; FILE __stdout; int fputc(int ch, FILE *f) { return (sendchar(ch)); } int ferror(FILE *f) { /* Your implementation of ferror */ return EOF; } void _ttywrch(int ch) { sendchar(ch);
105
OUTPUT: The Controller writes a string Hello World to serial port UART1 CONCLUSION:
You can change the string to be written to the serial port in the main program.
106
Exercise 14: AIM: Write a Program for PWM generation MRRs 2148 Syllabus Board has J19 for PWM Out HARDWARE CONFIGURATION: PWM CONNECTOR OUTPUT : J19 : PWM Pulse
ANS: #include <LPC21XX.H> /***************************************************************************/ /* Main Program PWM Generation */ /**************************************************************************/ int main(void) { unsigned int val,delay; PINSEL0 |= 0x00028000; PWMPR = 0x00000001; PWMPCR = 0x0000404; enabled PWMMCR PWMMR0 PWMMR1 PWMMR2 PWMLER PWMEMR PWMTCR PWMTCR = = = = = = = = 0x00000003; 0x000000FF; 0x00000080; 0x00000080; 0x00000007; 0x00000280; 0x00000002; 0x00000009; //Enable pin 0.7 //Load prescaler as PWM2
//PWM channel 2 double edge control, output //On match with timer reset the counter //set cycle rate to sixteen ticks //set rising edge of PWM2 to 2 ticks //set falling edge of PWM2 to 8 ticks //enable shadow latch for match 0 - 2 //Match 1 and Match 2 outputs set high //Reset counter and prescaler //enable counter and PWM, release counter from reset
107
ADCR ADCR
= 0x00250601; |= 0x01000000;
while(1) // main loop { for (delay=0;delay < 0x100;delay++) { ; } do { val = ADDR; } while ((val & 0x80000000) == 0); complete val = ((val >> 8) & 0x00FF); PWMMR1 = 0x00000000+val; PWMMR2 = 0x000000FF-val; PWMLER = 0x00000006; } }
// Read A/D Data Register //Wait for the conversion to //Extract the A/D result //Modulate PWM
OUTPUT: The Controller generates a PWM pulse on DAC Output pin. CONCLUSION:
You can change the values in the PWM registers for changing the PWM width.
108
RTOS Exercise1: AIM: Write a RTOS Program for blinking two LED MRRs 2148 Syllabus Board has microcontrollers PORT P1.16 P1.23 HARDWARE CONFIGURATION: LED0-LED7 JUMPER CLOSE JUMPER OPEN SCHEMATIC: : P1.16 to P1.23 : JP6, JP7,JP8, JP9,JP10,JP11,JP12,JP13,JP14,JP15 : JP17-JP22, J40&JP43, and JP46 JP49 8 LEDs Connected to
/***************************************************************************/ /* RTOS Program Blinking two leds */ /**************************************************************************/ #include <includes.h> //#include "includes.h" //#include "lcd_image.h" /**************************************************************************/ //VARIABLES ****************************************************************************/ OS_STK Task1stk[1023]; OS_STK Task2stk[1023]; OS_STK Task3stk[1023]; //char arr[]="\nADC0 VALUE --->"; /**************************************************************************/ FUNCTION PROTOTYPES /**************************************************************************/ void Task1(void *pdata);
109
void Task2(void *pdata); void Task3(void *pdata); void serial_tr(char ); void adc_serial_tx(); /**************************************************************************/ void main (void) { BSP_IntDisAll(); OSInit(); OSTaskCreate(Task1,0,&Task1stk[1023],45); OSTaskCreate(Task2,0,&Task2stk[1023],35); OSTaskCreate(Task3,0,&Task3stk[1023],25); OSStart(); } void delay() { for(int i=0x00;i<=0xff;i++) for(int j=0x00;j<=0xFf;j++); } /**************************************************************************** * STARTUP TASK * * Description : This is an example of a startup task. As mentioned in the book's text, you MUST * initialize the ticker only once multitasking has started. * Arguments : p_arg is the argument passed to 'Task()' by 'OSTaskCreate()'. * Notes : 1) The first line of code is used to prevent a compiler warning because 'p_arg' is not * used. The compiler should not generate any code for this statement. * 2) Interrupts are enabled once the task start because the Ibit of the CCR register was * set to 0 by 'OSTaskCreate()'. ***************************************************************************** **************************** */ void Task1(void *pdata) { IO1DIR=0XFF000000; while(1) { IO1PIN=0XFF000000; delay(); IO1PIN=0X00000000;
110
delay(); } } void Task2(void *pdata) { IO1DIR=0XFF000000; while(1) { IO1PIN=0X0F000000; delay(); IO1PIN=0X00000000; delay(); } } void Task3(void *pdata) { IO1DIR=0XFF000000; while(1) { IO1PIN=0XF0000000; delay(); IO1PIN=0X00000000; delay(); } }
OUTPUT : LED Blinking on the board Exercise RTOS Exercise2: A: Write a Program to use ADC and measure temperature sensor MRRs 2148 Syllabus Board has onboard ADC and LM35 Temperature sensor HARDWARE CONFIGURATION: ADC0 JUMPER CLOSE JUMPER OPEN OUTPUT
SCHEMATIC:
: : : :
111
/////////sample RTOS program for Blinking Temperature Sensor/////////// #include "includes.h" /*--------------------------------- Stack Declaration for 3 tasks -------------------*/ OS_STK Task1stk[100]; OS_STK Task2stk[100]; OS_STK Task3stk[100]; // OS_STK Task4stk[1000]; char speed = 30; /*--------------------------------- TASK Declaration ----------------------------*/ char data[17] = { 0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x 71}; void void void void Task1(void Task2(void Task3(void task4(void *pdata); *pdata); *pdata); *pdata);
//
112
void i2c(char addr,char dat) { char temp; I2C0CONSET = 0X20; temp = I2C0STAT; while(temp != 0x08) { temp = I2C0STAT; } I2C0DAT = addr; I2C0CONCLR = 0x28; temp = I2C0STAT; while(temp != 0x18) { temp = I2C0STAT; } I2C0DAT = dat; I2C0CONCLR = 0x08; temp = I2C0STAT; while(temp != 0x28) { temp = I2C0STAT; } I2C0CONSET = 0x10; I2C0CONCLR = 0x08; } /*--------------------------------- TASK1 Definition ------*/ void Task1(void *pdata) { LPC2148BSPInit(); for(;;) { for(int i = 0; i < 8; i++) { IO1SET |= 0x00010000 << i; OSTimeDly(30); IO1CLR |= 0x00010000 << i; OSTimeDly(30); } } } /*--------------------------------- TASK2 Definition ------*/ void Task2(void *pdata) {
-----------------------
-----------------------
113
for(;;) { printit("MRR Embedded Systems Pvt Ltd Chennai\r\n"); OSTimeDly(30); } } /*--------------------------------- TASK3 Definition ------*/ void Task3(void *pdata) { unsigned int adc1000,i,val; char address = 0x70; PINSEL0 |= 0x00000050; I2C0CONCLR = 0x6C; I2C0CONSET = 0x40; I2C0SCLH = 110; I2C0SCLL = 90; PINSEL1 |= 0x15000000; AD0CR = 0x01270E06; for(;;) { val = (AD0DR>>6)& 0x3ff; i=1000; do { adc1000 = val / i; i2c(address,data[adc1000]); val = val % i; i = i / 10; address = address + 0x02; if(address > 0x76) { address = 0x70; } }while(i!=0x00); OSTimeDly(20); } } void Task4(void *pdata) { unsigned int val1; for(;;) { val1 = (AD0DR >> 6)& 0x3ff; speed = val1 / 10; } } -----------------------
// // // // // // // // //
114
----------------------
//
LPC2148Dissall(); OSInit(); OSTaskCreate(Task1, 0, &Task1stk[99], 0); OSTaskCreate(Task2, 0, &Task2stk[99], 1); OSTaskCreate(Task3, 0, &Task3stk[99], 2); OSTaskCreate(Task4, 0, &Task4stk[999], 3); OSStart(); }
----------------------------
//////////////////////// sample RTOS program for Blinking 3 LED from 3 different tasks /////////// #include "includes.h" /*--------------------------------- Stack Declaration for 3 tasks -------------------*/ OS_STK Task1stk[100]; OS_STK Task2stk[100]; OS_STK Task3stk[100]; // OS_STK Task4stk[1000]; char speed = 30; /*--------------------------------- TASK Declaration ----------------------------*/ char data[17] = { 0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x 71}; void Task1(void *pdata); void Task2(void *pdata); void Task3(void *pdata); void task4(void *pdata);
//
void i2c(char addr,char dat) { char temp; I2C0CONSET = 0X20; temp = I2C0STAT; while(temp != 0x08)
115
{ temp = I2C0STAT; } I2C0DAT = addr; I2C0CONCLR = 0x28; temp = I2C0STAT; while(temp != 0x18) { temp = I2C0STAT; } I2C0DAT = dat; I2C0CONCLR = 0x08; temp = I2C0STAT; while(temp != 0x28) { temp = I2C0STAT; } I2C0CONSET = 0x10; I2C0CONCLR = 0x08; } /*--------------------------------- TASK1 Definition ------*/ void Task1(void *pdata) { LPC2148BSPInit(); for(;;) { for(int i = 0; i < 8; i++) { IO1SET |= 0x00010000 << i; OSTimeDly(30); IO1CLR |= 0x00010000 << i; OSTimeDly(30); } } } /*--------------------------------- TASK2 Definition ------*/ ---------------------------------------------
void Task2(void *pdata) { for(;;) { printit("MRR Embedded Systems Pvt Ltd\r\n Perungudi\r\n Chennai\r\n"); OSTimeDly(30); } }
116
/*--------------------------------- TASK3 Definition ------*/ void Task3(void *pdata) { unsigned int adc1000,i,val; char address = 0x70; PINSEL0 |= 0x00000050; I2C0CONCLR = 0x6C; I2C0CONSET = 0x40; I2C0SCLH = 110; I2C0SCLL = 90; PINSEL1 |= 0x15000000; AD0CR = 0x01270E06; for(;;) { val = (AD0DR>>6)& 0x3ff; i=1000; do { adc1000 = val / i; i2c(address,data[adc1000]); val = val % i; i = i / 10; address = address + 0x02; if(address > 0x76) { address = 0x70; } }while(i!=0x00); OSTimeDly(20); } } void Task4(void *pdata) { unsigned int val1; for(;;) { val1 = (AD0DR >> 6)& 0x3ff; speed = val1 / 10; } }
-----------------------
// // // // // // // // //
----------------------
LPC2148Dissall();
117
//
OSInit(); OSTaskCreate(Task1, 0, &Task1stk[99], 0); OSTaskCreate(Task2, 0, &Task2stk[99], 1); OSTaskCreate(Task3, 0, &Task3stk[99], 2); OSTaskCreate(Task4, 0, &Task4stk[999], 3); OSStart(); }
118
119