Anda di halaman 1dari 12

EX NO 1C : ROOM TEMPERATURE IN ARM PROCESSOR Aim : To verify room temperature in ARM Processor by using open source software Embest

IDE and Flash magic in ARM Processor. Apparatus Required : ARM Processor kit Adapter USB Port THEORY : The ARM TDMI processor is a member of the ARM family of general purpose 32 bit microprocessor. The ARM family offers high Performance for low power Consumption. The ARM Architecture is based on RISC Principles. Its instruction set and related decode mechanism are much simpler than CISC design. This simplicity gives A High instruction throughput. An excellent real time interrupt response. A small & cost effective 1 1 1

Procedure : Type the program in notepad and save it in the folder along with the including files. Open the softawre Embest IDE and select the new workspace in file menu. Select add files to folder and open the program and save it. All the settings should be changed in the project dialog box. Switch on the kit and rebuild the program. Open the software Flash Magic and Browse the Program and click start. Change the Switch position and reset button. The output will be analyzed in the kit.
/***************************************************/ /* Read Room temperature from LM35 /* and display it on LCD /***************************************************/

#include "LPC214x.h"

/* LPC21xx definitions */

int ReadADC(char ChannelNumber);

int main(void) { int a; unsigned char Channel = 1, t[7]; PINSEL1 = 0x01000000; InitializeLCD(); DisplayLCD(0,"Room Temperature"); while(1) { a=ReadADC(Channel); t[0] = a/100 + '0'; a -= (a/100) * 100; t[1] = a/10 + '0'; t[2] = '.'; t[3] = a%10 + '0'; t[4] = 'C'; t[5] = 0; DisplayLCD(1,t); LCDDelay1600(); } } // Display the room temperature // Read ADC channel 1 // Select ADC to pin P0.28 // Initialize LCD // Display message

//Read ADC data from given channel number int ReadADC(char ChannelNumber) { int val,ch;

ch = 1<<ChannelNumber;

AD0CR = 0x00210400 | ch; AD0CR |= 0x01000000;

// Setup A/D: 10-bit AIN @ 3MHz // Start A/D Conversion

do { val = AD0DR1; } while ((val & 0x80000000) == 0); val = ((val >> 6) & 0x03FF); // Wait for the conversion to complete // Extract the A/D result // Read A/D Data Register

AD0CR &= ~0x01000000;

// Stop A/D Conversion

return(val); }

// Return the Data Read

/***************************************************/ /* LCD Routines for 2 line X 16 Characters Display

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

#include "LPC214x.h"

/* LPC214x definitions */

void WriteCommandLCD(unsigned char CommandByte); void WriteDataLCD(unsigned char DataByte); void LCDDelay(void); void LCDDelay1600(void); void SendByte(unsigned char Value); void InitializeLCD();

void DataAddressDirection(void); void DisplayLCD(char LineNumber,char *Message); void DisplayLCD2Digit(char LineNumber,char CharPosition,char Data);

/* Initializes LCD */ void InitializeLCD() { DataAddressDirection(); IOSET0 = 0x00580000; // Set A0, A1, A2

WriteCommandLCD(0x38); LCDDelay1600();

//Command to select 8 bit interface

WriteCommandLCD(0x38); LCDDelay();

//Command to select 8 bit interface //Small delay

WriteCommandLCD(0x38); LCDDelay();

//Command to select 8 bit interface

WriteCommandLCD(0x0c); LCDDelay();

//Command to on cursor,blink cursor

WriteCommandLCD(0x06); LCDDelay();

//Command for setting entry mode

WriteCommandLCD(0x01); LCDDelay1600(); }

//Clear LCD

/* Writes a command byte to LCD */ void WriteCommandLCD(unsigned char CommandByte) { IOCLR1 = 0x03000000; SendByte(CommandByte); LCDDelay(); } //Small delay // Clear RS and RW

/* Send a byte of data to LCD */ void SendByte(unsigned char Value) { IOPIN1 &= 0xff00ffff; IOPIN1 |= Value << 16; IOSET0 = 0x00100000; IOCLR0 = 0x00480000; LCDDelay(); IOSET0 = 0x00580000; LCDDelay(); } /* Set A0, A1 & A2 to disable LCD */ /* Write data to data bus */ /* Generate chip enable signal for LCD */

/* Writes a Data byte to LCD */ void WriteDataLCD(unsigned char DataByte) { IOCLR1 = 0x01000000; IOSET1 = 0x02000000; SendByte(DataByte); LCDDelay(); } //Small delay /* clear RW */ /* Set RS */

/* Small delay */

void LCDDelay(void) { int a;

for(a=0;a<0x1000;a++); }

/* Big delay */ void LCDDelay1600(void) { long a;

for(a=0;a<0x050000;a++); }

/* Makes cursor visible */ void CursorON(void) { WriteCommandLCD(0x0f); } //Command to switch on cursor

/* Makes cursor invisible */ void CursorOFF(void) {

WriteCommandLCD(0x0c); }

//Command to switch off cursor

void DisplayLCD2Digit(char LineNumber,char CharPosition,char Data) { unsigned char a; if(LineNumber ==0) { //First Line a = 0x80; selection } else { //Second line a = 0xc0; selection } a+=(CharPosition); WriteCommandLCD(a); digit if( (Data & 0xf0) < 0xa0) { a = ((Data & 0xf0) >> 4) + '0'; } else { //Get the ASCII character //Check for less than 0xa0 //Calculate the character position //Send command to select the given //command for second line //command for first line

a = ((Data & 0xf0) >> 4) + 'A'- 0x0a; //Get the ASCII character } WriteDataLCD(a); if( (Data & 0x0f) < 0x0a) { a = (Data & 0x0f)+'0'; } else { a = (Data & 0x0f)+'A' - 0x0a; } WriteDataLCD(a); } //Get the ASCII character //Get the ASCII character //Display the first character //Check for less tham 0x0a

/* Displays a message on LCD */ void DisplayLCD(char LineNumber,char *Message) { int a;

if(LineNumber ==0) { //First Line WriteCommandLCD(0x80); } else { //Second line //Select the first line

WriteCommandLCD(0xc0); } while(*Message) { WriteDataLCD(*Message); Message++; } }

//Select the second line

//Display a character //Increment pointer

void DataAddressDirection(void) { IODIR0 |= 0x00580000; IODIR1 |= 0x03ff0000; } // Set A0, A1, A2 output lines

void __gccmain() {

Result : Thus the room temperature has been readed verified and validated by using open source software Embest IDE and magic in ARM processor.

Anda mungkin juga menyukai