0% found this document useful (0 votes)
5 views

Real time and embedded system lab exercise

The document outlines a series of lab exercises focused on real-time and embedded systems, including projects for LED blinking, motor driving, clock display, segment display, and interfacing with an LED. Each project includes steps for coding in Microc pro for PIC and schematic design in Proteus 8, detailing the necessary components and code snippets. The document serves as a practical guide for implementing these projects using specific microcontroller configurations and programming techniques.

Uploaded by

githouse36
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)
5 views

Real time and embedded system lab exercise

The document outlines a series of lab exercises focused on real-time and embedded systems, including projects for LED blinking, motor driving, clock display, segment display, and interfacing with an LED. Each project includes steps for coding in Microc pro for PIC and schematic design in Proteus 8, detailing the necessary components and code snippets. The document serves as a practical guide for implementing these projects using specific microcontroller configurations and programming techniques.

Uploaded by

githouse36
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/ 17

Prepared by Dereje Saifu

Real time and embedded system lab exercise


1. Program 1: LED light
In order to design and implement the project you should have to remember two
things:-
a. First open Microc pro for pic compiler for the code part and
b. Then open proteus 8 professional for schematic design part
Step 1
a. First open Microc pro for pic compiler

 Click on Project >> New Project

1
Prepared by Dereje Saifu

 Click on Next
 Type your project name eg. Blinking_LED_PIC, Select the Project Folder path and
select Device name P16F877A

Note:- Space is not allowed in Project Folder.

 Click NextClick Finish


 Then type the following code under code editor

//Microc pro for pic simple led blinking program


//Cs Extension Student
//Date 16/06/2015
void main()
{
TRISB.F0 = 0; //Makes RB0 Output PIN
while(1) //Infinite Loop
{
PORTB.F0 = 1; //LED ON
Delay_ms(1000); //1 Second Delay
PORTB.F0 = 0; //LED OFF
Delay_ms(1000); //1 Second Delay
}
}
 Again Save the file Blinking_LED_PIC
 Click on BuildBuild
 If the Microc pro for pic code is correct it displays Finished successfully under error,
warning and hint box

2
Prepared by Dereje Saifu

 If the Microc pro for pic code is correct, the compiler generate
Blinking_LED_PIC.hex file in the defined path
 For example the path of the above code in my project is
C:\Users\user\Documents\Real Time
Note:- Real Time is the folder created by myself for this project
Step 2
b. Then open proteus 8 professional schematic design
 Click on File
 New project wizard displayed
 Type project name e.g Blinking_LED_Pic
 Specify the path of your project e.g C:\Users\user\Documents\Real Time or
C:\Users\user\Documents or any other path

 Then click on Next>> Next>> Next>> Next>> Finish


3
Prepared by Dereje Saifu

 Draw the following schematic design


 The pick the following device
 P16F877A
 CRYSTAL
 LED-YELLOW
 RESISTOR
 02013A220JAT2A

 After finishing the schematic design


 Right-Click on the pic P16F877A, select Edit properties

4
Prepared by Dereje Saifu

 Edit component dialog box will displayed

 Click on program File select the hex file generated by Microc pro for pic compiler
 Click on Select file name folder

 Then select the Blinking_LED_PIC.hex file


 Click open
 Click ok

5
Prepared by Dereje Saifu

 Finally click on Run the simulation button or DebugRun the simulation

c. t

 Wow know successfully accomplished the project.


 To stop the simulation click on stop the simulation button

6
Prepared by Dereje Saifu

2. Program 2: Motor driving


Note:- do the same step (step1 and step 2) for the rest program 2… program n
a) Microc pro for pic code
void main()

CMCON = 0x07; // To turn off comparators

ADCON1 = 0x06; // To turn off analog to digital converters

TRISB = 0; // PORT B as output port

PORTB = 1; // Set RB0 to high

do

//To turn motor clockwise

PORTB.F0 = 1;

Delay_ms(2000); // 2 seconds delay

//To Stop motor

PORTB = 0; // or PORTB = 3 (3 = 0b00000011)

Delay_ms(2000); // 2 seconds delay

//To turn motor anticlockwise direction

PORTB.F1 = 1;

Delay_ms(2000); // 2 seconds delay

//To Stop motor

PORTB = 0; // or PORTB = 3 (3 = 0b00000011)

Delay_ms(2000); // 2 seconds delay

}while(1);

7
Prepared by Dereje Saifu

b) Proteus 8 schematic design


 The device needed for this project
 02013A220JAT2A
 BATTERY
 CRYSTAL
 L293D
 MOTOR-DC
 P16F877A

3. Program 3: Clock
a. Microc pro for pic code
// LCD module connections
sbit LCD_RS at RB2_bit;
sbit LCD_EN at RB3_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;

sbit LCD_RS_Direction at TRISB2_bit;


sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
// End LCD module connections

unsigned short read_ds1307(unsigned short address)


{
8
Prepared by Dereje Saifu

unsigned short r_data;


I2C1_Start();
I2C1_Wr(0xD0); //address 0x68 followed by direction bit (0 for write, 1 for read)
0x68 followed by 0 --> 0xD0
I2C1_Wr(address);
I2C1_Repeated_Start();
I2C1_Wr(0xD1); //0x68 followed by 1 --> 0xD1
r_data=I2C1_Rd(0);
I2C1_Stop();
return(r_data);
}

void write_ds1307(unsigned short address,unsigned short w_data)


{
I2C1_Start(); // issue I2C start signal
I2C1_Wr(0xD0); // send byte via I2C (device address + W)
I2C1_Wr(address); // send byte (address of DS1307 location)
I2C1_Wr(w_data); // send data (data to be written)
I2C1_Stop(); // issue I2C stop signal
}

unsigned char BCD2UpperCh(unsigned char bcd)


{
return ((bcd >> 4) + '0');
}

unsigned char BCD2LowerCh(unsigned char bcd)


{
return ((bcd & 0x0F) + '0');
}
int Binary2BCD(int a)
{
int t1, t2;
t1 = a%10;
t1 = t1 & 0x0F;
a = a/10;
t2 = a%10;
t2 = 0x0F & t2;
t2 = t2 << 4;
t2 = 0xF0 & t2;
t1 = t1 | t2;
return t1;
}

int BCD2Binary(int a)
{
int r,t;
9
Prepared by Dereje Saifu

t = a & 0x0F;
r = t;
a = 0xF0 & a;
t = a >> 4;
t = 0x0F & t;
r = t*10 + r;
return r;
}
int second;
int minute;
int hour;
int hr;
int day;
int dday;
int month;
int year;
int ap;

unsigned short set_count = 0;


short set;

char time[] = "00:00:00 PM";


char date[] = "00-00-00";

void main()
{
I2C1_Init(100000); //DS1307 I2C is running at 100KHz

CMCON = 0x07; // To turn off comparators


ADCON1 = 0x06; // To turn off analog to digital converters

TRISA = 0x07;
PORTA = 0x00;

Lcd_Init(); // Initialize LCD


Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_out(1,1,"Time:");
Lcd_out(2,1,"Date:");

do
{
set = 0;
if(PORTA.F0 == 0)
{
Delay_ms(100);
if(PORTA.F0 == 0)
10
Prepared by Dereje Saifu

{
set_count++;
if(set_count >= 7)
{
set_count = 0;
}
}
}
if(set_count)
{
if(PORTA.F1 == 0)
{
Delay_ms(100);
if(PORTA.F1 == 0)
set = 1;
}

if(PORTA.F2 == 0)
{
Delay_ms(100);
if(PORTA.F2 == 0)
set = -1;
}
if(set_count && set)
{
switch(set_count)
{
case 1:
hour = BCD2Binary(hour);
hour = hour + set;
hour = Binary2BCD(hour);
if((hour & 0x1F) >= 0x13)
{
hour = hour & 0b11100001;
hour = hour ^ 0x20;
}
else if((hour & 0x1F) <= 0x00)
{
hour = hour | 0b00010010;
hour = hour ^ 0x20;
}
write_ds1307(2, hour); //write hour
break;
case 2:
minute = BCD2Binary(minute);
minute = minute + set;
if(minute >= 60)
11
Prepared by Dereje Saifu

minute = 0;
if(minute < 0)
minute = 59;
minute = Binary2BCD(minute);
write_ds1307(1, minute); //write min
break;
case 3:
if(abs(set))
write_ds1307(0,0x00); //Reset second to 0 sec. and start Oscillator
break;
case 4:
day = BCD2Binary(day);
day = day + set;
day = Binary2BCD(day);
if(day >= 0x32)
day = 1;
if(day <= 0)
day = 0x31;
write_ds1307(4, day); // write date 17
break;
case 5:
month = BCD2Binary(month);
month = month + set;
month = Binary2BCD(month);
if(month > 0x12)
month = 1;
if(month <= 0)
month = 0x12;
write_ds1307(5,month); // write month 6 June
break;
case 6:
year = BCD2Binary(year);
year = year + set;
year = Binary2BCD(year);
if(year <= -1)
year = 0x99;
if(year >= 0x50)
year = 0;
write_ds1307(6, year); // write year
break;
}
}
}

second = read_ds1307(0);
minute = read_ds1307(1);
hour = read_ds1307(2);
12
Prepared by Dereje Saifu

hr = hour & 0b00011111;


ap = hour & 0b00100000;
dday = read_ds1307(3);
day = read_ds1307(4);
month = read_ds1307(5);
year = read_ds1307(6);

time[0] = BCD2UpperCh(hr);
time[1] = BCD2LowerCh(hr);
time[3] = BCD2UpperCh(minute);
time[4] = BCD2LowerCh(minute);
time[6] = BCD2UpperCh(second);
time[7] = BCD2LowerCh(second);

date[0] = BCD2UpperCh(day);
date[1] = BCD2LowerCh(day);
date[3] = BCD2UpperCh(month);
date[4] = BCD2LowerCh(month);
date[6] = BCD2UpperCh(year);
date[7] = BCD2LowerCh(year);

if(ap)
{
time[9] = 'P';
time[10] = 'M';
}
else
{
time[9] = 'A';
time[10] = 'M';
}
Lcd_out(1, 6, time);
Lcd_out(2, 6, date);
Delay_ms(100);

}while(1);
}
b. Proteus schematic design
 Devices needed
 24AA00
 02013A220JAT2A
 3005P-1-101
 BATTERY
 Button
 CRYSTAL
13
Prepared by Dereje Saifu

 DS1307
 LM016L
 MINRES47K
 P16F877A
 PULLDOWN
 PULLUP

4. Program 4: Segment
a. Microc pro for pic code
unsigned int Hex(int a)
{
switch(a)
{
case 1: return 0x06;
case 2: return 0x5B;
case 3: return 0x4F;
case 4: return 0x66;
case 5: return 0x6D;
case 6: return 0x7D;
case 7: return 0x07;
case 8: return 0x7F;
case 9: return 0x6F;

14
Prepared by Dereje Saifu

case 0: return 0x3F;


}
}
void main()
{
int s = 0;
int d = 10;
CMCON = 0x07; // To turn off comparators
ADCON1 = 0x06; // To turn off analog to digital converters
TRISB = 0x00;
TRISD = 0x00;
do
{
PORTB = Hex(s%10);
PORTD.F2 = 1;
Delay_ms(10);
PORTD.F2 = 0;
PORTB = Hex((s/10)%10);
PORTD.F1 = 1;
Delay_ms(10);
PORTD.F1 = 0;
PORTB = Hex((s/100)%10);
PORTD.F0 = 1;
Delay_ms(10);
PORTD.F0 = 0;
if(d>0)
{
d--;
if(d == 0)
{
s++;
15
Prepared by Dereje Saifu

d = 10;
}
if(s >= 999)
s = 0;
}
while(1);
}
b. Proteus schematic design
 Devices needed
 7SEG-COM-CATHODE
 9C08052A1002FKHFT
 02013A220JAT2A
 BATTERY
 BC548
 CRYSTAL
 P16F877A

5. Program 5: Interfacing LED


a. Microc pro for pic code
// LCD module connections
sbit LCD_RS at RC2_bit;
sbit LCD_EN at RC3_bit;
sbit LCD_D4 at RC4_bit;
sbit LCD_D5 at RC5_bit;
sbit LCD_D6 at RC6_bit;
sbit LCD_D7 at RC7_bit;
16
Prepared by Dereje Saifu

sbit LCD_RS_Direction at TRISC2_bit;


sbit LCD_EN_Direction at TRISC3_bit;
sbit LCD_D4_Direction at TRISC4_bit;
sbit LCD_D5_Direction at TRISC5_bit;
sbit LCD_D6_Direction at TRISC6_bit;
sbit LCD_D7_Direction at TRISC7_bit;
// End LCD module connections
void main()
{
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,1,"Welcome to Dello"); // Write text' Welcome to Dello ' in first
row
}
b. Proteus schematic design
 Devices needed
 02013A220JAT2A
 3005P-1-101
 BATTERY
 CRYSTAL
 LM016L
 P16F877A

//The End//
Thank you

17

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy