0% found this document useful (0 votes)
33 views12 pages

Embedded Assignment

This document contains an assignment submitted by Hammad Akbar to Raheel Bhutta. It includes 4 questions as part of Assignment #01-02 dealing with embedded systems. The questions involve getting data from ports and sending to other ports, toggling bits on ports, using timers to generate delays and squares waves, and displaying counter values on ports. It also includes a second assignment with 4 additional questions using timers to generate delays and square waves of different periods.

Uploaded by

Zaf Feer
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
Download as doc, pdf, or txt
0% found this document useful (0 votes)
33 views12 pages

Embedded Assignment

This document contains an assignment submitted by Hammad Akbar to Raheel Bhutta. It includes 4 questions as part of Assignment #01-02 dealing with embedded systems. The questions involve getting data from ports and sending to other ports, toggling bits on ports, using timers to generate delays and squares waves, and displaying counter values on ports. It also includes a second assignment with 4 additional questions using timers to generate delays and square waves of different periods.

Uploaded by

Zaf Feer
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1/ 12

ASSIGNMENT # 01-02

Submitted to: Raheel Bhutta


Submitted by: Hammad Akbar
Roll No: E08-141 (A)

Date: 24th Oct, 2010


Embedded Systems

ASSIGNMENT: 01

Q1: Get 8-bit data from PORTC and send it to


PORTB & PORTD?
#include<p18f4520.h>
#pragma config WDT=OFF
#pragma config OSC=HS
#pragma config LVP=OFF
#pragma config BOREN=OFF
void delay();
void main(void)
{
TRISC=1;
TRISB=0;
TRISD=0;
PORTB=PORTC;
PORTD=PORTC;
}
Q2: Toggle all bits of PORTB & PORTC?
#include<p18f4520.h>
#pragma config WDT=OFF
#pragma config OSC=HS

#pragma config LVP=OFF


#pragma config BOREN=OFF
void delay();
void main(void)
{
TRISB=0;
TRISC=0;
while(1)
{
PORTB=0X55;
PORTC=0XAA;
delay();
PORTB=~PORTB;
PORTC=~PORTC;
}
}
delay();
{
T0CON=0X08;
TMROH=0X85;
TMROL=0XEE;

T0CONbits.TMRON=1;
while(INTCONbits.TMR0IF==0);
T0CONbits.TMRON=0;
INTCONbits.TMRIF=0;
}

Q3:

#include<p18f4520.h>
#pragma config WDT=OFF
#pragma config OSC=HS
#pragma config LVP=OFF
#pragma config BOREN=OFF
#define TWO PORTBbits.RB2
#define FIVE PORTBbits.RB5
void delay();
void main(void)
{
TRISBbits.TRISRB2=1;

TRISBbits.TRISRB5=1;
while(1)
{
mybit=0X55;
mybit2=0XAA;
delay();
TWO=~TWO;
FIVE=~FIVE;
}
}
delay()
{
T0CON=0X08;
TMROH=0X8C;
TMROL=0XEE;
T0CONbits.TMRON=1;
while(INTCONbits.TMR0IF==0);
T0CONbits.TMRON=0;
INTCONbits.TMRIF=0;
}

Q4: Get status of RC3 and put on R4

#include<p18f4520.h>
#pragma config WDT=OFF
#pragma config OSC=HS
#pragma config LVP=OFF
#pragma config BOREN=OFF
#define two PORTCbits.RC3
#define five PORTCbits.RC4
void delay();
void main(void)
{
TRISCbits.TRISRC3=1;
TRISCbits.TRISRC4=0;
while(1)
{
Two=five;

ASSIGNMENT # 2
Q1: Generate square with time period of 2.5
seconds?

#include<p18f4520.h>
#pragma config WDT=OFF
#pragma config OSC=HS
#pragma config LVP=OFF
#pragma config BOREN=OFF
void delay();
void main(void)
{
TRISA=0;
PORTA=1;
while(1)
{
delay();
PORTA=~PORTA;
}
}

delay();
{
T0CON=0X06;
TMROH=0XA0;
TMROL=0XA1;
T0CONbits.TMRON=1;
while(INTCONbits.TMR0IF==0);
T0CONbits.TMRON=0;
INTCONbits.TMRIF=0;

Q2: Generate delay of 5ms,,with highest pre


scale using TIMER3 ?
#include<p18f4520.h>
#pragma config WDT=OFF
#pragma config OSC=HS
#pragma config LVP=OFF
#pragma config BOREN=OFF
void delay();
void main(void)
{
delay();

}
delay();
{
T3CON=0X30;
TMR3H=0Xf6;
TMR3L=0X3C;
T3CONbits.TMRON=1;
while(PIR2bits.TMR0IF==0);
T3CONbits.TMRON=0;
PIR2bits.TMRIF=0;
}

Q3: PROGRAM TIMER1 to be an event counter,


use 16 bit mode and display binary count on
PORTB & PORTC ?
#include<p18f4520.h>
#pragma config WDT=OFF
#pragma config OSC=HS

#pragma config LVP=OFF


#pragma config BOREN=OFF
void delay();
void main(void)
{
TRISB=0;
TRISC=0;
PORTB=0;
PORTC=0;
T1CON=0X00;
TMR1H=0X27;
TMR1L=0X10;
T1CONbits.TMRON=1;
PORTB=TMR1L;
PORTC=TMR1H;
while(PIR1bits.TMR0IF==0);
T1CONbits.TMRON=0;
PIR1bits.TMRIF=0;
}

Q4: Generate square with Time delay of 30 m


seconds ?
#include<p18f4520.h>
#pragma config WDT=OFF
#pragma config OSC=HS
#pragma config LVP=OFF
#pragma config BOREN=OFF
#define mybit PORTBbits.RB7
void delay();
void main(void)
{
TRISBbits.TRISRB7=1;
mybit=1;
while(1)
{
delay();
mybit=~mybit;
}
}

delay();
{
T0CON=0X01;
TMROH=0X7C;
TMROL=0X2A;
T0CONbits.TMRON=1;
while(INTCONbits.TMR0IF==0);
T0CONbits.TMRON=0;
INTCONbits.TMRIF=0;
}

You might also like