Eee 306 Lab 1
Eee 306 Lab 1
Submitted to,
Course instructor: Dr. Muhammed Mazharul Islam
Assistant Professor, EEE
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
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
// 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)
#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
Start
While (1)
LED blink
2nd pair
LED
LED off
1sec delay
LED blink
3rd pair
LED off
1sec delay
Go to start
CODE:
/*
* File: newmain.c
* Author: Hp
*
* Created on 18 February, 2024, 8:59 PM
*/
// 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)
#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: