51
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 1

m.tech esd lab manual for record

Embed Size (px)

DESCRIPTION

M.tech Emb Sys Manual

Citation preview

Page 1: m.tech esd lab manual for record

INTRODUCTIONDESCRIPTION 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.

1

Page 2: m.tech esd lab manual for record

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

2

Page 3: m.tech esd lab manual for record

1.4: APPLYING POWERConnect 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-02Pin No(9 Pin Male DB)

Host ComputerPin No (9 Pin Female DB)

2 (RXD) 2 (RXD)

3 (TXD) 3 (TXD)

5 (Signal GND) 5 (Signal GND)

3

Page 4: m.tech esd lab manual for record

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 U5main(){

AUXR = 0x10; //Accesiing Full XRAMCLKL = 0;led_init(); //Clearing ALL LEDs FROM L3 TO L10DelayMs(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)

4

Page 5: m.tech esd lab manual for record

{ i = 110;

while(i>0) i--; count--; }}

// To clear All LEDsvoid 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.

5

Page 6: m.tech esd lab manual for record

EXPERIMENT NO: 02PROGRAM 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 Operationsbit 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 XRAMled_init(); //CLearing All LEDs from L3 to L10timer0_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 FlagsET0 = 1; //Enabling Timer0 InterruptTR0 = 1; //Starting Timer0

}

void timer0_isr(void) interrupt 1{

L = ~L; //Toggling LED L2

6

Page 7: m.tech esd lab manual for record

TF0 = 0; //Clearing Interrupt Flag

TL0 = 0xff;TH0 = 0x6f; //Reloading Value into registers for every overflow

}

// To clear All LEDs L3 to L10void 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.

7

Page 8: m.tech esd lab manual for record

EXPERIMENT NO: 03LCD INTERFACE

AIM: To write a program for LCD testing. .

APPARATUS: SOFTWARE: Keil u IDE, Atmel Flip HARDWARE: Embedded control evaluation board, PCPROGRAM:

#include<at89c51xd2.h>#include<intrins.h>

// LCD FUNCTION PROTOTYPEvoid 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){

8

Page 9: m.tech esd lab manual for record

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)=1wr_cn();maxdelay();

temp1 = 0x0C; // D5(P3.3)=1,D4(P3.2)=1wr_cn();maxdelay();

temp1 = 0x08; // D5(P3.3)=1wr_cn();maxdelay();

temp1 = 0x28; lcd_comm();

maxdelay();

temp1 = 0x0f; //display on,cursor on lcd_comm();

maxdelay();

temp1 = 0x06; //shift cursor right with auto incrementlcd_comm();maxdelay();

temp1 = 0x80; //clear display with cursor on first positionlcd_comm();maxdelay();

}// Function to pass commands to LCDvoid lcd_comm(void) { var = temp1; temp1 = temp1 & 0xf0;

9

Page 10: m.tech esd lab manual for record

temp1 = temp1 >> 2;wr_cn();

temp1 = var & 0x0f;temp1 = temp1 << 2;wr_cn();

mindelay();}// Function to pass data to LCDvoid 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 LCDvoid wr_cn(void){

temp1 = temp1 & 0x7f; // RS(P3^7)=0temp1 = 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=1P3 = temp2;

10

Page 11: m.tech esd lab manual for record

_nop_();_nop_();_nop_();_nop_();_nop_();temp2 = temp2 & 0xbf; // EN = 0P3 = temp2;

}

// Function to clear the LCD displayvoid 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 L10void led_init(void){

unsigned int j;CLKL = 0;LED = 1;for(j=0;j<8;j++){

CLKL = 1; _nop_();

_nop_();CLKL =0;_nop_();

}

11

Page 12: m.tech esd lab manual for record

}

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.

12

Page 13: m.tech esd lab manual for record

EXPERIMENT NO: 04KEYPAD 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 SW40x8D -> ROW2 SW9 0x1D -> ROW1 SW50x8B -> ROW2 SW10 0x1B -> ROW1 SW60x87 -> ROW2 SW11 0x17 -> ROW1 SW7

0x8E,0x8D,0x8B,0x87 -> 8(1000) is for ROW2(P2.4*)=0;ROW1(P1.7*)=10x1E,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);

13

Page 14: m.tech esd lab manual for record

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 U8sbit SEL1 = P1^5; //Data Latch 1B of the 1st decoder of U8sbit ENL = P2^5; //Data Latch 2B of the 2nd decoder of U8sbit ROW2 = P2^4; //Second row of thw 2X4 keypadsbit ROW1 = P1^7; //First row of thw 2X4 keypadsbit CS = P1^4; //Chip select line for SPI device U3sbit 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 U5void main(){

AUXR = 0x10;//Accessing Ful XRAMled_init(); //For Clearing All LEDs L3 to L10P2 = 0xFF; //make Port 2 high;P1 = 0xFF; //make Port 1 high;P0 = 0x00; //port for 7-seg dataEN = 1; //Disabling 2nd DecoderENL = 0; //Data Latch Enable lineCS = 1; //to disable SPIwhile(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 LinesP2.7* to P2.3* are input lines to Contrller */

14

Page 15: m.tech esd lab manual for record

void key_press(void){

temp = P2 & 0x0F; //Read the keys(Masking the Lowr Nibble)DelayMs(1); //wait for debouncetemp = P2 & 0x0F; //Again Read the keys(Masking the Lowr Nibble)DelayMs(1); //wait for debounce

if(temp == 0x0F) //If No key has been pressedkey_flag = 0x00;

else{

key_flag = 0xFF;//If Key pressedDelayMs(1); //wait for debounce

while(temp == (temp2 = P2 & 0x0F));//waiting for key liftkey_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 ROWline with the COL lines... The reult carible is being compared with the Lookup Table key_arr[] and getting the correspondingindex 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

15

Page 16: m.tech esd lab manual for record

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-segmentENL = 0;SEL1 = 1; //Select lines for segmentsSEL0 = 1; //00 for U12,01 for U13

//10 for U14,11 for U15EN = 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 LEDsvoid 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.

16

Page 17: m.tech esd lab manual for record

EXPERIMENT NO: 05KEYPAD 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)

17

Page 18: m.tech esd lab manual for record

#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 :

18

Page 19: m.tech esd lab manual for record

Output : Void Note :*********************************************************************************************/void wait_lcd( void ){ LCD_CTRL_CLR |= LCDRS; LCD_CTRL_SET |= LCDRW |LCDEN; while(IO1PIN & LCD_BUSY_FLAG); /* wait for busy flag to become low */ LCD_CTRL_CLR |= LCDEN | LCDRW; LCD_DATA_DIR |= LCD_DATA_MASK; delay(100); }/********************************************************************************************** Function Name : lcd_command_write() Description : Input : Output : Void Note :*********************************************************************************************/void lcd_command_write( unsigned char command ){ unsigned char temp=0; unsigned int temp1=0;

temp=command; temp=(temp>>4)&0x0F; temp1=(temp<<10)&LCD_DATA_MASK;

LCD_CTRL_CLR = LCDRS; LCD_CTRL_SET = LCDEN; LCD_DATA_CLR = LCD_DATA_MASK; LCD_DATA_SET = temp1; delay(10000);

19

Page 20: m.tech esd lab manual for record

LCD_CTRL_CLR = LCDEN;

temp=command; temp&=0x0F; temp1=(temp<<10)&LCD_DATA_MASK; delay(100*2);

LCD_CTRL_CLR |= LCDRS; LCD_CTRL_SET |= LCDEN; LCD_DATA_CLR = LCD_DATA_MASK; LCD_DATA_SET = temp1; delay(10000); LCD_CTRL_CLR |= LCDEN; wait_lcd();}/********************************************************************************************** Function Name : set_lcd_port_output() Description : Input : Output : Void Note :*********************************************************************************************/void set_lcd_port_output( void ){ LCD_CTRL_DIR |= ( LCDEN | LCDRS | LCDRW ); LCD_CTRL_CLR |= ( LCDEN | LCDRS | LCDRW ); LCD_DATA_DIR |= LCD_DATA_MASK;}/* ********************************************************************************************* Function Name : lcd_clear() Description : Input : Output : Void

20

Page 21: m.tech esd lab manual for record

Note :*********************************************************************************************/void lcd_clear( void){ lcd_command_write( 0x01 );}/********************************************************************************************** Function Name : lcd_gotoxy() Description : Input : Output : Void Note :*********************************************************************************************/int lcd_gotoxy( unsigned int x, unsigned int y){ int retval = 0; if( (x > 1) && (y > 15) ) { retval = -1; } else { if( x == 0 ) { lcd_command_write( 0x80 + y ); /* command - position cursor at 0x00 (0x80 + 0x00 ) */ } else if( x==1 ){ lcd_command_write( 0xC0 + y ); /* command - position cursor at 0x40 (0x80 + 0x00 ) */ } } return retval;}

/********************************************************************************************** Function Name : lcd_data_write()

21

Page 22: m.tech esd lab manual for record

Description : Input : Output : Void Note :*********************************************************************************************/void lcd_data_write( unsigned char data ){ unsigned char temp=0; unsigned int temp1=0;

temp=data; temp=(temp>>4)&0x0F; temp1=(temp<<10)&LCD_DATA_MASK;

LCD_CTRL_SET |= LCDEN|LCDRS; LCD_DATA_CLR = LCD_DATA_MASK; LCD_DATA_SET = temp1; LCD_CTRL_CLR |= LCDEN;

temp=data; temp&=0x0F; temp1=(temp<<10)&LCD_DATA_MASK;

LCD_CTRL_SET |= LCDEN|LCDRS; LCD_DATA_CLR = LCD_DATA_MASK; LCD_DATA_SET = temp1; LCD_CTRL_CLR |= LCDEN; wait_lcd();}/********************************************************************************************** Function Name : lcd_putchar() Description : Input : Output : Void Note :

22

Page 23: m.tech esd lab manual for record

*********************************************************************************************/void lcd_putchar( int c ){ lcd_data_write( c );}

/********************************************************************************************** Function Name : lcd_putstring() Description : Input : Output : Void Note :*********************************************************************************************/void lcd_putstring( unsigned char line, char *string ){ unsigned char len = MAX_CHAR_IN_ONE_LINE;

lcd_gotoxy( line, 0 ); while(*string != '\0' && len--) { lcd_putchar( *string ); string++; }}

/********************************************************************************************** Function Name : lcd_backlight_on() Description : Input : Output : Void Note :

23

Page 24: m.tech esd lab manual for record

*********************************************************************************************/void lcd_backlight_on(){ LCD_BACK_LIGHT_DIR |= LCD_BACKLIGHT; LCD_BACK_LIGHT_SET |= LCD_BACKLIGHT;}

/********************************************************************************************** Function Name : turn_off_lcd_back_light()

Description :

Input :

Output : Void

Note :*********************************************************************************************/void turn_off_lcd_back_light_cb(void){ LCD_BACK_LIGHT_DIR |= LCD_BACKLIGHT; LCD_BACK_LIGHT_CLR |= LCD_BACKLIGHT;}

/********************************************************************************************** Function Name : init_lcd() Description : Input : Output : Void Note :*********************************************************************************************/void init_lcd( void ){

24

Page 25: m.tech esd lab manual for record

set_lcd_port_output(); delay(100*100); lcd_command_write(0x28); /* 4-bit interface, two line, 5X7 dots. */ lcd_clear() ; /* LCD clear */ lcd_command_write(0x02); /* cursor home */ lcd_command_write(0x06); /* cursor move direction */ lcd_command_write(0x0C) ; /* display on */ lcd_gotoxy(0, 0); lcd_clear(); lcd_putstring(0," N G X "); lcd_putstring(1," TECHNOLOGIES ");}#ifndef _LCD_H#define _LCD_H

#define MAX_CHAR_IN_ONE_LINE 16

enum ROW_NUMBERS{ LINE1, LINE2};

void init_lcd(void);void lcd_putstring(unsigned char line, char *string);void lcd_clear(void);void lcd_backlight_on(void);int lcd_gotoxy(unsigned int x, unsigned int y);void lcd_putchar(int c);

#endif

Result:

25

Page 26: m.tech esd lab manual for record

EXPERIMENT NO: 06EXTERNAL INTERRUPT HANDLER

AIM: To write the program for external interrupt handler for ARM7(LPC2148) and turn on buzzer on interrupt.

APPARATUS: SOFTWARE REQUIREMENTS: Keil u IDE, Flash Magiic HARDWARE REQUIREMENTS: LPC2148 development board, PC

PROGRAM:

Main.c file

#include <LPC214x.H> /* LPC21xx definitions */#include "ext_int.h"

int main (void) { init_ext_interrupt(); // initialize the external interrup

while (1) { }}

Ext_int.h

#ifndef _KEYPAD_H#define _KEYPAD_H#include <LPC214x.H> /* LPC21xx definitions */

#define KEY_NOT_PRESSED 0xFF

#define KEYPAD_DATA_DIR IODIR1 #define KEYPAD_DATA IOPIN1 #define KEYPAD_COL_SET IOSET1 #define KEYPAD_ROW_SET IOSET1 #define KEYPAD_COL_CLR IOCLR1 #define KEYPAD_ROW_CLR IOCLR1

#define COL_MASK (COL0 | COL1 | COL2 | COL3)#define ROW_MASK (ROW0 | ROW1 | ROW2 | ROW3)

#define COL0 (1 << 21) #define COL1 (1 << 22)#define COL2 (1 << 23)#define COL3 (1 << 24)

26

Page 27: m.tech esd lab manual for record

#define ROW0 (1 << 17) #define ROW1 (1 << 18) #define ROW2 (1 << 19) #define ROW3 (1 << 20)

void init_ext_interrupt(void);unsigned char key_hit(unsigned char **key);void Ext_ISR(void) __irq;unsigned char read_key(void);

#endif

Ext_int.c file

#include <LPC214x.H> /* LPC21xx definitions */#include "Ext_Int.h"#include "buzzer.h"

#define EXTINT_EINT2_MASK 0x4#define EXTMODE_EXTMODE2_MASK 0x4#define EXTPOLAR_EXTPOLAR2_MASK 0x4

// Vector Control Register bit definitions#define VIC_ENABLE (1 << 5)

// Convert Channel Number to Bit Value#define VIC_BIT(chan) (1 << (chan))#define VIC_EINT2 16

/****************************************************************************

****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 :********************************************************************************/

27

Page 28: m.tech esd lab manual for record

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 : key_init() Description : Input : Output : Void Note :*********************************************************************************************/void init_ext_interrupt(){ EXTMODE = EXTMODE_EXTMODE2_MASK; EXTPOLAR &= ~EXTPOLAR_EXTPOLAR2_MASK;

PINSEL0 = (PINSEL0 & ~(3U << 30)) | (1U << 31); /* initialize the interrupt vector */ VICIntSelect &= ~ VIC_BIT(VIC_EINT2); // EINT0 selected as IRQ VICVectAddr5 = (unsigned int)Ext_ISR; // address of the ISR VICVectCntl5 = VIC_ENABLE | VIC_EINT2; VICIntEnable = VIC_BIT(VIC_EINT2); // EINT0 interrupt enabled

EXTINT &= ~EXTINT_EINT2_MASK;}

/**********************************************************************************************

28

Page 29: m.tech esd lab manual for record

Function Name : keypad_ISR() Description : Input : Output : Void Note :*********************************************************************************************/void Ext_ISR(void) __irq{

turn_on_buzzer();delay(10000);

turn_off_buzzer();

EXTINT |= EXTINT_EINT2_MASK; //clear interruptVICVectAddr = 0;

}

Buzzer.h file

#ifndef _BUZZER_H#define _BUZZER_H

void turn_on_buzzer(void);void turn_off_buzzer(void);

#endif // _BUZZER_H

Buzzer.c file

#include <LPC214x.H> /* LPC21xx definitions */

#define BUZZER (1 << 25)#define BUZZER_DIR IO1DIR#define BUZZER_SET IO1SET#define BUZZER_CLR IO1CLR

/********************************************************************************************** Function Name : turn_on_buzzer()

29

Page 30: m.tech esd lab manual for record

Description : Input : Output : Void Note :*********************************************************************************************/void turn_on_buzzer(){ BUZZER_DIR |= BUZZER; BUZZER_CLR |= BUZZER;}

/********************************************************************************************** Function Name : turn_off_lcd_back_light()

Description :

Input :

Output : Void

Note :*********************************************************************************************/void turn_off_buzzer(void){ BUZZER_DIR |= BUZZER; BUZZER_SET |= BUZZER;}

30

Page 31: m.tech esd lab manual for record

EXPERIMENT NO: 07ANALOG 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++); }}

/**

31

Page 32: m.tech esd lab manual for record

********************************************************************************************

Function Name : process_adc()

Description :

Input : Void

Output : Void

Note :***********************************************************************************************/void process_adc(void){

unsigned short adc_value = 0; unsigned char buf[16] = {0};

adc_value = adc_read(ADC0, CHANNEL_3); sprintf((char *)buf, "ADC:%d ", adc_value); lcd_putstring(LINE1, (char *)buf);

}

/**********************************************************************************************

Function Name : main()

Description :

Input : Void

Output :

Note :***********************************************************************************************/int main (void) { init_adc0(); // Initialize ADC init_lcd(); // Initialize LCD

wait(100000); lcd_clear(); // clear display

32

Page 33: m.tech esd lab manual for record

while(1) { process_adc(); // Read ADC value and display it on first line of LCD wait(30000); }}

Lcd.h file

#ifndef _LCD_H#define _LCD_H

#define MAX_CHAR_IN_ONE_LINE 16

enum ROW_NUMBERS{ LINE1, LINE2};

void init_lcd(void);void lcd_putstring(unsigned char line, char *string);void lcd_clear(void);void lcd_backlight_on(void);int lcd_gotoxy(unsigned int x, unsigned int y);void lcd_putchar(int c);

#endif

Adc.h file

#ifndef _ADC_H#define _ADC_H

#define END_0F_CONVERSION_BIT (1<<31)#define END_OF_CONVERSION(i) (i & END_0F_CONVERSION_BIT)#define ADC_VALUE_MASK 0x03FF#define ADC_CHANNEL_NUMBER_MASK 0x07

#define CHANNEL_0 0#define CHANNEL_1 1#define CHANNEL_2 2#define CHANNEL_3 3#define CHANNEL_4 4

33

Page 34: m.tech esd lab manual for record

#define CHANNEL_5 5#define CHANNEL_6 6#define CHANNEL_7 7

/* A/D Control Register */

#define AD0_0 0x00000001#define AD0_1 0x00000002#define AD0_2 0x00000004#define AD0_3 0x00000008#define AD0_4 0x00000010#define AD0_5 0x00000020#define AD0_6 0x00000040#define AD0_7 0x00000080

#define AD1_0 0x00000001#define AD1_1 0x00000002#define AD1_2 0x00000004#define AD1_3 0x00000008#define AD1_4 0x00000010#define AD1_5 0x00000020#define AD1_6 0x00000040#define AD1_7 0x00000080

#define CLKDIV_BIT0 (1<<8)#define CLKDIV_BIT1 (1<<9)#define CLKDIV_BIT2 (1<<10)#define CLKDIV_BIT3 (1<<11)#define CLKDIV_BIT4 (1<<12)#define CLKDIV_BIT5 (1<<13)#define CLKDIV_BIT6 (1<<14)#define CLKDIV_BIT7 (1<<15)#define BURST (1<<16) //to eneble burst mode#define CLKS_BIT0 (1<<17)#define CLKS_BIT1 (1<<18)#define CLKS_BIT2 (1<<19)#define PDN (1<<21)#define START_BIT0 (1<<24)#define START_BIT1 (1<<25)#define START_BIT2 (1<<26)#define EDGE (1<<27)

/* A/D Global Data Register */

#define OVERRUN (1L<<30)

34

Page 35: m.tech esd lab manual for record

#define DONE (1L<<31)

/* A/D Interrupt Enable Register */

#define ADINTEN0 (1<<0)#define ADINTEN1 (1<<1)#define ADINTEN2 (1<<2)#define ADINTEN3 (1<<3)#define ADINTEN4 (1<<4)#define ADINTEN5 (1<<5)#define ADINTEN6 (1<<6)#define ADINTEN7 (1<<7)

#define ADGINTEN (1<<8)

#define ADC0 0#define ADC1 1#define ADC0CHANNELS 8#define ADC1CHANNELS 8

#define POWER_DOWN_ADC0() AD0CR &= ~(PDN)#define POWER_UP_ADC0() AD0CR |= (PDN)

#define POWER_DOWN_ADC1() AD1CR &= ~(PDN)#define POWER_UP_ADC1() AD1CR |= (PDN)

//TN_EVENT EVT_ADC0;//TN_EVENT EVT_ADC1;

void adc0_isr(void);void adc1_isr(void);void init_adc0( void );void init_adc1( void );unsigned short adc_read(unsigned char adc_num, unsigned char ch);

#endif

Adc.c file

#include "adc.h"#include <LPC214x.H> /* LPC214x definitions */

/********************************************************************************* Function Name :init_adc0()

35

Page 36: m.tech esd lab manual for record

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 :********************************************************************************/

36

Page 37: m.tech esd lab manual for record

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:

37

Page 38: m.tech esd lab manual for record

EXPERIMENT NO: 08SERIAL 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 "\n\r Testing UART0 NGX's BlueBoard \n\r BlueBoard Revision : 1 \n\r Firmware Version: 1 \n\r For more information on BlueBoard visit www.ngxtechnologies.com"#define UART1_TEXT "\n\r Testing UART1 NGX's BlueBoard \n\r BlueBoard Revision : 1 \n\r Firmware Version: 1 \n\r 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++); }}

38

Page 39: m.tech esd lab manual for record

/****************//* 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));

39

Page 40: m.tech esd lab manual for record

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

40

Page 41: m.tech esd lab manual for record

}//------------------------------------------------------------------------------------------------////---------------------------- 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:

41