Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
m.tech esd lab manual for record
1. 1
INTRODUCTION
DESCRIPTION OF EMBEDDED EVALUATION BOARD
1.1 INTRODUCTION
The Embedded Controller Evaluation Board provides the user with the features required to
understand the capabilities of an advanced microcontroller - the AT89C51ED2 Micro controller.
The AT89C51ED2 is architecturally compatible with the Intel 89C51. The board consists of
The Flash programmable AT89C51ED2 controller
8 numbers of LED’s
8 numbers of Switches
16 X 2 Line LCD Alphanumeric Display
RS232C compatible Serial Interface for communication , ISP
SPI compatible 12 bit ADC with Temperature Sensor Interface
4 numbers of multiplexed 7- Segment Displays
I2C 8-bit ADC/DAC Interface
I2C RTC
I2C NVROM
4 numbers of high Current Output lines
One changeover Relay for Experiments
In System Programming capability
1.2 SPECIFICATIONS
The Flash Programmable Embedded Controller Evaluation Board consists of
The Atmel 89C51ED2- 8-bit micro controller (U1) with operating frequency of
11.0592MHz with an external crystal and supply voltage of 5V. It has 64K bytes of flash
memory block for program and data and 1792 bytes of XRAM
A 26 pin FRC connector CN3 connected to Ports 0,1 and 2 of the controller, which is
compatible with ALS standard external interfaces.
26 pin FRC connector CN4 which can be connected to Port 0,1 and 2 Lines to study the
internal features of the controller , Reading Switches, PWM, ADC, DAC, RTC,
NVROM, 7-segment Displays etc.
A 9 pin D-type female connector CN2, RS232 serial i/o interface for UART experiments
and flash programming.
A 9 pin D-type male Connector CN1 for power connection (+5V and GND).
Push buttons switch SW2 for Reset and a Slide switch SW1 to select either program
mode or run mode.
2. 2
Push buttons switch SW3 for External Interrupt INT0.
Eight numbers of LED's (L3 to L10) interfaced through serial shift register
Eight key switches (SW4 to SW11) organized in 2 rows X 4 columns
8bit ADC / DAC using I2C device (U17)
NVROM 24C16 – I2C compatible (U7)
RTC - DS1307 - I2C compatible (U6)
Four numbers CC seven segment multiplexed displays (U12,U13,U14,U15)
One DPDT relay with contact terminated in relaimate (RLY1)
Four High Current Output (300 ma) using ULN2803 (U16)
One SPI ADC (MCP3202) with Temperature Sensor IC LM335 (U4)
Elegant enclosure with Test Points for monitoring (TPs)
1.3 BLOCK DIAGRAM
3. 3
1.4: APPLYING POWER
Connect a 9-pin D-type(DB) Female Connector to a 9-pin DB Male connector CN1
provided on the Embedded Controller Evaluation Board (ALS-EMB-EVAL-02).
The color code for the supply is
Pin No Voltages Color Code(Female)
9 VCC(+5) Orange/White/Blue
4,5 GND Yellow/Black
As soon as the power is applied the sign on message “EMBEDDED CONTROLLER
EVALUATION BOARD” appears on the LCD. If the sign on message will not appear check
the slide switch SW1 is in RUN position on the board and +5V is present at the corresponding
VCC inputs of the IC pins. (Ex. Pin-44 of AT89C51ED2). If not switch off the power supply and
verify that the IC's on the trainer are mounted properly or not. Press all the IC's tightly into their
bases, switch on again and if sign on message still doesn't appears, refer to the factory.
1.5: SERIAL COMMUNICATION OPERATION
To connect Embedded Controller Evaluation Board (ALS-EMB-EVAL-02) to host
computer system the procedure is as follows - Connect one end of the 9-pin RS232 cross cable
(Female Type) to the host computer system and other end (Male Type) to the serial port
connector
CN2 on the ALS-EMB-EVAL-02 board.
Set the host computer system baud rate, data length and parity bit. The default values are
9600 baud, 1 stop bit and none parity bit. This setting is done in Device Manager explorer of the
computer system.
RS232 Cable Connection
ALS-EMB-EVAL-02
Pin No(9 Pin Male DB)
Host Computer
Pin No (9 Pin Female DB)
2 (RXD) 2 (RXD)
3 (TXD) 3 (TXD)
5 (Signal GND) 5 (Signal GND)
4. 4
EXPERIMENT NO: 01
LED BLINKING
AIM: To write a program for the LEDs blinking.
APPARATUS: SOFTWARE: Keil u IDE, Atmel Flip
HARDWARE: Embedded control evaluation board, PC
PROGRAM:
#include<at89c51xd2.h>
#include<intrins.h>
unsigned char ref_byte = 0xFF,temp,count =0x00;
void DelayMs(unsigned int);
void led_init(void);
sbit CLKL = P2^6; //Clock Line (>CLK)of 8-bit shift reg U5 (Serial In Parralel Out)
sbit LED = P2^7; //Data Line of the 8-bit shift reg U5
main()
{
AUXR = 0x10; //Accesiing Full XRAM
CLKL = 0;
led_init(); //Clearing ALL LEDs FROM L3 TO L10
DelayMs(1000);
while(1)
{
temp = ref_byte;
LED = (temp & 0x80)? 0:1;
CLKL = 1;
DelayMs(1);
CLKL = 0;
ref_byte <<= 1;
count++;
if(count == 0x08)
{
count = 0x00;
ref_byte = 0x01;
}
DelayMs(1000);
}
}
void DelayMs(unsigned int count)
{ // mSec Delay 11.0592 Mhz
unsigned int i;
while(count)
5. 5
{
i = 110;
while(i>0) i--;
count--;
}
}
// To clear All LEDs
void led_init(void)
{
unsigned int j;
CLKL = 0;
LED = 1;
for(j=0;j<8;j++)
{
CLKL = 1;
_nop_();
_nop_();
CLKL =0;
_nop_();
}
}
OUTPUT: The LED blinking is being observed from L3 to L10 on the target board.
RESULT: Thus the LED blinking program is being compiled, debugged and executed successfully.
6. 6
EXPERIMENT NO: 02
PROGRAM ON TIMERS
AIM: To write a program for DELAY using TIMER-0 and switch on a LED in timer subroutine.
APPARATUS: SOFTWARE: Keil u IDE, Atmel Flip
HARDWARE: Embedded control evaluation board, PC
PROGRAM:
#include <at89c51xd2.h>
#include <intrins.h> //For _nop_();
void led_init(void);
void timer0_init(void);
sbit L = P1^5; //LED L2 Operation
sbit CLKL = P2^6; //Clock Line (>CLK)of 8-bit shift reg U5(Serial In parrale Out)
sbit LED = P2^7; //Data Line of the 8-bit shift reg U5
void main(void)
{
AUXR = 0x10; // Accesiing Ful XRAM
led_init(); //CLearing All LEDs from L3 to L10
timer0_init();
EA = 1; //Enabling Global Interrupt
while(1);
}
void timer0_init(void)
{
TMOD = 0x01; //Timer0 in Mode1,
TL0 = 0xff;
TH0 = 0x6f; //For 40ms Delay
TCON = 0x00; //TF0 = 0; //Clearing All Flags
ET0 = 1; //Enabling Timer0 Interrupt
TR0 = 1; //Starting Timer0
}
void timer0_isr(void) interrupt 1
{
L = ~L; //Toggling LED L2
7. 7
TF0 = 0; //Clearing Interrupt Flag
TL0 = 0xff;
TH0 = 0x6f; //Reloading Value into registers for every overflow
}
// To clear All LEDs L3 to L10
void led_init(void)
{
unsigned int j;
CLKL = 0;
LED = 1;
for(j=0;j<8;j++)
{
CLKL = 1;
_nop_();
_nop_();
CLKL =0;
_nop_();
}
}
OUTPUT: It is being observed that the routine delay of 40ms has been done. In ISR of timer0, LED
L2 that is connected to port line P1.5 is being toggled for every 40ms.
RESULT: Thus the program is being compiled, debugged and executed successfully.
8. 8
EXPERIMENT NO: 03
LCD INTERFACE
AIM: To write a program for LCD testing. .
APPARATUS: SOFTWARE: Keil u IDE, Atmel Flip
HARDWARE: Embedded control evaluation board, PC
PROGRAM:
#include<at89c51xd2.h>
#include<intrins.h>
// LCD FUNCTION PROTOTYPE
void lcd_init(void);
void lcd_comm(void);
void wr_cn(void);
void lcd_data(void);
void wr_dn(void);
void clear_lcd(void);
void maxdelay(void);
void mindelay(void);
unsigned int i=0;
unsigned char temp1=0x00,var=0x00;
unsigned char temp2;
void led_init(void);
unsigned char arr[32] = " EMBEDDED SYSTEMS AND VLSI ";
sbit CLKL = P2^6; //Clock Line (>CLK)of 8-bit shift reg U5 (Serial In Parralel Out)
sbit LED = P2^7; //Data Line of the 8-bit shift reg U5
void main(void)
{
AUXR = 0x10; // Accesiing Ful XRAM
led_init(); //CLearing All LEDs from L3 to L10
lcd_init(); // Initialize the LCD
clear_lcd();
temp1 = 0x80;
lcd_comm(); // Displaying at 1st line of LCD
for(i=0;i<32;i++)
{
if(i == 16)
{
9. 9
temp1 = 0xc0;
lcd_comm(); // Displaying at 2nd line of LCD
}
temp2 = arr[i];
lcd_data();
}
while(1);
}
void lcd_init(void)
{
temp1 = 0x0C; // D5(P3.3)=1,D4(P3.2)=1
wr_cn();
maxdelay();
temp1 = 0x0C; // D5(P3.3)=1,D4(P3.2)=1
wr_cn();
maxdelay();
temp1 = 0x0C; // D5(P3.3)=1,D4(P3.2)=1
wr_cn();
maxdelay();
temp1 = 0x08; // D5(P3.3)=1
wr_cn();
maxdelay();
temp1 = 0x28;
lcd_comm();
maxdelay();
temp1 = 0x0f; //display on,cursor on
lcd_comm();
maxdelay();
temp1 = 0x06; //shift cursor right with auto increment
lcd_comm();
maxdelay();
temp1 = 0x80; //clear display with cursor on first position
lcd_comm();
maxdelay();
}
// Function to pass commands to LCD
void lcd_comm(void)
{
var = temp1;
temp1 = temp1 & 0xf0;
10. 10
temp1 = temp1 >> 2;
wr_cn();
temp1 = var & 0x0f;
temp1 = temp1 << 2;
wr_cn();
mindelay();
}
// Function to pass data to LCD
void lcd_data(void)
{
var = temp2;
temp2 = temp2 & 0xf0; // convert the byte into nibble
temp2 = temp2 >> 2;
wr_dn();
temp2 = var & 0x0f;
temp2 = temp2 << 2;
wr_dn();
mindelay();
}
// Function to write to command reg of LCD
void wr_cn(void)
{
temp1 = temp1 & 0x7f; // RS(P3^7)=0
temp1 = temp1 | 0x43; // EN(P3^6)=1, TXD(P3^1)=1, RXD(P3^0)=1
P3 = temp1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
temp1 = temp1 & 0xbf; // EN(P3^6)=0,
P3 = temp1;
}
// Function to write to data reg of LCD
void wr_dn(void)
{
temp2 = temp2 | 0xc3; // RS(P3^7)=1,EN=1,TXD=1,RXD=1
P3 = temp2;
11. 11
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
temp2 = temp2 & 0xbf; // EN = 0
P3 = temp2;
}
// Function to clear the LCD display
void clear_lcd()
{
temp1 = 0x01;
lcd_comm();
maxdelay();
}
void maxdelay(void)
{
int i,j;
/* for(i=0;i<5;i++)
for(j=0;j<50;j++); //2.1ms Delay*/
for(i=0;i<10;i++)
for(j=0;j<50;j++); //4.1ms Delay*/
}
void mindelay(void)
{
int j;
for(j=0;j<60;j++); //0.52ms Delay
}
// To clear All LEDs L3 to L10
void led_init(void)
{
unsigned int j;
CLKL = 0;
LED = 1;
for(j=0;j<8;j++)
{
CLKL = 1;
_nop_();
_nop_();
CLKL =0;
_nop_();
}
12. 12
}
OUTPUT: “EMBEDDED SYSTEMS AND VLSI” is being observed on the LCD screen.
RESULT: Thus the LCD TEST program is being compiled, debugged and executed successfully.
13. 13
EXPERIMENT NO: 04
KEYPAD INTERFACE
AIM: To write the program to interface keypad to 8051.
APPARATUS: SOFTWARE REQUIREMENTS: Keil u IDE, Atmel Flip
HARDWARE REQUIREMENTS: Embedded control evaluation board, PC
PROGRAM:
#include<at89c51xd2.h>
#include<intrins.h>
/*key_arr :-->
0x8E -> ROW2 SW8 0x1E -> ROW1 SW4
0x8D -> ROW2 SW9 0x1D -> ROW1 SW5
0x8B -> ROW2 SW10 0x1B -> ROW1 SW6
0x87 -> ROW2 SW11 0x17 -> ROW1 SW7
0x8E,0x8D,0x8B,0x87 -> 8(1000) is for ROW2(P2.4*)=0;ROW1(P1.7*)=1
0x1E,0x1D,0x1B,0x17 -> 1(0001) is for ROW1(P1.7*)=0;ROW2(P2.4*)=1
E -> 1110 -> for P2.0* SW4 & SW8
D -> 1101 -> for P2.1* SW5 & SW9
D -> 1011 -> for P2.2* SW6 & SW10
D -> 0111 -> for P2.3* SW7 & SW11 */
unsigned char key_arr[8] = {0x8E,0x8D,0x8B,0x87,0x1E,0x1D,0x1B,0x17};
/*array_dec[10]:->
value= h g f e d c b a On 7-SEG U15
0x66 = 0 1 1 0 0 1 1 0 -> Displaying '4'
0x6D = 0 1 1 0 1 1 0 1 -> Displaying '5'
0x7D = 0 1 1 1 1 1 0 1 -> Displaying '6'
0x07 = 0 0 0 0 0 1 1 1 -> Displaying '7'
0x3F = 0 0 1 1 1 1 1 1 -> Displaying '0'
0x06 = 0 0 0 0 0 1 1 0 -> Displaying '1'
0x5B = 0 1 0 1 1 0 1 1 -> Displaying '2'
0x4F = 0 1 0 0 1 1 1 1 -> Displaying '3'
0x7F = 0 1 1 1 1 1 1 1 -> Displaying '8'
0x6F = 0 1 1 0 1 1 1 1 -> Displaying '9' */
unsigned char array_dec[10] = {0x66,0x6D,0x7D,0x07,0x3F,0x06,0x5B,0x4F,0x7F,0x6F};
unsigned char key_rtn=0x00,key_flag=0x00,temp =0x00,temp2 = 0x00;
unsigned char row = 0xEF,temp_row = 0x00,key = 0x00,tmp_rw1=0x00,tmp_rw2=0x00;
unsigned int i = 0;
void key_press(void);
void scan(void);
void DelayMs(unsigned int);
void Display(void);
void led_init(void);
14. 14
sbit EN = P1^2; //Latch Enable Line of second 2to4 LineDecoder of U8
//U8 is having two 2to4 line decoders
sbit SEL0 = P1^3; //Data Latch 1A of the 1st decoder of U8
sbit SEL1 = P1^5; //Data Latch 1B of the 1st decoder of U8
sbit ENL = P2^5; //Data Latch 2B of the 2nd decoder of U8
sbit ROW2 = P2^4; //Second row of thw 2X4 keypad
sbit ROW1 = P1^7; //First row of thw 2X4 keypad
sbit CS = P1^4; //Chip select line for SPI device U3
sbit CLKL = P2^6; //Clock Line (>CLK)of 8-bit shift reg U5(Serial In parrale Out)
sbit LED = P2^7; //Data Line of the 8-bit shift reg U5
void main()
{
AUXR = 0x10;//Accessing Ful XRAM
led_init(); //For Clearing All LEDs L3 to L10
P2 = 0xFF; //make Port 2 high;
P1 = 0xFF; //make Port 1 high;
P0 = 0x00; //port for 7-seg data
EN = 1; //Disabling 2nd Decoder
ENL = 0; //Data Latch Enable line
CS = 1; //to disable SPI
while(1)
{
ROW1 = 0; //fOR ROW1 (SW4 TO SW 7)
ROW2 = 1;
key_press();
if(key_flag == 0xFF)//If key Pressed
{
scan();
Display(); //Displying the num on the 7-Seg U15
}
ROW1 = 1; //fOR ROW2 (SW8 TO SW 11)
ROW2 = 0;
key_press();
if(key_flag == 0xFF)//If key Pressed
{
scan();
Display(); //Displying the num on the 7-Seg U15
}
} //end of while(1) loop
}
/* Key_press() function is used to check which portline has gone
LO Initialy the portlines P2.0*,P2.1*,P2.2*,P2.3* are HI, so when
pressing SWitches the perticular portline goes LO (Such that LO
at P1.7* will go to the perticular portline P2.0* to P2.3*).
P1.7* and P2.4* are Outpuit Lines
P2.7* to P2.3* are input lines to Contrller */
15. 15
void key_press(void)
{
temp = P2 & 0x0F; //Read the keys(Masking the Lowr Nibble)
DelayMs(1); //wait for debounce
temp = P2 & 0x0F; //Again Read the keys(Masking the Lowr Nibble)
DelayMs(1); //wait for debounce
if(temp == 0x0F) //If No key has been pressed
key_flag = 0x00;
else
{
key_flag = 0xFF;//If Key pressed
DelayMs(1); //wait for debounce
while(temp == (temp2 = P2 & 0x0F));//waiting for key lift
key_rtn = temp; //taking the value read 'temp' wen pressing key
//i.e. P2=0x0F (Initialy P2.0 to P2.3 are at HI)
//P2=0x0E wen SW4 0r SW8 are pressed depending upon ROW1&ROW2
//P2=0x0D wen SW5 0r SW9 are pressed depending upon ROW1&ROW2
//P2=0x0B wen SW6 0r SW10 are pressed depending upon ROW1&ROW2
//P2=0x07 wen SW7 0r SW11 are pressed depending upon ROW1&ROW2
}
}
/* scan() function is used for masking perticular ROW line and
getting it in one variable,after this combining the masked ROW
line with the COL lines... The reult carible is being compared
with the Lookup Table key_arr[] and getting the corresponding
index of the Display array array_dec[]
For Ex:
For key_arr[i=0] = 0x8E; key = i = 0 array_dec[key] = 0x66 '4'
For key_arr[i=3] = 0x87; key = i = 3 array_dec[key] = 0x07 '7'
For key_arr{i=4] = 0x1E; key = i = 4 array_dec[key] = 0x3F '0'
For key_arr{i=6] = 0x1B; key = i = 6 array_dec[key] = 0x5B '2' */
void scan(void)
{
tmp_rw1 = P1 & 0x80; //Masking P1.7* portline
tmp_rw2 = tmp_rw1 | (P2 & 0x10);//Masking P2.4* portline
tmp_rw2 = tmp_rw2 & 0x90; //Again Masking P1.7* & P2.4*
key_rtn = key_rtn | tmp_rw2; //Combining ROWs(P1.7*&P2.4*)//and COLs(P2.0* to
P2.3*)
for(i=0;i<8;i++)
if(key_rtn == key_arr[i])
key = i; //Getting the correspondin index value for
//displaying 0,1,2,3,4,5,6,7 on U15
}
/*Portlines P0.0* to P0.7* are given to the 7 segment displays
thru Buffer
16. 16
P0.0* to P0.7* ===> a,b,c,d,e,f,g,h segments respectivly */
void Display(void)
{
P0 = array_dec[key];//Decoding the key value to that of 7-segment
ENL = 0;
SEL1 = 1; //Select lines for segments
SEL0 = 1; //00 for U12,01 for U13
//10 for U14,11 for U15
EN = 0;
DelayMs(2);
EN = 1;
}
void DelayMs(unsigned int count)
{ // 0.1 mSec Delay 11.0592 Mhz
unsigned int i;
while(count)
{
i = 11;
while(i>0) i--;
count--;
}
}
// To clear All LEDs
void led_init(void)
{
unsigned int j;
CLKL = 0;
LED = 1;
for(j=0;j<8;j++)
{
CLKL = 1;
_nop_();
_nop_();
CLKL =0;
_nop_();
}
}
OUTPUT: It is being observed that key numbers 0 to 7 for switches SW4 to SW11 respectively
displayed on the right most 7-segment display U15.
RESULT: Thus the keypad program is being compiled, debugged and executed successfully.
17. 17
EXPERIMENT NO: 05
KEYPAD INTERFACE
AIM: To write the program to interface LCD to ARM7(LPC2148) microcontroller.
APPARATUS: SOFTWARE REQUIREMENTS: Keil u IDE, Flash Magiic
HARDWARE REQUIREMENTS: LPC2148 development board, PC
PROGRAM:
main.c file
#include "lcd.h"
int main (void)
{
init_lcd();
while (1)
{
lcd_data_write('a');
}
}
lcd.c file
#include <LPC214x.H> /* LPC214x definitions */
#include "lcd.h"
#define LCD_BACK_LIGHT_TIMEOUT 1000
#define LCD_BACKLIGHT (1 << 21)
#define LCD_BACK_LIGHT_DIR IO1DIR
#define LCD_BACK_LIGHT_SET IO1SET
#define LCD_BACK_LIGHT_CLR IO1CLR
#define LCD_DATA_DIR IO0DIR
#define LCD_DATA_SET IO0SET
#define LCD_DATA_CLR IO0CLR
#define LCD_CTRL_DIR IO1DIR
#define LCD_CTRL_SET IO1SET
#define LCD_CTRL_CLR IO1CLR
#define LCDRS (1 << 24)
#define LCDRW (1 << 23)
#define LCDEN (1 << 22)
18. 18
#define LCD_D4 (1 << 10)
#define LCD_D5 (1 << 11)
#define LCD_D6 (1 << 12)
#define LCD_D7 (1 << 13)
#define LCD_DATA_MASK (LCD_D4 | LCD_D5 | LCD_D6 | LCD_D7)
#define LCD_BUSY_FLAG LCD_D7
#define LCD_CONTROL_MASK 0x01C00000
/**
**************************************************************************
****1111
Function Name : delay()
Description :This function suspends the tasks for specified ticks.
Input : ticks:no of ticks in multiple of 1 usec
task: task to be suspended
Output : void
Note :
*******************************************************************************
*/
void delay(int count)
{
int j=0,i=0;
for(j=0;j<count;j++)
{
/* At 60Mhz, the below loop introduces
delay of 10 us */
for(i=0;i<35;i++);
}
}
/**
*********************************************************************************
***********
Function Name : wait_lcd()
Description :
Input :
31. 31
EXPERIMENT NO: 07
ANALOG TO DIGITAL CONVERSION
AIM: To write the program for analog to digital conversion and and display the digital value on
LCD.
APPARATUS: SOFTWARE REQUIREMENTS: Keil u IDE, Flash Magiic
HARDWARE REQUIREMENTS: LPC2148 development board, PC
PROGRAM:
Main.c file
#include <stdio.h>
#include <LPC214x.H> /* LPC214x definitions */
#include "lcd.h"
#include "adc.h"
/**
**************************************************************************
****1111
Function Name : wait()
Description :This function suspends the tasks for specified ticks.
Input : ticks:no of ticks in multiple of 1 usec
task: task to be suspended
Output : void
Note :
*******************************************************************************
*/
void wait(int count)
{
int j=0,i=0;
for(j=0;j<count;j++)
{
/* At 60Mhz, the below loop introduces
delay of 10 us */
for(i=0;i<35;i++);
}
}
/**
36. 36
Description : Initialises the ADC0
Input : None
Output : None
Note :
*******************************************************************************
*/
void init_adc0(void)
{
PINSEL1 = (PINSEL1 & ~(3 << 28)) | (1 << 28);
}
/**
*******************************************************************************
Function Name :init_adc1()
Description : Initialises the ADC1
Input : None
Output : None
Note :
*******************************************************************************
*/
void init_adc1(void)
{
}
/**
*******************************************************************************
Function Name : adc_read()
Description :
Input : adc number,channel
Output : 10 bit AD value
Note :
*******************************************************************************
*/
37. 37
unsigned short adc_read(unsigned char adc_num, unsigned char ch)
{
unsigned int i=0;
switch(adc_num)
{
case ADC0:
AD0CR = 0x00200D00 | (1<<ch); // select channel
AD0CR |= 0x01000000; // Start A/D Conversion
do
{
i = AD0GDR; // Read A/D Data Register
} while ((i & 0x80000000) == 0); // Wait for end of A/D Conversion
break;
case ADC1:
AD1CR = 0x00200D00 | (1<<ch); // select channel
AD1CR |= 0x01000000; // Start A/D Conversion
do
{
i = AD1GDR; // Read A/D Data Register
} while ((i & 0x80000000) == 0); // Wait for end of A/D Conversion
break;
}
return (i >> 6) & 0x03FF; // bit 6:15 is 10 bit AD value
}
Result:
38. 38
EXPERIMENT NO: 08
SERIAL COMMUNICATION
AIM: To write the program to perform serial communication using LPC2148 microcontroller.
APPARATUS: SOFTWARE REQUIREMENTS: Keil u IDE, Flash Magiic
HARDWARE REQUIREMENTS: LPC2148 development board, PC
PROGRAM:
#include <stdio.h> /* prototype declarations for I/O functions */
#include <LPC214x.H> /* LPC21xx definitions */
#include "Serial.h"
#define UART0_TEXT "nr Testing UART0 NGX's BlueBoard nr BlueBoard Revision : 1 nr
Firmware Version: 1 nr For more information on BlueBoard visit www.ngxtechnologies.com"
#define UART1_TEXT "nr Testing UART1 NGX's BlueBoard nr BlueBoard Revision : 1 nr
Firmware Version: 1 nr For more information on BlueBoard visit www.ngxtechnologies.com"
/**
**************************************************************************
****1111
Function Name : delay()
Description :This function suspends the tasks for specified ticks.
Input : ticks:no of ticks in multiple of 1 usec
task: task to be suspended
Output : void
Note :
*******************************************************************************
*/
void delay(int count)
{
int j=0,i=0;
for(j=0;j<count;j++)
{
/* At 60Mhz, the below loop introduces
delay of 10 us */
for(i=0;i<35;i++);
}
}
39. 39
/****************/
/* main program */
/****************/
int main (void) { /* execution starts here */
uart0_init(); // Initialize UART0
while (1) { /* An embedded program does not stop */
//uart0_getkey();
uart0_puts (UART0_TEXT); // Transffer data to PC through Serial
delay(100000);
}
}
Serial.c file
#include <LPC21xx.H> /* LPC21xx definitions */
#include "Serial.h"
#define CR 0x0D
/* implementation of putchar (also used by printf function to output data) */
int sendchar (int ch) { /* Write character to Serial Port */
if (ch == 'n') {
while (!(U1LSR & 0x20));
U1THR = CR; /* output CR */
}
while (!(U1LSR & 0x20));
return (U1THR = ch);
}
int uart0_getkey (void) { /* Read character from Serial Port */
while (!(U0LSR & 0x01));
return (U0RBR);
}
int uart1_getkey (void) { /* Read character from Serial Port */
while (!(U1LSR & 0x01));
40. 40
return (U1RBR);
}
void uart1_init()
{
/* initialize the serial interface */
PINSEL0 = 0x00050000; /* Enable RxD1 and TxD1 */
U1LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
U1DLL = 97; /* 9600 Baud Rate @ 15MHz VPB Clock */
U1LCR = 0x03; /* DLAB = 0 */
}
//------------------------------------------------------------------------------------------------//
//---------------------------- Function for send character 1 time via UART1-----------------------//
//------------------------------------------------------------------------------------------------//
void uart1_putc(char c)
{
while(!(U1LSR & 0x20)); // Wait until UART1 ready to send character
U1THR = c; // Send character
}
//------------------------------------------------------------------------------------------------//
//---------------------------- Function for send string via UART1---------------------------------//
//------------------------------------------------------------------------------------------------//
void uart1_puts(char *p)
{
while(*p) // Point to character
{
uart1_putc(*p++); // Send character then point to next character
}
}
//------------------------------------------------------------------------------------------------//
//---------------------------- Function for Initial UART0 ----------------------------------------//
//------------------------------------------------------------------------------------------------//
void uart0_init()
{
/* initialize the serial interface */
PINSEL0 = 0x00000005; /* Enable RxD0 and TxD0 */
U0LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
U0DLL = 97; /* 9600 Baud Rate @ 15MHz VPB Clock */
U0LCR = 0x03; /* DLAB = 0 */
}
//------------------------------------------------------------------------------------------------//
//---------------------------- Function for send character 1 time via UART0-----------------------//
//------------------------------------------------------------------------------------------------//
void uart0_putc(char c)
{
while(!(U0LSR & 0x20)); // Wait until UART0 ready to send character
U0THR = c; // Send character
41. 41
}
//------------------------------------------------------------------------------------------------//
//---------------------------- Function for send string via UART1---------------------------------//
//------------------------------------------------------------------------------------------------//
void uart0_puts(char *p)
{
while(*p) // Point to character
{
uart0_putc(*p++); // Send character then point to next character
}
}
Serial.h file
int uart0_getkey(void);
int uart1_getkey(void);
void uart1_init (void);
void uart0_init (void);
void uart1_putc (char);
void uart0_putc (char);
void uart1_puts(char *);
void uart0_puts(char *);
Result: