Lab Manual Advanced Microcontroller
Lab Manual Advanced Microcontroller
SYLLABUS
MICROCONTROLLER LAB
COURSE CONTENTS
LIST OF EXPERIMENTS
PART- A
1. i) Assembly level programs on Arithmetic and Logical operations instructions
ii) Write an ALP to divide a 32bit numbers by four without using DIV instructions
iii) Write a program to multiply two 32bit numbers without using multiply instructions (MUL)
2. Write an ALP to find cube of 32 bit numbers
3. Find the frequency of occurrence of the number 99h in an array of ‘n’ 32 bit numbers.
4. i) Write an ALP to find largest number among ten, 32bit numbers.
ii) Write an ALP to find smallest number among ten, 32bit numbers
5. i) Write an ALP to sort ten, 32bit numbers in ascending order.
ii)Write an ALP to sort ten, 32bit numbers in descending order
6. Write an ALP to move a block of data from one memory location to another memory
Location
7. Assembly programs on execution of various special instruction of the processor (Reverse, Signed and
Unsigned Field extract ,Bit Field , Signed and Unsigned extension instructions and so on )
8. Assembly programs on multiple sours file
PART A
STARTUP FILE
STACK_ADDR_123G EQU 0X20008000
THUMB
AREA ANS, DATA, READONLY
EXPORT __Vectors
__Vectors
DCD STACK_ADDR_123G
DCD Reset_Handler
MOV R1,#0X20000000
MOV R2,#0X40000000
ADDS R3,R2,R1
SUBS R4,R2,R1
DIV R5,R2,R1
MUL R6,R2,R1
STOP B STOP
END
INPUT : R1 = 0X20000000
R2 = 0X40000000
OUTPUT : R3 = 0X00000008
R4 = 0X 00000002
R5=0X 00000002
OUTPUT:
INPUT
ii) Write an ALP to divide a 32bit numbers by four without using DIV instructions.
Deartment of ECE, NMIT 7
MICROCONTROLLER LAB: 18ECL48
AREA ANS2,CODE,READONLY
THUMB
ENTRY
EXPORT __main
__main
LDR R0,=0X20000000
LDR R2,=0X20004000
LDR R1,[R0]
LSR R1,R1#2
STR R1, [R2]
STOP B STOP
END
OUTPUT:
OUTPUT:
LDR R1,=0X20000000
LDR R2,=0X20000008
LDR R3,[R1]
LDR R4,[R2]
MOV R0,#0X00000000
LOOP
ADD R0,R0,R3
SUBS R4,R4,#1
CMP R4,#0
BNE LOOP
MOV R5,R0
STOP B STOP
END
OUTPUT : R5 =0 X 00 00 01 DB
INPUT:
OUTPUT:
AREA ANS3,CODE,READONLY
THUMB
ENTRY
EXPORT __main
__main
LDR R1,=0XABCDEF33
UMULL R3,R4,R1,R1
UMULL R5,R6,R1,R3
UMULL R8,R7,R1,R4
ADDS R6,R8
ADC R7,R7,#0
STOP B STOP
END
3. Find the frequency of occurrence of the number 99h in an array of ‘n’ 16 bit numbers.
AREA ANS3,CODE,READONLY
THUMB
INPUT : 0x20000000 : 99 99 99 99 88
OUTPUT :0x20002000 : 04 00 00 00
INPUT:
OUTPUT:
EXPORT __main
__main
MOV R5,#03
LDR R1,=0X20000000
LDR R2,=0X2000401C
LDR R3,[R1]
LOOP1
ADD R1, R1,#04
LDR R4,[R1]
CMP R3, R4
BHI LOOP2
MOV R3, R4
LOOP2
SUBS R5, R5,#01
CMP R5,#00
BNE LOOP1
STR R3, [R2]
STOP B STOP
END
INPUT : 0X20000000 = 00 00 00 44 00 00 00 22 00 00 00 33 00 00 00 55
OUTPUT: 0X 2000401C = 00 00 00 55
INPUT:
OUTPUT:
ii) Write an ALP to find Smallest number among ten 32bit numbers
AREA ANS2,CODE,READONLY
THUMB
ENTRY
EXPORT __main
__main
MOV R5,#03
LDR R1,=0X20000000
LDR R2,=0X2000401C
LDR R3,[R1]
LOOP
ADD R1, R1,#04
LDR R4,[R1]
CMP R3, R4
BLS LOOP1
MOV R3, R4
LOOP1
SUBS R5, R5,#01
CMP R5,#00
BNE LOOP
STR R3, [R2]
STOP B STOP
END
INPUT : 0X20000000 = 00 00 00 44 00 00 00 22 00 00 00 33 00 00 00 55
OUTPUT: 0X 2000401C = 00 00 00 22
INPUT:
OUTPUT:
AREA ANS3,CODE,READONLY
THUMB
ENTRY
EXPORT __main
__main
MOV R8,#04
LDR R2,=CVALUE
LDR R3,=DVALUE
LOOP0
LDR R1,[R2],#04
STR R1,[R3],#04
SUBS R8,R8,#01
CMP R8,#00
BNE LOOP0
START1
MOV R5,#03
MOV R7,#00
LDR R1,=DVALUE
LOOP
LDR R2,[R1],#04
LDR R3,[R1]
CMP R2,R3
BLT LOOP2
STR R2,[R1],#-4
STR R3,[R1]
MOV R7,#01
ADD R1,#04
LOOP2
SUBS R5,R5,#01
CMP R5,#00
BNE LOOP
CMP R7,#00
BNE START1
BACK B BACK
CVALUE
DCD 0X44444444
DCD 0X11111111
DCD 0X33333333
DCD 0X22222222
AREA DATA1,DATA,READWRITE
DVALUE DCD 0X00000000
END
OUTPUT :
AREA ANS3,CODE,READONLY
THUMB
ENTRY
EXPORT __main
__main
MOV R8,#04
LDR R2,=CVALUE
LDR R3,=DVALUE
LOOP0
LDR R1,[R2],#04
STR R1,[R3],#04
SUBS R8,R8,#01
CMP R8,#00
BNE LOOP0
START1
MOV R5,#03
MOV R7,#00
LDR R1,=DVALUE
LOOP
LDR R2,[R1],#04
LDR R3,[R1]
CMP R2,R3
BGT LOOP2
STR R2,[R1],#-4
STR R3,[R1]
MOV R7,#01
ADD R1,#04
LOOP2
SUBS R5,R5,#01
CMP R5,#00
BNE LOOP
CMP R7,#00
BNE START1
BACK B BACK
CVALUE
DCD 0X44444444
DCD 0X11111111
DCD 0X33333333
DCD 0X22222222
AREA DATA1,DATA,READWRITE
DVALUE DCD 0X00000000
END
OUTPUT :
STOP B STOP
END
INPUT : 0X 20000000 : 46 00 00 00 47 00 00 00 69 00 00 00
OUTPUT: 0X 20002000 : 46 00 00 00 47 00 00 00 69 00 00 00
INPUT: R1=0X0123ABCD
OUTPUT:
LOOP
ADD R1, R0
SUBS R0, #01
BNE LOOP
BX LR
NOP
END
INPUT: R0: 05
OUTPUT: R1: 0F
INPUT: OUTPUT:
PART B
In addition, the TM4C123GH6PM microcontroller offers the advantages of ARM's widely available
development tools, System-on-Chip (SoC) infrastructure IP applications, and a large user community.
Additionally, the microcontroller uses ARM's Thumb-compatible Thumb-2 instruction set to reduce memory
requirements and, thereby, cost. Finally, much of the TM4C123GH6PM microcontroller code is compatible
to the Tiva™ C Series product line, providing flexibility across designs.
Features:
• 32-bit ARM Cortex-M4F architecture optimized for small-footprint embedded applications
• 80-MHz operation; 100 DMIPS performance
• Outstanding processing performance combined with fast interrupt handling
• Thumb-2 mixed 16-/32-bit instruction set delivers the high performance expected of a 32-bit
ARM core in a compact memory size usually associated with 8- and 16-bit devices, typically
in the range of a few kilobytes of memory for microcontroller-class applications.
➢ Single-cycle multiply instruction and hardware divide
➢ Atomic bit manipulation (bit-banding), delivering maximum memory
Utilization and streamlined peripheral control
➢ Unaligned data access, enabling data to be efficiently packed into memory
• IEEE754-compliant single-precision Floating-Point Unit (FPU)
• 16-bit SIMD vector processing unit
• Fast code execution permits slower processor clock or increases sleep mode time
• Harvard architecture characterized by separate buses for instruction and data
Deartment of ECE, NMIT 24
MICROCONTROLLER LAB: 18ECL48
Low registers
Registers R0-R7 are accessible by all instructions that specify a general-purpose Register
High registers
Registers R8-R12 are accessible by all 32-bit instructions that specify a general-purpose register.
Registers R8-R12 are not accessible by most 16-bit instructions. Registers R13, R14, and R15 have the
following special functions:
The Rn registers are 32-bit general-purpose registers for data operations and can be accessed from
either privileged or unprivileged mode.
The PSR, IPSR, and EPSR registers can only be accessed in privileged mode; the APSR register can be
accessed in either privileged or unprivileged mode. APSR contains the current state of the condition flags
from previous instruction executions.
EPSR contains the Thumb state bit and the execution state bits for the If-Then (IT) instruction or the
Interruptible-Continuable Instruction (ICI) field for an interrupted load multiple or store multiple instruction.
Attempts to read the EPSR directly through application software using the MSR instruction always return
zero. Attempts to write the EPSR using the MSR instruction in application software are always ignored.
Fault handlers can examine the EPSR value in the stacked PSR to determine the operation that faulted.
IPSR contains the exception type number of the current Interrupt Service Routine (ISR). These
registers can be accessed individually or as a combination of any two or all three registers, using the register
name as an argument to the MSR or MRS instructions. For example, all of the registers can be read using
PSR with the MRS instruction, or APSR only can be written to using APSR with the MSR instruction.
27/21:8/6:5 Reserved To provide compatibility with future products, the value of a reserved
bit should be preserved across a read-modify-write operation.
26 AHP Alternative Half-Precision
When set, alternative half-precision format is selected. When clear,
IEEE half-precision format is selected
25 DN Default NaN Mode
When set, any operation involving one or more NaNs returns the
Default NaN. When clear, NaN operands propagate through to the
output of a floating-point operation
24 FZ Flush-to-Zero Mode
When set, Flush-to-Zero mode is enabled. When clear, Flush-to-Zero
mode is disabled and the behavior of the floating-point system is
fully
compliant with the IEEE 754 standard
23:22 RMODE Rounding Mode
The specified rounding mode is used by almost all floating-point
instructions.
Value Description
0x0 Round to Nearest (RN) mode
0x1 Round towards Plus Infinity (RP) mode
0x2 Round towards Minus Infinity (RM) mode
0x3 Round towards Zero (RZ) mode
On-Chip Memory
Figure above Illustrates the internal SRAM, ROM, and Flash memory blocks and control logic.
The TM4C123GH6PM Microcontroller is integrated with the following set of on-chip memory
⚫ 32 KB single-cycle SRAM
⚫ 256 KB Flash memory
⚫ 2KB EEPROM
⚫ Internal ROM loaded with TivaWare for C Series software :
➢ TivaWare Peripheral Driver Library
➢ TivaWare Boot Loader
➢ Advanced Encryption Standard (AES) cryptography tables
➢ Cyclic Redundancy Check (CRC) error detection functionality
Figure above Illustrates the internal EEPROM block and control logic. The EEPROM block is
connected to the AHB bus
SRAM
The internal SRAM of the TM4C123GH6PM device is located at address 0x2000.0000 of the device
memory map. To reduce the number of time consuming read-modify-write (RMW) operations, ARM
provides bit-banding technology in the processor. With a bit-band-enabled processor, certain regions in the
memory map (SRAM and peripheral space) can use address aliases to access individual bits in a single,
atomic operation. The bit-band base is located at address 0x2200.0000.
The bit-band alias is calculated by using the formula:
For example, if bit 3 at address 0x2000.1000 is to be modified, the bit-band alias is calculated as:
0x2200.0000 + (0x1000 * 32) + (3 * 4) = 0x2202.000C
With the alias address calculated, an instruction performing a read/write to address 0x2202.000C allows
direct access to only bit 3 of the byte at address 0x2000.1000
ROM
The internal ROM of the TM4C123GH6PM device is located at address 0x0100.0000 of the device
memory map. Detailed information on the ROM contents can be found in the Tiva C Series
The ROM contains the following components:
• TivaWare Boot Loader and vector table
• TivaWare Peripheral Driver Library (DriverLib) release for product - specific
Peripherals and interfaces
• Advanced Encryption Standard (AES) cryptography tables
• Cyclic Redundancy Check (CRC) error detection functionality
The boot loader is used as an initial program loader (when the Flash memory is empty) as well as an
application-initiated firmware upgrade mechanism (by calling back to the boot loader). The Peripheral
Driver Library APIs in ROM can be called by applications, reducing Flash memory requirements and freeing
the Flash memory to be used for other purposes (such as additional features in the application). Advance
Encryption Standard (AES) is a publicly defined encryption standard used by the U.S. Government and
Cyclic Redundancy Check (CRC) is a technique to validate if a block of data has the same contents as when
previously checked
EEPROM
The TM4C123GH6PM microcontroller includes an EEPROM with the following features:
• 2Kbytes of memory accessible as 512 32-bit words
• 32 blocks of 16 words (64 bytes) each
• Built-in wear levelling
• Access protection per block
• Lock protection option for the whole peripheral as well as per block using 32-
bit to 96-bit unlock codes (application selectable)
• Interrupt support for write completion to avoid polling
• Endurance of 500K writes (when writing at fixed offset in every alternate
page in circular fashion) to 15M operations (when cycling through two pages)
per each 2-page block.
Functional Description
The EEPROM module provides a well-defined register interface to support accesses to the EEPROM
with both a random access style of read and write as well as a rolling or sequential access scheme.
A protection mechanism allows locking EEPROM blocks to prevent writes under a set of
circumstances as well as reads under the same or different circumstances. The password model allows the
application to lock one or more EEPROM blocks to control access on 16-word boundaries.
Theory of Operation
The EEPROM operates using a traditional Flash bank model which implements EEPROM-type cells,
but uses sector erase. Additionally, words are replicated in the pages to allow 500K+ erase cycles when
needed, which means that each word has a latest version. As a result, a write creates a new version of the
word in a new location, making the previous value obsolete.
Each sector contains two blocks. Each block contains locations for the active copy plus six redundant
copies. Passwords, protection bits, and control data are all stored in the pages.
When a page runs out of room to store the latest version of a word, a copy buffer is used. The copy
buffer copies the latest words of each block. The original page is then erased. Finally, the copy buffer
contents are copied back to the page. This mechanism ensures that data cannot be lost due to power down,
even during an operation. The EEPROM mechanism properly tracks all state information to provide
complete safety and protection.
Memory Model
This section describes the processor memory map, the behaviour of memory accesses, and the bit-
banding features. The processor has a fixed memory map that provides up to 4 GB of addressable memory.
The Code, SRAM, and external RAM regions can hold programs. However, it is recommended that
programs always use the Code region because the Cortex-M4F has separate buses that can perform
instruction fetches and data accesses simultaneously.
Memory
Peripherals
START END Description
0x4000.1000 0x4000.1FFF Watchdog timer 1
0x4000.2000 0x4000.3FFF Reserved
0x4000.4000 0x4000.4FFF GPIO Port A
0x4000.5000 0x4000.5FFF GPIO Port B
0x4000.6000 0x4000.6FFF GPIO Port C
0x4000.7000 0x4000.7FFF GPIO Port D
0x4000.8000 0x4000.8FFF SSI0
0x4000.9000 0x4000.9FFF SSI1
0x4000.A000 0x4000.AFFF SSI2
0x4000.B000 0x4000.BFFF SSI3
0x4000.C000 0x4000.CFFF UART0
0x4000.6000 0x4000.6FFF GPIO Port C
0x4000.7000 0x4000.7FFF GPIO Port D
0x4000.8000 0x4000.8FFF SSI0
0x4000.9000 0x4000.9FFF SSI1
0x4000.A000 0x4000.AFFF SSI2
0x4000.B000 0x4000.BFFF SSI3
0x4000.C000 0x4000.CFFF UART0
0x4000.D000 0x4000.DFFF UART1
0x4000.E000 0x4000.EFFF UART2
0x4000.F000 0x4000.FFFF UART3
0x4001.0000 0x4001.0FFF UART4
0x4001.1000 0x4001.1FFF UART5
0x4001.2000 0x4001.2FFF UART6
0x4001.3000 0x4001.3FFF UART7
0x4001.4000 0x4001.FFFF Reserved
0x4002.0000 0x4002.0FFF I2C 0
0x4002.1000 0x4002.1FFF I2C 1
0x4002.2000 0x4002.2FFF I2C 2
0x4002.3000 0x4002.3FFF I2C 3
0x4002.4000 0x4002.4FFF GPIO Port E
0x4002.5000 0x4002.5FFF GPIO Port F
0x4002.6000 0x4002.7FFF Reserved
0x4002.8000 0x4002.8FFF PWM 0
0x4002.9000 0x4002.9FFF PWM 1
0x4002.A000 0x4002.BFFF Reserved
0x4002.C000 0x4002.CFFF QEI0
0x4002.D000 0x4002.DFFF QEI1
0x4002.E000 0x4002.FFFF Reserved
Deartment of ECE, NMIT 36
MICROCONTROLLER LAB: 18ECL48
LABLE J1 J3 LABLE
VCC 1 21 VBUS
CS(2) A11 PB5 2 22 GND
RX(1) PB0 3 23 PD0 A7 SCL(3) SCK(3)
TX(1) PB1 4 24 PD1 A6 SDA(3) CS(3)
RX(5) SCL(2) A9 PE4 5 25 PD2 A5 MISO(3)
TX(5) SDA(2) A8 PE5 6 26 PD3 A4 MOSI(3)
SCK(2) A10 PB4 7 27 PE1 PE1 A2 TX(7)
MOSI(0) PA5 8 28 PE2 PE2 A1
SCL(1) PA6 9 29 PE3 PE3 A0
SDA(1) PA7 10 30 PF1 PF1 RED_LIGHT MOSI(1)
LABLE J4 J2 LABLE
SCK(1) BLUE LED PF2 40 20 GND
CS(1) GREEN LED PF3 39 19 PB2 SCL(0)
SDA(0) PB3 38 18 PE0 A3
RX(1) PC4 37 17 PF0 PUSH2 MIS0(1)
TX(1) PC5 36 16 RESET
RX(3) PC6 35 15 PB7 MISI(2)
TX(3) PC7 34 14 PB6 MISO(2)
RX(2) PD6 33 13 PA4 MIS0(0)
TX(2) PD7 32 12 PA3 CS(0)
PUSH PF4 31 11 PA2 SCK(0)
Features:
⚫ 12v dc voltage is used to power up the board
⚫ On board DAC with stereo output connector
⚫ On 16*2 LCD Module
⚫ On board module to connect wireless Devices such as Zigbee, Bluetooth, RF and Wi-Fi
⚫ Slot for micro SD card
⚫ Analog Hex keypad(4*4)
⚫ 7-Segment Display
⚫ LED Array
⚫ On board RTC with Battery module
PORTA
(Internally connected to 7-SEGMENT DISPLAY
all peripheral)
PORTD
ADC ADC 8 8
8 8
PORT E
KEYPAD
PORT B/C/F
PORT D
PORTD
POT
LDR
Software Required:
1. Install CCSv5 or CCSv6. (http://processors.wiki.ti.com/index.php/Download_CCS)
Tiva C Series and Evaluation Kits provide a low-cost way to start designing with Tiva microcontrollers using Keil
RealView Microcontroller Development Kit (MDK) for ARM controllers.
Requirements:
Hardware:
Software:
• ICDI drivers
• Keil MDK 4
• TivaWare
1.0 Creating Project by Importing from TivaWare:
1.3 Use the dialog box to navigate to the Project0 program in the directory appropriate for your board.
From the location where you installed TivaWare, the Hello project is located in:
c\ti\TivaWare_C_Seriesn.n\examples\boards\ek-TM4C123lxl\Project0
1.4 Select the Project0.uvproj project file and click Open. The project opens in the IDE
Select Project → Rebuild all target files, or click the Rebuild all button (icon)
All of
the
The
process
takes a
few
seconds. A progress bar will show at the bottom of the IDE window as the device is programmed.
When it is finished, the Build window will show that th device was erased, programmed, and verified
OK.
Save Project by creating a new folder anywhere in computer (preferred location c\ti\TivaWare_C_Series-
n.n\examples\boards\(user define folder))
2.2 Once the project file (.uvproj) is saved, a dialog window appears asking you to select the device
that you are using. Select the appropriate device under the Texas Instruments list
(TM4C123GH6PM)
It will open template window files select .c and name source file name and edit source file with
application code
Right click
on Project
tool (TivaWare) select Add
Existing File
to Group
A new folder type option will be available under Target1 as shown below, name can be changed
Brows to c\ti\TivaWare_C_Seriesn.n\driverlib\rvmdk\driver.lib
Deartment of ECE, NMIT 51
MICROCONTROLLER LAB 18ECL48
2.8 option for target (Add TivaWare Hooks/ Configure Your Hardware/ Set up Debug)
Add the path of TivaWare by selecting new add path as shown below (Path:c/ti/tivaware c series xx.xx)
Click ok
For debugging connection need to be selected click on Debug Tab select use emulator option and select debugger
as stellaries ICDI and click OK and complete target option setting
LED2
PF3
LED3
OUTPUT PORTS:
PORT F Pin1 – LED1
PORT F Pin2 – LED2
PORT F Pin3 – LED3
Expected Output: RED, GREEN & BLUE Lights in Launch Pad blinks in accordance with delay
Program
/* RGB LED */
#include <stdint.h>
#include "inc\tm4c123gh6pm.h"
void delayMs(int n);
int main(void)
{
/* enable clock to GPIOF/B/C at clock gating control register */
SYSCTL_RCGCGPIO_R |= SYSCTL_RCGCGPIO_R5;//PF
while(1)
{
GPIO_PORTF_DATA_R = 0x02;
delayMs(500);
GPIO_PORTF_DATA_R = 0x04;
delayMs(500);
GPIO_PORTF_DATA_R = 0x08;
delayMs(500);
}}
Deartment of ECE, NMIT 54
{
MICROCONTROLLER LAB 18ECL48
Internal Circuit:
This register controls the clock gating logic in normal Run mode. Each bit controls a clock enable for a given interface,
function, or module. If set, the module receives a clock and functions. Otherwise, the module is unclocked and disabled
(saving power). If the module is unclocked, reads or writes to the module generate a bus fault. The reset state of these bits is
0 (unclocked) unless otherwise noted, so that all functional modules are disabled. It is the responsibility of software to enable
the ports necessary for the application. Note that these registers may contain more bits than there are interfaces, functions,
or modules to control. This configuration is implemented to assure reasonable code compatibility with other family and
future parts. RCGC2 is the clock configuration register for running operation, SCGC2 for Sleep operation, and DCGC2 for
Deep- Sleep operation. Setting the ACG bit in the Run-Mode Clock Configuration (RCC) register specifies that the system uses
sleep modes. Note that there must be a delay of 3 system clocks after a module clock is enabled beforeany registers in that
module are accessed.
The GPIODIR register is the data direction register. Setting a bit in the GPIODIR register configures the corresponding pin to
be an output, while clearing a bit configures the corresponding pin to be an input. All bits are cleared by a reset, meaning all
GPIO pins are inputs by default.
The GPIODEN register is the digital enable register. By default, all GPIO signals except those listedbelow are configured out
of reset to be undriven (tristate). Their digital function is disabled; they donot drive a logic value on the pin and they do not
allow the pin voltage into the GPIO receiver. Touse the pin as a digital input or output (either GPIO or alternate function),
the corresponding GPIODENbit must be set.
The GPIODATA register is the data register. In software control mode, values written in theGPIODATA register are transferred
onto the GPIO port pins if the respective pins have beenconfigured as outputs through the GPIO Direction (GPIODIR) register
In order to write to GPIODATA, the corresponding bits in the mask, resulting from the address busbits [9:2], must be set.
Otherwise, the bit values remain unchanged by the write.Similarly, the values read from this register are determined for each
bit by the mask bit derived fromthe address used to access the data register, bits [9:2]. Bits that are set in the address mask
causethe corresponding bits in GPIODATA to be read, and bits that are clear in the address mask causethe corresponding bits
in GPIODATA to be read as 0, regardless of their value.A read from GPIODATA returns the last bit value written if the
respective pins are configured asoutputs, or it returns the value on the corresponding input pin when these are configured as
inputs.All bits are cleared by a reset.
TMC123GH6PM
INPUTPORTS:
PORT F PIN 4
OUTPUT PORTS:
PORT F Pin 1 – LED1 Red LED
Expected Output:
By Pressing switch SW1 Corresponding Red LED glows
Internal Circuit:
#include "TM4C123GH6PM.h"
int main(void)
while(1)
The GPIOPUR register is the pull-up control register. When a bit is set, a weak pull-up resistor on the corresponding GPIO
signal is enabled. Setting a bit in GPIOPUR automatically clears the corresponding bit in the GPIO Pull-Down Select
(GPIOPDR) register (see page 679). Write access to this register is protected with the GPIOCR register. Bits in GPIOCR that
are cleared prevent writes to the equivalent bit in this register.
This section lists and describes the NVIC registers, in numerical order by address offset. The NVIC registers can only be
fully accessed from privileged mode, but interrupts can be pended while in unprivileged mode by enabling the
Configuration and Control (CFGCTRL) register. Any other unprivileged mode access causes a bus fault. Ensure software
uses correctly aligned register accesses. The processor does not support unaligned accesses to NVIC registers. An
interrupt can enter the pending state even if it is disabled. Before programming the VTABLE register to relocate the
vector table, ensure the vector table entries of the new vector table are set up for fault handlers, NMI, and all enabled
exceptions such as interrupts.
The ENn registers enable interrupts and show which interrupts are enabled.Bit 0 of EN0 corresponds to Interrupt 0; bit
31 corresponds to Interrupt 31. Bit 0 of EN1 corresponds to Interrupt 32; bit 31 corresponds to Interrupt 63. Bit 0 of
If a pending interrupt is enabled, the NVIC activates the interrupt based on its priority. If an interrupt is not enabled,
asserting its interrupt signal changes the interrupt state to pending, but the NVI never activates the interrupt, regardless
of its priority.
L293DD
MOTOR
(TM4C123GH6PM)
⚫ L1
⚫ L2
/* DC_Motor _CLK*/
#include <stdint.h>
#include "inc\tm4c123gh6pm.h"
void delayMs(int n);
int main(void)
{
/* enable clock to GPIOF/B/C at clock gating control register */
SYSCTL_RCGCGPIO_R |= SYSCTL_RCGCGPIO_R5;//PF
while(1)
{
GPIO_PORTF_DATA_R = 0x08;
delayMs(500);
} }
{
int i, j;
for(i = 0 ; i < n; i++)
MICROCONTROLLER LAB 18ECL48
/* DC_Motor _AntiCLK*/
#include <stdint.h>
#include "inc\tm4c123gh6pm.h"
int main(void)
{
/* enable clock to GPIOF/B/C at clock gating control register */
SYSCTL_RCGCGPIO_R |= SYSCTL_RCGCGPIO_R5;//PF
while(1)
{
GPIO_PORTF_DATA_R = 0x04;
delayMs(500);
0x08 to PF{}
then/*it do
willnothing
enable for
PF3 1and
ms */
disable PF2
}
X X X X 1 0 X X
X X X X 0 1 X X
(TM4C123GH6PM)
EXPECTED OUTPUT:
Internal Circuit
Description
The Device is a monolithic integrated high voltage, high current four channel driver designed
to accept standard DTL or TTL logic levels and drive inductive loads (such as relays solenoids, DC and
stepping motors) and switching power transistors. To simplify use as two bridges each pair of channels is
equipped with an enable input. A separate supply input is provided for the logic, allowing operation at a
lower voltage and internal clamp diodes are included. This device is suitable for use in switching applications
at frequencies up to 5 kHz. The L293D is assembled in a 16 lead plastic package which has 4 centre pins
connected together and used for heat sinking The L293DD is assembled in a 20 lead surface mount which
has 8 centre pins connected together and used for heat sinking.
Benefits & Features:
1. 600mA OUTPUT CURRENT CAPABILITY PER CHANNEL
2. 1.2A PEAK OUTPUT CURRENT (non repetitive) PER CHANNEL
3. ENABLE FACILITY OVERTEMPERATURE PROTECTION
4. LOGICAL "0" INPUT VOLTAGE UP TO 1.5 V (HIGH NOISE IMMUNITY)
5. INTERNAL CLAMP DIODE
int main(void)
{
/* enable clock to GPIOF/B/C at clock gating control register */
SYSCTL_RCGCGPIO_R |= SYSCTL_RCGCGPIO_R5;//PF
SYSCTL_RCGCGPIO_R |= SYSCTL_RCGCGPIO_R1;//PB
SYSCTL_RCGCGPIO_R |= SYSCTL_RCGCGPIO_R2;//PC
GPIO_PORTB_DIR_R = 0x08;//PB3
GPIO_PORTC_DIR_R = 0x10;//PC4
GPIO_PORTB_DEN_R = 0x08;
GPIO_PORTC_DEN_R = 0x10;
while(1)
{
GPIO_PORTF_DATA_R = 0x04; /* PF2 =1*/
delayMs(500);
GPIO_PORTF_DATA_R = 0;
delayMs(500);
GPIO_PORTF_DATA_R = 0x08; /* PF3 =1 */
delayMs(500);
GPIO_PORTF_DATA_R = 0;
delayMs(500);
delayMs(500);
GPIO_PORTC_DATA_R = 0x10; /* P2 =1*/ Deartment of ECE, NMIT 45
delayMs(500);
GPIO_PORTC_DATA_R = 0;
delayMs(500);
MICROCONTROLLER LAB 18ECL48
TM4C123GH6PM
PF2 LED_G
Buzzer
/* LED_BUZZER_SW1 */
#include <stdint.h>
#include "inc\tm4c123gh6pm.h"
void delayMs(int n);
int value;
int main(void)
{
/* enable clock to GPIO F/D at clock gating control register *//* GPIO PORT D PIN 7 is
connected to Buzzer */
SYSCTL_RCGCGPIO_R |= SYSCTL_RCGCGPIO_R3;//PD
SYSCTL_RCGCGPIO_R |= SYSCTL_RCGCGPIO_R5;//PF
while (1)
{
{
int i, j;
for(i = 0 ; i < n; i++)
for(j = 0; j < 4180; j++)
{} /* do nothing for 1 ms */
}
The GPIOLOCK register enables write access to the GPIOCR register (see page 685). Writing 0x4C4F.434B to the
GPIOLOCK register unlocks the GPIOCR register. Writing any other value to the GPIOLOCK register re-enables the
locked state. Reading the GPIOLOCK register returns the lock status rather than the 32-bit value that was
previously written. Therefore, when write accesses are disabled, or locked, reading the GPIOLOCK register returns
0x0000.0001. When write accesses are enabled, or unlocked, reading the GPIOLOCK register returns 0x0000.0000.
The GPIOCR register is the commit register. The value of the GPIOCR register determines which bits of the
GPIOAFSEL, GPIOPUR, GPIOPDR, and GPIODEN registers are committed when a write to these registers is performed.
If a bit in the GPIOCR register is cleared, the data being written to the corresponding bit in the GPIOAFSEL, GPIOPUR,
GPIOPDR, or GPIODEN registers cannot be committed and retains its previous value. If a bit in the GPIOCR register is
set, the data being written to the corresponding bit of the GPIOAFSEL, GPIOPUR, GPIOPDR, or GPIODEN registers is
committed to the register and reflects the new value. The contents of the GPIOCR register can only be modified if
the status in the GPIOLOCK register is unlocked. Writes to the GPIOCR register are ignored if the status in the
GPIOLOCK register is locked.
The GPIOPUR register is the pull-up control register. When a bit is set, a weak pull-up resistor on the corresponding
GPIO signal is enabled. Setting a bit in GPIOPUR automatically clears the corresponding bit in the GPIO Pull- Down
Select (GPIOPDR) register Write access to this register is protected with the GPIOCR register. Bits in GPIOCR that are
cleared prevent writes to the equivalent bit in this register.
ir
SYSCTL_RCGCGPIO_R = 0x10;
GPIO_PORTE_DIR_R = 0x1F;
GPIO_PORTE_DEN_R = 0x1F;
while(1){
for(i=0;i<=15;i++)
{
shift_out1(a[i]);
shift_out1(a[i]);
shift_out1(a[i]);
shift_out1(a[i]);
shift_out1(a[i]);
for(j=0;j<=7;j++)
{
GPIO_PORTE_DATA_R = 0x00; //PE3 pin(sclk) is low (0000 0000)
check = (str &(1<<j));
if(check)
GPIO_PORTE_DATA_R = 0x04; //PE2 pin(sdat) is high (0000 0100)
else
GPIO_PORTE_DATA_R |= 0x00;
GPIO_PORTE_DATA_R |= 0x08; //PE3 pin(sclk) is high (0000 1000)
GPIO_PORTE_DATA_R |= 0x10;
}
}
void delayMs(int n)
{
int i, j;
for(i = 0 ; i < n; i++)
for(j = 0; j < 4180; j++)
{} /* do nothing for 1 ms */
}
APPENDIX
TM4C123GH6PM Microcontroller
All members of the Tiva C Series, including the TM4C123GH6PM microcontroller, are designed
around an ARM Cortex-M processor core. The ARM Cortex-M processor provides the core for a high-
performance; low-cost platform that meets the needs of minimal memory implementation, reduced pin
count, and low power consumption, while delivering outstanding computational performance and
exceptional system response to interrupts.