0% found this document useful (0 votes)
89 views47 pages

Final - Sem-VII-ESD - Instructor Lab Manual

This program uses a DS18B20 temperature sensor and graphic LCD to display real-time temperature readings. It initializes the DS18B20 and graphic LCD, takes temperature measurements periodically, calculates the CRC to check for errors, and displays the temperature on the LCD along with a graphical indicator of the reading.

Uploaded by

Ketan Salvi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
89 views47 pages

Final - Sem-VII-ESD - Instructor Lab Manual

This program uses a DS18B20 temperature sensor and graphic LCD to display real-time temperature readings. It initializes the DS18B20 and graphic LCD, takes temperature measurements periodically, calculates the CRC to check for errors, and displays the temperature on the LCD along with a graphical indicator of the reading.

Uploaded by

Ketan Salvi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 47

Simulation Result:

Program:

This program multiplexes the number 1234


; on the four 7-segment displays.

; Note: a logic 0 lights a display segment.

start:
SETB P3.3 ;|
SETB P3.4 ; | enable display 3
MOV P1, #11111001B ; put pattern for 1 on display
CALL delay
CLR P3.3 ; enable display 2
MOV P1, #10100100B ; put pattern for 2 on display
CALL delay
CLR P3.4 ;|
SETB P3.3 ; | enable display 1
MOV P1, #10110000B ; put pattern for 3 on display
CALL delay
CLR P3.3 ; enable display 0
MOV P1, #10011001B ; put pattern for 4 on display
CALL delay
JMP start ;
MOV R0, #200
DJNZ R0, $
RET
Program :
Transmitting data on 8051 serial port

CLR SM0 ;
SETB SM1 ;

MOV A, PCON ;
SETB ACC.7 ;
MOV PCON, A ;

MOV TMOD, #20H ;


MOV TH1, #243 ;
MOV TL1, #243 ;
SETB TR1 ;

MOV 30H, #'a' ;


MOV 31H, #'b' ;
MOV 32H, #'c' ;

MOV 33H, #0 ;
MOV R0, #30H ;
MOV A, @R0 ;
JZ finish ;
MOV C, P ;
MOV ACC.7, C ;
MOV SBUF, A ;
INC R0 ;
JNB TI, $ ;
CLR TI ;
JMP again ;
JMP $ ;
Receiver data on 8051 serial port

CLR SM0 ;
SETB SM1 ;

SETB REN ;
MOV A, PCON ;
SETB ACC.7 ;
MOV PCON, A ;
MOV TMOD, #20H ;
MOV TH1, #0FDH ;
MOV TL1, #0FDH ;
SETB TR1 ;
MOV R1, #30H ;
JNB RI, $ ;
CLR RI ;
MOV A, SBUF ;
CJNE A, #0DH, skip ;
JMP finish ;
MOV @R1, A ;
INC R1 ;
JMP again ;
JMP $ ;

Simulation Results:
Simulation Result
:
1. Result:
Fig.1: Embedded system in a car
Program:

* Connect the FRC connector cable from CN13 on the training Kit module to the Graphic LCD
Module

* Ensure there is a pull up voltage for DS18B20'DQ pin

#include "LPC21xx.h" /* LPC21xx definitions */

#include "types.h"

#include <string.h>

#include <stdio.h>

#include "glcd.h"

#include "fonts.h"

#include "DS18b20.H"

extern const uint8_t demo_pic[];

void Delay_milliSecond(unsigned short interval);

int main(void)

char str[256];

unsigned int fI,chI,wd,ht,x,y;

unsigned char result,calcCRC,rePrint;

unsigned short temp;

float temperature;

unsigned char rBuff[9];

PINSEL2 = 0x00000000;// Selected for GPIO //Prevent ETM to get Active

PINSEL1 = 0;

PINSEL0 = 0;

glcd_Init();

strcpy(str,(const char*)"128 X 64 Pixel");


glcd_Text(0,0,FONT_NINE_DOT,str); strcpy(str,(const
char*)"Graphic LCD");

glcd_Text(0,fonts[FONT_NINE_DOT-1].glyph_height+2,FONT_NINE_DOT,str);

glcd_UpdateAll();

Delay_US(1000 * 5000);

glcd_ClrScr(GLCD_CLEAR_ALL);

glcd_demopic();

Delay_US(1000 * 5000)
glcd_SetInvert(GLCD_MODE_INVERTED);

glcd_UpdateAll();

Delay_US(1000 * 5000);

glcd_ClrScr(GLCD_CLEAR_ALL);

//glcd_Box(uint8_t x, uint8_t y, uint8_t width, uint8_t height,uint8_t mode);

glcd_Box(GLCD_RIGHT/4,GLCD_BOTTOM/4,GLCD_RIGHT/2,GLCD_BOTTOM/2,GLCD_

MODE_SET);

glcd_UpdateAll();

Delay_US(1000 * 5000);

glcd_Box(GLCD_RIGHT/4+1,GLCD_BOTTOM/4+1,GLCD_RIGHT/2-2,GLCD_BOTTOM/2
- 2,GLCD_MODE_CLEAR);

glcd_UpdateAll();

Delay_US(1000 * 5000);

glcd_ClrScr(GLCD_CLEAR_ALL);

//glcd_Circle(uint8_t xCenter, uint8_t yCenter,uint8_t radius, uint8_t mode);

glcd_Circle(GLCD_RIGHT/4,GLCD_BOTTOM/2,GLCD_BOTTOM/2,GLCD_MODE_SET);

glcd_UpdateAll();

Delay_US(1000 * 10000);

glcd_ClrScr(GLCD_CLEAR_ALL);

glcd_SetInvert(GLCD_MODE_NORMAL);

glcd_UpdateAll();

Delay_US(1000 * 5000);

glcd_ClrScr(GLCD_CLEAR_ALL);

fI = 0;

chI = 0;

for(fI = 0; fI < FONT_COUNT; ++fI)

glcd_ClrScr(GLCD_CLEAR_ALL);

wd = 0;

ht = fonts[fI].glyph_height;

for(chI = '0'; chI <= fonts[fI].glyph_end; ++chI)

{
wd += (fonts[fI].store_width * 8);

if(wd > GLCD_RIGHT)

wd = (fonts[fI].store_width * 8);

ht += (fonts[fI].glyph_height) + 1;

if( ht > GLCD_BOTTOM ) break;

str[0] = chI;

str[1] = '\0';

//void glcd_Text(uint8_t left, uint8_t top, uint8_t font, const char *str);

glcd_Text(wd-fonts[fI].store_width * 8,ht-
fonts[fI].glyph_height,fI,str);

glcd_UpdateAll();

Delay_US(1000 * 10000);

glcd_SetInvert(GLCD_MODE_NORMAL);

result = Init_DS18B20();

if(result)

glcd_ClrScr(GLCD_CLEAR_ALL);

strcpy(str,(const char*)"Init_DS18B20() Error");

glcd_Text(0,GLCD_BOTTOM-fonts[FONT_NINE_DOT-1].glyph_height
- 2,FONT_NINE_DOT,str);

glcd_UpdateAll();

while(1);

WriteCommand(SKIP_ROM);
WriteCommand(WRITE_SCRATCHPAD);

WriteCommand(0);

WriteCommand(0);

WriteCommand(RESOLUTION_12);

WriteCommand(SKIP_ROM);

WriteCommand(WRITE_SCRATCHPAD);

WriteCommand(0);

WriteCommand(0);

WriteCommand(RESOLUTION_12);
result = Init_DS18B20();

if(result)

glcd_ClrScr(GLCD_CLEAR_ALL);

strcpy(str,(const char*)"Init_DS18B20() Error");

glcd_Text(0,GLCD_BOTTOM-fonts[FONT_NINE_DOT-1].glyph_height
-2,FONT_NINE_DOT,str);

glcd_UpdateAll();

while(1);

WriteCommand(SKIP_ROM);

WriteCommand(COPY_SCRATCHPAD);

//Save Configuration into EEPROM

Delay_milliSecond(10 * 2);

//Flash Writing Time Interval

rePrint = 1;

while(1)

// Temerature Scanning Mode

result = Init_DS18B20();

if(result)

glcd_ClrScr(GLCD_CLEAR_ALL);

strcpy(str,(const char*)"Init_DS18B20() Error");


glcd_Text(0,GLCD_BOTTOM-fonts[FONT_NINE_DOT1].

glyph_height-2,FONT_NINE_DOT,str);

glcd_UpdateAll();

while(1);

}
WriteCommand(SKIP_ROM);

/* Function : Issue Convert Temperature command and wait for its completion */

//ConvertTemperature();

WriteCommand(CONVERT_T);

Delay_milliSecond(1000);

result = Init_DS18B20();

if(result)

glcd_ClrScr(GLCD_CLEAR_ALL);

strcpy(str,(const char*)"Init_DS18B20() Error");


glcd_Text(0,GLCD_BOTTOM-fonts[FONT_NINE_DOT1].
glyph_height-2,FONT_NINE_DOT,str);

glcd_UpdateAll();

while(1);

WriteCommand(SKIP_ROM);

WriteCommand(READ_SCRATCHPAD);

ReadByte(rBuf
alcCRC = CalculateCRC(rBuff,8);
if(calcCRC != rBuff[8])

rePrint = 1;

glcd_ClrScr(GLCD_CLEAR_ALL);

sprintf(str,(const char*)"CRC Read: %#X",rBuff[8]);


glcd_Text(0,1,FONT_NINE_DOT,str);

sprintf(str,(const char*)"CRC Calc: %#X",calcCRC);

glcd_Text(0,fonts[FONT_NINE_DOT-1].

glyph_height+1,FONT_NINE_DOT,str);

else

temp = rBuff[0];

temp |= rBuff[1] << 8;

temperature = (float)temp / 16.0;

if(rePrint)

rePrint = 0;

glcd_ClrScr(GLCD_CLEAR_ALL); sprintf(str,(const
char*)"Room Temperature"); glcd_Text(0,0

*(fonts[FONT_NINE_DOT].glyph_height+3),FONT_NINE_DOT,str);

sprintf(str,(const char*)"Celcius:%2.3f

",temperature);

glcd_Text(0,2

*(fonts[FONT_SEVEN_DOT].glyph_height+3),FONT_SEVEN_DOT,str);

x = 15 * 7 + 5;

y = 2 *(fonts[FONT_SEVEN_DOT].glyph_height+3);

glcd_Sphere(x,y-1,3,GLCD_MODE_SET);

37
glcd_Sphere(x,y,3,GLCD_MODE_SET);

//void glcd_Box(uint8_t x, uint8_t y, uint8_t width,


uint8_theight,uint8_t mode);

x = 15 * 7 + 5 - 2 -1;

y = 2 *(fonts[FONT_SEVEN_DOT].glyph_height+3);
glcd_Box(x,y,7,(42)*(fonts[FONT_SEVEN_DOT].glyp
h_height+3),GLCD_MODE_SET);

x = 15 * 7 + 5;

y = 4 *(fonts[FONT_SEVEN_DOT].glyph_height+3);
glcd_Sphere(x,y,5,GLCD_MODE_SET);

x = 15 * 7 + 5;

y = 4 *(fonts[FONT_SEVEN_DOT].glyph_height+3) + 1;
glcd_Sphere(x,y,5,GLCD_MODE_SET);

else

sprintf(str,(const char*)"Celcius: %2.3f ",temperature);

glcd_Text(0,2

*(fonts[FONT_SEVEN_DOT].glyph_height+3),FONT_SEVEN_DOT,str);

glcd_UpdateAll();

void Delay_milliSecond(unsigned short interval)

38
{

unsigned short i,j;

for(i=0; i < interval; ++i)

//Approximately 1 ms Interval

for(j = 0; j < (unsigned short)3500; ++j)

__nop();

};

39
Program:

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

* rtc.c: Realtime clock C file for Philips LPC214x Family Microprocessors

* History

* 2005.10.01 ver 1.00 Prelimnary version, first Release

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

// modified by Martin Thomas

#include "LPC214x.h" /* LPC21xx definitions */

#include "type.h"

#include "irq.h"

#include "timer.h"

#include "rtc.h"

volatile DWORD alarm_on = 0;

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

** Function name: RTCHandler

**

** Descriptions: RTC interrupt handler, it executes based on the

** the alarm setting

**

** parameters: None

** Returned value: None

**

40
*****************************************************************************/

void RTCHandler (void) __irq

ILR |= ILR_RTCCIF; /* clear interrupt flag */

IENABLE; /* handles nested interrupt */

alarm_on = 1;

IDISABLE;

VICVectAddr = 0; /* Acknowledge Interrupt */

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

** Function name: RTCInit

**

** Descriptions: Initialize RTC timer

**

** parameters: None

** Returned value: None

**

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

void RTCInit( void )

alarm_on = 0;

// mthomas: replaced for 32kHz-XTAL

#if 0

41
/*--- Initialize registers ---*/

AMR = 0;

CIIR = 0;

CCR = 0;

PREINT = PREINT_RTC;

PREFRAC = PREFRAC_RTC;

#endif

AMR = 0;

CIIR = 0;

CCR = 0;

PREINT = PREINT_RTC;

PREFRAC = PREFRAC_RTC;

CCR = CCR_CLKEN; /* disabale CTC-Reset and enable clock with CLKEN */

CCR |= CCR_CLKSRC; // LPC213x: switch to 32kHz XTAL:

// LPC213x: disconnect RTC from System-Clock (=connect to 32kHz)

PCONP &= ~(1UL<<9);

return;

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

** Function name: RTCStart

**

** Descriptions: Start RTC timer

**

** parameters: None

** Returned value: None

42
**

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

void RTCStart( void )

/*--- Start RTC counters ---*/

CCR |= CCR_CLKEN;

ILR = ILR_RTCCIF;

return;

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

** Function name: RTCStop

**

** Descriptions: Stop RTC timer

**

** parameters: None

** Returned value: None

**

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

void RTCStop( void )

/*--- Stop RTC counters ---*/

CCR &= ~CCR_CLKEN;

return;

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

** Function name: RTC_CTCReset

43
**

** Descriptions: Reset RTC clock tick counter

**

** parameters: None

** Returned value: None

**

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

void RTC_CTCReset( void )

/*--- Reset CTC ---*/

CCR |= CCR_CTCRST;

return;

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

** Function name: RTCSetTime

**

** Descriptions: Setup RTC timer value

**

** parameters: None

** Returned value: None

**

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

void RTCSetTime( RTCTime Time )

SEC = Time.RTC_Sec;

MIN = Time.RTC_Min;

HOUR = Time.RTC_Hour;

44
DOM = Time.RTC_Mday;

DOW = Time.RTC_Wday;

DOY = Time.RTC_Yday;

MONTH = Time.RTC_Mon;

YEAR = Time.RTC_Year;

return;

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

** Function name: RTCSetAlarm

**

** Descriptions: Initialize RTC timer

**

** parameters: None

** Returned value: None

**

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

void RTCSetAlarm( RTCTime Alarm )

ALSEC = Alarm.RTC_Sec;

ALMIN = Alarm.RTC_Min;

ALHOUR = Alarm.RTC_Hour;

ALDOM = Alarm.RTC_Mday;

ALDOW = Alarm.RTC_Wday;

ALDOY = Alarm.RTC_Yday;

ALMON = Alarm.RTC_Mon;

ALYEAR = Alarm.RTC_Year;

return;

45
}

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

** Function name: RTCGetTime

**

** Descriptions: Get RTC timer value

**

** parameters: None

** Returned value: The data structure of the RTC time table

**

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

RTCTime RTCGetTime( void )

RTCTime LocalTime;

LocalTime.RTC_Sec = SEC;

LocalTime.RTC_Min = MIN;

LocalTime.RTC_Hour = HOUR;

LocalTime.RTC_Mday = DOM;

LocalTime.RTC_Wday = DOW;

LocalTime.RTC_Yday = DOY;

LocalTime.RTC_Mon = MONTH;

LocalTime.RTC_Year = YEAR;

return LocalTime;

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

** Function name: RTCSetAlarmMask

46
**

** Descriptions: Set RTC timer alarm mask

**

** parameters: Alarm mask setting

** Returned value: None

**

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

void RTCSetAlarmMask( DWORD AlarmMask )

/*--- Set alarm mask ---*/

AMR = AlarmMask;

return;

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

** End Of File

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

47

You might also like