Module 4 Embedded Systems
Module 4 Embedded Systems
Introduction to ARM
Programming
1
Department of EECE-19ECS431-EMBEDDED SYSTEMS 2
2
LPC214x Pin configuration
• LPC2148 have 2 PORTS, P0 and P1. Each pin of these ports are
named as P0.0, P0.1, P0.2, P1.0, P1.2 etc.
IOxDIR
IOxSET
• IOxSET is GPIO output set register. This register is commonly used
in conjunction with IOxCLR register described below.
for(;x>0;x--)
for(j=0; j<0x1FFF; j++);
}
• A 16×2 LCD means it can display 16 characters per line and there
are 2 such lines. In this LCD each character is displayed in a 5×7
pixel matrix.
• LCD 16x2 is 16 pin device which has 8 data pins (D0-D7) and 3
control pins (RS, RW, EN). The remaining 5 pins are for supply and
backlight for the LCD.
The data register stores the data to be displayed on the LCD. The data
is the ASCII value of the character to be displayed on the LCD.
LCD 16x2 can be used in 4-bit mode or 8-bit mode depending on the
requirement of the application
unchanged(i.e. RS = 1, RW = 0) */
delay_ms(5);
}
• #include <lpc214x.h>
• #include <stdint.h>
• #include "LCD-16x2-8bit.h"
• #include <stdio.h>
• #include <string.h>
• int main(void)
• {
• uint32_t result;
float voltage;
• char volt[18];
• LCD_Init();
• PINSEL1 = 0x01000000; /* P0.28 as AD0.1 */
• AD0CR = 0x00200402; /* ADC operational, 10-bits, 11 clocks for conversion */
•
Department of EECE-19ECS431-EMBEDDED SYSTEMS 39
Interfacing LM35 with LPC2148
• while(1)
• {
• AD0CR = AD0CR | (1<<24); /* Start Conversion */
• while ( (AD0DR1 & 0x80000000) ==0); /* Wait till DONE */
• result = AD0DR1;
• result = (result>>6);
• result = (result & 0x000003FF);
• voltage = ( (result/1023.0) * 3.3 ); /* Convert ADC value to equivalent voltage */
• LCD_Command(0x80);
• sprintf(volt, "Voltage=%.2f V ", voltage);
• LCD_String(volt);
• memset(volt, 0, 18);
• }
Department of EECE-19ECS431-EMBEDDED SYSTEMS 40
• }
ADC (Analog to Digital Converter)
• Analog to Digital Converter(ADC) is used to convert analog signal into
digital form. LPC2148 has two inbuilt 10-bit ADC i.e. ADC0 & ADC1.
• Hence, we can connect 6 distinct types of input analog signals to ADC0 and
8 distinct types of input analog signals to ADC1.
Monitor the DONE bit (bit number 31) of the corresponding ADxDRy (ADC
Data Register) till it changes from 0 to 1. This signals completion of
conversion. We can also monitor DONE bit of ADGSR or the DONE bit
corresponding to the ADC channel in the ADCxSTAT register.
Read the ADC result from the corresponding ADC Data Register.
ADxDRy. E.g. AD0DR1 contains ADC result of channel 1 of ADC0.