0% found this document useful (0 votes)
42 views10 pages

Eee 306 Lab 1

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)
42 views10 pages

Eee 306 Lab 1

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/ 10

EAST WEST UNIVERSITY

Department of Electrical & Electronic Engineering


EEE306: Fundamentals of Embedded Systems
Semester: Spring 2024
Section: 1
Experiment No. 1
Introduction to Microcontroller based circuit programming
and simulation
Submitted by,
Name: MD Ahsanul Habib
ID: 2021-3-80-013

Submitted to,
Course instructor: Dr. Muhammed Mazharul Islam
Assistant Professor, EEE

Date of submission: 21/02/24


Objective:
The goal of this lab is to learn to program and simulate microcontroller-based
circuits for specific tasks.
Principle:
Microcontrollers are electronic circuits that can be programmed to perform a
wide variety of tasks. There are many families of microcontroller units (i.e.,
MCUs) available in the market, and the two most popular among these are AVR
and PIC (Programmable Interface Controllers). Both the MCU families are
manufactured by Microchip Technology Inc. The following figure shows the
input/ output pins of the IC.

In this experiment, you will learn how to program and simulate the PIC16F690
MCU for simple tasks. This is an 8-bit microcontroller. We are going to see the
use of basic input and output using push button and LED and also learn to write
codes to program the microcontroller. For the code, we are going to use
MPLAB X IDE software with XC8 compiler.
Equipment:
1. PIC16F690 Microcontroller.
2. Resistors
3. Green LEDs.
4. Push-button.
5. Ground.
6. Software: MPLAB IDE, Proteus 8.15
Circuit diagram: Task-1

Figure (01): Task-1

Flow chart: Start

While If RA0=0 yes LED blink


AND RA1=1 1sec delay

No

LED blink
off

Back to the
start

Code:
/*
* File: newmain_lab.c
* Author: Hp
*
* Created on 6 February, 2024, 11:25 PM
*/
// PIC16F690 Configuration Bit Settings

// 'C' source line config statements

// CONFIG
#pragma config FOSC = INTRCIO // Oscillator Selection bits (INTOSCIO oscillator: I/O
function on RA4/OSC2/CLKOUT pin, I/O function on RA5/OSC1/CLKIN)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled and can be
enabled by SWDTEN bit of the WDTCON register)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = OFF // MCLR Pin Function Select bit (MCLR pin function is
digital input, MCLR internally tied to VDD)
#pragma config CP = OFF // Code Protection bit (Program memory code protection is
disabled)
#pragma config CPD = OFF // Data Code Protection bit (Data memory code protection is
disabled)
#pragma config BOREN = OFF // Brown-out Reset Selection bits (BOR disabled)
#pragma config IESO = OFF // Internal External Switchover bit (Internal External
Switchover mode is disabled)
#pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enabled bit (Fail-Safe Clock
Monitor is disabled)

// #pragma config statements should precede project file includes.


// Use project enums instead of #define for ON and OFF.

#include <xc.h>
#define _XTAL_FREQ 8000000
void main(void) {
TRISA0 = 1;
TRISA1 = 1;
TRISC0= 0;
TRISC1= 0;
TRISC2= 0;
TRISC3= 0;
ANSEL = 0x00;
ANSELH = 0x00;
nRABPU = 0;
WPUA0=1;
WPUA1=1;
//MCLR = 0;
while(1)
{
if(RA0==0&&RA1==1)
{
RC0=1;
__delay_ms(1000);
RC0=0;
__delay_ms(500);
RC1=1;
__delay_ms(1000);
RC1=0;
__delay_ms(500);
RC2=1;
__delay_ms(1000);
RC2=0;
__delay_ms(500);
RC3=1;
__delay_ms(1000);
RC3=0;
__delay_ms(500);
}
else
{
RC0=0;
RC1=0;
RC2=0;
RC3=0;
}
}
return;
}

Circuit diagram:
Task-2

Figure (02): Task-2


Flow chart:

Start

While (1)

LED blink 1st


pair

LED off 1sec


delay

LED blink
2nd pair
LED

LED off
1sec delay

LED blink
3rd pair

LED off 1sec


delay

LED blink 4th


pair

LED off
1sec delay

Go to start

CODE:
/*
* File: newmain.c
* Author: Hp
*
* Created on 18 February, 2024, 8:59 PM
*/

// PIC16F690 Configuration Bit Settings

// 'C' source line config statements

// CONFIG
#pragma config FOSC = INTRCIO // Oscillator Selection bits (INTOSCIO oscillator: I/O
function on RA4/OSC2/CLKOUT pin, I/O function on RA5/OSC1/CLKIN)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled and can be
enabled by SWDTEN bit of the WDTCON register)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = OFF // MCLR Pin Function Select bit (MCLR pin function is
digital input, MCLR internally tied to VDD)
#pragma config CP = OFF // Code Protection bit (Program memory code protection is
disabled)
#pragma config CPD = OFF // Data Code Protection bit (Data memory code protection is
disabled)
#pragma config BOREN = OFF // Brown-out Reset Selection bits (BOR disabled)
#pragma config IESO = OFF // Internal External Switchover bit (Internal External
Switchover mode is disabled)
#pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enabled bit (Fail-Safe Clock
Monitor is disabled)

// #pragma config statements should precede project file includes.


// Use project enums instead of #define for ON and OFF.

#include <xc.h>
#define _XTAL_FREQ 8000000
void main(void) {
//PORTA = 0;
TRISC0 = 0;
TRISC1 = 0;
TRISC2 = 0;
TRISC3 = 0;
TRISC4 = 0;
TRISC5 = 0;
TRISC6 = 0;
TRISC7 = 0;
ANSEL = 0x00;
ANSELH = 0x00;
//WPUA0=1;
//WPUA1=1;
//WPUA2=1;
//WPUA4=1;
while(1)
{
PORTC = 0;
RC0=1;
RC1=1;
__delay_ms(500);
RC0=0;
RC1=0;
__delay_ms(500);
RC2=1;
RC3=1;
__delay_ms(500);
RC2=0;
RC3=0;
__delay_ms(500);
RC4=1;
RC5=1;
__delay_ms(500);
RC4=0;
RC5=0;
__delay_ms(500);
RC6=1;
RC7=1;
__delay_ms(500);
RC6=0;
RC7=0;
__delay_ms(500);
}
return;
}

Discussion:

In this lab experiment we learnt to program the PIC16F690 microcontroller. In


task-1 We have built a system where if a button is pressed 4 LEDs start to blink
sequentially and if another button is pressed the blinking stops. The second
button should be pressed until a complete cycle of sequential blinking is
completed. Complete a full cycle of sequential blinking and stop blinking when
the 2nd switch is pressed. In task-2 we have built a system a system where total
of 8 LEDs blink in pairs with 1 second delay. It works properly, the simulation
correctly solves the problem in the code.

You might also like