Arm Microcontroller Finrrdds23c GGT
Arm Microcontroller Finrrdds23c GGT
Arm Microcontroller Finrrdds23c GGT
CONTENTS
1. INTRODUCTION 2
2. EXECUTION STEPS 3
3. EXPERIMENTS 13
4:-Display digital output for given analog input using internal ADC 27
4. Viva Question 73
INTRODUCTION
Microcontroller or Microprocessor is an electronic device which accepts data from memory or
input devices, process it according to instruction and sends or store result either in output devices
or memory.
Microprocessor contains no RAM, no ROM, and I/O ports on the chip itself only CPU or
processor is present. To make it functional all should be added.
ARM Cortex M3 Series:
ARM was founded in 1990 as Advanced RISC Machines Ltd., a joint venture of Apple
Computer, Acorn Computer Group, and VLSI Technology. In 1991, ARM introduced the ARM6
processor family, and VLSI became the initial licensee. Subsequently, additional companies,
including Texas Instruments, NEC, Sharp and ST Microelectronics, licensed the ARM processor
designs
Nowadays ARM partners ship in excess of 2 billion ARM processors each year. Unlike many
semiconductor companies, ARM does not manufacture processors or sell the chips directly.
Instead it licenses the processor designs to business partners. This business model is commonly
called Intellectual
2. EXECUTION STEPS
Step1: Open the Keil software and select the New Microvision project from Project Menu as
shown below.
Step2: Browse to your project folder and provide the project name and click on
save.
Step3: Once the project is saved a new pop up “Select Device for Target” opens, Select the
controller(NXP:LPC1768) and click on OK.
Step5: As LPC1768 needs the startup code, click on Yes option to include the LPC17xx
Startup file.
Step7: Type the code or Copy paste the below code snippet.
Step11: Build the project and fix the compiler errors/warnings if any.
Step12: Code is compiled with no errors. The .hex file is still not generated.
Step13: Click on Target Options to select the option for generating .hex file.
Step17: Check the project folder for the generated .hex file.
Now open the flash magic software and follow the below steps.
1. Select the IC from Select Menu(LPC1768).
2. Select the COM Port. Check the device manger for detected Com port.
3. Select Baud rate from 9600
4. Select None Isp Option.
5. Oscillator Freq 12.000000(12Mhz).
6. Check the Erase blocks used by Hex file option
7. Browse and Select the hex file.
8. Check the Verify After Programming Option.
9. If DTR and RTS are used then go to Options->Advanced Options-> Hardware Config
and select the Use DTR and RTS Option.
10. Hit the Start Button to flash the hex file.
11. Once the hex file is flashed, Reset the board. Now the controller should run your
application code.
EXPERIMENTS
Experiment No1: Display Hello word in UART
UART module
UART module and registers. LPC1768 has 4-UARTs numbering 0-3, similarly the pins are also
named as RXD0-RXD3 and TXD0-TXD3.As the LPC1768 pins are multiplexed for multiple
functionalities, first they have to be configured as UART pins.
Below table shows the multiplexed UARTs pins.
Port Pin
PINSEL_FUNC_0 PINSEL_FUNC_1 PINSEL_FUNC_2 PINSEL_FUNC_3
Pin Number
P0.02 98 GPIO TXD0 ADC0[7]
P0.03 99 GPIO RXD0 ADC0[6]
P2_0 48 GPIO PWM1[1] TXD1
P2.1 49 GPIO PWM1[2] RXD1
P0.10 62 GPIO TXD2 SDA2 MAT3[0]
P0.11 63 GPIO RXD2 SCL2 MAT3[1]
P0.0 82 GPIO CAN1_Rx TXD3 SDA1
P0.1 85 GPIO CAN1_Tx RXD3 SCL1
UART Registers
The below table shows the registers associated with LPC1768 UART.
Register Description
RBR Contains the recently received Data
THR Contains the data to be transmitted
FCR FIFO Control Register
LCR Controls the UART frame formatting(Number of Data Bits, Stop bits)
DLL Least Significant Byte of the UART baud rate generator value.
DLM Most Significant Byte of the UART baud rate generator value.
Main Code:-
#include <lpc17xx.h>
#include "stdutils.h"
#define SBIT_WordLenght 0x00u
#define SBIT_DLAB 0x07u
#define SBIT_FIFO 0x00u
#define SBIT_RxFIFO 0x01u
#define SBIT_TxFIFO 0x02u
#define SBIT_RDR 0x00u
#define SBIT_THRE 0x05u
UART_PCLK PCLK
0x00 SystemFreq/4
0x01 SystemFreq
0x02 SystemFreq/2
0x03 SystemFreq/8
**/
switch( var_UartPclk_u32 )
{
case 0x00:
var_Pclk_u32 = SystemCoreClock/4;
break;
case 0x01:
var_Pclk_u32 = SystemCoreClock;
break;
case 0x02:
var_Pclk_u32 = SystemCoreClock/2;
break;
case 0x03:
var_Pclk_u32 = SystemCoreClock/8;
break;
}
PWM REGISTERS:
The registers associated with LPC1768 PWM are
IR-> Interrupt Register: The IR can be written to clear interrupts. The IR can be read to
identify which of eight possible interrupt sources are pending.
TCR-> Timer Control Register: The TCR is used to control the Timer Counter functions.
The Timer Counter can be disabled or reset through the TCR.
PR- > Prescale Register: The TC is incremented every PR+1 cycles of PCLK.
MCR-> Match Control Register: The MCR is used to control if an interrupt is generated
and if the TC is reset when a Match occurs.
MR0 – MR6-> Match Register: Each can be enabled in the MCR to reset the TC, stop both
the TC and PC, and/or generate an interrupt when it matches the TC.
PCR-> PWM Control Register: Enables PWM outputs and selects PWM channel types as
either single edge or double edge controlled.
LCR-> Load Enable Register: Enables use of new PWM match values.
Note: for detailed description of each registers kindly refer PWM waveform section
If you need to control the speed of a DC motor you have a few options. Controlling the
speed by controlling either voltage or current is inefficient. Let’s understand a bit the speed
control of DC motor Using Pulse Width Modulation because controlling how long the
voltage is applied with a certain frequency gives you the best control over the motor’s
speed.
Conventional power supplies tend to generate lots of heat because are working as variable
resistors pumping current through external circuits. The pulse width modulation circuits are
digital circuits which produce pulsed current. Due to the fact that the pulsed width
modulation power supplies works in a state in between on and off, the heat generated is
very low compared to the conventional power supplies.
The duty cycle of the circuit can be changed by pressing the switches SW22 and SW23. If we
increase the duty cycle(press SW22), the speed of the motor increases and if we decrease the
duty cycle(press SW23), the speed of the motor decreases.
Main code:-
#include <lpc17xx.h>
int main(void)
{
int dutyCycle;
SystemInit();
/* Cofigure pins(P2_2 ) for PWM mode. */
LPC_PINCON->PINSEL4 = (1<<PWM_3) ;
LPC_PWM1->PCR = (1<<SBIT_PWMENA3);
while(1)
{
{
LPC_PWM1->MR3 = dutyCycle; /* Increase the dutyCycle from 0-100 */
delay_ms(5);
}
if(!(LPC_GPIO2->FIOPIN & 0x00000800))//if sw 23 pressed
{
while(!(LPC_GPIO2->FIOPIN & 0x00000800));
Stepper motor
A stepper motor or step motor or stepping motor is a brushless DC electric motor that divides a
full rotation into a number of equal steps. The motor's position can then be commanded to move
and hold at one of these steps without any position sensor for feedback (an open-loop controller),
as long as the motor is carefully sized to the application in respect to torque and speed.
Figure 1
In the above example, we used a motor with a resolution of 90 degrees or demonstration
purposes. In reality, this would not be a very practical motor for most applications. The
average stepper motor's resolution -- the amount of degrees rotated per pulse -- is much
higher than this. For example, a motor with a resolution of 1.8 degrees would move its
rotor 1.8 degrees per step, thereby requiring 200 pulses (steps) to complete a full 360
degree rotation.
Here we are using 200 pole stepper motor hence it gives 360degree/200 pole=1.8 degree per
step.
So for example if we need 120 degree rotation then we have to apply approximately 67 pulses to
complete 120 degree rotation
120/1.8=66.66==67 steps approximately.
Here one cycle means 4 steps. So if we need 90 degree rotation then 90/1.8=50 steps.
Here one cycle means 4 steps. So 50/4=12.5 =~ 13. So we need 13 cycles to rotate 90 degree.
If we want to run 180 degree then 180/1.8=100. So 100/4=25 cycles would make a stepper
motor to rotate 180 degree.
#include <lpc17xx.h>
for(i=0;i<ms;i++)
for(j=0;j<20000;j++); //delay subroutine
for(cycle=0; cycle<13; cycle++)// for loop condition for number of rotation. It gives
approx 90 degree rotation
{
LPC_GPIO0->FIOPIN = 0x00008000 ; // p0.15 pin
delay(100);
LPC_GPIO0->FIOPIN = 0x00010000 ;// p0.16 pin
delay(100);
LPC_GPIO0->FIOPIN = 0x00020000 ; // p0.17 pin
delay(100);
LPC_GPIO0->FIOPIN = 0x00040000 ;// p0.18 pin
delay(100);
}
}
void delay()
{
int i,j;
for(i=0;i<0xff;i++)
for(j=0;j<0x400;j++);
}
LPC_GPIO0->FIODIR |= 0x00078000;
while(1)
{
if(rotate==1)
{
LPC_GPIO0->FIOPIN = 0x00008000 ;
delay();
LPC_GPIO0->FIOPIN = 0x00010000 ;
delay();
LPC_GPIO0->FIOPIN = 0x00020000 ;
delay();
LPC_GPIO0->FIOPIN = 0x00040000 ;
delay();
}
else
{
LPC_GPIO0->FIOPIN = 0x00040000 ;
delay();
LPC_GPIO0->FIOPIN = 0x00020000 ;
delay();
LPC_GPIO0->FIOPIN = 0x00010000 ;
delay();
LPC_GPIO0->FIOPIN = 0x00008000 ;
delay();
}
rotate=1;
}
else if(!(LPC_GPIO2->FIOPIN & 0x00001000))
{
while(!(LPC_GPIO2->FIOPIN & 0x00001000));
rotate=0;
}
}
}
Experiment No 4:-Display digital output for given analog input using internal
ADC
LPC1768 ADC Block
LPC1768 has an inbuilt 12 bit Successive Approximation ADC which is multiplexed among 8
input pins.
The ADC reference voltage is measured across VREFN to VREFP, meaning it can do the
conversion within this range. Usually the VREFP is connected to VDD and VREFN is connected
to GND.
As LPC1768 works on 3.3 volts, this will be the ADC reference voltage.
Now the $$resolution of ADC = 3.3/(2^{12}) = 3.3/4096 =0.000805 = 0.8mV$$
The below block diagram shows the ADC input pins multiplexed with other GPIO pins.
The ADC pin can be enabled by configuring the corresponding PINSEL register to select ADC
function.
When the ADC function is selected for that pin in the Pin Select register, other Digital signals are
disconnected from the ADC input pins.
ADC Registers
The below table shows the registers associated with LPC1768 ADC.
We are going to focus only on ADCR and ADGDR as these are sufficient for simple A/D
conversion.
However once you are familiar with LPC1768 ADC, you can explore the other features and the
associated registers.
Register Description
ADCR A/D COntrol Register: Used for Configuring the ADC
A/D Global Data Register: This register contains the ADC’s DONE bit and the
ADGDR
result of the most recent A/D conversion
ADINTEN A/D Interrupt Enable Register
ADDR0 - A/D Channel Data Register: Contains the recent ADC value for respective
ADDR7 channel
A/D Status Register: Contains DONE & OVERRUN flag for all the ADC
ADSTAT
channels
#include "lpc17xx.h"
#include "lcd.h"
#define VREF 3.3 //Reference Voltage at VREFP pin, given VREFN = 0V(GND)
#define ADC_CLK_EN (1<<12)
#define SEL_AD0_2 (1<<2) //Select Channel AD0.2
#define CLKDIV 1 //ADC clock-divider (ADC_CLOCK=PCLK/CLKDIV+1) = 12.5Mhz @
25Mhz PCLK
#define PWRUP (1<<21) //setting it to 0 will power it down
#define START_CNV (1<<24) //001 for starting the conversion immediately
#define ADC_DONE (1U<<31) //define it as unsigned value or compiler will throw #61-D
warning
#define ADCR_SETUP_SCM ((CLKDIV<<8) | PWRUP)
////////// Init ADC0 CH2 /////////////////
Init_ADC()
{
// Convert Port pin 0.25 to function as AD0.2
LPC_SC->PCONP |= ADC_CLK_EN; //Enable ADC clock
LPC_ADC->ADCR = ADCR_SETUP_SCM | SEL_AD0_2;
LPC_PINCON->PINSEL1 |= (1<<18) ; //select AD0.2 for P0.25
}
}
////////// DISPLAY ADC VALUE /////////////////
Display_ADC()
{
unsigned int adc_value = 0;
char buf[4] = {5};
float voltage = 0.0;
adc_value = Read_ADC();
sprintf((char *)buf, "%3d", adc_value); // display 3 decima place
lcd_putstring16(0,"ADC VAL = 000 "); //1st line display
lcd_putstring16(1,"Voltage 00 V"); //2nd line display
lcd_gotoxy(0,10);
lcd_putstring(buf);
voltage = (adc_value * 3.3) / 4095 ;
lcd_gotoxy(1,8);
sprintf(buf, "%3.2f", voltage);
lcd_putstring(buf);
}
////////// MAIN /////////////////
int main (void)
{
init_lcd();
Init_ADC();
lcd_putstring16(0,"** HMSIT **");
lcd_putstring16(1,"** TUMKUR **");
delay(60000);
delay(60000);
delay(60000);
lcd_putstring16(0,"ADC Value.. ");
lcd_putstring16(1,"voltage.......");
while(1)
{
Display_ADC();
delay(100000);
}
}
LCD Code:-
#include "lpc17xx.h"
#include "lcd.h"
void Lcd_CmdWrite(unsigned char cmd);
void Lcd_DataWrite(unsigned char dat);
#define LCDRS 9
#define LCDRW 10
#define LCDEN 11
#define LCD_D4 19
#define LCD_D5 20
#define LCD_D6 21
#define LCD_D7 22
#define LcdData LPC_GPIO0->FIOPIN
#define LcdControl LPC_GPIO0->FIOPIN
#define LcdDataDirn LPC_GPIO0->FIODIR
#define LcdCtrlDirn LPC_GPIO0->FIODIR
#define LCD_ctrlMask ((1<<LCDRS)|(1<<LCDRW)|(1<<LCDEN))
#define LCD_dataMask ((1<<LCD_D4)|(1<<LCD_D5)|(1<<LCD_D6)|(1<<LCD_D7))
void delay(unsigned int count)
{
int j=0, i=0;
for (j=0;j<count;j++)
for (i=0;i<50;i++);
}
void sendNibble(char nibble)
{
LcdData&=~(LCD_dataMask); // Clear previous data
LcdData|= (((nibble >>0x00) & 0x01) << LCD_D4);
LcdData|= (((nibble >>0x01) & 0x01) << LCD_D5);
LcdData|= (((nibble >>0x02) & 0x01) << LCD_D6);
LcdData|= (((nibble >>0x03) & 0x01) << LCD_D7);
}
void Lcd_CmdWrite(unsigned char cmd)
{
sendNibble((cmd >> 0x04) & 0x0F); //Send higher nibble
LcdControl &= ~(1<<LCDRS); // Send LOW pulse on RS pin for selecting Command register
LcdControl &= ~(1<<LCDRW); // Send LOW pulse on RW pin for Write operation
LcdControl |= (1<<LCDEN); // Generate a High-to-low pulse on EN pin
delay(100);
LcdControl &= ~(1<<LCDEN);
delay(10000);
sendNibble(cmd & 0x0F); //Send Lower nibble
LcdControl &= ~(1<<LCDRS); // Send LOW pulse on RS pin for selecting Command register
LcdControl &= ~(1<<LCDRW); // Send LOW pulse on RW pin for Write operation
LcdControl |= (1<<LCDEN); // Generate a High-to-low pulse on EN pin
delay(100);
LcdControl &= ~(1<<LCDEN);
delay(1000);
}
LcdControl |= (1<<LCDRS); // Send HIGH pulse on RS pin for selecting data register
LcdControl &= ~(1<<LCDRW); // Send LOW pulse on RW pin for Write operation
LcdControl |= (1<<LCDEN); // Generate a High-to-low pulse on EN pin
delay(100);
LcdControl &= ~(1<<LCDEN);
delay(1000);
}
void lcd_clear( void)
{
Lcd_CmdWrite( 0x01 );
}
int lcd_gotoxy( unsigned char x, unsigned char y)
{
unsigned char retval = TRUE;
lcd_gotoxy( line, 0 );
while(*string != '\0' && len--)
{
lcd_putchar( *string );
string++;
}
}
void init_lcd( void )
{
LcdDataDirn |= LCD_dataMask; // Configure all the LCD pins as output
LcdCtrlDirn |= LCD_ctrlMask;
Lcd_CmdWrite(0x03);//
delay(2000);
Lcd_CmdWrite(0x03);//
delay(1000);
Lcd_CmdWrite(0x03);//
delay(100);
Lcd_CmdWrite(0x2);// Initialize LCD in 4-bit mode
Lcd_CmdWrite(0x28);// enable 5x7 mode for chars
Where VALUE is the 10-bit digital value which is to be converted into its Analog counterpart
and VREF is the input reference voltage.
Pins relating to LPC1768 DAC block:
Pin Description
Analog Output pin. Provides the converted Analog signal which is referenced to V SSA
AOUT
i.e. the Analog GND. Set Bits[21:20] in PINSEL1 register to [10] to enable this
(P0.26)
function.
These are reference voltage input pins used for both ADC and DAC. V REFP is positive
VREFP,
reference voltage and VREFN is negative reference voltage pin. In example shown
VREFN
below we will use VREFN=0V(GND).
VDDA is Analog Power pin and VSSA is Ground pin used to power the ADC module.
VDDA,
These are generally same as VCC and GND but with additional filtering to reduce
VSSA
noise.
DAC Registers in ARM Cortex-M3 LPC176x
The DAC module in ARM LPC1768/LPC1769 has 3 registers viz. DACR, DACCTRL,
DACCNTVAL. In this tutorial we will only go through to DACR register since the other two are
related with DMA operation, explaining which is not in the scope of this tutorial. Just note that
DMA is used to update new values to DACR from memory without the intervention of CPU.
This is particularly useful when generation different types of waveforms using DAC. We will
cover this in another tutorial.
Also note that the DAC doesn’t have a power control it in PCONP register. Simply select the
AOUT alternate function for pin P0.26 using PINSEL1 register to enable DAC ouput.
The DACR register in LPC1768
The field containing bits [15:6] is used to feed a digital value which needs to be converted and
bit 16 is used to select settling time. The bit significance is as shown below:
1. Bit[5:0]: Reserved.
2. Bit[15:6] – VALUE: After a new VALUE is written to this field, given settling time
selected using BIAS has elapsed, we get the converted Analog voltage at the output. The
formula for analog voltage at AOUT pin is as shown above.
3. Bit[16] – BIAS: Setting this bit to 0 selects settling time of 1us max with max current
consumption of 700uA at max 1Mhz update rate. Setting it to 1 will select settling time of
2.5us but with reduce max current consumption of 300uA at max 400Khz update rate.
4. Bits[31:17]: Reserved
#include "LPC17xx.h"
uint32_t val;
int main()
{
SystemInit();
LPC_PINCON->PINSEL1 |= 0x02<<20; //p0.26 pinsel bits 20 and 21
while(1)
{
while(1)
{
val++;// increment values by 6
LPC_DAC->DACR=(val<<6);//send values to dac
if(val>=0x3ff)// if value exceeds 1024
{
break;
}
}
while(1)
{
val--; // decrement value by 6
LPC_DAC->DACR=(val<<6);// send value to dac
if(val<=0x000)// if value come down by 0
{
break;
}
}
}
}
#include "LPC17xx.h"
void delay(unsigned int ms)// delay subroutine
{
unsigned int i,j;
for(i=0;i<ms;i++)
for(j=0;j<2000;j++);
}
int main()
{
SystemInit();
LPC_PINCON->PINSEL1 |= 0x02<<20;//p0.26 pinsel bits 20 and 21
while(1)
{
LPC_DAC->DACR=0xffff;// send maximum values to dac
delay(20); // delay
delay(20);
}
There are various methods to provide an input for the GPIO pins of a microcontroller which can
be software controlled or hardware controlled. We have seen a hardware controlled method by
taking an input from a switch or a press button. Push Button Interfacing with LPC1768
The keypad is another external input device which is hardware controlled, but is used for a
specific purpose.
In this tutorial we take a look at how a 4×4 matrix keypad is interfaced with the LPC1768
microcontroller. The input taken from the matrix keypad will be displayed on a 16x2 lcd display
Basic Configuration
NOTE: Please read this section carefully as it is important to understand the hardware
connection before writing a software for this application.
As we are using a 4×4 matrix keypad, a total of 8 input-output pins of the micro-
controller will be required for interfacing.
One half of the 8 pins will be hardware controlled and the other half will be software
controlled.
/////////////////////////////////////////////
break;
key++;
if (!(KEY_CTRL_PIN & (1<<ROW2)))
break;
key++;
if (!(KEY_CTRL_PIN & (1<<ROW3)))
break;
key++;
if (!(KEY_CTRL_PIN & (1<<ROW4)))
break;
key++;
}
if (key == 0x10)
lcd_putstring16(1,"Key Pressed = ");
else
{
lcd_gotoxy(1,14);
lcd_putchar(keyPadMatrix[key]);
}
}
}
Main code:-
#include <lpc17xx.h>
{
unsigned int i,j;
for(i=0;i<ms;i++)
for(j=0;j<60000;j++);
}
#define SBIT_CNTEN 0
#define SBIT_PWMEN 2
#define SBIT_PWMMR0R 1
#define SBIT_PWMENA1 9
int main(void)
{
int dutyCycle;
SystemInit();
/* Cofigure pins(P2_0 ) for PWM mode. */
LPC_PINCON->PINSEL4 = (1<<PWM_1) ;
while(1)
{
for(dutyCycle=0; dutyCycle<100; dutyCycle++)
{
LPC_PWM1->MR1 = dutyCycle; /* Increase the dutyCycle from 0-100 */
delay_ms(5);
}
delay_ms(5);
}
}
}
EINTx Pins
LPC1768 has four external interrupts EINT0-EINT3.
As LPC1768 pins are multi functional, these four interrupts are available on multiple pins.
Below table shows mapping of EINTx pins.
Port Pin PINSEL_FUNC_0 PINSEL_FUNC_1 PINSEL_FUNC_2 PINSEL_FUNC_3
P2.10 GPIO EINT0 NMI
P2.11 GPIO EINT1 I2STX_CLK
P2_12 GPIO EINT2 I2STX_WS
P2.13 GPIO EINT3 I2STX_SDA
EINT Registers
Below table shows the registers associated with LPC1768 external interrupts.
Register Description
PINSELx To configure the pins as External Interrupts
External Interrupt Flag Register contains interrupt flags for EINT0,EINT1, EINT2
EXTINT
& EINT3.
EXTMODE External Interrupt Mode register(Level/Edge Triggered)
EXTINT
31:4 3 2 1 0
RESERVED EINT3 EINT2 EINT1 EINT0
EINTx: Bits will be set whenever the interrupt is detected on the particular interrupt pin.
If the interrupts are enabled then the control goes to ISR.
Writing one to specific bit will clear the corresponding interrupt.
EXTMODE
31:4 3 2 1 0
RESERVED EXTMODE3 EXTMODE2 EXTMODE1 EXTMODE0
EXTMODEx: This bits is used to select whether the EINTx pin is level or edge Triggered
0: EINTx is Level Triggered.
1: EINTx is Edge Triggered.
EXTPOLA
R
31:4 3 2 1 0
RESERVED EXTPOLAR3 EXTPOLAR2 EXTPOLAR1 EXTPOLAR0
EXTPOLARx: This bits is used to select polarity(LOW/HIGH, FALLING/RISING) of the
EINTx interrupt depending on the EXTMODE register.
0: EINTx is Active Low or Falling Edge (depending on EXTMODEx).
1: EINTx is Active High or Rising Edge (depending on EXTMODEx).
Main code:-
#include <lpc17xx.h>
void EINT1_IRQHandler(void)
{
LPC_SC->EXTINT = (1<<SBIT_EINT1); /* Clear Interrupt Flag */
LPC_GPIO1->FIOPIN ^= (1<< LED1); /* Toggle the LED1 everytime INTR1 is generated
*/
}
void EINT2_IRQHandler(void)
{
LPC_SC->EXTINT = (1<<SBIT_EINT2); /* Clear Interrupt Flag */
LPC_GPIO1->FIOPIN ^= (1<< LED2); /* Toggle the LED2 everytime INTR2 is generated
*/
}
int main()
{
SystemInit();
while(1)
{
// Do nothing
}
}
The displays common pin is generally used to identify which type of 7-segment display it is. As
each LED has two connecting pins, one called the “Anode” and the other called the “Cathode”,
there are therefore two types of LED 7-segment display called: Common Cathode (CC) and
Common Anode (CA).
The difference between the two displays, as their name suggests, is that the common cathode has
all the cathodes of the 7-segments connected directly together and the common anode has all the
anodes of the 7-segments connected together and is illuminated as follows.
1. The Common Cathode (CC) – In the common cathode display, all the cathode connections of
the LED segments are joined together to logic “0” or ground. The individual segments are
illuminated by application of a “HIGH”, or logic “1” signal via a current limiting resistor to
forward bias the individual Anode terminals (a-g).
Common Cathode 7-segment Display
2. The Common Anode (CA) – In the common anode display, all the anode connections of the
LED segments are joined together to logic “1”. The individual segments are illuminated by
applying a ground, logic “0” or “LOW” signal via a suitable current limiting resistor to the
Cathode of the particular segment (a-g).
Common Anode 7-segment Display
In general, common anode displays are more popular as many logic circuits can sink more
current than they can source. Also note that a common cathode display is not a direct
replacement in a circuit for a common anode display and vice versa, as it is the same as
connecting the LEDs in reverse, and hence light emission will not take place.
Depending upon the decimal digit to be displayed, the particular set of LEDs is forward biased.
For instance, to display the numerical digit 0, we will need to light up six of the LED segments
corresponding to a, b, c, d, e and f. Thus the various digits from 0 through 9 can be displayed
using a 7-segment display as shown.
Then for a 7-segment display, we can produce a truth table giving the individual segments that
need to be illuminated in order to produce the required decimal digit from 0 through 9 as shown
below.
1 × ×
2 × × × × ×
3 × × × × ×
4 × × × ×
5 × × × × ×
6 × × × × × ×
7 × × ×
8 × × × × × × ×
9 × × × × ×
Driving a 7-segment Display
Although a 7-segment display can be thought of as a single display, it is still seven individual
LEDs within a single package and as such these LEDs need protection from over current. LEDs
produce light only when it is forward biased with the amount of light emitted being proportional
to the forward current.
This means then that an LEDs light intensity increases in an approximately linear manner with
an increasing current. So this forward current must be controlled and limited to a safe value by
an external resistor to prevent damage to the LED segments.
The forward voltage drop across a red LED segment is very low at about 2-to-2.2 volts, (blue
and white LEDs can be as high as 3.6 volts) so to illuminate correctly, the LED segments should
be connected to a voltage source in excess of this forward voltage value with a series resistance
used to limit the forward current to a desirable value.
Typically for a standard red coloured 7-segment display, each LED segment can draw about 15
mA to illuminated correctly, so on a 5 volt digital logic circuit, the value of the current limiting
resistor would be about 200Ω (5v – 2v)/15mA, or 220Ω to the nearest higher preferred value.
So to understand how the segments of the display are connected to a 220Ω current limiting
resistor consider the circuit below.
Main Code:-
#include <lpc17xx.h>
for(i=0;i<ms;i++)
for(j=0;j<40000;j++);
}
while(1)
{
delay_ms(200);
LPC_GPIO1->FIOCLR = 0x00004713;//clear all segments
delay_ms(200);
LPC_GPIO1->FIOCLR = 0x00004713;//clear all segments
LPC_GPIO1->FIOSET = 0x00004012;//set set b,c,g to make C
delay_ms(200);
LPC_GPIO1->FIOCLR = 0x00004713;//clear all segments
LPC_GPIO1->FIOSET = 0x00000401;//set a,f to make d
delay_ms(200);
LPC_GPIO1->FIOCLR = 0x00004713;//clear all segments
LPC_GPIO1->FIOSET = 0x00000012;//set b,c to make E
delay_ms(200);
LPC_GPIO1->FIOCLR = 0x00004713;//clear all segments
LPC_GPIO1->FIOSET = 0x00000112;//set b,c,d to make F
delay_ms(200);
}
}
Here switch is pulled up to +3.3 volt. So when pressed port should read active low
signal(0),normal condition is active high(1)
Main code:-
#include <lpc17xx.h>
uint32_t switchStatus;
LPC_GPIO1->FIODIR = 0x1ff80000; /* P1.xx defined as Outputs */
LPC_GPIO1->FIOCLR = 0x1ff80000; /* turn off all the LEDs&relay&buzzer */
LPC_GPIO2->FIODIR = 0x00000000; /* P2.xx defined as input */
while(1)
{
}
else //if switch released
{
LPC_GPIO1->FIOPIN =
(0<<buzzerPinNumber)|(0<<relayPinNumber)|(0<<LedPinNumber); //if switch released
led,relay,buzzer off
}
}
}
SPI - LPC1768
SPI - ADC
ADC Lines
CS P0.28
CLK P0.27
Dout P3.26
MCP
3202
Din P3.25
Main code:-
#include <LPC17xx.H>
#include <stdint.h>
#include <stdio.h>
#include "delay.h"
#include "spi_manul.h"
#include "lcd.h"
#define pulse_val 2
main()
{
unsigned int spi_rsv=0;
float vin;
char buf[20];
SystemInit ();
lcd_init();
lcd_str("SPI 3202-b");
delay(60000);
delay(60000);
while(1)
{
lcd_clr();
lcd_cmd(0x80);
spi_rsv = spi_data1(15);
vin = ( ( spi_rsv & 0xfff ) * (3.3) ) / 4096 ;
sprintf(buf,"Temp: %0.2f degC",(vin*100) );
lcd_str(buf);
delay(50000);
delay(50000);
}
}
SPI ADC data fetching program:-
#include <LPC17xx.H>
#include "delay.h"
#define pulse_val 2
#define CLK 1<<27
#defineCS 1<<28
#define DDOUT 26
#defineDOUT 1<<25
#defineDIN 1<<26
#define spi_stst 0
unsigned int spi_data(char sel)
{
char clks = 4;
LPC_GPIO0->FIODIR |= CS|CLK;
LPC_GPIO3->FIODIR = DOUT;
LPC_GPIO0->FIOSET = CS|CLK;
LPC_GPIO3->FIOCLR = DOUT;
nop_delay(100);
#if spi_stst
if ( LPC_GPIO3->FIOPIN & DIN )
{
return 'P';
}
#endif
LPC_GPIO0->FIOCLR = CS;
nop_delay(pulse_val);
while(clks)
{
LPC_GPIO0->FIOCLR = CLK;
nop_delay(pulse_val);
LPC_GPIO0->FIOSET = CLK;
nop_delay(pulse_val);
clks--;
}
LPC_GPIO0->FIOCLR = CLK;
nop_delay(pulse_val);
if (!( LPC_GPIO3->FIOPIN & DIN ) )
{
return 'U';
}
clks = 12;
while(clks)
{
clks--;
LPC_GPIO0->FIOCLR = CLK;
nop_delay(pulse_val);
LPC_GPIO0->FIOSET = CLK;
nop_delay(pulse_val);
}
nop_delay(pulse_val);
if (!( LPC_GPIO3->FIOPIN & DIN ) )
{
return 'U';
}
return 'Z';
}
unsigned int spi_data1(char sel)
{
unsigned int spi_reg=0;
char clks = 12;
LPC_GPIO0->FIODIR |= CS|CLK;
LPC_GPIO3->FIODIR = DOUT;
LPC_GPIO0->FIOSET = CS|CLK;
LPC_GPIO3->FIOSET = DOUT;
LPC_GPIO3->FIOPIN = DIN;
nop_delay(100);
LPC_GPIO0->FIOCLR = CS;
//start condi
LPC_GPIO0->FIOCLR = CLK;
LPC_GPIO3->FIOSET = DOUT;
nop_delay(pulse_val);
LPC_GPIO0->FIOSET = CLK;
nop_delay(5);
//single mode
LPC_GPIO0->FIOCLR = CLK;
LPC_GPIO3->FIOSET = DOUT;
nop_delay(pulse_val);
LPC_GPIO0->FIOSET = CLK;
nop_delay(5);
//chanl 1
LPC_GPIO0->FIOCLR = CLK;
LPC_GPIO3->FIOSET = DOUT;
nop_delay(pulse_val);
LPC_GPIO0->FIOSET = CLK;
nop_delay(5);
//msb first
LPC_GPIO0->FIOCLR = CLK;
LPC_GPIO3->FIOSET = DOUT;
nop_delay(pulse_val);
LPC_GPIO0->FIOSET = CLK;
nop_delay(5);
//smpling
// LPC_GPIO0->FIOCLR = CLK;
// nop_delay(pulse_val);
// LPC_GPIO0->FIOSET = CLK;
// nop_delay(2);
//null bit
LPC_GPIO0->FIOCLR = CLK;
nop_delay(pulse_val);
LPC_GPIO0->FIOSET = CLK;
// while ( ( LPC_GPIO3->FIOPIN & DIN ) == DIN );
// if( !( LPC_GPIO3->FIOPIN & DIN ) );
// {
// return 'U';
// }
nop_delay(5);
clks = 12;
while(clks)
{
LPC_GPIO0->FIOCLR = CLK;
nop_delay(pulse_val);
LPC_GPIO0->FIOSET = CLK;
if( ( LPC_GPIO3->FIOPIN & DIN ) )
{
spi_reg |= 1<<(clks-1);
}
else
{
spi_reg = spi_reg;
}
clks--;
nop_delay(5);
}
nop_delay(1);
return spi_reg;
}
#include <LPC17xx.H>
#include "delay.h"
#define RRW (7<<9)
#define DATA_L (15<<19)
void lcd_pin(void)
{
LPC_GPIO0->FIODIR |= RRW|DATA_L;
}
LPC_GPIO0->FIOCLR |= RRW|DATA_L;
delay(10);
LPC_GPIO0->FIOCLR |= RRW|DATA_L;
delay(10);
lcd_cmd(0x03);
delay(1000);
lcd_cmd(0x03);
delay(100);
lcd_cmd(0x2);
lcd_cmd(0x28);
lcd_cmd(0x0e);
lcd_cmd(0x06);
lcd_cmd(0x01);
delay(1);
}
4. Viva Question
1. These are few very simple and general ARM processor interview questions
2. What are the types of CORTEX-M series ?
3. How do you select a specific CORTEX-M processor ?
4. What is Microprocessor?
Microprocessor is a CPU fabricated on a single chip program controlled device, which
fetched the instructions from memory, decodes and execute the instructions. Three basic
characteristic differentiate microprocessor.
5. Instruction Set: The set of instruction microprocessor can execute.
6. Bandwidth: The number of bit’s processed in a single instruction
7. Clock Speed: Given in MHz Megahertz, the clock speed determines how many instructions
per second the processor can execute.
8. In addition to this, microprocessors are classified as being RISC (Reduced Instruction Set
Computer) or CISC (Complex Instruction Set Computer).
9. What are the basic units of Microprocessor?
The basic units or block of microprocessor are ALU, an Array of Registers and control unit.
10. Give Examples for8/16/32-bit Microprocessor?
8-bit Processors- 8085, Z80, 6800
16-bit Processors- 8086, 68000, Z8000
32-bit Processors- 80386, 80486
64-bit Processors- Intel 64(x64), AMD64, IBM (Power PC), SUN (SPARC).
11. What are 1st/ 2nd/3rd/4th generation processors?
The processors made of PMOS, NMOS, HMOS, HCMOS technology are called 1st/
2nd/3rd/4th generation processor’s and are made up of 4, 8, 16, 32-bits.
12. What does microprocessor speed depends on?
The speed of microprocessor depends on various factors such as Data Bus Width (Number
of instruction it processes) and clock speed.
13. What is Software and Hardware?
The software is set of instruction or commands needed for performing a specific task by
programmable device or a computing machine. The hardware refers to the component or
device used to form computing machine in which software can be run and tested. Without
software hardware is idle machine.
14. Distinguish between microprocessor and microcontroller?
The microprocessor is a digital integrated circuit that can be programmed with a series of
instructions to perform a specified function on data. The microcontroller is tiny little
computer on single integrated circuit, which has memory, input-output on chip itself. So
we can say microprocessor can perform few functions but microcontroller can perform
many functions.
15. What are disadvantages of Microprocessor?
Microprocessor has limitation on size of data. Most microprocessor does not support
floating point operation.
16. What is the difference between microprocessor and microcontroller?
op-codes and more bit handling instructions also microcontroller defined as a device that
includes microprocessor, memory and input-output signal lines in a single chip.
17. What is an Instruction?
An instruction is an order given to a computer processor by a computer program. At the
lowest level each instruction set is a sequence of 0s and 1s that describes a physical
operation that computer is to perform (such as “Add”) and depending on the particular
instruction type, the specification of special storage areas called registers that may
contain data be used in carrying out the instruction or the location in computer memory
of data.
18. What is clock cycle?
The speed of computer processor is determined by clock cycle, which is amount of time
between two pulses of an oscillator. In general, the higher number of pulses per second
the faster the computer processor will be able to process information.
19. ARM stands for Advanced RISC Machines ____________
a) Advanced Rate Machines
b) Advanced RISC Machines
c) Artificial Running Machines
d) Aviary Running Machines
View Answer
Answer: b
Explanation: ARM is a type of system architecture.
20. The main importance of ARM micro-processors is providing operation with ______
a) Low cost and low power consumption
b) Higher degree of multi-tasking
c) Lower error or glitches
d) Efficient memory management
View Answer
Answer: a
Explanation: The Stand alone feature of the ARM processors is that they’re economically
viable.
21. ARM processors where basically designed for _______
a) Main frame systems
b) Distributed systems
c) Mobile systems
d) Super computers
View Answer
Answer: c
Explanation: These ARM processors are designed for handheld devices.
22. The ARM processors doesn’t support Byte address ability ?
a) True
b) False
View Answer
Answer: b
Explanation: The ability to store data in the form of consecutive bytes.
23. The address space in ARM is ______
a) 224
b) 264
c) 216
d) 232
View Answer
Answer: d
Explanation: None.