You are on page 1of 213

____________________________________________________________________________

AT91RM9200
Workbook
____________________________________________________________________________

1. Overview of ARM9 Architecture


1.1 Introduction
The AT91RM9200 microcontroller offers a flexible configuration of on- and off-chip
memories together with an extensive set of peripherals for control, communication
and data storage purposes.
It is based on the ARM920T 200-MIPS advanced 32-bit RISC processor with 16K byte
instruction and 16K byte data cache memories. It features 16K bytes of on-chip
SRAM and 128K bytes of ROM, together with an external bus interface with
controllers for SDRAM and static memories including NAND Flash and CompactFlash.
Its extensive peripheral set includes USB Full Speed Host and Device Ports, 10/100
Base T Ethernet MAC, Multimedia Card Interface (MCI), three Synchronous Serial
Controllers (SSC), four USARTs, Master/Slave Serial Peripheral Interface (SPI), Timer
Counters (TC) and Two Wire Interface (TWI). Four 32-bit Parallel I/O Controllers
multiplex the pins to/from these peripherals in order to reduce the device pin count,
and peripheral DMA channels maximize the data throughput between these
interfaces and the on- and off-chip memories.
The AT91RM9200 has a fully featured system controller for efficient system
management, including two on-chip oscillators and PLLs, clock generator, advanced
interrupt controller (AIC), debug unit (DBGU), periodic interval timer, watchdog timer
and real-time clock with alarm interrupt. It is supplied in a 208-pin PQFP or 266-ball
BGA package.
The AT91RM9200 is supported by the AT91RM9200-EK Evaluation Board and
extensive third-party application development tools. It supports both Linux and
Windows CE. It targets applications requiring enhanced performance such as host
processors for system control and connectivity. Examples include telematics systems
connecting GPS receivers and GPRS communications, industrial automation, medical
systems and point-of-sales terminals. It can also be used in conjunction with Atmels
Finger Chip fingerprint sensor for advanced biometrics-based security applications.

______________________________________________________________
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

1.2 Features of ARM9 Core


Incorporates the ARM920T ARM Thumb Processor
1. 200 MIPS at 180 MHz, Memory Management Unit
2. 16-KByte Data Cache, 16-KByte Instruction Cache, Write Buffer
3. In-circuit Emulator including Debug Communication Channel
Low Power: 30.4 mA on VDDCORE, 3.1 mA in Standby Mode
Additional Embedded Memories
1. 16K Bytes of SRAM and 128K Bytes of ROM
External Bus Interface (EBI)
1. Supports SDRAM, Static Memory, Burst Flash, Glueless Connection to
CompactFlash, SmartMedia and NAND Flash
System Peripherals for Enhanced Performance:
1. Enhanced Clock Generator and Power Management Controller
2. Two On-chip Oscillators with Two PLLs
3. Very Slow Clock Operating Mode and Software Power Optimization
Capabilities
4. Four Programmable External Clock Signals
5. System Timer Including Periodic Interrupt, Watchdog and Second Counter
6. Real-time Clock with Alarm Interrupt
7. Debug Unit, Two-wire UART and Support for Debug Communication Channel
8. Advanced Interrupt Controller with 8-level Priority, Individually Maskable
Vectored Interrupt Sources, Spurious Interrupt Protected Seven External
Interrupt Sources and One Fast Interrupt Source
9. Four 32-bit PIO Controllers with Up to 122 Programmable I/O Lines, Input
Change Interrupt and Open-drain Capability on Each Line
10. 20-channel Peripheral Data Controller (DMA)

______________________________________________________________
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Ethernet MAC 10/100 Base-T


1. Media Independent Interface (MII) or Reduced Media Independent Interface
(RMII)
2. Integrated 28-byte FIFOs and Dedicated DMA Channels for Receive and
Transmit
USB 2.0 Full Speed (12 Mbits per second) Host Double Port
1. Dual On-chip Transceivers (Single Port Only on 208-lead PQFP Package)
2. Integrated FIFOs and Dedicated DMA Channels

USB 2.0 Full Speed (12 Mbits per second) Device Port
1. On-chip Transceiver, 2-Kbyte Configurable Integrated FIFOs
Multimedia Card Interface (MCI)
1. Automatic Protocol Control and Fast Automatic Data Transfers
2. MMC and SD Memory Card-compliant, Supports Up to Two SD Memory Cards
Three Synchronous Serial Controllers (SSC)
1. Independent Clock and Frame Sync Signals for Each Receiver and Transmitter
2. I2S Analog Interface Support, Time Division Multiplex Support
3. High-speed Continuous Data Stream Capabilities with 32-bit Data Transfer
Four Universal Synchronous/Asynchronous Receiver/Transmitters (USART)
1. Support for ISO7816 T0/T1 Smart Card
2. Hardware and Software Handshaking
3. RS485 Support, IrDA Up To 115 Kbps
4. Full Modem Control Lines on USART1
Master/Slave Serial Peripheral Interface (SPI)
1. 8- to 16-bit Programmable Data Length, 4 External Peripheral Chip Selects
Two 3-channel, 16-bit Timer/Counters (TC)

______________________________________________________________
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

1. Three External Clock Inputs, Two Multi-purpose I/O Pins per Channel
2. Double PWM Generation, Capture/Waveform Mode, Up/Down Capability
Two-wire Interface (TWI)
1. Master Mode Support, All 2-wire Atmel EEPROMs Supported
IEEE 1149.1 JTAG Boundary Scan on All Digital Pins
Power Supplies
1. 1.65V to 1.95V for VDDCORE, VDDOSC and VDDPLL
2. 1.65V to 3.6V for VDDIOP (Peripheral I/Os) and for VDDIOM (Memory I/Os)
Available in a 208-lead PQFP or 256-ball BGA Package

______________________________________________________________
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

1.3 CPU Block Diagram :

______________________________________________________________
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

1.4 ARM9TDMI Processor Details:


1.4.1 Instruction Type
Instructions are either 32 bits (in ARM state) or 16 bits (in Thumb state).
1.4.2 Data Types
ARM9TDMI supports byte (8-bit), half-word (16-bit) and word (32-bit) data types.
Words must be aligned to four-byte boundaries and half-words to two-byte
boundaries.
Unaligned data access behavior depends on which instruction is used in a particular
location.
1.4.3 ARM9TDMI Operating Modes
The ARM9TDMI, based on ARM architecture v4T, supports seven processor modes:
User: Standard ARM program execution state
FIQ: Designed to support high-speed data transfer or channel processes
IRQ: Used for general-purpose interrupt handling
Supervisor: Protected mode for the operating system
Abort mode: Implements virtual memory and/or memory protection
System: A privileged user mode for the operating system
Undefined: Supports software emulation of hardware coprocessors
Mode changes may be made under software control, or may be brought about by
external interrupts or exception processing. Most application programs will execute in
User Mode. The non-user modes, known as privileged modes, are entered in order to
service interrupts or exceptions or to access protected resources.
1.4.4 ARM9TDMI Registers
The ARM9TDMI processor core consists of a 32-bit data path and associated control
logic. That data path contains 31 general-purpose registers, coupled to a full shifter,
Arithmetic Logic Unit and multiplier.
At any one time, 16 registers are visible to the user. The remainder is synonyms
used to speed up exception processing.

______________________________________________________________
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Register 15 is the Program Counter (PC) and can be used in all instructions to
reference data relative to the current instruction.
R14 holds the return address after a subroutine call.
R13 is used (by software convention) as a stack pointer.
1.4.4.1 Registers used in Operating Modes:

Register R0 to R7 are unbanked registers, thus each of them refers to the same 32bit physical register in all processor modes. They are general purpose registers, with
no special uses managed by the architecture, and can be used wherever an
instruction allows a general purpose register to be specified.

______________________________________________________________
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Registers R8 to R14 are banked registers. This means that each of them depends of
the current processor mode.
1.4.4.2 Modes and Exception Handling
All exceptions have banked registers for R14 and R13.
After an exception, R14 holds the return address for exception processing. This
address is used both to return after the exception is processed and to address the
instruction that caused the exception.
R13 is banked across exception modes to provide each exception handler with a
private stack pointer.
The fast interrupt mode also banks registers 8 to 12 so that interrupt processing can
begin without the need to save these registers.
A seventh processing mode, System Mode, does not have any banked registers. It
uses the User Mode registers. System Mode runs tasks that require a privileged
processor mode and allows them to invoke all classes of exceptions.
1.4.4.3 Status Registers
All other processor states are held in status registers. The current operating
processor status is in the Current Program Status Register (CPSR). The CPSR holds:
Four ALU flags (Negative, Zero, Carry, and Overflow),
Two interrupt disable bits (one for each type of interrupt),
One bit to indicate ARM or Thumb execution
Five bits to encode the current processor mode
All five exception modes also have a Saved Program Status Register (SPSR) which
holds the CPSR of the task immediately before the exception occurred.

______________________________________________________________
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

1.4.5 Exception Types


The ARM9TDMI supports five types of exceptions and a privileged processing mode
for each type. The types of exceptions are:
Fast interrupt (FIQ)
Normal interrupt (IRQ)
Memory aborts (used to implement memory protection or virtual memory)
Attempted execution of an undefined instruction
Software interrupt (SWIs)
Exceptions are generated by internal and external sources.
More than one exception can occur at the same time.
When an exception occurs, the banked version of R14 and the SPSR for the
exception mode are used to save the state.
To return after handling the exception, the SPSR is moved to the CPSR and R14 is
moved to the PC. This can be done in two ways:
Use of a data-processing instruction with the S-bit set, and the PC as the
destination
Use of the Load Multiple with Restore CPSR instruction (LDM)
1.4.6 ARM Instruction Set Overview
The ARM instruction set is divided into:
Branch instructions
Data processing instructions
Status register transfer instructions
Load and Store instructions
Coprocessor instructions
Exception-generating instructions
ARM instructions can be executed conditionally. Every instruction contains a 4-bit
condition code field (bits [31:28]).

______________________________________________________________
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

1.4.6.1 ARM Instructions List

______________________________________________________________ 10
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

1.4.7 Thumb Instruction Set Overview


The Thumb instruction set is a re-encoded subset of the ARM instruction set.
The Thumb instruction set is divided into:
Branch instructions
Data processing instructions
Load and Store instructions
Load and Store multiple instructions
Exception-generating instruction
In Thumb mode, eight general-purpose registers are available, R0 to R7, that are the
same physical registers as R0 to R7 when executing ARM instructions. Some Thumb
instructions also access the Program Counter (ARM Register 15), the Link Register
(ARM Register 14) and the Stack Pointer (ARM Register 13). Further instructions
allow limited access to the ARM register 8 to 15.
1.4.7.1 Thumb Instruction List

______________________________________________________________ 11
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

1.4.8 Memory Management Unit (MMU)


The ARM920T processor implements an enhanced ARM architecture v4 MMU to
provide translation and access permission checks for the instruction and data address
ports of the ARM9TDMI core. The MMU is controlled from a single set of two-level
page tables stored in the main memory, providing a single address and translation
protection scheme. Independently, instruction and data TLBs in the MMU can be
locked and flushed.

1.4.8.1 Domain
A domain is a collection of sections and pages. The ARM920T supports 16 domains.
Access to the domains is controlled by the Domain Access Control register.
1.4.8.2 MMU Faults
The MMU generates alignment faults, translation faults, domain faults and
permission faults.
Alignment fault checking is not affected by whether the MMU is enabled or not.
The access controls of the MMU detect the conditions that produce these faults. If
the fault is a result of memory access, the MMU aborts the access and signals the
fault to the CPU core. The MMU stores the status and address fault in the FSR and
FAR registers (only for faults generated by data access).
The MMU does not store fault information about faults generated by an instruction
fetch.

______________________________________________________________ 12
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

1.4.9 CPU Pin Details

______________________________________________________________ 13
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

______________________________________________________________ 14
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

2. EPBARM9 Target System


2.1 Introduction to ARM9 Target System
The ARM9 board is intended for use in evaluation of the ARM9 core and peripherals
and developing prototypes using proven reference design platform. The standard kit
includes the development boards, serial cable, and distribution CD. The serial cable
allows simple program download and debug support from a standard serial terminal
which is independent of the host operation system. The distribution CD includes
sample source programs, and building cross-compiler tool chain and reference Linux
kernel.
2.2 The ARM9 Board Features

180 MHz, 200 MIPS ARM9 highly-integrated core (AT91RM9200)


Independent 16KB instruction and 16KB data caches
32 MB SDRAM memory
8 MB parallel Flash memory
SD/MMC card support
10/100 Ethernet
USB 2.0 full speed host port
USB 2.0 full speed device port
RS-232 serial, dual transceiver, two DB9 connector
16KB boot EEPROM with boot loader
16KB internal SRAM
128KB internal ROM
Many signals available on 20 pin connector
Core clock up to 180 MHz
On- chip RTC and DMA
JTAG connector

2.3 Memory Detail


Memory Type
Internal SRAM
Internal ROM
External SDRAM
ROM/Flash size

Size
16kB
128kB
32MB
8MB

Start address
0x00200000
0x00100000
0x20000000
0x10000000

End address
0x0021f400
0x001fa000
0x22000000
0x10400000

______________________________________________________________ 15
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

2.4 Peripheral Detail


Type

Reference

USB Device Port

J4

Memory Location
Start
End
0XFFFB0000
0XFFFB4000

ID

USB Host Port

J5

0XFFFB0000

0XFFFB4000

23

Ethernet

J13

0XFFFBC000

0XFFFC0000

24

UART0

J3

0XFFFC0000

0XFFFC4000

06

DBGU

J1

0XFFFFF200

0XFFFFF400

07

TWI

U8

0XFFFB8000

0XFFFBC000

12

SPI

J8

0XFFFE0000

0XFFFE4000

13

MCI

J6

0XFFB4000

0XFFFB8000

10

SSC

J7

0XFFFD0000

0XFFFD4000

14

PORT A

J11

0XFFFFF400

0XFFFFF600

02

PORT B

J12

0XFFFFF000

0XFFFFF800

03

11

______________________________________________________________ 16
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

2.5 Board Layout

2.6 Detailed On-Board Peripheral Information


2.6.1 SDRAM
The 32 MB SDRAM is allocated at address 0x20000000. The devices are configured
during the auto-boot operation.
2.6.2 Parallel FLASH
The 8 MB parallel FLASH is allocated at address 0x10000000. The devices can be
erased and programmed using the U-boot utility.
2.6.3 USB full speed host port
This device is controlled by the internal register of the AT91Rm9200. The power
available for USB host port does not provide over current detection prevention as
specified in the USB spec. The supply is internally protected against over-current
conditions and can optionally be disabled via jumper.

______________________________________________________________ 17
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

2.6.4 Power Supply


Type: SMPS
Ratings: 5 Volt and 1 Ampere
2.6.5 Jumper Setting:

Power Jumper: JMP4 and JMP5, connect this jumper which is near supply on
board.

Booting Selection Jumper: JMP1, selection of booting procedure


EEPROM selection jumper: JMP6, to connect EEPROM short this jumper
JTAG selection jumper: JMP1, to select JTAG connect this jumper.
Flash selection jumper: JP6, to select the External Flash connect this
Jumper.
2.7 Connector information
There are different connectors on the target system. The details for each connector
are shown below:

______________________________________________________________ 18
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

2.7.1 GPIO Connector J11


PIN
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

Signal
PA0
PA1
PA2
PA3
PA4
PA5
PA6
PA17
PA18
PA19
PA20
PA21
PA22
PA23
PA24
PA25
PA26
3.3V
5.0 V
GND

Function
MISO/PCK3
MOSI/PCK0
SPCK/IRQ4
NPCS0/IRQ5
NPCS1/PCK1
NPCS2/TXD3
NPCS3/RXD3
TXD0/TIOA0
RXD0/TIOB0
SCK0/TIOA1
CTS0/TIOB1
RTS0/TIOA2
RXD2/TIOB2
TXD2/IRQ3
SCK2/PCK1
TWD/IRQ2
TWCK/IRQ1

______________________________________________________________ 19
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

2.7.2 GPIO Connector J12


PIN
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

SIGNAL
PB0
PB1
PB2
PB3
PB4
PB5
PB6
PB7
PB8
PB9
PB10
PB11
PB20
PB21
PB22
PB23
PB24
3.3V
5.0V
GND

FUNCTION
TF0/RTS3
TK0/CTS3
TD0/SCK3
RD0/MCDA1
RK0/MCDA2
RF0/MCDA3
TF1/TIOA3
TK1/TIOA3
TD1/TIOA4
RD1/TIOB4
RK1/TIOA5
RF1/TIOB5
TXD1
RXD1
SCK1
DCD1
CTS1

______________________________________________________________ 20
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

2.7.3 JTAG connector J10


PIN
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

SIGNAL
3.3V
3.3V
NTRST
GND
TDI
GND
TMS
GND
TCK
GND
GND
GND
TDO
GND
NRST
GND
NC
GND
NC
GND

2.7.4 MMC Connector J6


Pin
1
2
3
4
5
6
7
8
9
10

signal
Pa27
Pa28
Pa29
Pb3
Pb4
Pb5
Vcc
Gnd
Vcc
Gnd

function
MCCK
MCCDA
MCDA0
MCDA1
MCDA2
MCDA3
3.3
Gnd
3.3
Gnd

______________________________________________________________ 21
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

2.7.5 SCC J7
Pin
1
2
3
4
5
6
7
8
9
10

Signal
Pb8
Pb9
Pb10
Pb11
Pb12

function
TDI
RDI
TK
RK1
TF1

3. Unpacking the ARM9 Target Board


The Educational Practice Board for ARM9 (ARM920T) target is a self learning and
developing tool to learn the ARM9 core and Embedded Linux. The following is the list
of the items provided with the target:

ARM9 Target System


5V SMPS Power Supply
Serial Cable
Ethernet Cable
DVD
User Manual

______________________________________________________________ 22
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

4. Viewing CD Contents
4.1 Introduction:
The distribution DVD contains all the necessary files required to work with the ARM9
target systems. The following is the list of the contents:

Images
ARM-9 Tool Chain
source code
Setup Utilities
Board manual

4.1.1 Folder Description


Images
stage1.bin
u-boot.bin
rammonitor.bin
ramtest.bin
bootloader.bin
uImage/ linux-2.6.20.4
jffs2

: binary image file to first time boot the board.


: It is image for U-boot.
: Image file for boot loader
: Linux kernel image
: file system image with examples

ARM-9 tool chain


buildroot.tar.bz
Source Code
This folder contains the source code of different lab sessions (.c files)
Copy sourcecode\lab to /home directory of your LINUX host PC.
Copy sourcecode\exercises to /home directory of your LINUX host PC.
Copy sourcecode\IDEexample folder to your D:\ drive of your windows
PC.
Setup

Utilities
tftp32 utility
winscp utility
putty utility
ARM IDE setup

Board manual
ARM9 board manual
Note:
Here programs given in the CD content at sourcecode/exercises folder/directory
are the reference programs for the exercises given after each lab programs.

______________________________________________________________ 23
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

5. ARM9 software setup


Installing the software used for ARM-9 board involves following steps

Installing
Installing
Installing
Installing

the
the
the
the

toolchain for ARM-9


winscp utility
putty utility
tftp32 utility

5.1 Installing the ARM9 tool chain

This session explains how to install toolchain for ARM-9 target board
Note that separate version of Linux are used by the target and the host Linux
PC.
The following Linux host operating system is supported for use with the
ARM9 target board.
o

Open SUSE 11.0

To install the ARM9 toolchain, follow this step:1. Log in as root on your host Linux PC.
2. Copy the build_root.tar from the Edutech DVD to the /opt folder.
3. Now type the following command to Un-tar (Un-zip) the build_root.tar
4. [root@EDUTECH] tar vxf build_root.tar.
5. This command will take approx 5 min for execution.
6. After executing this command you will see a folder build_root in the /opt
folder.
7. As the folder is created, it means your toolchain has successfully installed.

______________________________________________________________ 24
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

5.2 Installing the WinSCP utility


OBJECTIVE: HOW TO INSTALL WinSCP. PROCEDURE:
1. Copy the set up from the Edutech DVD/CD ,and paste it on your desktop.
2. Then click on WinSCP icon.

3.Then you will be able to see the above window.

______________________________________________________________ 25
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

4. Now click on the Next button ,then you see the below window.

5. Again click on Next button ,you will see the below window.

______________________________________________________________ 26
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

6. Now select the Norton Commander interface and click Next and you will see
below window.

______________________________________________________________ 27
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

7. Now
Click the Install button.

8. Now select the Yes, restart the computer now and click on Finish button.
9. Now click on the Icon as soon below, from your desktop.

Winscp.lnk

______________________________________________________________ 28
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

10. After clicking that Icon you will see the below window.

10
11. Enter the Host name:, User

name: and Password: and click Login.

______________________________________________________________ 29
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

12. After Login, you will see the below window. In this window on right hand side is
the Linux window/Host window, left hand side is the Window PC window/remote
window. Now you can copy your data from Host PC to Remote PC and Via-Versa.

______________________________________________________________ 30
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

5.3 Installing the putty utility


PROCEDURE:
1. Copy the set up from the DVD/CD ,and paste it on your desktop.
2. Then click on PUTTY icon.
3. Then you will be able to see the below window.
4. Now enter the I.P. address ,and press OPEN.

______________________________________________________________ 31
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

5. Enter the login name and password

______________________________________________________________ 32
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

6.Now you can access the remote PC.

______________________________________________________________ 33
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

5.4 Installation of tftp32 utility


The Tftp Protocol
TFTP (Trivial File Transfer Protocol) is a simple protocol used to transfer files to and
from a TFTP server (daemon).
TFTP is designed to be compact and easy to implement. Therefore, it lacks most of
the features of a regular FTP. The only thing it can do is read and write files from/to
a remote server. It cannot list directories, and currently has no provisions for user
authentication.
TFTPD32 is a TFTP server for Windows 95/98/Me and Windows NT/2000/XP.
Installation of tftp32:1. Copy the TFTPUtility folder from DVD to your windows PC.
2. Put that folder to C:\
3. And also make shortcut of tftp32Utility on your desktop.

Shortcut to tftpd32.exe.lnk

4. Double click on shortcut of tftp32 icon. You will below screen

______________________________________________________________ 34
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

5. Click on browse option and select appropriate path from which you want to
transfer the file to ARM9 target system.

6. After selecting appropriate file click OK.


7. Now verify that you have selected correct files by clicking on showdir
button. As shown below.

______________________________________________________________ 35
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

5.5 Installation of Complete Setup of ARM IDE


5.5.1 Recommended PC configuration:

1GHz 32 bit (x86) or 64 bit (x64) processor.


256 MB system memory.
20 GB hard drive with at least 1 GB of available space.
CD ROM drive.
1 USB2.0 port.
Windows ME/NT/2000/XP

5.5.2 Additional software requirement: If a window ME/NT/2000/XP is used, you must have to
download the windows installer in your PC.
For installing ARM IDE you must check whether .NET Frame
Work is installed in your PC. If it is not installed, see the
procedure given below.
5.5.3 Installation of .NET Frame Work: Open the CD ROM.
Double click on the dotnetfx folder shown below.

Click on the Next.

click on Install.

______________________________________________________________ 36
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Click on finish.
Now .NET Frame Work is installed in your PC.

______________________________________________________________ 37
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

5.5.4 Installation of ARM IDE :

Open the CD ROM.


Double click on ARM IDE setup folder.
Double click on setup folder shown below.

Click on Next.

______________________________________________________________ 38
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Select the path to store ARM IDE setup using Browse button shown below
then click on Next.

______________________________________________________________ 39
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Click on Next.

Click on Close.

______________________________________________________________ 40
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Now ARM IDE is installed in your PC and shortcut IDE.exe folder shown
below will automatically generate on your Desktop.

5.5.5 Uninstallation of ARM IDE:

Go to control panel.
Click on change or remove program.
Find ARM IDE setup then click Remove.
Now ARM IDE is uninstalled from your PC.

______________________________________________________________ 41
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

6. Setting up hardware
6.1 Board Operation Steps:

First check whether the Power Supply is +5 v or not by multimeter

Now Disconnect JMP4 & JMP5

Connect power supply

Check voltage at the body of U2 = 3.3v, U3 = 1.8v by multimeter

Connect back jumper JMP 4 & JMP 5

Check jumper setting,


JP6-> short, JMP1 -> short 2 pins towards connector
JMP6-> short, JMP2 -> open, JMP3 -> open

Check LED3 status whether LED3 blink or not.(if not blink Ethernet error)

Connect serial cable J1 to PC

Connect Ethernet J13 to PCs Ethernet connector

______________________________________________________________ 42
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

7. Executing a simple program


7.1 Executing a simple program using ARMIDE-Windows Environment.
7.1.1 Creating a new project using ARMIDE

Double click on IDE.exe folder on Desktop.

Click on Project menu then click on new project.

The window shown below will be generated. In Project name give your
project name and Project path section give path, where you want to save
your project then click on OK.
Note: - Make sure that path, which you have selected, does not contain any
space in folder name.

______________________________________________________________ 43
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

The window shown below will be generated. Click on Target Selection


then Select CORE(ARM9), Select Manufacturer(ATMEL), And Select
CPU(AT91RM9200).

______________________________________________________________ 44
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Click on Linker Option.


In Run mode :select ROM
In Out put :select Bin.
In Optimization select level of optimization like s,1,2,3. s is the slandered
optimization level.

Note: For ARM9 Target Board Select bin file as output file for program
execution.

Click on IDE Setting.


Select the MAKE File path shown below.
C:\ProgramFiles\Edutech\ARM_IDE\WinARM\realease\ARM9\ Makefile

Select the Linker File path shown below.


C:\Program Files\Edutech\ARM_IDE\WinARM\realease\ARM9\ AT91RM9200ROM.ld

______________________________________________________________ 45
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Select the Start up File path shown below.


C:\Program Files\Edutech\ARM_IDE\WinARM\realease\ARM9\ cstartup.S

______________________________________________________________ 46
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Now Editor Window, Project Window, Output Window will open automatically.

About Editor Window:- In this window you are allow to write your
program.

About Project Window:- In this window you will find Source Files, Library
Files, Command Files, Linker File, Start Up File and RTOS(if any). As shown
below you can add or remove any file by using right click on respected file.

About Output Window:- In this window you will find your output of project
after compiling it. If any error or warning in your project then you can see it
in this window.

______________________________________________________________ 47
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

7.1.2 WRITING A FIRST PROGRAM using ARMIDE

For writing programs first do all the step of creating a project section.
In Editor Window write a program.
Add required files from Project Window.
Click on compile menu then click on Build or Re Build.
See the Output Window. If you find Error None then go on next step
otherwise correct the error.

7.1.2.1 Program Execution on IDE:


To execute this program follow the steps
1. Connect the target board to the PC using serial cable. Use J1 connector
for serial connection.
2. Connect 5volt supply to J14 connector.
3. Set hyper terminal Parameter on windows PC in the following way
START ->ACCESSORIES->COMMUNICATION->HYPER TERMINAL.
Enter The Name :
Select COM PORT:
RESET Default
bits/sec:115200
Apply ok
It opens hyper terminal window
4. Power on the Target board.
5. Reset the board using RESET key PB1 of board , It will display
CCCCCCCCCC on window.
6. Depends on ASK board connect flat cable to J11 or J12 connector
accordingly
7. On hyper terminal window select TRANSFER option
transfer -> send file->protocol->X modem->Browse File->CD>ARM9-> LAB.bin->send

______________________________________________________________ 48
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Program:

#include <stdio.h>
int main(void)
{
int i;
for (i = 1; i <= 5 ; i++)
{
printf("C: Hello world!!! %d\n", i);
}
return 0;
}

______________________________________________________________ 49
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

7.2 Creating and Executing a simple program using Buildroot Tollchain On


linux environment
Program:

#include <stdio.h>
int main(void)
{
int i;
for (i = 1; i <= 5 ; i++)
{
printf("C: Hello Friends!!! %d\n", i);
}
return 0;
}

1. Open the terminal program


2. login as user using command
linux $su
type password
3. Make a folder for your program using command
linux $mkdir test
4. Open the Editor using command
linux/test $ vi test.c
Write a c program as show above & save it with .c extension
5. Now compile the C program using command
linux /test $ arm-linux-gcc test.c o test.o
Above command compile the program.
6. After compilation check whether object file is created or not by using command
linux $ ls
7. copy object file to /root/tftpboot
(put this file where the path of tftp server exist {at yast/ network service
/tftp server at there you will fine boot image ditectory})
______________________________________________________________ 50
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

$ cp test.o /root/tftpboot
8. to copy test.o to target board follow this command
[root@EDUTECH/home]: tftp g r test.o 192.168.0.96
[root@EDUTECH/home]: chmod 777 test.o
9.Execute the program from target board.
[root@EDUTECH/home]: ./test.o

______________________________________________________________ 51
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

8. Demo Example
8.1 Interfacing Basic Devices with ARM9 Target using IDE
8.1.1 SEVEN SEGMENT DISPLAY INTERFACING
Objective:
To study Seven Segment Display Interface with ARM9 target board:
Study of Seven Segment board
Study of Seven Segment Display interface with AT91rm9200
Writing C program to interface Seven Segment Display
Part List:

Procedure:

Educational practice board for ARM 9 target board.


Power supply
Serial cable
Flat cable
PC
Edutech IDE
Seven Segment Display Interface Board.

Write C program in editor window of ARMIDE, build it using


compile option.

To execute this program follow the steps


1. Connect the target board to the PC using serial cable. Use J1
connector for serial connection.
2. Connect 5volt supply to J14 connector.
3. Set hyper terminal Parameter on windows PC in the following
way:

______________________________________________________________ 52
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

START ->ACCESSORIES->COMMUNICATION->HYPER TERMINAL


Enter The Name:
Select COM PORT:
RESET Default
Bits/sec: 115200
Apply ok
It opens hyper terminal window

Power on the Target board


Reset the board using RESET key PB1.
Stop booting of board by pressing any key.
It will display C on hyper terminal window.
Connect the Seven Segment Display Interface Board to the
CPU target board as follows:

1) Connect J1 connector through


board.

flat cable to J12 connector of Target

2) Connect J2 connector through flat cable to J11 connector of Target


board.
Transfer the binary file to the target as shown:
Transfer -> send file->protocol->X modem->Browse File->D:\IDEexamples\ex1>7seg. bin->send

______________________________________________________________ 53
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Program Description:
This Program will display number 1234 on seven segment display
Pin Assignment:
Connection between Seven segment board J1 connector to J12 connector of target
board
J12 Connector of Target
Board
PA0
PA1
PA2
PA3
PA4
PA5
PA6
PA17
PA18
PA19
PA20
PA21
PA22
PA23
PA24
PA25
PA26
3.3V
5.0 V
GND

J1 Connector of Seven
Segment Board
N.C.
N.C.
N.C.
N.C.
N.C.
N.C.
N.C.
N.C.
N.C.
Digit 1
Digit 2
Digit 3
Digit 4
N.C.
N.C.
N.C.
N.C.
N.C
VCC
Ground

______________________________________________________________ 54
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

J2 connector of seven segments to J11 of target board


J11 Connector of Target
Board
PB0
PB1
PB2
PB3
PB4
PB5
PB6
PB7
PB8
PB9
PB10
PB11
PB20
PB21
PB22
PB23
PB24
3.3V
5.0V
GND

J2 Connector of Seven
Segment
Segment a
Segment b
Segment c
Segment d
Segment e
Segment f
Segment g
Segment dp
N.C.
N.C.
N.C.
N.C.
N.C.
N.C.
N.C.
N.C.
N.C.
N.C.
VCC
Ground

______________________________________________________________ 55
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Program Folder:
<EX1>
Program Listing:
#include"sevenseg.h"
#include <at91rm9200.h>
/*

include the particular header files */

void seg_init()
{
SEGMENTLINES1=0XFFFFFF;
SEGMENTLINES2=0XFFFFFF;
SEGMENTOUT1=0xFFFFFFFF;
SEGMENTOUT2=0xFFFFFFFF;
}
void seg1ment1(unsigned int a)
{
SEGMENTDATA1=0X007F;
SEGMENTSELECT1=0x00100E00;
SEGMENTDATA2=num[a];
SEGMENTSELECT2=SET(20);
}
void seg1ment2(unsigned int a)
{
SEGMENTDATA1=0X007F;
SEGMENTSELECT1=0x00100E00;
SEGMENTDATA2=num[a];
SEGMENTSELECT2=SET(11);
}
void seg1ment3(unsigned int a)
{
SEGMENTDATA1=0X007F;
SEGMENTSELECT1=0x00100E00;
SEGMENTDATA2=num[a];
SEGMENTSELECT2=SET(10);
}
void seg1ment4(unsigned int a)
{
SEGMENTDATA1=0X007F;
SEGMENTSELECT1=0x00100E00;
SEGMENTDATA2=num[a];
SEGMENTSELECT2=SET(9);
}

______________________________________________________________ 56
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________
void main()
{
seg_init();
while(1){
seg1ment4(1);
delay_ms(900);
seg1ment3(2);
delay_ms(900);
seg1ment2(3);
delay_ms(900);
seg1ment1(4);
delay_ms(900);}
}

______________________________________________________________ 57
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

8.1.2 LCD INTERFACING


Objective:
To study LCD Interface with ARM9 target board:
Study of LCD board
Study of LCD interface with AT91rm9200 Target Board
Writing C program to interface LCD
Part List:

Procedure:

Educational practice board for ARM 9 target board.


Power supply
Serial cable
Flat cable
PC
Edutech IDE
LCD Interface Board.

Write C program in editor window of ARMIDE, build it using compile


option.

To execute this program follow the steps as shown,


1. Connect the target board to the PC using serial cable. Use J1
connector for serial connection.
2. Connect 5volt supply to J14 connector.
3. Set hyper terminal Parameter on windows PC in the following
way

START->ACCESSORIES->COMMUNICATION->HYPER
TERMINAL.
Enter The Name:
Select COM PORT:
RESET Default
Bits/sec: 115200
Apply o k

______________________________________________________________ 58
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

It opens hyper terminal window

Power on the Target board


Reset the board using RESET key PB1.
Stop booting of board by pressing any key.
It will display C on hyper terminal window.
LCD Interface Board connection to target board as follows:
Connect J1 connector through flat cable to J11 connector of Target board.

Transfer binary file to Target Board.


->
send
file->protocol->X
Transfer

modem->Browse

File->

D:\IDEexamples\ex2->LCD. bin->send
Program Description:
This Program will display EDUTECH on LCD
Pin Assignment:
J11 of target board connected to J1 of LCD board
J11 Connector of
Target Board
PA0
PA1
PA2
PA3
PA4
PA5
PA6
PA17
PA18
PA19
PA20
PA21
PA22
PA23
PA24
PA25
PA26
3.3V
5.0 V
Ground

J1 Connector of
LCD/Keyboard
KB Column 0
KB Column 1
KB Column 2
KB Column 3
KB Column 4
KB Row0
KB Row 1
KB Row 2
N.C.
LCD Data Line D4
LCD Data Line D5
LCD Data Line D6
LCD Data Line D7
LCD RS Line
LCD EN line
KB Row 3
KB Row 4
N.C
VCC
Ground

J2 Connector of
LCD/Keyboard
N.C.
N.C.
N.C.
N.C.
N.C.
N.C.
N.C.
N.C.
N.C.
N.C.
N.C.
N.C.
N.C.
N.C.
N.C.
N.C.
N.C.
N.C.
VCC
Ground

______________________________________________________________ 59
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Program Folder:
<EX2>
Program Listing:

#include <at91rm9200.h>
#include "lcd.h"
AT91PS_SYS LCD=(AT91PS_SYS)AT91C_BASE_SYS;
void Edutech_Delay();
/**********************************************************************
Function Name
: void Lcddat(void)
Input
: cms,rspin
Output
: It Latches the data on the LCD pins
Description
: This function is used to latch the data on the LCD
Data lines.
**********************************************************************/
void Lcddat(char cms,char rspin)
{
long dat=cms;
dat = dat<<19;
LCD->PIOA_SODR=dat;
LCD->PIOA_CODR=~dat;
//LCD_PIN = cms;
Edutech_Delay();
if(rspin)
LCD->PIOA_SODR=LCD_RS_PIN ;
else
LCD->PIOA_CODR=LCD_RS_PIN ;
//LCD_RS_PIN = rspin;
Edutech_Delay();
LCD->PIOA_SODR=LCD_EN_PIN ;
//LCD_EN_PIN = 1;
Edutech_Delay();
//LCD_EN_PIN = 0;
LCD->PIOA_CODR=LCD_EN_PIN ;
}
/**********************************************************************
Function Name
: void LcdCommand(char lcdcommand)
Input
: lcdcommand
Output
: standard LCD command is passed.
Description
: This function is used to pass commands.
**********************************************************************/

______________________________________________________________ 60
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________
void LcdCommand(char lcdcommand)
{
char dat;
dat = (lcdcommand>>4);
Lcddat(dat,RS_LOW);
Lcddat(lcdcommand,RS_LOW);
}
/**********************************************************************
Function Name
: void LcdData(char lcdcommand)
Input
: lcddata
Output
: Data is passed.
Description
: This function is used to pass Data.
**********************************************************************/
void LcdData(char lcddata)
{
char dat;
dat = (lcddata>>4);
Lcddat(dat,RS_HIGH);
Lcddat(lcddata,RS_HIGH);
}
/**********************************************************************
Function Name
: void LcdInit(void)
Input
: none
Output
: LCD gets initialized.
Description
: This function is used Initializing the LCD.
**********************************************************************/
void LcdInit()
{
Edutech_Delay();
LcdCommand(0x03);
Edutech_Delay();
LcdCommand(0x03);
Edutech_Delay();
LcdCommand(0x03);
Edutech_Delay();
LcdCommand(0x02);
Edutech_Delay();
LcdCommand(0x02);
Edutech_Delay();
LcdCommand(0x28);
Edutech_Delay();
LcdCommand(0x08);
Edutech_Delay();
LcdCommand(0x01);
Edutech_Delay();
LcdCommand(0x0C);
Edutech_Delay();

// set entry mode for 4 bit interface

// cursor home

// display off

// display on

______________________________________________________________ 61
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________
LcdCommand(0x06); // set entry mode
Edutech_Delay();
}
/**********************************************************************
Function Name
: void LcdClear(void)
Input
: none
Output
: LCD gets cleared and at the home position.
Description
: This function is used to clear the LCD.
**********************************************************************/
void LcdClear()
{
LcdCommand(0x01);
Edutech_Delay();
}
/**********************************************************************
Function Name
: void LcdCursorSet(void)
Input
: Specified Row number and Column.
Output
: LCD cursor gets set at the specified Row and
Column.
Description
: This function is used to set cursor at specified
position.
**********************************************************************/
void LcdCursorSet(char row,char column)
{
char lcdcommand=0;
switch(row)
{
case ROW1:
lcdcommand= ROWADDR1+column;
break;
case ROW2:
lcdcommand= ROWADDR2+column;
break;
case ROW3:
if (ROWADDR3==ROWADDR1)
{
lcdcommand= ROWADDR3+column;
}
else
lcdcommand= ROWADDR3+column;
break;
case ROW4:
if(ROWADDR4==ROWADDR2)
{
lcdcommand= ROWADDR4+column;
}
else
______________________________________________________________ 62
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________
lcdcommand= ROWADDR4+column;
break;
}
LcdCommand(lcdcommand);
}
/**********************************************************************
Function Name
: void LcdDisplayString(char *string,char row,char
column)
Input
: String , Specified Row and Column.
Output
: String is displayed at specified Row and Column
position
Description
: This function is used to display string at
specified position.
**********************************************************************/
void LcdDisplayString(char *string,char row,char column)
{
char i=0;
LcdCursorSet(row,column);
i=column;
while(*string != '\0' && i<=COLUMNSIZE)
{
LcdData(*string++);
i++;
}
}
/**********************************************************************
Function Name
: void LcdDisplayStringCenter(char *string,char row)
Input
: String & Specified Row .
Output
: String is displayed at centre of the specified
position.
Description
: This function is used to display string at centre.
**********************************************************************/
void LcdDisplayStringCenter(char *string,char row)
{
char length,space=0,i=0;
LcdCursorSet(row,0);
length = strlen(string);
if(length < COLUMNSIZE)
{
space = (( - length)/2);
for(i=0; i<space;i++)
{
LcdData(' ');
}
while(*string != '\0')
______________________________________________________________ 63
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________
{
LcdData(*string++);
//i++;
}
for(i=0; i<space;i++)
{
LcdData(' ');
}
}
else
{
while(*string != '\0')
{
LcdData(*string++);
//
i++;
}
}
}
/**********************************************************************
Function Name : void LcdDisplayNumber(char number,char row,char
column,char type)
Input
: Number, Specified Row and Column,type.
Output
: Number is displayed at the specified position.
Description
: This function is used to display number or ASCII
characters.
**********************************************************************/
void LcdDisplayNumber(char number,char row,char column,char type)
{
char nible=0;
LcdCursorSet(row,column);
if(type==DIGIT)
{
number=number+0x30;
type=ASCII;
}
else if(type==VALUE)
{
nible = ((number >> 4) & 0x0F);
if((nible >= 0x0) && (nible <= 0x9))
nible = nible +0x30;
else
nible = nible +0x37;
LcdData(nible);
nible = (number & 0x0F);
if((nible >= 0x0) && (nible <= 0x9))
nible = nible +0x30;
else
nible = nible +0x37;
type=ASCII;
number = nible;
}
______________________________________________________________ 64
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

if(type==ASCII)
{
LcdData(number);
}
}
void Edutech_Delay()
{
int i;
for(i=0;i<9000;i++){}
}
void main()
{
LCD->PIOA_OER=LCD_PIN;
LcdInit();
LcdClear();
LcdDisplayString("EDUTECH",0,0);
}

______________________________________________________________ 65
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

8.1.3 RELAY INTERFACING


Objective:
To study Relay Interface with ARM9 target board:
Study of Relay board
Study of Relay board interface with AT91rm9200 Target Board
Writing C program to interface Relay
Part List:

Educational practice board for ARM 9 target board.


Power supply
Serial cable
Flat cable
PC
Edutech IDE
Relay Interface Board

Procedure:
Write C program in editor window of ARMIDE, build it using compile option.
To execute this program follow the steps
Connect the target board to the PC using serial cable. Use J1 connector for
serial connection.
Connect 5volt supply to J14 connector.
Set hyper terminal Parameter on windows PC in the following

way

START ->ACCESSORIES->COMMUNICATION->HYPER
TERMINAL.

Enter The Name :

Select COM PORT:

RESET Default

Bits/sec: 115200

Apply ok

It opens hyper terminal window

______________________________________________________________ 66
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Power on the Target board


Reset the board using RESET key PB1.
Stop booting of board by pressing any key.
It will display C on hyper terminal window.
Relay Interface Board connection to target board as follows:
Connect J1 connector through flat cable to J11 connector of Target board.

Transfer binary file to target board.


->
send
file->protocol->X
Transfer

modem->Browse

File->

D:\IDEexamples\ex3->relay. bin->send
Program Description:
This Program will make relay on/off for specific time.
Pin Assignment:
Relay ask J1 connector to J11 of Target board
J11 Connector of Target
Board
PA0
PA1
PA2
PA3
PA4
PA5
PA6
PA17
PA18
PA19
PA20
PA21
PA22
PA23
PA24
PA25
PA26
3.3V
5.0 V
GND

J1 Connector of Relay
N.C.
N.C.
N.C.
Mechanical Relay
Mechanical Relay
Mechanical Relay
Mechanical Relay
N.C.
N.C.
N.C.
N.C.
N.C.
N.C.
N.C.
N.C.
N.C.
N.C.
N.C.
VCC
Ground

1
2
3
4

______________________________________________________________ 67
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Program Folder:
<EX3>
Program Listing:
#include <at91rm9200.h>
AT91PS_SYS Relay=(AT91PS_SYS)AT91C_BASE_SYS;
//#include "new.h"
//#define set(x) (1<<x)
//#define clr(x) (0<<x)
void delay_ms(unsigned long ms);
int main (void)
{
Relay->PIOA_PER=0XF00FF;
Relay->PIOA_OER = 0xFffff;//set(1); // output enable reg
while(1)
{
Relay->PIOA_SODR = 0xF00ff;//set(1); //set high on PA1
delay_ms(100000); // delay function
Relay->PIOA_CODR = 0xF00ff;//set(1); // Set low on PA1
delay_ms(100000);
}
}
void delay_ms(unsigned long ms)
{
while(ms)
{
--ms;
}
}

______________________________________________________________ 68
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

8.1.4 STEPPER MOTOR INTERFACING


Objective:
To study Stepper Motor Interface with ARM9 target board:
Study of Stepper Motor board
Study of Stepper Motor interface with AT91rm9200 Target Board
Writing C program to interface Stepper Motor
Part List:

Educational practice board for ARM 9 target board.


Power supply
Serial cable
Flat cable
PC
Edutech IDE
Stepper Motor Interface Board.

Procedure:
Write C program in editor window of ARMIDE, build it using compile option.
To execute this program follow the steps
1. Connect the target board to the PC using serial cable. Use J1
connector for serial connection.
2. Connect 5volt supply to J14 connector.
3. Set hyper terminal Parameter on windows PC in the following
way START ->ACCESSORIES->COMMUNICATION->HYPER

TERMINAL.
Enter The Name:
Select COM PORT:
RESET Default
Bits/sec: 115200
Apply ok
It opens hyper terminal window

______________________________________________________________ 69
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Power on the Target board


Reset the board using RESET key PB1.
Stop booting of board by pressing any key.
It will display C on hyper terminal window.
Stepper Motor Interface Board connection to target board as follows:
Connect J1 connector through flat cable to J12 connector of Target
board.
Transfer binary file to target board as shown below.

Transfer -> send file->protocol->X modem->Browse


D:\IDEexamples\ex4->STEPPERMOTOR. bin->send

File->

Program Description:
This Program will move Stepper Motor in clockwise and anticlockwise
direction for given period.
Pin Assignment:
Stepper Motors J1 connector to J12 connector of Target board
J12 Connector of Target
Board
PB0
PB1
PB2
PB3
PB4
PB5
PB6
PB7
PB8
PB9
PB10
PB11
PB20
PB21
PB22
PB23
PB24
3.3V
5.0V
GND

J1 Connector of Stepper
Motor
N.C.
N.C.
N.C.
N.C.
N.C.
N.C.
N.C.
N.C.
N.C.
L4 (Green)
N.C.
L3 (Blue)
N.C.
L2 (Orange)
N.C.
L1 (Red)
N.C.
N.C.
VCC
Ground

______________________________________________________________ 70
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Program Folder:
<EX4>
Program Listing:

//-----------------------------------------------------------------//
STEPPERMOTR.c
//-----------------------------------------------------------------//
#include <at91rm9200.h>
AT91PS_SYS SM=(AT91PS_SYS)AT91C_BASE_SYS;
void
{

Stepper_Init()
SM->PIOB_PER=0XFFFFFFFF;
SM->PIOB_OER=0XFFFFFFFF;

}
/********************************************************************
Function Name
: void rotate_clockwise(unsigned int d)
Input
: delay parameter d.
return type
: None.
Description
: This function is used to step the stepper motor
in the clockwise direction.
********************************************************************/
void rotate_anticlockwise(unsigned int d,unsigned int rotate)
{
int sm[4]= {0x01100000,0x00500000,0x00400400,0x01000400};
int i;
while(rotate!= 0)
{
for(i=0;i<4;i++)
{
SM->PIOB_SODR= sm[i];
Delay_ms(d);
SM->PIOB_CODR = sm[i];
}
rotate--;
}
}
/********************************************************************
Function Name
: void rotate_anticlockwise(unsigned int d)
Input
: delay parameter d.
return type
: None.
Description
: This function is used to step the stepper motor
in the Anti - clockwise direction.
********************************************************************/

______________________________________________________________ 71
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________
void rotate_clockwise(unsigned int d,unsigned int rotate)
{
int sm[4]= {0x01100000,0x00500000,0x00400400,0x01000400};
int i;
while(rotate!=0)
{
for(i=3;i>=0;i--)
{
SM->PIOB_SODR= sm[i];
Delay_ms(d);
SM->PIOB_CODR = sm[i];
}
rotate--;
}
}
Delay_ms(int ms)
{
while(ms)
{
--ms;
}
}

void main()
{
Stepper_Init();
while(1)
{
rotate_clockwise(5000,1000);
rotate_anticlockwise(5000,1000);
}
}

______________________________________________________________ 72
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

8.1.5 MATRIX KEYBOARD INTERFACING


Objective:
To study Matrix Keyboard Interface with ARM9 target board:
Study of Matrix Keyboard board
Study of Matrix Keyboard interface with AT91rm9200 Target Board
Writing C program to interface Matrix Keyboard
Part List:

Educational practice board for ARM 9 target board.


Power supply
Serial cable
Flat cable
PC
Edutech IDE
Matrix Keyboard Interface Board.

Procedure:
Write C program in editor window of ARMIDE, build it using compile
option.
To execute this program follow the steps
1. Connect the target board to the PC using serial cable. Use J1
connector for serial connection.
2. Connect 5volt supply to J14 connector.

3. Set hyper terminal Parameter on windows PC in the following


way START ->ACCESSORIES->COMMUNICATION->HYPER
TERMINAL.
Enter The Name:
Select COM PORT:
RESET Default
Bits/sec: 115200
Apply o k
It opens hyper terminal window

______________________________________________________________ 73
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Power on the Target board


Reset the board using RESET key PB1.
Stop booting of board by pressing any key.
It will display C on hyper terminal window.
Matrix Keyboard Interface Board connection to target board as
follows:
Connect J1 connector through flat cable to J11 connector of Target
board.

Transfer binary file to target board as shown below :

Transfer -> send file->protocol->X


D:\IDEexamples\ex5->KEYBOARD. bin->send

modem->Browse

File->

Program Description:
This Program will detect the key press and display column/row wise hex value
on LCD accordingly.
Pin Assignment:
J11 of target board connected to J1 of LCD/Keyboard board
J11 Connector of
Target Board
PA0
PA1
PA2
PA3
PA4
PA5
PA6
PA17
PA18
PA19
PA20
PA21
PA22
PA23
PA24
PA25
PA26
3.3V
5.0 V
Ground

J1 Connector of
LCD/Keyboard
KB Column 0
KB Column 1
KB Column 2
KB Column 3
KB Column 4
KB Row0
KB Row 1
KB Row 2
N.C.
LCD Data Line D4
LCD Data Line D5
LCD Data Line D6
LCD Data Line D7
LCD RS Line
LCD EN line
KB Row 3
KB Row 4
N.C
VCC
Ground

J2 Connector of
LCD/Keyboard
N.C.
N.C.
N.C.
N.C.
N.C.
N.C.
N.C.
N.C.
N.C.
N.C.
N.C.
N.C.
N.C.
N.C.
N.C.
N.C.
N.C.
N.C.
VCC
Ground

______________________________________________________________ 74
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Program Folder:
<EX5>
Program Listing:

#include<at91rm9200.h>
#include<lcd_Arm9.h>
#include "matrix.h"
#define SET(X) (1<<X)
void delay_ms(unsigned int ms)
{
while(ms)
{
while(ms)
--ms;
}
}
void Edutech_MatrixKbrd_init()
{
KB->PIOA_PER|=0XFFFFFFFF;
KB->PIOA_OER|=0XFFFFFFE0;
PORTA_CLEAR|=0XFFFFFFE0;
}

//SELECT LINES
//ROW AS OUTPUT
//CLEAR ALL ROWS

/********************************************************************
Function Name
: Edutech_280X_KeyDetect(void)
Input
: None
Output
: value of the detected key.
Description
: This function is used to detecte key which has
been pressed.
********************************************************************/
char Edutech_KeyDetect(void)
{
unsigned int data;
PORTA_CLEAR|= ROWPINS_PORTA;
row = Edutech_FindRow();
col = Edutech_FindCol();
data= col+(row*10);
if((row >=0 && row <=4) && (col >=0 && col <=4))
{
return (data);
}
else
return (data);
}

______________________________________________________________ 75
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

/********************************************************************
Function Name
: Edutech_280X_FindCol(void)
Input
: None
Output
: value of the Column detected.
Description
: This function is used to detect the Column of key
pressed.
********************************************************************/
int Edutech_FindCol(void)
{
long int i;
KB->PMC_PCER=0X1F;
i=PORTA_DATA_READ;
i = (i & MCOLUMNALL);
switch(i)
{
case

MCOLUMN0:
return(0);

case

MCOLUMN1:
return(1);

case

MCOLUMN2:
return(2);

case

MCOLUMN3:
return(3);

case

MCOLUMN4:
return(4);

}
return(-1);
}
/********************************************************************
Function Name
: Edutech_280X_FindRow(void)
Input
: None
Output
: value of the Row detected.
Description
: This function is used to detect the Row of key
pressed.
********************************************************************/
int Edutech_FindRow(void)
{
int i;
long int j=0;
for(i=0;i<5;i++)
{
PORTA_SET|= ROWPINS_PORTA;
switch(i)
{
case 0:

PORTA_CLEAR=SET(5);

______________________________________________________________ 76
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

case 1:
case 2:
case 3:
case 4:

break;
PORTA_CLEAR=SET(6);
break;
PORTA_CLEAR=SET(17);
break;
PORTA_CLEAR=SET(25);
break;
PORTA_CLEAR=SET(26);
break;

}
KB->PMC_PCER=0XFFFFFFE0;
j= PORTA_DATA_READ;
if((j & MCOLUMNALL) != MCOLUMNALL)
{
PORTA_CLEAR = ROWPINS_PORTA;
return(i);
}
}
PORTA_CLEAR = ROWPINS_PORTA;
return(-1);
}
/********************************************************************
Function Name
: Edutech_280X_KeyPressed()
Input
: None
Output
: key pressed or not.
Description
: This function is used to know key pressed or not.
********************************************************************/
int Edutech_KeyPressed(void)
{
long int i=0;
PORTA_CLEAR|= 0X06020060;
KB->PMC_PCER|=0X1F;
i = PORTA_DATA_READ;
if((i & MCOLUMNALL) != MCOLUMNALL)
{
Edutech_Delay(100000);
if((i & MCOLUMNALL) != MCOLUMNALL)
{
return(1);
}
}
else
{
return(0);
}
return(-1);
}

______________________________________________________________ 77
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

/********************************************************************
Function Name
: Edutech_280X_AllKeyOpen()
Input
: None
Output
: All key opened or not.
Description
: This function is used to know all key opened or
not.
********************************************************************/
int Edutech_AllKeyOpen(void)
{
unsigned int i=0;
KB->PMC_PCER=0X1F;
i = PORTA_DATA_READ;
if((i & MCOLUMNALL) == MCOLUMNALL)
{
return(1);
}
else
{
return(0);
}
}
int col,data,row;
void main()
{
unsigned int data=0;
KB->PIOA_OER|=LCD_PIN;
Edutech_MatrixKbrd_init();
LcdInit();
LcdClear();
while(1)
{
KB->PIOA_CODR|=0X06020060;
while(Edutech_KeyPressed())
{
data=Edutech_KeyDetect();
row=data/10;
col=data%10;
LcdCommand(0x80);
LcdData(row+48);
LcdData(col+48);
while(!( Edutech_AllKeyOpen()))
{
}
delay_ms(100000);
}
}
}
______________________________________________________________ 78
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

8.1.6 GRAPHIC LCD INTERFACING


Objective:
To study Graphic LCD Interface with ARM9 target board:
Study of Graphic LCD board
Study of Graphic LCD interface with AT91rm9200 Target Board
Writing C program to interface Graphic LCD
Part List:

Educational practice board for ARM 9 target board.


Power supply
Serial cable
Flat cable
PC
Edutech IDE
Graphic LCD Interface Board.

Procedure:
Write C program in editor window of ARMIDE, build it using compile
option.
To execute this program follow the steps
1) Connect the target board to the PC using serial cable. Use J1
connector for serial connection.
2) Connect 5volt supply to J14 connector.

3) Set hyper terminal Parameter on windows PC in the following


way START ->ACCESSORIES->COMMUNICATION->HYPER
TERMINAL.
Enter The Name:
Select COM PORT:
RESET Default
Bits/sec: 115200
Apply o k
It opens hyper terminal window

______________________________________________________________ 79
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Power on the Target board


Reset the board using RESET key PB1.
Stop booting of board by pressing any key.
It will display C on hyper terminal window.
Graphic LCD Interface Board connection to target board as follows:
Connect J1 connector through flat cable to J11 connector of Target
board.
Transfer binary file to target board as shown below:

Transfer -> send file->protocol->X


D:\IDEexamples\ex6->GLCD. bin->send

modem->Browse

File->

Program Description:
This Program will display alphabets abcde.
Pin Assignment:
GRAPHIC LCD J2 CONNECTOR TO J11 CONNECTOR OF TARGET BOARD

J11 Connector of Target


Board
PA0
PA1
PA2
PA3
PA4
PA5
PA6
PA17
PA18
PA19
PA20
PA21
PA22
PA23
PA24
PA25
PA26
3.3V
5.0 V
GND

J2 Connector of Graphic
LCD
Vss
Vdd
Vo
/RD
/WR
A0
DB0
DB1
DB2
DB3
DB4
DB5
DB6
DB7
/CS
/RES
VEE
NC
NC
Vss

______________________________________________________________ 80
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Program Folder:
<EX6>
Program Listing:
#include<at91rm9200.h>
#include "glcd.h"
//#include "edulogo.inc"
#define SET(x) (1<<x)
#define CLR(x) (0<<x)
AT91PS_SYS GLCD=(AT91PS_SYS)AT91C_BASE_SYS;
void output_high(int data)
{
GLCD->PIOA_SODR=data;
}
void glcd_init(void)
{
GLCD->PIOA_PER=GLCD_PIN;
delay_ms(200);
GLCD->PIOA_OER=GLCD_PIN;
delay_ms(200);
output_low(GLCD_RST);
delay_ms(200);
delay_ms(200);
output_high(GLCD_RST);
delay_ms(200);
delay_ms(200);
GLCD->PIOA_SODR=GLCD_PIN;
//System Set
glcd_cmd(0x40);
glcd_dat(0x30);
glcd_dat(0x87);
glcd_dat(0x07);
glcd_dat(0x27);
glcd_dat(0x2f);
glcd_dat(0xef);
glcd_dat(0x28);
glcd_dat(0x00);
//Scroll
glcd_cmd(0x44);
glcd_dat(0x00);
glcd_dat(0x00);
glcd_dat(0xf0);
glcd_dat(0xb0);
glcd_dat(0x04);
glcd_dat(0xf0);
glcd_dat(0x00);
______________________________________________________________ 81
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________
glcd_dat(0x00);
glcd_dat(0x00);
glcd_dat(0x00);
glcd_cmd(0x5d);
glcd_dat(0x07);
glcd_dat(0x07);
glcd_cmd(0x4c);
glcd_cmd(0x5a);

glcd_dat(0x00);
glcd_cmd(0x5b);
glcd_dat(0x00);
glcd_cmd(0x58);
glcd_dat(0x16);
glcd_clr();
}
void output_low(int data)
{
GLCD->PIOA_CODR=data;
}
void glcd_cmd(unsigned long int cmd)
{
output_high(GLCD_A0);
//a0 high
output_high(GLCD_A0);
//a0 high
cmd=cmd<<(19);
// Data shift
GLCD->PIOA_SODR=cmd;
GLCD->PIOA_CODR=((~cmd)&GLCD_DATAPIN);
output_low(GLCD_CS);
//CS CLEAR
output_low(GLCD_WR);
delay_ms(200);
output_high(GLCD_WR);
output_high(GLCD_CS);
GLCD->PIOA_SODR=GLCD_PIN;
delay_ms(200);
}
void glcd_dat(unsigned long int dat)
{
output_low(GLCD_A0);
output_low(GLCD_A0);
dat=dat<<(19);
GLCD->PIOA_SODR=dat;
GLCD->PIOA_CODR=((~dat)&GLCD_DATAPIN);
output_low(GLCD_CS);
output_low(GLCD_WR);
delay_ms(200);
output_high(GLCD_WR);
output_high(GLCD_CS);

______________________________________________________________ 82
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________
GLCD->PIOA_SODR=GLCD_PIN;
delay_ms(200);
}
void glcd_clr(void)
{
int j;
glcd_cmd(0x46);
glcd_dat(0x00);
glcd_dat(0x00);
glcd_cmd(0x42);
for(j=0;j<1200;j++)
{
glcd_dat(0x20);
}
glcd_cmd(0x46);
glcd_dat(0xb0);
glcd_dat(0x04);
glcd_cmd(0x42);
for(j=0;j<9600;j++)
{
glcd_dat(0x00);
}
delay_ms(10);
glcd_cmd(0x59);
delay_ms(50);
}
void setaddr(unsigned int addrl,unsigned int addrh)
{
glcd_cmd(0x46);
glcd_dat(addrl);
glcd_dat(addrh);
}
void display(char *str)
{
glcd_cmd(0x42);
while(*str)
{
glcd_dat(*str);
str++;
}
}
/*void graphic(int row,int col,int low,int high)
{
int a,b;
glcd_cmd(0x4f);

______________________________________________________________ 83
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________
for(a=0;a<col;a++)
{
setaddr(low,high);
glcd_cmd(0x42);
for(b=0;b<row;b++)
{
glcd_dat(data[a][b]);
}
low++;
}
}*/
delay_ms(int ms)
{
while(ms){--ms;}
}
void main()
{
glcd_init();
//while(1)
{
setaddr(0x00,0x00);
glcd_cmd(0x42);
glcd_dat(0x41);
display("ABCDEFGH");
}
}

______________________________________________________________ 84
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

8.1.7 UART INTERFACING


Objective:
To study UART Interface with ARM9 target board:
Study of UART Interface with AT91rm9200 Target Board
Writing C program to interface UART
Part List:

Educational practice board for ARM 9 target board.


Power supply
2 Serial cable
PC
Edutech IDE

Procedure:
write C program in editor window of ARMIDE, build it using compile
option.
To execute this program follow the steps
1. Connect the target board to the PC using serial cable. Use J1
connector for serial connection.
2. Connect 5volt supply to J14 connector.
3. Set hyper terminal Parameter on windows PC in the following
way

START ->ACCESSORIES->COMMUNICATION->HYPER TERMINAL.


Enter The Name :
Select COM PORT:
RESET Default
bits/sec:115200
Apply o k
It opens hyper terminal window

______________________________________________________________ 85
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Power on the Target board


Reset the board using RESET key PB1.
Stop booting of board by pressing any key.
It will display C on hyper terminal window.
For UART Interfacing with ARM9 target board following are the
connection:
Connect Serial Cable from J3 connector to COM Port of PC

Transfer binary file to target board as shown below:

Transfer -> send file->protocol->X


D:\IDEexamples\ex7->UART. bin->send

modem->Browse

File->

Program Description:
If UART communication is successful, it will display "UART Init." On hyper terminal
window.
Program Folder:
<EX7>
Program Listing:
#include <at91rm9200.h>
//#include "NEW.H"
#define
AT91C_US_ASYNC_MODE
(AT91C_US_USMODE_NORMAL
+
AT91C_US_NBSTOP_1_BIT + AT91C_US_PAR_NONE + AT91C_US_CHRL_8_BITS +
AT91C_US_CLKS_CLOCK)
#define AT91C_MASTER_CLOCK 60000000
char GetChar[10],i=0;
//#define
AT91C_US_ASYNC_MODE
(AT91C_US_USMODE_NORMAL
+
AT91C_US_NBSTOP_1_BIT + AT91C_US_PAR_NONE + AT91C_US_CHRL_8_BITS +
AT91C_US_CLKS_CLOCK)
static void Enable_Debug_USART(AT91PS_DBGU pUSART) {
AT91PS_PDC pPDC = (AT91PS_PDC)&(pUSART->DBGU_RPR);
AT91PS_PIO pPio = (AT91PS_PIO)AT91C_BASE_PIOA;
pPio->PIO_ASR =
((unsigned)AT91C_PA31_DTXD)
((unsigned)AT91C_PA30_DRXD);
pPio->PIO_BSR = 0;

pPio->PIO_PDR =
((unsigned)AT91C_PA31_DTXD)
((unsigned)AT91C_PA30_DRXD);
pUSART->DBGU_CR
=AT91C_US_RSTRX
AT91C_US_RXDIS | AT91C_US_TXDIS;
pUSART->DBGU_BRGR

|
|

AT91C_US_RSTTX

|
=

______________________________________________________________ 86
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________
((((AT91C_MASTER_CLOCK*10)/(9600*16))+5)/10);
pUSART->DBGU_IDR = 0;
pUSART->DBGU_IER = AT91C_US_RXRDY;
pPDC->PDC_PTCR = AT91C_PDC_RXTDIS;
pPDC->PDC_PTCR = AT91C_PDC_TXTDIS;
pPDC->PDC_TNPR = 0;
pPDC->PDC_TNCR = 0;
pPDC->PDC_RNPR = 0;
pPDC->PDC_RNCR = 0;
pPDC->PDC_TPR = 0;
pPDC->PDC_TCR = 0;
pPDC->PDC_RPR = 0;
pPDC->PDC_RCR = 0;
pPDC->PDC_PTCR = AT91C_PDC_RXTEN;
pPDC->PDC_PTCR = AT91C_PDC_TXTEN;
pUSART->DBGU_MR = AT91C_US_ASYNC_MODE;
pUSART->DBGU_CR = AT91C_US_TXEN;
pUSART->DBGU_CR = AT91C_US_RXEN;
}
void SendData(AT91PS_DBGU pUSART,char transmit)
{
while (!(pUSART->DBGU_CSR & AT91C_US_TXRDY));
{
pUSART->DBGU_THR = (transmit & 0x1FF);
}
}
char GetCh(AT91PS_DBGU pUSART)
{
while(!(pUSART->DBGU_CSR & AT91C_US_RXRDY));
{
GetChar[i++] = (pUSART->DBGU_RHR & 0x1FF);
return(1);
}
//
else
return(0);
}
void DebugPrintf(char *buffer)
{
while(*buffer != '\0')
{
SendData(((AT91PS_DBGU)AT91C_BASE_DBGU),*buffer++);
}
}
void main(void)
{
char i=0;
while(1)
{
DebugPrintf("UART Init.");
//i++;

______________________________________________________________ 87
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________
}
/*asm(".equ test, 0x10F80000");
//char *ptr;
//ptr=&test;
DebugPrintf("shailesh");
asm("ldr
r0,=test");
//asm("MOV r0,&ptr");
asm("mov lr, pc");
asm("BX r0");*/
/*while(i<10)
{
if(GetCh(((AT91PS_DBGU)AT91C_BASE_DBGU)))
{
}
}
for(i=0;i<10;i++)
{
SendData(((AT91PS_DBGU)AT91C_BASE_DBGU),GetChar[i]);
if(GetChar[i] == 0x0D)*/
SendData(((AT91PS_DBGU)AT91C_BASE_DBGU),'s');
//}
}

______________________________________________________________ 88
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

8.2 Interfacing Basic OS based linux programs with ARM9 Target with
linux
Lab 1
Objective:
To observe the booting process and practice basic commands using ARM9 target
board.
Steps:
1. Connect the target board to the PC using the serial cable. Use the J1
connector for the serial connection.
2. Connect the supplied Ethernet cable to the J13 connector on the target and
the PC
3. Open the hyper terminal OR minicom and make the settings as mentioned:
Baud Rate = 115200, data bit 8, parity = none, stop bit = 1
4. Power on the target board
5. Observe on the screen the booting process. If you do not see the boot
process, check the settings one again as mentioned above and apply reset to
the target.
6. Login as 'root' on the terminal
7. Check the following commands using the following the steps:
[root@EDUTECH]cd ..
[root@EDUTECH]ls
[root@EDUTECH]cd /home
[root@EDUTECH/home]ls
[root@EDUTECH/home]cd ..
[root@EDUTECH/]

______________________________________________________________ 89
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Lab 2
Objective:
To write a simple program to display Hello World using ARM9 target board, build it,
and execute it using the target board.
Program:

#include <stdio.h>
int main(void)
{
int i;
for (i = 1; i <= 5 ; i++)
{
printf("C: Hello world!!! %d\n", i);
}
return 0;
}

Steps:
To execute:

to execute program from ARM9 target board go to /home/Example directory by


this command
[root@EDUTECH~]:cd /home/example

now execute lab2 by this command


[root@EDUTECH~]:./lab2

______________________________________________________________ 90
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

To modify:

Start the Lab2 sesssion in linux host PC.


$ cd /home/lab/lab2

Using the Editor modify the lab2.c program


$ vi lab2.c

Build the program.


$ make

Copy it to the /root/tftpboot


$ cp lab2 /root/tftpboot

Copy lab2 to target board.


[root@EDUTECH/home]: tftp -g -r lab2 192.168.0.96
[root@EDUTECH/home]: chmod 777 lab2

Execute the program from target board


[root@EDUTECH/home]:./lab2

______________________________________________________________ 91
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Lab 3
Objective:
To write a simple program to create process using ARM9 target board, build it, and
execute it using the target board.
Program:
#include <unistd.h>
#include <sys/types.h>
#include <errno.h>
#include <stdio.h>
#include <sys/wait.h>
#include <stdlib.h>
/* this program create a process*/
void child_process()
{
int i;
for (i=0; i < 5; i++)
{
printf("I am child process!\n");
}
}
int main()
{
pid_t childpid; /* variable to store the child's pid */
int retval;
/* child process: user-provided return code */
int status;
/* parent process: child's exit status */
childpid = fork();
if (childpid >= 0) /* fork succeeded */
{
if (childpid == 0) /* fork() returns 0 to the child process
*/
{
printf("CHILD: I am the child process!\n");
printf("CHILD: Here's my PID: %d\n", getpid());
printf("CHILD: My parent's PID is: %d\n", getppid());
printf("CHILD: The value of my copy of childpid is:
%d\n", childpid);
child_process();
printf("CHILD: Sleeping for 1 second...\n");
sleep(1);
printf("CHILD: Enter an exit value (0 to 255): ");
scanf(" %d", &retval);
printf("CHILD: Goodbye!\n");
exit(retval);
}
else /* fork() returns new pid to the parent process */
______________________________________________________________ 92
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________
{
printf("PARENT: I am the parent process!\n");
printf("PARENT: Here's my PID: %d\n", getpid());
printf("PARENT: The value of my copy of childpid is
%d\n", childpid);
printf("PARENT: I will now wait for my child to
exit.\n");
wait(&status); /* wait for child to exit, and store its
status */
printf("PARENT: Child's exit code is: %d\n",
WEXITSTATUS(status));
printf("PARENT: Goodbye!\n");
exit(0); /* parent exits */
}
}
else /* fork returns -1 on failure */
{
perror("fork"); /* display error message */
exit(0);
}
}

Steps:
To execute:
to execute program from ARM9 target board go to /home/Example directory
by this command
[root@EDUTECH~]:cd /home/example
now execute lab3 by this command
[root@EDUTECH~]:./lab3

______________________________________________________________ 93
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

To modify:

Start the Lab3 sesssion in linux host PC.

$ cd /home/lab/lab3
Using the Editor modify the lab3.c program
$ vi lab3.c

Build the program.


$ make

Copy it to the /root/tftpboot


$ cp lab3 /root/tftpboot

Copy lab3 to target board.


[root@EDUTECH/home]: tftp -g -r lab3 192.168.0.96
[root@EDUTECH/home]: chmod 777 lab3

Execute the program from target board


[root@EDUTECH/home]:./lab3

______________________________________________________________ 94
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Lab 4
Objective:
To write a simple program to create clone of process, build it, and execute it using
the target board.
Program:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <sched.h>
#include <sys/wait.h>
#define GOT1
(1 << 1)
#define GOT2
(1 << 2)
#define GOT3
(1 << 3)
#define ALLGOT
(GOT1|GOT2|GOT3)
void child_handler(int sig)
{
printf("I got a SIGCHLD\n");
}
int clone_main(void *arg)
{
unsigned long input = (unsigned long)arg;
int secs = input * 4;
printf("Clone got %lu, sleeping for %i secs\n", input, secs);
sleep(secs);
return input + 20;
}
int main(void)
{
int clone1, clone2, clone3;
char clone1_stack[8192], clone2_stack[8192],
clone3_stack[8192];
int status, nostatus, result, wpid;
//signal(SIGCHLD, child_handler);
if ((clone1 = clone(clone_main, clone1_stack, 0, (void*)1)) ==
-1) {
perror("Clone 1 failed");
exit(-1);
}
if ((clone2 = clone(clone_main, clone2_stack, 0, (void*)2)) ==
-1) {
perror("Clone 2 failed");
exit(-2);
}
if ((clone3 = clone(clone_main, clone3_stack, 0, (void*)3)) ==
-1) {
______________________________________________________________ 95
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________
perror("Clone 3 failed");
exit(-3);
}
sleep(1);
printf("Parent: waiting for the clones to die.\n");
nostatus = status = 0;
while (1) {
if ((wpid = waitpid(clone1, &result, WNOHANG|__WCLONE))
== -1)
nostatus |= GOT1;
if (wpid == clone1) {
status |= GOT1;
printf("Clone1 gave back %i\n",
WEXITSTATUS(result));
}
if ((wpid = waitpid(clone2, &result, WNOHANG|__WCLONE))
== -1)
nostatus |= GOT2;
if (wpid == clone2) {
status |= GOT2;
printf("Clone2 gave back %i\n",
WEXITSTATUS(result));
}
if ((wpid = waitpid(clone3, &result, WNOHANG|__WCLONE))
== -1)
nostatus |= GOT3;
if (wpid == clone3) {
status |= GOT3;
printf("Clone3 gave back %i\n",
WEXITSTATUS(result));
}
if (status == ALLGOT || nostatus == ALLGOT)
break;
}
if (status == ALLGOT) {
printf("Clones exited.\nGoodbye.\n");
return EXIT_SUCCESS;
} else {
perror("Waiting for clones failed");
return EXIT_FAILURE;
}
}

______________________________________________________________ 96
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Steps:
To execute:
to execute program from ARM9 target board go to /home/Example directory
by this command
[root@EDUTECH~]:cd /home/example
now execute lab4 by this command
[root@EDUTECH~]:./lab4
To modify:

Start the Lab4 sesssion in linux host PC.


$ cd /home/lab/lab4

Using the Editor modify the lab4.c program


$ vi lab4.c

Build the program.


$ make

Copy it to the /root/tftpboot


$ cp lab4 /root/tftpboot

Copy lab4 to target board.


[root@EDUTECH/home]: tftp -g -r lab4 192.168.0.96
[root@EDUTECH/home]: chmod 777 lab4

Execute the program from target board


[root@EDUTECH/home]:./lab4

______________________________________________________________ 97
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Lab 5
Objective:
To write a simple program to create thread, build it, and execute it using the target
board.
Program:
#include <stdio.h>
#include <string.h>
#include <pthread.h>
#define
NUM_THREADS 5
/* this program create the thread*/
void *PrintHello(void * threadid)
{
int tid;
tid = (int)threadid;
printf("Hello World! It's me, thread #%d!\n", tid);
pthread_exit(NULL);
}
int main(int argc, char *argv[])
{
pthread_t threads[NUM_THREADS]; //define the thread variable
int rc,i;
for(i=0;i<=NUM_THREADS;i++)
{
printf("In main: creating thread %d\n", i);
rc = pthread_create(&threads[i], NULL, PrintHello, (void *)i);
if (rc)
{
printf("ERROR; return code from pthread_create() is %d\n", rc);
exit(-1);
}
}
pthread_exit(NULL);
}

______________________________________________________________ 98
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Steps:
To execute:
to execute program from ARM9 target board go to /home/Example directory
by this command
[root@EDUTECH~]:cd /home/example
now execute lab5 by this command
[root@EDUTECH~]:./lab5
To modify:
1. Start the Lab5 sesssion in linux host PC.
$ cd /home/lab/lab5
2. Using the Editor modify the lab5.c program
$ vi lab5.c
3. Build the program.
$ make
4.

Copy it to the /root/tftpboot


$ cp lab5 /root/tftpboot

5. Copy lab5 to target board.


[root@EDUTECH/home]: tftp -g -r lab5 192.168.0.96
[root@EDUTECH/home]: chmod 777 lab5
6. Execute the program from target board
[root@EDUTECH/home]:./lab5

______________________________________________________________ 99
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Lab 6
Objective:
To write a simple program to create thread and pass the argument , build it, and
execute it using the target board.
Program:
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
static pthread_key_t str_key;
static pthread_once_t str_alloc_key_once = PTHREAD_ONCE_INIT;
static void str_alloc_key(void);
static void str_alloc_destroy_accu(void * accu);
char * str_accumulate(const char * s)
{
char * accu;
pthread_once(&str_alloc_key_once, str_alloc_key);
accu = (char *) pthread_getspecific(str_key);
if (accu == NULL) {
accu = malloc(1024);
if (accu == NULL) return NULL;
accu[0] = 0;
pthread_setspecific(str_key, (void *) accu);
printf("Thread %lx: allocating buffer at %p\n", pthread_self(),
accu);
}
strcat(accu, s);
return accu;
}
static void str_alloc_key(void)
{
pthread_key_create(&str_key, str_alloc_destroy_accu);
printf("Thread %lx: allocated key %d\n", pthread_self(), str_key);
}
static void str_alloc_destroy_accu(void * accu)
{
printf("Thread %lx: freeing buffer at %p\n", pthread_self(), accu);
free(accu);
}
void * process(void * arg)
{
char * res;
______________________________________________________________ 100
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________
res = str_accumulate("Result of ");
res = str_accumulate((char *) arg);
res = str_accumulate(" thread");
printf("Thread %lx: \"%s\"\n", pthread_self(), res);
return NULL;
}
int main(int argc, char ** argv)
{
char * res;
pthread_t th1, th2;
res = str_accumulate("Result of ");
pthread_create(&th1, NULL, process, (void *) "first");
pthread_create(&th2, NULL, process, (void *) "second");
str_accumulate("initial thread");
printf("Thread %lx: \"%s\"\n", pthread_self(), res);
pthread_join(th1, NULL);
pthread_join(th2, NULL);
exit(0);
}

res =

Steps:
To execute:

to execute program from ARM9 target board go to /home/Example directory


by this command

[root@EDUTECH~]:cd /home/example

now execute lab6 by this command

[root@EDUTECH~]:./lab6

______________________________________________________________ 101
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

To modify:

Start the Lab6 sesssion in linux host PC.


$ cd /home/lab/lab6

Using the Editor modify the lab6.c program


$ vi lab6.c

Build the program.


$ make

Copy it to the /root/tftpboot


$ cp lab6 /root/tftpboot

Copy lab6 to target board.


[root@EDUTECH/home]: tftp -g -r lab6 192.168.0.96
[root@EDUTECH/home]: chmod 777 lab6

Execute the program from target board


[root@EDUTECH/home]:./lab6

______________________________________________________________ 102
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Lab 7
Objective:
To write a simple program of synchronization between thread using conditional
variable build it, and execute it using the target board.
Program:
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
pthread_mutex_t count_mutex
= PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t condition_mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t condition_cond = PTHREAD_COND_INITIALIZER;
void *functionCount1();
void *functionCount2();
int count = 0;
#define COUNT_DONE 10
#define COUNT_HALT1 3
#define COUNT_HALT2 6
main()
{
pthread_t thread1, thread2;
pthread_create( &thread1, NULL, &functionCount1, NULL);
pthread_create( &thread2, NULL, &functionCount2, NULL);
pthread_join( thread1, NULL);
pthread_join( thread2, NULL);
exit(0);
}
void *functionCount1()
{
for(;;)
{
pthread_mutex_lock( &condition_mutex );
while( count >= COUNT_HALT1 && count <= COUNT_HALT2 )
{
pthread_cond_wait( &condition_cond, &condition_mutex );
}
pthread_mutex_unlock( &condition_mutex );
pthread_mutex_lock( &count_mutex );
count++;
printf("Counter value functionCount1: %d\n",count);
pthread_mutex_unlock( &count_mutex );
if(count >= COUNT_DONE) return(NULL);
}
}
void *functionCount2()
{
for(;;)
{
pthread_mutex_lock( &condition_mutex );
if( count < COUNT_HALT1 || count > COUNT_HALT2 )
{
pthread_cond_signal( &condition_cond );
______________________________________________________________ 103
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________
}
pthread_mutex_unlock( &condition_mutex );
pthread_mutex_lock( &count_mutex );
count++;
printf("Counter value functionCount2: %d\n",count);
pthread_mutex_unlock( &count_mutex );
if(count >= COUNT_DONE) return(NULL);
}
}

Steps:
To execute:

To execute program from ARM9 target board go to /home/Example directory


by this command
[root@EDUTECH~]:cd /home/example

Now execute lab7 by this command

[root@EDUTECH~]:./lab7
To modify:

Start the Lab7 sesssion in linux host PC.


$ cd /home/lab/lab7

Using the Editor modify the lab7.c program


$ vi lab7.c

Build the program.


$ make

Copy it to the /root/tftpboot


$ cp lab7 /root/tftpboot

Copy lab7 to target board.


[root@EDUTECH/home]: tftp -g -r lab7 192.168.0.96
[root@EDUTECH/home]: chmod 777 lab7

Execute the program from target board


[root@EDUTECH/home]:./lab7

______________________________________________________________ 104
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Lab 8
Objective:
To write a simple program of syncronization between thread using mutex build it,
and execute it using the target board.
Program:
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
void *functionC();
pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER;
int counter = 0;
main()
{
int rc1, rc2;
pthread_t thread1, thread2;
/* Create independent threads each of which will execute functionC
*/
if( (rc1=pthread_create( &thread1, NULL, &functionC, NULL)) )
{
printf("Thread creation failed: %d\n", rc1);
}
if( (rc2=pthread_create( &thread2, NULL, &functionC, NULL)) )
{
printf("Thread creation failed: %d\n", rc2);
}
/* Wait till threads are complete before main continues. Unless we
*/
/* wait we run the risk of executing an exit which will terminate
*/
/* the process and all threads before the threads have completed.
*/
pthread_join( thread1, NULL);
pthread_join( thread2, NULL);
exit(0);
}
void *functionC()
{
pthread_mutex_lock( &mutex1 );
counter++;
printf("Counter value: %d\n",counter);
pthread_mutex_unlock( &mutex1 );
}

______________________________________________________________ 105
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Steps:
To execute:

To execute program from ARM9 target board go to /home/Example directory


by this command
[root@EDUTECH~]:cd /home/example

Now execute lab8 by this command


[root@EDUTECH~]:./lab8

To modify:

Start the Lab8 sesssion in linux host PC.


$ cd /home/lab/lab8

Using the Editor modify the lab8.c program


$ vi lab8.c

Build the program.


$ make

Copy it to the /root/tftpboot


$ cp lab8 /root/tftpboot

Copy lab8 to target board.


[root@EDUTECH/home]: tftp -g -r lab8 192.168.0.96
[root@EDUTECH/home]: chmod 777 lab8

Execute the program from target board


[root@EDUTECH/home]:./lab8

______________________________________________________________ 106
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Lab 9
Objective:
To write a simple program of Interporcess communication between two process
using pipe build it, and execute it using the target board.
Program:
#include <unistd.h>
#include <sys/types.h>
#include <errno.h>
#include <stdio.h>
#include <sys/wait.h>
#include <stdlib.h>
int main()
{
int n; /* store the number of characters read */
char buf[100]; /* store the characters read */
int fd[2];
printf("Starting the pipe.c program\n\n");
printf("Create the pipe\n\n");
pipe(fd); /* fd[0] read; fd[1] write */
printf("Create the child process using fork\n");
if ( fork() == 0 ) /* create child, test return value */
{
close(fd[1]); /* close write end - not needed in this
example */
printf("child is running...\n");
printf("about to read from the pipe\n");
n = read( fd[0], buf, 100); /* child reads from pipe
*/
printf("after reading from the pipe\n");
printf("the value of n is: %d\n",n);
printf("the value in the buffer is: %s\n\n", buf);
}
else /* parent*/
{
close(fd[0]); /* close read end - not needed for this
example */
printf("parent is running...\n");
printf("about to write to the pipe\n");
write( fd[1], "Writing to pipe\n", 16); /* parent writes to
pipe */
printf("after writing to the pipe\n\n");
}
printf("Ending the c program\n");
exit(0);
}

______________________________________________________________ 107
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Steps:
To execute:

To execute program from ARM9 target board go to /home/Example directory


by this command
[root@EDUTECH~]:cd /home/example

Now execute lab9 by this command


[root@EDUTECH~]:./lab9

To modify:

Start the Lab9 sesssion in linux host PC.


$ cd /home/lab/lab9

Using the Editor modify the lab9.c program


$ vi lab9.c

Build the program.


$ make

Copy it to the /root/tftpboot


$ cp lab9 /root/tftpboot

Copy lab9 to target board.


[root@EDUTECH/home]: tftp -g -r lab9 192.168.0.96
[root@EDUTECH/home]: chmod 777 lab9

Execute the program from target board


[root@EDUTECH/home]:./lab9

______________________________________________________________ 108
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Lab 10
Objective:
To write a simple program of Interporcess communication between two process
using signal build it, and execute it using the target board.
Program:
#include <unistd.h>
#include <sys/types.h>
#include <errno.h>
#include <stdio.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <signal.h>
void sighup(); /* routines child will call upon sigtrap */
void sigint();
void sigquit();
int main()
{
int pid;
/* get child process */
if ((pid = fork()) < 0)
{
perror("fork");
exit(1);
}
if (pid == 0)
{ /* child */
signal(SIGHUP,sighup); /* set function calls */
signal(SIGINT,sigint);
signal(SIGQUIT, sigquit);
for(;;); /* loop for ever */
}
else /* parent */
{ /* pid hold id of child */
printf("\nPARENT: sending SIGHUP\n\n");
kill(pid,SIGHUP);
sleep(3); /* pause for 3 secs */
printf("\nPARENT: sending SIGINT\n\n");
kill(pid,SIGINT);
sleep(3); /* pause for 3 secs */
printf("\nPARENT: sending SIGQUIT\n\n");
kill(pid,SIGQUIT);
sleep(3);
}
return(0);
}

______________________________________________________________ 109
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________
void sighup()
{
signal(SIGHUP,sighup); /* reset signal */
printf("CHILD: I have received a SIGHUP\n");
}
void sigint()
{
signal(SIGINT,sigint); /* reset signal */
printf("CHILD: I have received a SIGINT\n");
}
void sigquit()
{
printf("My DADDY has Killed me!!!\n");
exit(0);
}

Steps:
To execute:

To execute program from ARM9 target board go to /home/Example directory


by this command
[root@EDUTECH~]:cd /home/example

Now execute lab10 by this command


[root@EDUTECH~]:./lab10

______________________________________________________________ 110
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

To modify:

Start the Lab10 sesssion in linux host PC.


$ cd /home/lab/lab10

Using the Editor modify the lab10.c program


$ vi lab10.c

Build the program.


$ make

Copy it to the /root/tftpboot


$ cp lab10 /root/tftpboot

Copy lab10 to target board.


[root@EDUTECH/home]: tftp -g -r lab10 192.168.0.96
[root@EDUTECH/home]: chmod 777 lab10

Execute the program from target board


[root@EDUTECH/home]:./lab10

______________________________________________________________ 111
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Lab 11
Objective:
To write a simple program of Interporcess communication between two process
using semaphore build it, and execute it using the target board.
Program:
#include <stdio.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>
union semun {
int val;
struct semid_ds *buf;
ushort *array;
}
main()
{ int i,j;
int pid;
int semid; /* semid of semaphore set */
key_t key = 1234; /* key to pass to semget() */
int semflg = IPC_CREAT | 0666; /* semflg to pass to semget() */
int nsems = 1; /* nsems to pass to semget() */
int nsops; /* number of operations to do */
struct sembuf *sops = (struct sembuf *) malloc(2*sizeof(struct
sembuf));
/* ptr to operations to perform */
/* set up semaphore */
if ((semid = semget(key, nsems, semflg)) == -1) {
perror("semget: semget failed");
exit(1);
} else
(void) fprintf(stderr, "semget: semget succeeded: semid =\
%d\n", semid);
/* get child process */
if ((pid = fork()) < 0) {
perror("fork");
exit(1);
}
if (pid == 0)
{ /* child */
i = 0;
while (i < 1) {/* allow for 3 semaphore sets */
nsops = 2;
/* wait for semaphore to reach zero */
sops[0].sem_num = 0; /* We only use one track */
sops[0].sem_op = 0; /* wait for semaphore flag to become zero
*/
sops[0].sem_flg = SEM_UNDO; /* take off semaphore asynchronous
______________________________________________________________ 112
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________
*/
sops[1].sem_num = 0;
sops[1].sem_op = 1; /* increment semaphore -- take control of
track */
sops[1].sem_flg = SEM_UNDO | IPC_NOWAIT; /* take off semaphore
*/
/* Recap the call to be made. */
(void) fprintf(stderr,"\nsemop:Child Calling semop(%d,
&sops, %d) with:", semid, nsops);
for (j = 0; j < nsops; j++)
{
(void) fprintf(stderr, "\n\tsops[%d].sem_num = %d, ", j,
sops[j].sem_num);
(void) fprintf(stderr, "sem_op = %d, ", sops[j].sem_op);
(void) fprintf(stderr, "sem_flg = %#o\n", sops[j].sem_flg);
}
/* Make the semop() call and report the results. */
if ((j = semop(semid, sops, nsops)) == -1) {
perror("semop: semop failed");
}
else
{
(void) fprintf(stderr, "\tsemop: semop returned %d\n",
j);
(void) fprintf(stderr, "\n\nChild Process Taking Control
of Track: %d/3 times\n", i+1);
sleep(5); /* DO Nothing for 5 seconds */
nsops = 1;
/* wait for semaphore to reach zero */
sops[0].sem_num = 0;
sops[0].sem_op = -1; /* Give UP COntrol of track */
sops[0].sem_flg = SEM_UNDO | IPC_NOWAIT; /* take
off semaphore, asynchronous */
if ((j = semop(semid, sops,
nsops)) == -1) {
perror("semop: semop failed");
}
else
(void) fprintf(stderr, "Child Process Giving up
Control of Track: %d/3 times\n", i+1);
sleep(5); /* halt process to allow parent to
catch semaphor change first */
}
++i;
}
}
else /* parent */
{ /* pid hold id of child */
i = 0;
while (i < 1) { /* allow for 3 semaphore sets */
nsops = 2;
______________________________________________________________ 113
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________
/* wait for semaphore to reach zero */
sops[0].sem_num = 0;
sops[0].sem_op = 0; /* wait for semaphore flag to become zero
*/
sops[0].sem_flg = SEM_UNDO; /* take off semaphore asynchronous
*/
sops[1].sem_num = 0;
sops[1].sem_op = 1; /* increment semaphore -- take control of
track */
sops[1].sem_flg = SEM_UNDO | IPC_NOWAIT; /* take off semaphore
*/
/* Recap the call to be made. */
(void) fprintf(stderr,"\nsemop:Parent Calling semop(%d,
&sops, %d) with:", semid, nsops);
for (j = 0; j < nsops; j++)
{
(void) fprintf(stderr, "\n\tsops[%d].sem_num = %d, ", j,
sops[j].sem_num);
(void) fprintf(stderr, "sem_op = %d, ", sops[j].sem_op);
(void) fprintf(stderr, "sem_flg = %#o\n", sops[j].sem_flg);
}
/* Make the semop() call and report the results. */
if ((j = semop(semid, sops, nsops)) == -1) {
perror("semop: semop failed");
}
else
{
(void) fprintf(stderr, "semop: semop returned %d\n", j);
(void) fprintf(stderr, "Parent Process Taking Control of
Track: %d/3 times\n", i+1);
sleep(5); /* Do nothing for 5 seconds */
nsops = 1;
/* wait for semaphore to reach zero */
sops[0].sem_num = 0;
sops[0].sem_op = -1; /* Give UP COntrol of track */
sops[0].sem_flg = SEM_UNDO | IPC_NOWAIT; /* take
off semaphore, asynchronous */
if ((j = semop(semid, sops, nsops)) == -1) {
perror("semop: semop failed");
}
else
(void) fprintf(stderr, "Parent Process Giving up
Control of Track: %d/3 times\n", i+1);
sleep(5); /* halt process to allow child to
catch semaphor change first */
}
++i;
}
}
}

______________________________________________________________ 114
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Steps:
To execute:

To execute program from ARM9 target board go to /home/Example directory


by this command
[root@EDUTECH~]:cd /home/example

Now execute lab11 by this command


[root@EDUTECH~]:./lab11

To modify:

Start the Lab11 sesssion in linux host PC.


$ cd /home/lab/lab11

Using the Editor modify the lab11.c program


$ vi lab11.c

Build the program.


$ make

Copy it to the /root/tftpboot


$ cp lab11 /root/tftpboot

Copy lab11 to target board.


[root@EDUTECH/home]: tftp -g -r lab11 192.168.0.96
[root@EDUTECH/home]: chmod 777 lab11

Execute the program from target board


[root@EDUTECH/home]:./lab11

______________________________________________________________ 115
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Lab 12
Objective:
To write a simple program of Inter process communication between two process
using shared memory, build it, and execute it using the target board.
Client Program:
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <stdio.h>
#define SHMSZ
27
main()
{
int shmid;
key_t key;
char *shm, *s;
/*
* We need to get the segment named
* "5678", created by the server.
*/
key = 5678;
/*
* Locate the segment.
*/
if ((shmid = shmget(key, SHMSZ, 0666)) < 0) {
perror("shmget");
exit(1);
}
/*
* Now we attach the segment to our data space.
*/
if ((shm = shmat(shmid, NULL, 0)) == (char *) -1) {
perror("shmat");
exit(1);
}
/*
* Now read what the server put in the memory.
*/
for (s = shm; *s != NULL; s++)
putchar(*s);
putchar('\n');
/*
* Finally, change the first character of the
* segment to '*', indicating we have read the segment.*/
*shm = '*';
exit(0);
}

______________________________________________________________ 116
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Server Program:
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <stdio.h>
#define SHMSZ
27
main()
{
char c;
int shmid;
key_t key;
char *shm, *s;
/*
* We'll name our shared memory segment
* "5678".
*/
key = 5678;
/*
* Create the segment.
*/
if ((shmid = shmget(key, SHMSZ, IPC_CREAT | 0666)) < 0) {
perror("shmget");
exit(1);
}
/*Now we attach the segment to our data space.*/
if ((shm = shmat(shmid, NULL, 0)) == (char *) -1) {
perror("shmat");
exit(1);
}
/*Now put some things into the memory for the
other process to read.*/
s = shm;
for (c = 'a'; c <= 'z'; c++)
*s++ = c;
*s = NULL;
/*
* Finally, we wait until the other process
* changes the first character of our memory
* to '*', indicating that it has read what
* we put there.
*/
printf("Run Clinet Process\n");
while (*shm != '*')
sleep(1);
exit(0);
}

______________________________________________________________ 117
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Steps:
To execute:

To execute program from ARM9 target board go to /home/Example directory


by this command
[root@EDUTECH~]:cd /home/example

Now execute lab12 by this command


[root@EDUTECH~]:./lab12server &
[root@EDUTECH~]:./lab12client

To modify:
Steps for server program:

Start the Lab12server session in linux host PC.


$ cd /home/lab/lab12/server

Using the Editor modify the server.c program


$ vi server.c

Build the program.


$ make

Copy it to the /root/tftpboot


$ cp lab12server /root/tftpboot

Copy lab12server to target board.

[root@EDUTECH/home]: tftp -g -r lab12server


192.168.0.96
[root@EDUTECH/home]: chmod 777 lab12server

Execute the program from target board in background


[root@EDUTECH/home]:./lab12server &

______________________________________________________________ 118
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Steps for client program:

Start the Lab12client session in linux host PC.


$ cd /home/lab/lab12/client

Using the Editor modify the client.c program


$ vi client.c

Build the program.


$ make

Copy it to the /root/tftpboot


$ cp lab12client /root/tftpboot

Copy lab12client to target board.

[root@EDUTECH/home]: tftp -g -r lab12client


192.168.0.96
[root@EDUTECH/home]: chmod 777 lab12client

Execute the program from target board


[root@EDUTECH/home]:./lab12client

______________________________________________________________ 119
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

8.3 Interfacing Basic ASK based linux programs with ARM9 Target with
linux
Lab13
Objective:
To study the simple LED Interface with ARM9 target board
Part List:

Educational practice board for ARM 9 target board.


Power supply
Serial cable
Flat cable
Linux PC
S-Lcd Interface Board.
8 LEDs

Program Description:
This Program will glow alternate LED on S-Lcd module
Pin Assignment:
Connection between S-Lcd connector to J11 connector of target board
Procedure:

to execute program from ARM9 target board go to /home/Example directory


by this command
[root@EDUTECH~]:cd /home/example

now execute lab13 by this command


[root@EDUTECH~]:./lab13.o

______________________________________________________________ 120
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Editing program

Now if you want to edit this lab13.c file go to /home/lab/lab13 by this


command in linux host PC.
Linux-dje5:~ # cd /home/lab/lab13

Edit lab13.c by this command


Linux-dje5:~ # vi lab13.c

Now save and exit from vi editor by this command


Esc + : + wq + enter

Now compile your program by this command


Linux-dje5:~ # arm-linux-gcc lab13.c o lab13.o
Above command compile the program.

After compilation check whether object file is created or not by using


command
Linux-dje5:~ # ls

copy object file to /root/tftpboot by this command


Linux-dje5:~ # cp test /root/tftpboot

copy test to target board by this command


[root@EDUTECH/home]: tftp g r lab13.o 192.168.0.96
[root@EDUTECH/home]: chmod 777 lab13.o

Execute the program from target board by this command


[root@EDUTECH/home]: ./lab13.o

______________________________________________________________ 121
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Program:-

#include <linux/ioctl.h>
#define DEVICE_NAME "SLCD_LED"
#define MAJOR_NUM 60
#define
#define
#define
#define

INIT_GPIO_B
_IOWR(MAJOR_NUM, 0, int *)
GPIO_B_CLEAR
_IOWR(MAJOR_NUM, 1, int *)
GPIO_B_SET
_IOWR(MAJOR_NUM, 2, int *)
GPIO_B_READ
_IOWR(MAJOR_NUM, 3, int *)

#include
#include
#include
#include
#include
#include
#include

<stdio.h>
<unistd.h>
<stdlib.h>
<errno.h>
<fcntl.h>
<string.h>
<sys/ioctl.h>

#define FATAL do { fprintf(stderr, "Error at line %d, file %s (%d)


[%s]\n", \
__LINE__, __FILE__, errno, strerror(errno)); exit(1); } while(0)

static void port_B_clear(int gpio, unsigned long port_value)


{
int ret_val;
ret_val = ioctl(gpio, GPIO_B_CLEAR, &port_value);
if (ret_val < 0)
{
printf("ioctl_set_msg failed:%d\n", ret_val);
exit(-1);
}
}

static void port_B_set(int gpio, unsigned long port_value)


{
int ret_val;
ret_val = ioctl(gpio, GPIO_B_SET, &port_value);
if (ret_val < 0)
{
printf("ioctl_set_msg failed:%d\n", ret_val);
exit(-1);
}
}
static void port_B_read(int gpio, unsigned long port_value)
{
int ret_val;
ret_val = ioctl(gpio, GPIO_B_READ, &port_value);
if (ret_val < 0)
______________________________________________________________ 122
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________
{
printf("ioctl_set_msg failed:%d\n", ret_val);
exit(-1);
}
}
static void init_gpio_B(int gpio)
{
int ret_val;
ret_val = ioctl(gpio, INIT_GPIO_B);
if (ret_val < 0)
{
printf("ioctl_set_msg failed:%d\n", ret_val);
exit(-1);
}
}
int main()
{
int gpio;
int n,i;
/* gpio test */
if ((gpio = open("/dev/SLCD_LED", O_RDWR)) < 0)
FATAL;
init_gpio_B(gpio);
while(1)
{
sleep(1);
port_B_clear(gpio, 0x01500400);
port_B_set(gpio, 0x00A00A00);

sleep(1);
port_B_clear(gpio, 0x00A00A00);
port_B_set(gpio, 0x01500400);
}
if (close(gpio) < 0)
FATAL;
return 0;
}

EXERCISES
EG1
EG2
EG3

Write a program to make alternate LED on and off.


Write a program to demonstrate BCD counter using LED
Write a program to demonstrate night rider program using LED

______________________________________________________________ 123
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Lab14
Objective:
To study the simple 7-segment Interface of with ARM9 target board
Part List:

Educational practice board for ARM 9 target board.


Power supply
Serial cable
Flat cable
Linux PC
S-Lcd Interface Board.
One 7-segment

Program Description:
This Program will display 0-9 digit on 7-segment on S-Lcd module
Pin Assignment:
Connection between S-Lcd connector to J12 connector of ARM-9target board
Procedure:

to execute program from ARM9 target board go to /home/Example directory


by this command
[root@EDUTECH~]:cd /home/example

now execute lab14 by this command


[root@EDUTECH~]:./lab14.o

______________________________________________________________ 124
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Editing program

Now if you want to edit this lab14.c file go to /home/lab/lab14 by this


command in linux host PC.
Linux-dje5:~ # cd /home/lab/lab14

Edit lab14.c by this command


Linux-dje5:~ # vi lab14.c

Now save and exit from vi editor by this command


Esc + : + wq + enter

Now compile your program by this command


Linux-dje5:~ # arm-linux-gcc lab14.c o lab14.o
Above command compile the program.

After compilation check whether object file is created or not by using


command
Linux-dje5:~ # ls

copy object file to /root/tftpboot by this command


Linux-dje5:~ #

cp lab14.o /root/tftpboot

copy test to target board by this command


[root@EDUTECH/home]: tftp g r lab14.o 192.168.0.96
[root@EDUTECH/home]: chmod 777 lab14.o

Execute the program from target board by this command


[root@EDUTECH/home]: ./lab14.o

______________________________________________________________ 125
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Program:-

#include
#include
#include
#include
#include

<stdio.h>
<stdlib.h>
<fcntl.h>
<unistd.h>
<sys/ioctl.h>

/* open */
/* exit */

#include "7segment.h"
display_digit(char digit,int file_desc, struct Segment_display
*message)
{
int ret_val;
message->digit = digit;
ret_val = ioctl(file_desc, DISPLAY_SEGMENT, message);
if (ret_val < 0) {
printf("ioctl_set_msg failed:%d\n", ret_val);
exit(-1);
}
}
segment_init(int file_desc)
{
int ret_val;
ret_val = ioctl(file_desc, SEGMENT_INIT);
if (ret_val < 0) {
printf("ioctl_set_msg failed:%d\n", ret_val);
exit(-1);
}
}
main()
{
int file_desc_7segment, ret_val,i;
struct Segment_display display;
file_desc_7segment = open("/dev/SLCD_7SEGMENT", 0);
if (file_desc_7segment < 0) {
printf("Can't open device file: %s\n", DEVICE_FILE_NAME);
exit(-1);
}
segment_init(file_desc_7segment);
for( i=0; i<=9; i++ )
{
display_digit(i,file_desc_7segment,&display);
printf("i=%d\n",i);
sleep(1);
}
close(file_desc_7segment);
}

______________________________________________________________ 126
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Lab15
Objective:
To study the simple LCD Interface of with ARM9 target board
Part List:

Educational practice board for ARM 9 target board.


Power supply
Serial cable
Flat cable
Linux PC
S-Lcd Interface Board.
One 16x2 LCD

Program Description:
This Program will display string on LCD of S-Lcd module
Pin Assignment:
Connection between S-Lcd connector to J11 connector of ARM-9target board
Procedure:

To execute program from ARM9 target board go to /home/Example directory


by this command
[root@EDUTECH~]:cd /home/example

Now execute lab15 by this command


[root@EDUTECH~]:./lab15.o

______________________________________________________________ 127
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Editing program

Now if you want to edit this lab15.c file go to /home/lab/lab15 by this


command in linux host PC.
Linux-dje5:~ # cd /home/lab/lab15

Edit lab15.c by this command


Linux-dje5:~ # vi lab15.c

Now save and exit from vi editor by this command


Esc + : + wq + enter

Now compile your program by this command


Linux-dje5:~ # arm-linux-gcc lab15.c o lab15.o
Above command compile the program.

After compilation check whether object file is created or not by using


command
Linux-dje5:~ #

copy object file to /root/tftpboot by this command


Linux-dje5:~ #

ls

cp lab15.o /root/tftpboot

copy test to target board by this command


[root@EDUTECH/home]: tftp g r lab15.o 192.168.0.96
[root@EDUTECH/home]: chmod 777 lab15.o

Execute the program from target board by this command


[root@EDUTECH/home]: ./lab15.o

______________________________________________________________ 128
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Program:-

#include <linux/ioctl.h>
#include
#include
#include
#include
#include
#include
#include

<stdio.h>
<unistd.h>
<stdlib.h>
<errno.h>
<fcntl.h>
<string.h>
<sys/ioctl.h>

#include "lcd.h"

#define FATAL do { fprintf(stderr, "Error at line %d, file %s (%d)


[%s]\n", \
__LINE__, __FILE__, errno, strerror(errno)); exit(1); } while(0)
int data;
struct lcd_display display;
int main()
{
int file_desc_lcd;
file_desc_lcd = open("/dev/SLCD_LCD", 0);
if (file_desc_lcd < 0)
{
printf("Can't open >>>> Slcd <<<< device file: %s\n",
DEVICE_FILE_NAME_LCD);
exit(-1);
}
init_lcd(file_desc_lcd);

//initialise matrix keyboard

lcd_cmd(0x01,file_desc_lcd,&display);
//lcd clear cmd
lcd_string(1,0,"Edutech Systems", file_desc_lcd, &display);
//displays string
lcd_string(2,0,"baroda lab15", file_desc_lcd, &display);
//displays string
close(file_desc_lcd);
return 0;
}

______________________________________________________________ 129
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

EXERCISES
EG4
Write a simple program to display single character on LCD
EG5
Write a simple program to display single character on different
location of LCD
EG6
Write a simple program to display string on LCD
EG7
Write a simple program to display string on different line number on
LCD

______________________________________________________________ 130
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Lab16
Objective:
To study the simple switch Interface with ARM9 target board
Part List:

Educational practice board for ARM 9 target board.


Power supply
Serial cable
Flat cable
Linux PC
S-Lcd Interface Board.

Program Description:
This Program will display switch number on minicom of hyperterminal on S-Lcd
module
Pin Assignment:
Connection between S-Lcd connector to J11 connector of ARM-9target board
Procedure:

To execute program from ARM9 target board go to /home/Example directory


by this command
[root@EDUTECH~]:cd /home/example

Now execute lab16 by this command


[root@EDUTECH~]:./lab16.o

______________________________________________________________ 131
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Editing program

Now if you want to edit this lab16.c file go to /home/lab/lab16 by this


command in linux host PC.
Linux-dje5:~ # cd /home/lab/lab16

Edit lab16.c by this command


Linux-dje5:~ # vi lab16.c

Now save and exit from vi editor by this command


Esc + : + wq + enter

Now compile your program by this command


Linux-dje5:~ # arm-linux-gcc lab16.c o lab16.o
Above command compile the program.

After compilation check whether object file is created or not by using


command
Linux-dje5:~ # ls

copy object file to /root/tftpboot by this command


Linux-dje5:~ # cp lab16.o /root/tftpboot

copy test to target board by this command


[root@EDUTECH/home]: tftp g r lab16.o 192.168.0.96
[root@EDUTECH/home]: chmod 777 lab16.o

Execute the program from target board by this command


[root@EDUTECH/home]: ./lab16.o

______________________________________________________________ 132
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Program:-

#include <linux/ioctl.h>
#include
#include
#include
#include
#include
#include
#include
#define
#define
#define
#define
#define

<stdio.h>
<unistd.h>
<stdlib.h>
<errno.h>
<fcntl.h>
<string.h>
<sys/ioctl.h>

DEVICE_NAME "SLCD_KEY"
MAJOR_NUM 66
AT91_GPIO_MAGIC ('o')
AT91_GPIO_IOC_INP
_IO(AT91_GPIO_MAGIC, 1)
INIT_SWITCH
_IO(AT91_GPIO_MAGIC, 2)

#define FATAL do { fprintf(stderr, "Error at line %d, file %s (%d)


[%s]\n", \
__LINE__, __FILE__, errno, strerror(errno)); exit(1); } while(0)
int main()
{
int gpio;
int n;
/* external input with interrupt test */
if ((gpio = open("/dev/SLCD_KEY", O_RDWR)) < 0)
FATAL;
printf("/dev/key opened.\n\n");
//for (n = 0; n <= 5; n++)
init_switch(gpio);
while(1)
{
//printf("Setting up /dev/key for external input with
interrupt.\n\n");
sleep(1);
if (ioctl(gpio, AT91_GPIO_IOC_INP) < 0)
FATAL;
//printf("/dev/key got interrupt pulse.\n");
}
if (close(gpio) < 0)
FATAL;
printf("/dev/key closed.\n\n");
return 0;
}
init_switch(int file_desc)
{
int ret_val;

______________________________________________________________ 133
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

ret_val = ioctl(file_desc, INIT_SWITCH);


if (ret_val < 0)
{
printf("ioctl_switch_init failed:%d\n", ret_val);
exit(-1);
}
}

______________________________________________________________ 134
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Lab17
Objective:
To study the simple relay Interface with ARM9 target board
Part List:

Educational practice board for ARM 9 target board.


Power supply
Serial cable
Flat cable
Linux PC
Relay Interface Board.

Program Description:
This Program will switch relay simultaneously
Pin Assignment:
Connection between relay connector J1 to J12 connector of ARM-9target board
Procedure:

To execute program from ARM9 target board go to /home/Example directory


by this command
[root@EDUTECH~]:cd /home/example

Now execute lab17 by this command


[root@EDUTECH~]:./lab17.o

______________________________________________________________ 135
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Editing program

Now if you want to edit this lab17.c file go to /home/lab/lab17 by this


command in linux host PC.
Linux-dje5:~ # cd /home/lab/lab17

Edit lab17.c by this command


Linux-dje5:~ # vi lab17.c

Now save and exit from vi editor by this command


Esc + : + wq + enter

Now compile your program by this command


Linux-dje5:~ # arm-linux-gcc lab17.c o lab17.o
Above command compile the program.

After compilation check whether object file is created or not by using


command
Linux-dje5:~ #

copy object file to /root/tftpboot by this command


Linux-dje5:~ #

ls

cp lab17.o /root/tftpboot

copy test to target board by this command


[root@EDUTECH/home]: tftp g r lab17.o 192.168.0.96
[root@EDUTECH/home]: chmod 777 lab17.o

Execute the program from target board by this command


[root@EDUTECH/home]: ./lab17.o

______________________________________________________________ 136
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Program:-

#include <linux/ioctl.h>

#include
#include
#include
#include
#include
#include
#include
#include

<stdio.h>
<unistd.h>
<stdlib.h>
<errno.h>
<fcntl.h>
<string.h>
<sys/ioctl.h>
"relayuser.h"

#define FATAL do { fprintf(stderr, "Error at line %d, file %s (%d)


[%s]\n", \
__LINE__, __FILE__, errno, strerror(errno)); exit(1); } while(0)

int main()
{
int file_desc_rel;
signed long int temp,count;
int i = 0;
struct relay step;
/* gpio test */
if ((file_desc_rel = open("/dev/ASK06_RELAY", O_RDWR)) < 0)
FATAL;
printf("enter value ...................->
scanf("%d",&count );

");

init_relay(file_desc_rel);
for(temp = 0; temp < count; temp++)
{
right(i,file_desc_rel,&step); //use as per program
application;
i++;
if ( i > 3 )
i = 0;
}
if (close(file_desc_rel) < 0)
FATAL;
return 0;
}

______________________________________________________________ 137
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Lab18
Objective:
To study the simple stepper motor Interface with ARM9 target board
Part List:

Educational practice board for ARM 9 target board.


Power supply 5.0 v
Power supply 12.0 v
Serial cable
Flat cable
Linux PC
Stepper motor Interface Board.
Stepper motor

Program Description:
This Program will rotate stepper motor in clockwise direction in terms of
degree inserted by keyboard on minicom or hyperteminal
Pin Assignment:
Connection between stepper motor connector J1 to J12 connector of ARM-9target
board
Procedure:

To execute program from ARM9 target board go to /home/Example directory


by this command
[root@EDUTECH~]:cd /home/example

Now execute lab18 by this command


[root@EDUTECH~]:./lab18.o

______________________________________________________________ 138
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Editing program

Now if you want to edit this lab18.c file go to /home/lab/lab18 by this


command in linux host PC.
Linux-dje5:~ # cd /home/lab/lab18

Edit lab18.c by this command


Linux-dje5:~ # vi lab18.c

Now save and exit from vi editor by this command


Esc + : + wq + enter

Now compile your program by this command


Linux-dje5:~ # arm-linux-gcc lab18.c o lab18.o
Above command compile the program.

After compilation check whether object file is created or not by using


command
Linux-dje5:~ #

copy object file to /root/tftpboot by this command


Linux-dje5:~ #

ls

cp lab18.o /root/tftpboot

copy test to target board by this command


[root@EDUTECH/home]: tftp g r lab18.o 192.168.0.96
[root@EDUTECH/home]: chmod 777 lab18.o

Execute the program from target board by this command


[root@EDUTECH/home]: ./lab18.o

______________________________________________________________ 139
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Program:-

#include <linux/ioctl.h>
#include
#include
#include
#include
#include
#include
#include

<stdio.h>
<unistd.h>
<stdlib.h>
<errno.h>
<fcntl.h>
<string.h>
<sys/ioctl.h>

#include "lcd.h"
#include "sm.h"
#define FATAL do { fprintf(stderr, "Error at line %d, file %s (%d)
[%s]\n", \
__LINE__, __FILE__, errno, strerror(errno)); exit(1); } while(0)
int data;
struct lcd_display display;
int main()
{
int file_desc_lcd, file_desc_stepper;
signed long int temp,deg,count;
int i = 0;
struct stepper_motor step;
file_desc_lcd = open("/dev/ ASK01_LCD", 0);
if (file_desc_lcd < 0)
{
printf("Can't open >>>> lcd <<<< device file: %s\n",
DEVICE_FILE_NAME_LCD);
exit(-1);
}
file_desc_stepper = open("/dev/ ASK05_STMOTOR", O_RDWR);
if (file_desc_stepper < 0)
{
printf("Can't open >>>> stepper motor <<<<device file:
%s\n", DEVICE_FILE_NAME_SM);
exit(-1);
}
init_lcd(file_desc_lcd);
//initialise matrix keyboard
init_steppermotor(file_desc_stepper);
lcd_cmd(0x01,file_desc_lcd,&display);
//lcd clear cmd
lcd_string(1,0,"lcd displys CAR", file_desc_lcd, &display);
//displays string
sleep(1);

______________________________________________________________ 140
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

while(1)
{
lcd_cmd(0x01,file_desc_lcd,&display);
//lcd clear cmd
lcd_string(1,0,"ST-MOTOR program", file_desc_lcd,
&display); //displays string
printf("Enter Value in Degree...................-> ");
scanf("%d",&deg );
count = deg * 0.5556;
printf("\n\n Stepper-Motor roatating in clockwise\n\n");
lcd_cmd(0x01,file_desc_lcd,&display);
//lcd clear cmd
lcd_string(1,0,"StepperMotor in", file_desc_lcd,
&display);
lcd_string(2,0,"Clockwise", file_desc_lcd, &display);
for(temp = 0; temp < count; temp++)
{
clockwise(i,file_desc_stepper,&step);
i++;
if ( i > 3 )
i = 0;
}
}
close(file_desc_lcd);
close(file_desc_stepper);
return 0;
}

EXERCISES
EG8
EG9

Write a simple program to rotate stepper motor in clockwise direction


Write a simple program to rotate stepper motor in Anti-clockwise direction

______________________________________________________________ 141
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Lab19
Objective:
To study the simple 7-segment keyboard Interface with ARM9 target board
Part List:

Educational practice board for ARM 9 target board.


Power supply 5.0 v
Serial cable
Flat cables
Linux PC
7segment-keyboard Interface Board.

Program Description:
This Program will displays number 0-9 on all the segments of 7segkeyboard ASK.
Pin Assignment:
Connection between 7segment-keyboard J1 to J12 connector of ARM-9target board
and 7segment-keyboard J2 to J11 connector of ARM-9target board
Procedure:

To execute program from ARM9 target board go to /home/Example directory


by this command
[root@EDUTECH~]:cd /home/example

Now execute lab19 by this command


[root@EDUTECH~]:./lab19.o

______________________________________________________________ 142
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Editing program

Now if you want to edit this lab19.c file go to /home/lab/lab19 by this


command in linux host PC.
Linux-dje5:~ # cd /home/lab/lab19

Edit lab19.c by this command


Linux-dje5:~ # vi lab19.c

Now save and exit from vi editor by this command


Esc + : + wq + enter

Now compile your program by this command


Linux-dje5:~ # arm-linux-gcc lab14.c o lab19.o
Above command compile the program.

After compilation check whether object file is created or not by using


command
Linux-dje5:~ #

copy object file to /root/tftpboot by this command


Linux-dje5:~ #

ls

cp lab19.o /root/tftpboot

copy test to target board by this command


[root@EDUTECH/home]: tftp g r lab19.o 192.168.0.96
[root@EDUTECH/home]: chmod 777 lab19.o

Execute the program from target board by this command


[root@EDUTECH/home]: ./lab19.o

______________________________________________________________ 143
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Program:-

#include
#include
#include
#include
#include

<stdio.h>
<stdlib.h>
<fcntl.h>
<unistd.h>
<sys/ioctl.h>

/* open */
/* exit */

#include "7segment_user.h"
main()
{
int file_desc, ret_val, data_change, digit_change;
struct Segment_display display;
file_desc = open("/dev/ASK02_7SEGMENT", 0);
if (file_desc < 0) {
printf("Can't open device file: %s\n", DEVICE_FILE_NAME);
exit(-1);
}

segment_kb_init(file_desc);
for( data_change = 0 ; data_change <= 9 ; data_change++ )
{
seg_1(
seg_2(
seg_3(
seg_4(

data_change
data_change
data_change
data_change

,
,
,
,

file_desc
file_desc
file_desc
file_desc

,
,
,
,

&display
&display
&display
&display

);
);
);
);

printf("data_change = %d\n",data_change );
sleep(1);
}
close(file_desc);
}

______________________________________________________________ 144
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Lab20
Objective:
To study the simple LCD Interface with ARM9 target board
Part List:

Educational practice board for ARM 9 target board.


Power supply 5.0 v
Serial cable
Flat cable
Linux PC
Lcd-keyboard ASK1
Flat cable

Program Description:
This Program will displays string on lcd of lcd-keboard ASK
Pin Assignment:
Connection between Lcd-keyboard J1 to J11 connector of ARM-9target
Procedure:

To execute program from ARM9 target board go to /home/Example directory


by this command
[root@EDUTECH~]:cd /home/example

Now execute lab20 by this command


[root@EDUTECH~]:./lab20.o

______________________________________________________________ 145
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Editing program

Now if you want to edit this lab20.c file go to /home/lab/lab20 by this


command in linux host PC.
Linux-dje5:~ # cd /home/lab/lab20

Edit lab20.c by this command


Linux-dje5:~ # vi lab20.c

Now save and exit from vi editor by this command


Esc + : + wq + enter

Now compile your program by this command


Linux-dje5:~ # arm-linux-gcc lab20.c o lab20.o
Above command compile the program.

After compilation check whether object file is created or not by using


command
Linux-dje5:~ #

copy object file to /root/tftpboot by this command


Linux-dje5:~ #

ls

cp lab20.o /root/tftpboot

copy test to target board by this command


[root@EDUTECH/home]: tftp g r lab20.o 192.168.0.96
[root@EDUTECH/home]: chmod 777 lab20.o

Execute the program from target board by this command


[root@EDUTECH/home]: ./lab20.o

______________________________________________________________ 146
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Program:-

#include <linux/ioctl.h>
#include
#include
#include
#include
#include
#include
#include

<stdio.h>
<unistd.h>
<stdlib.h>
<errno.h>
<fcntl.h>
<string.h>
<sys/ioctl.h>

#include "lcd.h"
#define FATAL do { fprintf(stderr, "Error at line %d, file %s (%d)
[%s]\n", \
__LINE__, __FILE__, errno, strerror(errno)); exit(1); } while(0)
int data;
struct lcd_display display;
int main()
{
int file_desc_lcd;
file_desc_lcd = open("/dev/ ASK01_LCD", 0);
if (file_desc_lcd < 0)
{
printf("Can't open >>>> lcd <<<< device file: %s\n",
DEVICE_FILE_NAME_LCD);
exit(-1);
}
init_lcd(file_desc_lcd);

//initialise matrix keyboard

lcd_cmd(0x01,file_desc_lcd,&display);
//lcd clear cmd
lcd_string(1,0,"Edutech Systems", file_desc_lcd, &display);
//displays string
lcd_string(2,0,"Vadodara", file_desc_lcd, &display);
//displays string
close(file_desc_lcd);
return 0;
}

______________________________________________________________ 147
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Lab21
Objective:
To study the simple LCD commands for lcd with ARM9 target board
Part List:

Educational practice board for ARM 9 target board.


Power supply 5.0 v
Serial cable
Flat cable
Linux PC
Lcd-keyboard ASK1

Program Description:
This Program will displays string shifting left and right on LCD of lcdkeboard ASK
Pin Assignment:
Connection between Lcd-keyboard J1 to J11 connector of ARM-9target
Procedure:

To execute program from ARM9 target board go to /home/Example directory


by this command
[root@EDUTECH~]:cd /home/example

Now execute lab21 by this command


[root@EDUTECH~]:./lab21.o

______________________________________________________________ 148
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Editing program

Now if you want to edit this lab21.c file go to /home/lab/lab21 by this


command in linux host PC.
Linux-dje5:~ # cd /home/lab/lab21

Edit lab21.c by this command


Linux-dje5:~ # vi lab21.c

Now save and exit from vi editor by this command


Esc + : + wq + enter

Now compile your program by this command


Linux-dje5:~ # arm-linux-gcc lab21.c o lab21.o
Above command compile the program.

After compilation check whether object file is created or not by using


command
Linux-dje5:~ # ls

copy object file to /root/tftpboot by this command


Linux-dje5:~ # cp lab21.o /root/tftpboot

copy test to target board by this command


[root@EDUTECH/home]: tftp g r lab21.o 192.168.0.96
[root@EDUTECH/home]: chmod 777 lab21.o

Execute the program from target board by this command


[root@EDUTECH/home]: ./lab21.o

______________________________________________________________ 149
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Program:-

#include <linux/ioctl.h>
#include
#include
#include
#include
#include
#include
#include

<stdio.h>
<unistd.h>
<stdlib.h>
<errno.h>
<fcntl.h>
<string.h>
<sys/ioctl.h>

#include "lcd.h"
#define FATAL do { fprintf(stderr, "Error at line %d, file %s (%d)
[%s]\n", \
__LINE__, __FILE__, errno, strerror(errno)); exit(1); } while(0)

void Delay(int delay)


{
int i,j;
for(i=0;i<=delay;i++)
{
for(j=0;j<=1000;j++){}
}
}
int data;
struct lcd_display display;
int main()
{
int file_desc_lcd,i;
file_desc_lcd = open("/dev/ASK01_LCD", 0);
if (file_desc_lcd < 0)
{
printf("Can't open >>>> lcd <<<< device file: %s\n",
DEVICE_FILE_NAME_LCD);
exit(-1);
}
init_lcd(file_desc_lcd);

//initialise matrix keyboard

lcd_cmd(0x01,file_desc_lcd,&display);
//lcd clear cmd
lcd_string(1,0,"Edutech Systems", file_desc_lcd, &display);
//displays string
lcd_string(2,0,"Vadodara", file_desc_lcd, &display);
//displays string

for(i = 0; i <=5; i++)


{
lcd_cmd(0x1C,file_desc_lcd,&display);

//shift right

cmd
Delay(100);

______________________________________________________________ 150
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

}
for(i = 0; i <=5; i++)
{
lcd_cmd(0x18,file_desc_lcd,&display);

//shift left

cmd
Delay(100);
}
close(file_desc_lcd);
return 0;
}

EXERCISES
EG10 Write a simple program to display string and shift string in left direction in
LCD of LCD-KB with required delay.
EG11 Write a simple program to display string and shift string in right direction in
LCD of LCD-KB with required delay.

______________________________________________________________ 151
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Lab22
Objective:
To study the simple 5x5 matrix keyboard interfacing on with ARM9 target board
Part List:

Educational practice board for ARM 9 target board.


Power supply 5.0 v
Serial cable
Flat cable
Linux PC
Lcd-keyboard ASK1
Flat cable

Program Description:
This Program will displays key number of 5x5 matrix keyboard on LCD of
lcd-keboard ASK
Pin Assignment:
Connection between Lcd-keyboard J1 to J11 connector of ARM-9target
Procedure:

To execute program from ARM9 target board go to /home/Example directory


by this command
[root@EDUTECH~]:cd /home/example

Now execute lab22 by this command


[root@EDUTECH~]:./lab22.o

______________________________________________________________ 152
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Editing program

Now if you want to edit this lab22.c file go to /home/lab/lab22 by this


command in linux host PC.
Linux-dje5:~ # cd /home/lab/lab22

Edit lab22.c by this command


Linux-dje5:~ # vi lab22.c

Now save and exit from vi editor by this command


Esc + : + wq + enter

Now compile your program by this command


Linux-dje5:~ # arm-linux-gcc lab22.c o lab22.o
Above command compile the program.

After compilation check whether object file is created or not by using


command
Linux-dje5:~ #

copy object file to /root/tftpboot by this command


Linux-dje5:~ #

ls

cp lab22.o /root/tftpboot

copy test to target board by this command


[root@EDUTECH/home]: tftp g r lab22.o 192.168.0.96
[root@EDUTECH/home]: chmod 777 lab22.o

Execute the program from target board by this command


[root@EDUTECH/home]: ./lab22.o

______________________________________________________________ 153
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Program:-

#include <linux/ioctl.h>
#include
#include
#include
#include
#include
#include
#include

<stdio.h>
<unistd.h>
<stdlib.h>
<errno.h>
<fcntl.h>
<string.h>
<sys/ioctl.h>

#include "kb.h"
#include "lcd.h"
#define FATAL do { fprintf(stderr, "Error at line %d, file %s (%d)
[%s]\n", \
__LINE__, __FILE__, errno, strerror(errno)); exit(1); } while(0)
int data;
struct lcd_display display;
int main()
{
int file_desc_lcd, file_desc_keyboard;
int key;

file_desc_lcd = open("/dev/ASK01_LCD", 0);


if (file_desc_lcd < 0)
{
printf("Can't open >>>> lcd <<<< device file: %s\n",
DEVICE_FILE_NAME_LCD);
exit(-1);
}
file_desc_keyboard = open("/dev/ASK01_MATKB", O_RDWR);
if (file_desc_keyboard < 0)
{
printf("Can't open >>>> keyboard <<<<device file: %s\n",
DEVICE_FILE_NAME_KEYBOARD);
exit(-1);
}
init_keyboard(file_desc_keyboard); //initialise matrix
keyboard
init_lcd(file_desc_lcd);
//initialise matrix keyboard
lcd_cmd(0x01,file_desc_lcd,&display);
//lcd clear cmd
lcd_string(1,0,"lcd displys KB", file_desc_lcd, &display);
//displays string

while(1)
{
key = read_keyboard(file_desc_keyboard,data);

______________________________________________________________ 154
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________
lcd_cursor_set(2, 0, file_desc_lcd, &display);
key_on_lcd(key,file_desc_lcd);
printf("\n user key value is = %d \n",key);
sleep(1);
}
close(file_desc_keyboard);
close(file_desc_lcd);
return 0;
}
int key_on_lcd(int key1,int file_desc_lcd)
{
unsigned int row,col;
row = key1/ 10;
col = key1% 10;
row = row + 48;
col = col + 48;
lcd_data(row,file_desc_lcd,&display);
lcd_data(col,file_desc_lcd,&display);
}

EXERCISES
EG12 Write a simple program to display key number on LCD of LCD-KB.
( like A , B , C , D etc.)
EG13 Write a simple program to display different string on LCD while pressing
different key of LCD-KB
EG14 Write a simple program to explore different LCD command on LCD.

______________________________________________________________ 155
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Lab23
Objective:
To study the simple CG-RAM programming of LCD with ARM9 target board

Part List:

Educational practice board for ARM 9 target board.


Power supply 5.0 v
Serial cable
Flat cable
Linux PC
Lcd-keyboard ASK1
Flat cable

Program Description:
This Program will display car on LCD when we press keys on 5x5 matrix
keyboard on lcd-keyboard ASK
Press A for displaying car
Press B for shifting car on right sight
Press C for shifting car on left sight
Pin Assignment:
Connection between Lcd-keyboard J1 to J11 connector of ARM-9target
Procedure:

To execute program from ARM9 target board go to /home/Example directory


by this command
[root@EDUTECH~]:cd /home/example

Now execute lab23 by this command


[root@EDUTECH~]:./lab23.o

______________________________________________________________ 156
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Editing program

Now if you want to edit this lab23.c file go to /home/lab/lab23 by this


command in linux host PC.
Linux-dje5:~ # cd /home/lab/lab23

Edit lab23.c by this command


Linux-dje5:~ # vi lab23.c

Now save and exit from vi editor by this command


Esc + : + wq + enter

Now compile your program by this command


Linux-dje5:~ # arm-linux-gcc lab23.c o lab23.o
Above command compile the program.

After compilation check whether object file is created or not by using


command
Linux-dje5:~ #

copy object file to /root/tftpboot by this command


Linux-dje5:~ #

ls

cp lab23.o /root/tftpboot

copy test to target board by this command


[root@EDUTECH/home]: tftp g r lab23.o 192.168.0.96
[root@EDUTECH/home]: chmod 777 lab23.o

Execute the program from target board by this command


[root@EDUTECH/home]: ./lab23.o

______________________________________________________________ 157
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Program:-

#include
#include
#include
#include
#include
#include
#include
#include

<linux/ioctl.h>
<stdio.h>
<unistd.h>
<stdlib.h>
<errno.h>
<fcntl.h>
<string.h>
<sys/ioctl.h>

#include "kb.h"
#include "lcd.h"

#define FATAL do { fprintf(stderr, "Error at line %d, file %s (%d)


[%s]\n", \
__LINE__, __FILE__, errno, strerror(errno)); exit(1); } while(0)
int data;
struct lcd_display display;
int main()
{
int file_desc_lcd, file_desc_keyboard;
int key, shift, loop;

int i = 0;
file_desc_lcd = open("/dev/ASK01_LCD", 0);
if (file_desc_lcd < 0)
{
printf("Can't open >>>> lcd <<<< device file: %s\n",
DEVICE_FILE_NAME_LCD);
exit(-1);
}
file_desc_keyboard = open("/dev/ASK01_MATKB", O_RDWR);
if (file_desc_keyboard < 0)
{
printf("Can't open >>>> keyboard <<<<device file: %s\n",
DEVICE_FILE_NAME_KEYBOARD);
exit(-1);
}
init_keyboard(file_desc_keyboard);
keyboard
init_lcd(file_desc_lcd);
keyboard

//initialise matrix
//initialise matrix

lcd_cmd(0x01,file_desc_lcd,&display);
//lcd clear cmd
lcd_string(1,0,"lcd displys CAR", file_desc_lcd, &display);
//displays string
car_on_cgram(file_desc_lcd);
sleep(1);

______________________________________________________________ 158
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

while(1)
{
lcd_cmd(0x01,file_desc_lcd,&display);
//lcd clear cmd
lcd_string(1,0,"Press 1 for CAR", file_desc_lcd,
&display); //displays string
while((key = read_keyboard(file_desc_keyboard,data)) ==
55);
if (key == 20)

//this if statement is for displaying

car on lcd
{
car_on_lcd(file_desc_lcd);
sleep(1);
while((key =
read_keyboard(file_desc_keyboard,data)) != 30);
for(shift = 0; shift <=15; shift++)
{
lcd_cmd(0x1C,file_desc_lcd,&display);
//shift right cmd;shift car in right direction
sleep(1);
}
while((key =
read_keyboard(file_desc_keyboard,data)) != 40);
for(shift = 0; shift <=15; shift++)
{
lcd_cmd(0x18,file_desc_lcd,&display);
//shift left cmd;shift car in left direction
sleep(1);
}
}
else
{
lcd_string(1,0,"Press 1 for CAR", file_desc_lcd,
&display); //displays string
}
sleep(1);
}
close(file_desc_keyboard);
close(file_desc_lcd);
return 0;

}
int car_on_cgram(int file_desc_lcd)
{
lcd_cmd(0x01,file_desc_lcd,&display);

//lcd clear cmd

lcd_cmd(0x02,file_desc_lcd,&display);

//come home cmd

______________________________________________________________ 159
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________
lcd_cmd(0x40,file_desc_lcd,&display);
mode cmd address = 0x40 first add of first character

//cg-ram enter

lcd_data(0x00,file_desc_lcd,&display);
for making car in cg_ram location 0-6
lcd_data(0x01,file_desc_lcd,&display);
for making car in cg_ram location 0-6
lcd_data(0x03,file_desc_lcd,&display);
for making car in cg_ram location 0-6
lcd_data(0x1F,file_desc_lcd,&display);
for making car in cg_ram location 0-6
lcd_data(0x1F,file_desc_lcd,&display);
for making car in cg_ram location 0-6
lcd_data(0x1F,file_desc_lcd,&display);
for making car in cg_ram location 0-6
lcd_data(0x1F,file_desc_lcd,&display);
for making car in cg_ram location 0-6
lcd_data(0x0F,file_desc_lcd,&display);
for making car in cg_ram location 0-6

//data

lcd_data(0x1F,file_desc_lcd,&display);
for making car in cg_ram location 0-6
lcd_data(0x1F,file_desc_lcd,&display);
for making car in cg_ram location 0-6
lcd_data(0x03,file_desc_lcd,&display);
for making car in cg_ram location 0-6
lcd_data(0x03,file_desc_lcd,&display);
for making car in cg_ram location 0-6
lcd_data(0x1F,file_desc_lcd,&display);
for making car in cg_ram location 0-6
lcd_data(0x1F,file_desc_lcd,&display);
for making car in cg_ram location 0-6
lcd_data(0x1F,file_desc_lcd,&display);
for making car in cg_ram location 0-6
lcd_data(0x1F,file_desc_lcd,&display);
for making car in cg_ram location 0-6

//data

lcd_data(0x1E,file_desc_lcd,&display);
for making car in cg_ram location 0-6
lcd_data(0x1F,file_desc_lcd,&display);
for making car in cg_ram location 0-6
lcd_data(0x11,file_desc_lcd,&display);
for making car in cg_ram location 0-6
lcd_data(0x11,file_desc_lcd,&display);
for making car in cg_ram location 0-6
lcd_data(0x1F,file_desc_lcd,&display);
for making car in cg_ram location 0-6
lcd_data(0x1F,file_desc_lcd,&display);
for making car in cg_ram location 0-6
lcd_data(0x1F,file_desc_lcd,&display);
for making car in cg_ram location 0-6
lcd_data(0x1F,file_desc_lcd,&display);
for making car in cg_ram location 0-6

//data

lcd_data(0x00,file_desc_lcd,&display);
for making car in cg_ram location 0-6
lcd_data(0x00,file_desc_lcd,&display);

//data

//data
//data
//data
//data
//data
//data
//data

//data
//data
//data
//data
//data
//data
//data

//data
//data
//data
//data
//data
//data
//data

//data

for making car in cg_ram location 0-6


______________________________________________________________ 160
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________
lcd_data(0x18,file_desc_lcd,&display);
for making car in cg_ram location 0-6
lcd_data(0x1F,file_desc_lcd,&display);
for making car in cg_ram location 0-6
lcd_data(0x1F,file_desc_lcd,&display);
for making car in cg_ram location 0-6
lcd_data(0x1F,file_desc_lcd,&display);
for making car in cg_ram location 0-6
lcd_data(0x1F,file_desc_lcd,&display);
for making car in cg_ram location 0-6
lcd_data(0x1F,file_desc_lcd,&display);
for making car in cg_ram location 0-6

//data

lcd_data(0x00,file_desc_lcd,&display);
for making car in cg_ram location 0-6
lcd_data(0x00,file_desc_lcd,&display);
for making car in cg_ram location 0-6
lcd_data(0x00,file_desc_lcd,&display);
for making car in cg_ram location 0-6
lcd_data(0x1C,file_desc_lcd,&display);
for making car in cg_ram location 0-6
lcd_data(0x1E,file_desc_lcd,&display);
for making car in cg_ram location 0-6
lcd_data(0x1F,file_desc_lcd,&display);
for making car in cg_ram location 0-6
lcd_data(0x1F,file_desc_lcd,&display);
for making car in cg_ram location 0-6
lcd_data(0x1F,file_desc_lcd,&display);
for making car in cg_ram location 0-6

//data

lcd_data(0x07,file_desc_lcd,&display);
for making car in cg_ram location 0-6
lcd_data(0x07,file_desc_lcd,&display);
for making car in cg_ram location 0-6
lcd_data(0x00,file_desc_lcd,&display);
for making car in cg_ram location 0-6
lcd_data(0x00,file_desc_lcd,&display);
for making car in cg_ram location 0-6
lcd_data(0x00,file_desc_lcd,&display);
for making car in cg_ram location 0-6
lcd_data(0x00,file_desc_lcd,&display);
for making car in cg_ram location 0-6
lcd_data(0x00,file_desc_lcd,&display);
for making car in cg_ram location 0-6
lcd_data(0x00,file_desc_lcd,&display);
for making car in cg_ram location 0-6

//data

lcd_data(0x1C,file_desc_lcd,&display);
for making car in cg_ram location 0-6
lcd_data(0x1C,file_desc_lcd,&display);
for making car in cg_ram location 0-6
lcd_data(0x00,file_desc_lcd,&display);
for making car in cg_ram location 0-6
lcd_data(0x00,file_desc_lcd,&display);
for making car in cg_ram location 0-6
lcd_data(0x00,file_desc_lcd,&display);

//data

//data
//data
//data
//data
//data

//data
//data
//data
//data
//data
//data
//data

//data
//data
//data
//data
//data
//data
//data

//data
//data
//data
//data

for making car in cg_ram location 0-6


______________________________________________________________ 161
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________
lcd_data(0x00,file_desc_lcd,&display);
for making car in cg_ram location 0-6
lcd_data(0x00,file_desc_lcd,&display);
for making car in cg_ram location 0-6
lcd_data(0x00,file_desc_lcd,&display);
for making car in cg_ram location 0-6

//data
//data
//data

}
int car_on_lcd(int file_desc_lcd)
{
lcd_cmd(0x01,file_desc_lcd,&display);
lcd_cmd(0x80,file_desc_lcd,&display);
first char cmd; row0-column0

//lcd clear cmd


//first line,

lcd_data(0x00,file_desc_lcd,&display);
ram data col 0
lcd_data(0x01,file_desc_lcd,&display);
ram data col 1
lcd_data(0x02,file_desc_lcd,&display);
ram data col 2
lcd_data(0x03,file_desc_lcd,&display);
ram data col 3
lcd_data(0x04,file_desc_lcd,&display);
ram data col 4

//first row cg-

lcd_cmd(0xC0,file_desc_lcd,&display);
cmd column 0
lcd_data(0x05,file_desc_lcd,&display);
cg-ram data

//second row

lcd_cmd(0xC4,file_desc_lcd,&display);
cmd column 4
lcd_data(0x06,file_desc_lcd,&display);
cg-ram data
}

//first row cg//first row cg//first row cg//first row cg-

//second row

//second row
//second row

EXERCISES
EG15 Write a simple program to explain CG-RAM programming to make edutech
logo.

______________________________________________________________ 162
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Lab24
Objective:
To study the simple on-chip RTC Interface with ARM9 target board
Part List:

Educational practice board for ARM 9 target board.


Power supply 5.0 v
Serial cable
Flat cable
Linux PC
Lcd-keyboard ASK1
Flat cable

Program Description:
This Program will displays time on minicom or hyperterminal
Pin Assignment:
Connection between Lcd-keyboard J1 to J11 connector of ARM-9target
Procedure:

To execute program from ARM9 target board go to /home/Example directory


by this command

[root@EDUTECH~]:cd /home/example

Now execute lab24 by this command

[root@EDUTECH~]:./lab24.o

______________________________________________________________ 163
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Editing program

Now if you want to edit this lab24.c file go to /home/lab/lab24 by this


command in linux host PC.
Linux-dje5:~ # cd /home/lab/lab24

Edit lab24.c by this command


Linux-dje5:~ # vi lab24.c

Now save and exit from vi editor by this command


Esc + : + wq + enter

Now compile your program by this command


Linux-dje5:~ # arm-linux-gcc lab24.c o lab24.o
Above command compile the program.

After compilation check whether object file is created or not by using


command
Linux-dje5:~ #

copy object file to /root/tftpboot by this command


Linux-dje5:~ #

ls

cp lab24.o /root/tftpboot

copy test to target board by this command


[root@EDUTECH/home]: tftp g r lab24.o 192.168.0.96
[root@EDUTECH/home]: chmod 777 lab24.o

Execute the program from target board by this command


[root@EDUTECH/home]: ./lab24.o

______________________________________________________________ 164
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Program:-

#include
#include
#include
#include
#include

<stdio.h>
<stdlib.h>
<fcntl.h>
<unistd.h>
<sys/ioctl.h>

/* open */
/* exit */

#include "lcd.h"
#include "rtc.h"
struct rtc_time time_date;
void Delay(int delay)
{
int i,j;
for(i=0;i<=delay;i++)
{
for(j=0;j<=1000;j++){}
}
}
main()
{
int file_desc_lcd, file_desc_rtc;
struct lcd_display display;
time_date.sec
time_date.min
time_date.hour
time_date.year
time_date.mon
time_date.date
time_date.wday

=
=
=
=
=
=
=

50;
59;
23;
1999;
12;
31;
1;

file_desc_lcd = open("/dev/ASK01_LCD", 0);


if (file_desc_lcd < 0)
{
printf("Can't open >>>> lcd <<<< device file: %s\n",
DEVICE_FILE_NAME_LCD);
exit(-1);
}
file_desc_rtc = open("/dev/ARM9_RTC", 0);
if (file_desc_rtc < 0)
{
printf("Can't open >>>> rtc1 <<<<device file: %s\n",
DEVICE_FILE_NAME_RTC);
exit(-1);
}
init_lcd(file_desc_lcd);
lcd_cmd(0x01,file_desc_lcd,&display);
//lcd clear cmd
lcd_string(1,0,"RTC displys time ", file_desc_lcd, &display);
//displays string

______________________________________________________________ 165
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

sleep(1);
rtc_init(file_desc_rtc, &time_date);
while(1)
{
rtc_read(file_desc_rtc, &time_date);
}
close(file_desc_rtc);
close(file_desc_lcd);
}

______________________________________________________________ 166
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Lab25
Objective:
To study the enrollment of fingerprint with ARM-9 target board
Part List

File List

Educational practice board for ARM 9 target board.


Power supply
Serial cable
Flat cable
Linux PC
Finger Print
Lcd-keyboard ASK1

: lcd.h, kb.h

Program Description:
This Program will Enroll ID number and store Number to Finger Print.
Pin Assignment:

Connection between LCD-keyboard J1 to J11 connector of ARM-9target


Connection between serial port of Finger Print to serial port of ARM-9target
Connect Finger Print USB connector to USB device port of PC or ARM-9target

Procedure:

To execute program from ARM9 target board go to /home/Example directory


by this command
[root@EDUTECH~]:cd /home/example

Now execute Enroll by this command


[root@EDUTECH~]:./lab25.o

______________________________________________________________ 167
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Editing program

Now if you want to edit this lab25.c file go to /home/lab/lab25 by this


command in linux host PC.
Linux-dje5:~ # cd /home/lab/lab25/

Edit lab25.c by this command


Linux-dje5:~ # vi lab25.c

Now save and exit from vi editor by this command


Esc + : + wq + enter

Now compile your program by this command


Linux-dje5:~ # arm-linux-gcc lab25.c o lab25.o
Above command compile the program.

After compilation check whether object file is created or not by using


command
Linux-dje5:~ # ls

copy object file to /root/tftpboot by this command


Linux-dje5:~ # cp lab25.o /root/tftpboot

copy test to target board by this command


[root@EDUTECH/home]: tftp g r lab25.o 192.168.0.96
[root@EDUTECH/home]: chmod 777 lab25.o

Execute the program from target board by this command


[root@EDUTECH/home]: ./ lab25.o

______________________________________________________________ 168
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Output:
Following is the output shown on the screen of ASK1 ( LCD-KB) when the program is
executed.
Edutech System
Finer Print
Connecting
Connection Done
Entering
Master Mode
Master Mode DONE
A=Enroll
Enter ID
If Enroll will be selected then
Enroll 1 start
Put Finger...
Enroll 1 done
Lift Finger
Enroll 2 start
Put Finger...
Enroll 2 done
Lift Finger

______________________________________________________________ 169
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Flow chart:

______________________________________________________________ 170
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Lab26
Objective:
To study the identify ID of fingerprint with ARM-9 target board
Part List

File List

Educational practice board for ARM 9 target board.


Power supply
Serial cable
Flat cable
Linux PC
Finger Print
Lcd-keyboard ASK1

: lcd.h, kb.h

Program Description:
This Program will Identify ID number stored on Finger Print.
Pin Assignment:

Connection between Lcd-keyboard J1 to J11 connector of ARM-9target


Connection between serial port of Finger Print to serial port of ARM-9target
Connect Finger Print USB connector to USB device port of PC or ARM-9target

Procedure:

To execute program from ARM9 target board go to /home/Example directory


by this command
[root@EDUTECH~]:cd /home/example

Now execute Identify by this command


[root@EDUTECH~]:./lab26.o

______________________________________________________________ 171
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Editing program

Now if you want to edit this lab26.c file go to /home/lab/lab26 by this


command in linux host PC.
Linux-dje5:~ # cd /home/lab/lab26

Edit lab26.c by this command


Linux-dje5:~ # vi lab26.c

Now save and exit from vi editor by this command


Esc + : + wq + enter

Now compile your program by this command


Linux-dje5:~ # arm-linux-gcc lab26.c o lab26.o
Above command compile the program.

After compilation check whether object file is created or not by using


command
Linux-dje5:~ # ls

copy object file to /root/tftpboot by this command


Linux-dje5:~ # cp lab26.o /root/tftpboot

copy test to target board by this command


[root@EDUTECH/home]: tftp g r lab26.o 192.168.0.96
[root@EDUTECH/home]: chmod 777 lab26.o

Execute the program from target board by this command


[root@EDUTECH/home]: ./lab26.o

______________________________________________________________ 172
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Output:
Following is the output shown on the screen of ASK-LCD when the program is
executed.
Edutech System
Finer Print
connecting...
Connection Done
Entering...
Master Mode
Master Mode DONE
F1=Identify
If Identify will be selected then
Identify Start
Put ur finger...
ID=3
Identify Done

______________________________________________________________ 173
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Flow chart:

______________________________________________________________ 174
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Lab27
Objective:
To study the delete ID number of fingerprint with ARM-9 target board
Part List

File List

Educational practice board for ARM 9 target board.


Power supply
Serial cable
Flat cable
Linux PC
Finger Print
Lcd-keyboard ASK1

: lcd.h, kb.h

Program Description:
This Program will Delete ID number stored on Finger Print.
Pin Assignment:

Connection between Lcd-keyboard J1 to J11 connector of ARM-9target


Connection between serial port of Finger Print to serial port of ARM-9target
Connect Finger Print USB connector to USB device port of PC or ARM-9target

Procedure:

To execute program from ARM9 target board go to /home/Example directory


by this command
[root@EDUTECH~]:cd /home/example

Now execute Delete by this command


[root@EDUTECH~]:./lab27.o

______________________________________________________________ 175
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Editing program

Now if you want to edit this lab27.c file go to /home/lab/lab27 by this


command in linux host PC.
Linux-dje5:~ # cd /home/lab/lab27

Edit lab27.c by this command


Linux-dje5:~ # vi lab27.c

Now save and exit from vi editor by this command


Esc + : + wq + enter

Now compile your program by this command


Linux-dje5:~ # arm-linux-gcc lab27.c o lab27.o
Above command compile the program.

After compilation check whether object file is created or not by using


command
Linux-dje5:~ # ls

copy object file to /root/tftpboot by this command


Linux-dje5:~ # cp lab27.o /root/tftpboot

copy test to target board by this command


[root@EDUTECH/home]: tftp g r lab27.o 192.168.0.96
[root@EDUTECH/home]: chmod 777 lab27.o

Execute the program from target board by this command


[root@EDUTECH/home]: ./lab27.o

______________________________________________________________ 176
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Output:
Following is the output shown on the screen of ASK-LCD when the program is
executed.
Edutech System
Finer Print
connecting...
Connection Done
Entering...
Master Mode
Master Mode DONE
D=Delete
Enter ID
If Delete will be selected then
Entering...
Delete Mode
ID 3 Delete
Delete Done

______________________________________________________________ 177
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Flow chart:

EXERCISES
EG16 Write a simple program to enroll, identify and delete finger-print id using
ASK-LCD in a single program.

______________________________________________________________ 178
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Lab28
Objective:
To write a program to demonstrate basic working of RFID with ARM-9 target board
Part List

File List

Educational practice board for ARM 9 target board.


Power supply
Serial cable
Flat cable
Linux PC
RFID module
Lcd_keyboard ASK-1
: lcd.h, kb.h

Program Description:
This Program will display holder number on ASK-1 LCD-KB
Pin Assignment:

Connection between LCD-keyboard J1 to J11 connector of ARM-9target


Board.
Connect DB9 connector of RFID MODULE to J3 (UART1) of ARM-9 target
Board.

Procedure:

To execute program from ARM9 target board go to /home/Example directory


by this command
[root@EDUTECH~]:cd /home/example

Now execute Enroll by this command


[root@EDUTECH~]:./lab28.o

______________________________________________________________ 179
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Editing program

Now if you want to edit this lab28.c file go to /home/lab/lab28 by this


command in linux host PC.
Linux-dje5:~ # cd /home/lab/lab28

Edit lab28.c by this command


Linux-dje5/home/lab/:~ # vi lab28.c

Now save and exit from vi editor by this command


Esc + : + wq + enter

Now compile your program by this command


Linux-dje5/home/lab/:~#arm-linux-gcc lab28.c o lab28.o
Above command compile the program.

After compilation check whether object file is created or not by using


command
Linux-dje5/home/lab/:~ # ls

copy object file to /root/tftpboot by this command


Linux-dje5/home/lab/:~ #cp lab28.o /root/tftpboot

copy test to target board by this command


[root@EDUTECH/home]: tftp g r lab28.o 192.168.0.96
[root@EDUTECH/home]: chmod 777 lab28.o

Execute the program from target board by this command


[root@EDUTECH/home]: ./lab28.o

______________________________________________________________ 180
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Flow chart:

______________________________________________________________ 181
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Lab29
Objective:
To write a program to demonstrate basic working of RFID with on-chip RTC of ARM9
CPU and LCD with ARM-9 target board
Part List

File List

Educational practice board for ARM 9 target board.


Power supply
Serial cable
Flat cable
Linux PC
RFID module
Lcd_keyboard ASK1
: lcd.h, kb.h, rtc.h

Program Description:
This Program will display holder number with time on ASK-1 LCD-KB
Pin Assignment:

Connection between LCD-keyboard J1 to J11 connector of ARM-9target


Board.
Connect DB9 connector of RFID MODULE to J3 (UART1) of ARM-9 target
Board.

Procedure:

To execute program from ARM9 target board go to /home/Example directory


by this command
[root@EDUTECH~]:cd /home/example

Now execute Enroll by this command


[root@EDUTECH~]:./lab29.o

______________________________________________________________ 182
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Editing program

Now if you want to edit this lab29.c file go to /home/lab/lab29 by this


command in linux host PC.
Linux-dje5:~ # cd /home/lab/lab29

Edit lab29.c by this command


Linux-dje5/home/lab/:~ # vi lab29.c

Now save and exit from vi editor by this command


Esc + : + wq + enter

Now compile your program by this command


Linux-dje5/home/lab/:~#arm-linux-gcc lab29.c o lab29.o
Above command compile the program.

After compilation check whether object file is created or not by using


command
Linux-dje5/home/lab/:~ # ls

copy object file to /root/tftpboot by this command


Linux-dje5/home/lab/:~ #cp lab29.o /root/tftpboot

copy test to target board by this command


[root@EDUTECH/home]: tftp g r lab29.o 192.168.0.96
[root@EDUTECH/home]: chmod 777 lab29.o

Execute the program from target board by this command


[root@EDUTECH/home]: ./ lab29.o

______________________________________________________________ 183
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Flow chart:

______________________________________________________________ 184
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

EXERCISES
EG17 Write a simple program to demonstrate basic working of RFID with ARM-9
target board using SLCD

______________________________________________________________ 185
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Lab30
Objective:
To write a program to initialize the GSM module with ARM-9 target board
Part List

Educational practice board for ARM 9 target board.


Power supply
Serial cable
Flat cable
Linux PC
GSM Module
SIM Card

Program Description:
This Program will initialize the GSM module.
Pin Assignment:

Connection of Power supply to the GSM module.


Connection between serial port of GSM module to serial port of ARM-9target
Connect the antenna to the GSM module.

Procedure:

To execute program from ARM9 target board go to /home/Example directory


by this command
[root@EDUTECH~]:cd /home/example

Now execute lab30.o by this command


[root@EDUTECH~]:./lab30.o

______________________________________________________________ 186
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Editing program

Now if you want to edit this lab30.c file go to /home/lab/lab30 by this


command in linux host PC.
Linux-dje5:~ # cd /home/lab/lab30

Edit lab30.c by this command


Linux-dje5:~ # vi lab30.c

Now save and exit from vi editor by this command


Esc + : + wq + enter

Now compile your program by this command


Linux-dje5:~ # arm-linux-gcc lab30.c o lab30.o
Above command compile the program.

After compilation check whether object file is created or not by using


command
Linux-dje5:~ # ls

copy object file to /root/tftpboot by this command


Linux-dje5:~ # cp lab30.o /root/tftpboot

copy test to target board by this command


[root@EDUTECH/home]: tftp g r lab30.o 192.168.0.96
[root@EDUTECH/home]: chmod 777 lab30.o

Execute the program from target board by this command


[root@EDUTECH/home]: ./lab30.o

______________________________________________________________ 187
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Output:
[root@EDUTECH:/home/default] ./lab30.o
Serial port is initialised
Receiving data in buffer...Output
AT
OK
###########...Connection Succcessful... ##########

______________________________________________________________ 188
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Lab31
Objective:
To write a program to call a number using GSM module with ARM-9 target board
Part List

Educational practice board for ARM 9 target board.


Power supply
Serial cable
Flat cable
Linux PC
GSM Module
SIM Card

Program Description:
This Program will call the mobile number with the help of GSM module.
Pin Assignment:

Connection of Power supply to the GSM module.


Connection between serial port of GSM module to serial port of ARM-9target
Connect the antenna to the GSM module.

Procedure:

To execute program from ARM9 target board go to /home/Example directory


by this command
[root@EDUTECH~]:cd /home/example

Now execute lab31.o by this command


[root@EDUTECH~]:./lab31.o

______________________________________________________________ 189
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Editing program

Now if you want to edit this lab31.c file go to /home/lab/lab31 by this


command in linux host PC.
Linux-dje5:~ # cd /home/lab/lab31

Edit lab31.c by this command


Linux-dje5:~ # vi lab31.c

Now save and exit from vi editor by this command


Esc + : + wq + enter

Now compile your program by this command


Linux-dje5:~ # arm-linux-gcc lab31.c o lab31.o
Above command compile the program.

After compilation check whether object file is created or not by using


command
Linux-dje5:~ # ls

copy object file to /root/tftpboot by this command


Linux-dje5:~ #

cp lab31.o /root/tftpboot

copy test to target board by this command


[root@EDUTECH/home]: tftp g r lab31.o 192.168.0.96
[root@EDUTECH/home]: chmod 777 lab31.o

Execute the program from target board by this command


[root@EDUTECH/home]: ./lab31.o

______________________________________________________________ 190
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Output:
[root@EDUTECH:/home/default] ./lab31.o
Serial port is initialised
Receiving data in buffer...Output
AT
OK
###########...Connection Succcessful... ##########
Enter mobile number
9974772530
########### Calling...!! #############
Receiving data in buffer...Output
ATD9974772530;
###########...Call Succcessful... ##########
EXERCISES
EG18 Write a simple program to give a call using GSM module by fix mobile number
through program

______________________________________________________________ 191
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Lab32
Objective:
To write a program to give a miss call using GSM module with ARM-9 target board
Part List

Educational practice board for ARM 9 target board.


Power supply
Serial cable
Flat cable
Linux PC
GSM Module
SIM Card

Program Description:
This Program will miss call to the given number using GSM module.
Pin Assignment:

Connection of Power supply to the GSM module.


Connection between serial port of GSM module to serial port of ARM-9target
Connect the antenna to the GSM module.

Procedure:

To execute program from ARM9 target board go to /home/Example directory


by this command
[root@EDUTECH~]:cd /home/example

Now execute lab32.o by this command


[root@EDUTECH~]:./ lab32.o

______________________________________________________________ 192
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Editing program

Now if you want to edit this lab32.c file go to /home/lab/lab32 by this


command in linux host PC.
Linux-dje5:~ # cd /home/lab/lab32

Edit lab32.c by this command


Linux-dje5:~ # vi lab32.c

Now save and exit from vi editor by this command


Esc + : + wq + enter

Now compile your program by this command


Linux-dje5:~ # arm-linux-gcc lab32.c o lab32.o
Above command compile the program.

After compilation check whether object file is created or not by using


command
Linux-dje5:~ # ls

copy object file to /root/tftpboot by this command


Linux-dje5:~ # cp lab32.o /root/tftpboot

copy test to target board by this command


[root@EDUTECH/home]: tftp g r lab32.o 192.168.0.96
[root@EDUTECH/home]: chmod 777 lab32.o

Execute the program from target board by this command


[root@EDUTECH/home]: ./lab32.o

______________________________________________________________ 193
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Output:
[root@EDUTECH:/home/default] ./lab32.o
Serial port is initialised
Receiving data in buffer...Output
AT
OK
###########...Connection Succcessful... ##########
Enter mobile number
9974772530
########### Calling...!! #############
Receiving data in buffer...Output
ATD9974772530;
###########...Call Succcessful... ##########
###########...Hanging up...!! #############received SIGIO signal.
Receiving data in buffer...Output
ATH
OK
###########...Call Suspended... ##########

EXERCISES
EG19 Write a simple program to give a miss call using GSM module by fix mobile
number through program

______________________________________________________________ 194
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Lab33
Objective:
To write a program to send sms using GSM module with ARM-9 target board
Part List

Educational practice board for ARM 9 target board.


Power supply
Serial cable
Flat cable
Linux PC
GSM Module
SIM Card

Program Description:
This Program will send sms to the given number using GSM module.
Pin Assignment:

Connection of Power supply to the GSM module.


Connection between serial port of GSM module to serial port of ARM-9target
Connect the antenna to the GSM module.

Procedure:

To execute program from ARM9 target board go to /home/Example directory


by this command
[root@EDUTECH~]:cd /home/example

Now execute lab33.o by this command


[root@EDUTECH~]:./lab33.o

______________________________________________________________ 195
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Editing program

Now if you want to edit this lab33.c file go to /home/lab/lab33 by this


command in linux host PC.
Linux-dje5:~ # cd /home/lab/lab33

Edit lab33.c by this command


Linux-dje5:~ # vi lab33.c

Now save and exit from vi editor by this command


Esc + : + wq + enter

Now compile your program by this command


Linux-dje5:~ # arm-linux-gcc lab33.c o lab33.o
Above command compile the program.

After compilation check whether object file is created or not by using


command
Linux-dje5:~ # ls

copy object file to /root/tftpboot by this command


Linux-dje5:~ # cp lab33.o /root/tftpboot

copy test to target board by this command


[root@EDUTECH/home]: tftp g r lab33.o 192.168.0.96
[root@EDUTECH/home]: chmod 777 lab33.o

Execute the program from target board by this command


[root@EDUTECH/home]: ./lab33.o

______________________________________________________________ 196
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Output:
[root@EDUTECH:/home/default] ./lab34.o
Serial port is initialised
Receiving data in buffer...Output
AT
OK
###########...Connection Succcessful... ##########
Enter mobile number
9974772530
Enter content of SMS..
Input :hello world
########### ...Sending SMS...!! #############
Receiving data in buffer..
Output
###########...SMS Sent... ##########
EXERCISES
EG20 Write a simple program to send SMS using GSM module on fix mobile number
and fix message through program.

______________________________________________________________ 197
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Lab34
Objective:
To write a program to read sms of SIM card using GSM module with ARM-9 target
board
Part List

Educational practice board for ARM 9 target board.


Power supply
Serial cable
Flat cable
Linux PC
GSM Module
SIM Card

Program Description:
This Program will read sms of SIM card using GSM module.
Pin Assignment:

Connection of Power supply to the GSM module.


Connection between serial port of GSM module to serial port of ARM-9target
Connect the antenna to the GSM module.

Procedure:

To execute program from ARM9 target board go to /home/Example directory


by this command
[root@EDUTECH~]:cd /home/example

Now execute lab34.o by this command


[root@EDUTECH~]:./ lab34.o

______________________________________________________________ 198
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Editing program

Now if you want to edit this lab34.c file go to /home/lab/lab34 by this


command in linux host PC.
Linux-dje5:~ # cd /home/lab/GSM/lab34

Edit lab34.c by this command


Linux-dje5:~ # vi lab34.c

Now save and exit from vi editor by this command


Esc + : + wq + enter

Now compile your program by this command


Linux-dje5:~ # arm-linux-gcc lab34.c o lab34.o
Above command compile the program.

After compilation check whether object file is created or not by using


command
Linux-dje5:~ # ls

copy object file to /root/tftpboot by this command


Linux-dje5:~ # cp lab34.o /root/tftpboot

copy test to target board by this command


[root@EDUTECH/home]: tftp g r lab34.o 192.168.0.96
[root@EDUTECH/home]: chmod 777 lab34.o

Execute the program from target board by this command


[root@EDUTECH/home]: ./lab34.o

______________________________________________________________ 199
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Output:
[root@EDUTECH:/home/default] ./lab34.o
Serial port is initialised
Receiving data in buffer...Output
AT
OK
###########...Connection Succcessful... ##########
####### SMS read..#######
Enter SMS index No...
1
Receiving data in buffer...Output
AT+CMGR=1
+CMGR: "REC READ","For You",,"08/11/17,09:08:32+22"
Living in the Favorable & Non-Favourable situation is PART OF LIVING But
Smiling in all Situations is called ART OF LIVING. Keep Smiling!!
OK

EXERCISES
EG21 Write a simple program to read fix number of SMS of SIM card using GSM
module.

______________________________________________________________ 200
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Lab35
Objective:
To write a program to read phonebook using GSM module with ARM-9 target board
Part List

Educational practice board for ARM 9 target board.


Power supply
Serial cable
Flat cable
Linux PC
GSM Module
SIM Card

Program Description:
This Program will read phonebook contacts of SIM card.
Pin Assignment:

Connection of Power supply to the GSM module.


Connection between serial port of GSM module to serial port of ARM-9target
Connect the antenna to the GSM module.

Procedure:

To execute program from ARM9 target board go to /home/Example directory


by this command
[root@EDUTECH~]:cd /home/example

Now execute lab35.o by this command


[root@EDUTECH~]:./lab35.o

______________________________________________________________ 201
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Editing program

Now if you want to edit this lab35.c file go to /home/lab/lab35 by this


command in linux host PC.
Linux-dje5:~ # cd /home/lab/lab35

Edit lab35.c by this command


Linux-dje5:~ # vi lab35.c

Now save and exit from vi editor by this command


Esc + : + wq + enter

Now compile your program by this command


Linux-dje5:~ # arm-linux-gcc lab35.c o lab35.o
Above command compile the program.

After compilation check whether object file is created or not by using


command
Linux-dje5:~ # ls

copy object file to /root/tftpboot by this command


Linux-dje5:~ # cp lab35.o /root/tftpboot

copy test to target board by this command


[root@EDUTECH/home]: tftp g r lab35.o 192.168.0.96
[root@EDUTECH/home]: chmod 777 lab35.o

Execute the program from target board by this command


[root@EDUTECH/home]: ./lab35.o

______________________________________________________________ 202
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Output:
[root@EDUTECH:/home/default] ./lab35.o
Serial port is initialised
Receiving data in buffer...Output
AT
OK
###########...Connection Succcessful... ##########
####### Phone book read..#######
Enter Contact index No...
4
Receiving data in buffer...Output
AT+CPBR=10
+CPBR: 10,"9975639116",129,"Jigar Home
OK

EXERCISES
EG22 Write a simple program to read fix number of phonebook using GSM module.

______________________________________________________________ 203
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Lab36
Objective:
To write a program to search phonebook contacts of SIM card using GSM module
with ARM-9 target board
Part List

Educational practice board for ARM 9 target board.


Power supply
Serial cable
Flat cable
Linux PC
GSM Module
SIM Card

Program Description:
This Program will search phonebook contacts of SIM card.
Pin Assignment:

Connection of Power supply to the GSM module.


Connection between serial port of GSM module to serial port of ARM-9target
Connect the antenna to the GSM module.

Procedure:

To execute program from ARM9 target board go to /home/Example directory


by this command
[root@EDUTECH~]:cd /home/example

Now execute lab36.o by this command


[root@EDUTECH~]:./lab36.o

______________________________________________________________ 204
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Editing program

Now if you want to edit this lab36.c file go to /home/lab/lab36 by this


command in linux host PC.
Linux-dje5:~ # cd /home/lab/lab36

Edit lab36.c by this command


Linux-dje5:~ # vi lab36.c

Now save and exit from vi editor by this command


Esc + : + wq + enter

Now compile your program by this command


Linux-dje5:~ # arm-linux-gcc lab36.c o lab36.o
Above command compile the program.

After compilation check whether object file is created or not by using


command
Linux-dje5:~ # ls

copy object file to /root/tftpboot by this command


Linux-dje5:~ # cp lab36.o /root/tftpboot

copy test to target board by this command


[root@EDUTECH/home]: tftp g r lab36.o 192.168.0.96
[root@EDUTECH/home]: chmod 777 lab36.o

Execute the program from target board by this command


[root@EDUTECH/home]: ./lab36.o

______________________________________________________________ 205
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Output:
Serial port is initialised
Receiving data in buffer...Output
AT
OK
###########...Connection Succcessful... ##########
####### Phonebook Search #######
Enter Character...
H
Receiving data in buffer...Output
AT+CPBF="H"
+CPBF: 37,"9935601273",129,"Herat"
+CPBF: 38,"9758033171",129,"Hiren"
+CPBF: 39,"02874449848",129,"HOME"
OK

EXERCISES
EG23 Write a simple program to search phonebook contacts by fix character of SIM
card using GSM module.

______________________________________________________________ 206
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Lab37
Objective:
To write a program to call, miss call, and message using GSM module with ARM-9
target board
Part List

File List

Educational practice board for ARM 9 target board.


Power supply
Serial cable
Flat cable
Linux PC
GSM Module
SIM Card
Lcd_keyboard ASK-1

: kb.h, lcd.h

Program Description:
This Program will first ask for mobile number.after entering mobile number by ASK-1,
it will ask for selection of call, miss call or message. On proper selection it will
execute that application on GSM module.
Pin Assignment:

Connection of Power supply to the GSM module.


Connection between serial port of GSM module to serial port of ARM-9target
Connect the antenna to the GSM module.

Procedure:

To execute program from ARM9 target board go to /home/Example directory


by this command
[root@EDUTECH~]:cd /home/example

Now execute lab37.o by this command


[root@EDUTECH~]:./ lab37.o

______________________________________________________________ 207
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Editing program

Now if you want to edit this lab37.c file go to /home/lab/lab37 by this


command in linux host PC.
Linux-dje5:~ # cd /home/lab/lab37

Edit lab37.c by this command


Linux-dje5:~ # vi lab37.c

Now save and exit from vi editor by this command


Esc + : + wq + enter

Now compile your program by this command


Linux-dje5:~ # arm-linux-gcc lab37.c o lab37.o
Above command compile the program.

After compilation check whether object file is created or not by using


command
Linux-dje5:~ # ls

copy object file to /root/tftpboot by this command


Linux-dje5:~ # cp lab37.o /root/tftpboot

copy test to target board by this command


[root@EDUTECH/home]: tftp g r lab37.o 192.168.0.96
[root@EDUTECH/home]: chmod 777 lab37.o

Execute the program from target board by this command


[root@EDUTECH/home]: ./lab37.o

______________________________________________________________ 208
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Lab38
Objective:
To write a program to print the message on thermal paper using thermal printer
module with ARM-9 target board
Part List

Educational practice board for ARM 9 target board.


Power supply
Serial cable
Flat cable
Linux PC
Thermal Printer
Power cable of thermal printer
ASK-01

Program Description:
This Program will print the message on thermal paper using thermal printer module
with ARM-9 target board
Pin Assignment:

Connection between LCD-keyboard J1 to J11 connector of ARM-9target


Board.
Connect DB9 connector of Thermal Printer to J3 (UART1) of ARM-9 target
Board
Connect power cable of thermal printer.

Procedure:

To execute program from ARM9 target board go to /home/Example directory


by this command
[root@EDUTECH~]:cd /home/example

Now execute lab38.o by this command


[root@EDUTECH~]:./lab38.o

______________________________________________________________ 209
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Editing program

Now if you want to edit this lab38.c file go to /home/lab/lab38 by this


command in linux host PC.
Linux-dje5:~ # cd /home/lab/lab38

Edit lab38.c by this command


Linux-dje5:~ # vi lab38.c

Now save and exit from vi editor by this command


Esc + : + wq + enter

Now compile your program by this command


Linux-dje5:~ # arm-linux-gcc lab38.c o lab38.o
Above command compile the program.

After compilation check whether object file is created or not by using


command
Linux-dje5:~ # ls

copy object file to /root/tftpboot by this command


Linux-dje5:~ # cp lab38.o /root/tftpboot

copy test to target board by this command


[root@EDUTECH/home]: tftp g r lab38.o 192.168.0.96
[root@EDUTECH/home]: chmod 777 lab38.o

Execute the program from target board by this command


[root@EDUTECH/home]: ./lab38.o

______________________________________________________________ 210
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Output:
The below lines will get printed on thermal paper in normal default font size.
Ketan Patel
Edutech Systems
304-Sarjan Complex
Dandia Dazar
Vadodara

______________________________________________________________ 211
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Lab39
Objective:
To write a program to print the different size of fonts of message on thermal paper
using thermal printer module with ARM-9 target board.
Part List

File List

Educational practice board for ARM 9 target board.


Power supply
Serial cable
Flat cable
Linux PC
Thermal Printer
Power cable of thermal printer
Lcd_keyboard ASK-01

: kb.h, lcd.h

Program Description:
This program will print the different size of fonts of message on thermal paper using
thermal printer module.
Pin Assignment:

Connection between LCD-keyboard J1 to J11 connector of ARM-9target


Board.
Connect DB9 connector of Thermal Printer to J3 (UART1) of ARM-9 target
Board
Connect power cable of thermal printer.

Procedure:

To execute program from ARM9 target board go to /home/Example directory


by this command
[root@EDUTECH~]:cd /home/example

Now execute lab39.o by this command


[root@EDUTECH~]:./ lab39.o

______________________________________________________________ 212
Edutech Systems

____________________________________________________________________________
AT91RM9200
Workbook
____________________________________________________________________________

Editing program

Now if you want to edit this lab39.c file go to /home/lab/lab39 by this


command in linux host PC.
Linux-dje5:~ # cd /home/lab/lab39

Edit lab39.c by this command


Linux-dje5:~ # vi lab39.c

Now save and exit from vi editor by this command


Esc + : + wq + enter

Now compile your program by this command


Linux-dje5:~ # arm-linux-gcc lab39.c o lab39.o
Above command compile the program.

After compilation check whether object file is created or not by using


command
Linux-dje5:~ # ls

copy object file to /root/tftpboot by this command


Linux-dje5:~ # cp lab39.o /root/tftpboot

copy test to target board by this command


[root@EDUTECH/home]: tftp g r lab39.o 192.168.0.96
[root@EDUTECH/home]: chmod 777 lab39.o

Execute the program from target board by this command


[root@EDUTECH/home]: ./lab39.o

Output:
The below lines will get printed on thermal paper in different fonts size as
entered by user via LCD-Keyboard.
Ketan Patel
Edutech Systems
304-Sarjan Complex
Dandia Dazar
Vadodara

______________________________________________________________ 213
Edutech Systems

You might also like