Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
14 views4 pages

Lab 1

This document outlines a practical workshop for 1st-year Electrical Engineering students on Embedded C programming for the PIC16F877 microcontroller. It includes objectives such as understanding indirect addressing, EEPROM, and Flash memory operations, along with hands-on coding exercises and simulations using mikroC and Proteus. Deliverables include written responses, modified code, simulation screenshots, and a comprehensive report detailing the workshop outcomes.

Uploaded by

Oussama Chouker
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)
14 views4 pages

Lab 1

This document outlines a practical workshop for 1st-year Electrical Engineering students on Embedded C programming for the PIC16F877 microcontroller. It includes objectives such as understanding indirect addressing, EEPROM, and Flash memory operations, along with hands-on coding exercises and simulations using mikroC and Proteus. Deliverables include written responses, modified code, simulation screenshots, and a comprehensive report detailing the workshop outcomes.

Uploaded by

Oussama Chouker
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/ 4

Practical Workshop

Embedded C
Program Electrical Engineering
Level 1st year
Supervisor : Pr. JENKAL Wissam

Lab 1: Introduction to Embedded C Programming for PIC16F877

Introduction
This lab workshop introduces programming for the PIC16F877 microcontroller using Embedded C in
mikroC. It covers memory operations using indirect addressing, EEPROM, and Flash memory read/write
operations. The workshop includes hands-on coding exercises and simulation in ISIS Proteus.

Objectives
At the end of this lab, the following concepts and skills should be acquired:

 Understanding indirect addressing using FSR and INDF.


 Implementing EEPROM read/write operations.
 Implementing Flash memory read/write operations.
 Debugging and simulating code using Proteus ISIS.

Required Software
• mikroC PRO for PIC
• Proteus ISIS for simulation

Part 1: Indirect Addressing in Memory


Compile and simulate the following code in mikroC and Proteus. Observe the changes in PORTB and
analyze how indirect addressing is used.

Code 1: Indirect Addressing


void main() {
unsigned char i;
unsigned char values[] = {10, 20, 30, 40, 50};
for (i = 0; i < 5; i++) {

Embedded C 1
FSR = &values[i];
INDF = i + 5;
}
TRISB = 0x00;
for (i = 0; i < 5; i++) {
FSR = &values[i];
PORTB = INDF;
Delay_ms(500);
}
}

Tasks
 Explain the role of FSR and INDF in the code.
 Describe how memory is modified.
 Predict the values displayed on PORTB and explain why.

Part 2: EEPROM Read/Write Operations


Modify the following code to write and read different EEPROM values. Simulate in Proteus and observe
results.

Code 2: EEPROM Read/Write


void MyEEPROM_Write(unsigned short address, unsigned short datas) {
EEADR = address;
EEDATA = datas;
EECON1.EEPGD = 0;
EECON1.WREN = 1;
INTCON.GIE = 0;
EECON2 = 0x55;
EECON2 = 0xAA;
EECON1.WR = 1;
INTCON.GIE = 1;
while (EECON1.WR);
EECON1.WREN = 0;
}

Embedded C 2
unsigned short MyEEPROM_Read(unsigned short address) {
EEADR = address;
EECON1.EEPGD = 0;
EECON1.RD = 1;
return EEDATA;
}

void main() {
TRISB = 0x00;
MyEEPROM_Write(0x10, 0x55);
Delay_ms(10);
PORTB = MyEEPROM_Read(0x10);
while (1);
}

Tasks
 Explain the role of EECON1.EEPGD.
 Justify the need for the EECON2 protection sequence.
 Modify the program to write 0xAA to EEPROM address 0x20 and verify the result.

Part 3: Flash Memory Operations


Develop a program to write and read data from Flash memory following the given flowchart. Use Proteus
to verify the results.

Flowchart for Flash Memory Write Operation


1. Set the address and data.

2. Enable Flash write mode.

3. Execute the write protection sequence.

4. Write data to Flash.

5. Wait until the write operation completes.

6. Disable Flash write mode.

Flowchart for Flash Memory Read Operation


1. Set the address to read.

Embedded C 3
2. Enable Flash read mode.

3. Read the stored data.

4. Store and display the data on PORTB and PORTD.

Tasks
 Differentiate EEPROM and Flash memory operations.
 Explain the necessity of the EECON2 protection sequence for Flash writing.
 Implement the Flash write and read operations to store 0x2A3B at address 0x1200 and display it on
PORTB and PORTD.

Simulation in Proteus
• Use a PIC16F877 microcontroller in Proteus.

• Add LEDs on PORTB and PORTD to visualize data changes.

• Observe EEPROM and Flash memory modifications.

• Use mikroC debugging tools to analyze memory values.

Deliverables
The following items should be provided upon completion of the lab:

 Written responses to all questions and tasks.


 Modified versions of the EEPROM read/write code with different addresses and values.
 Developed Flash memory read/write program based on the provided flowchart.
 Screenshots of the Proteus simulations showing memory changes and LED outputs.
 Debugging observations and explanations from mikroC.
 Prepare a comprehensive report detailing the workshop, including objectives, methodology,
implementation steps, results, and observations. Submit the final version in PDF format on the
platform: ecours-ensa.uiz.ac.ma.

Embedded C 4

You might also like