Sei sulla pagina 1di 8

Task 1:

Write a program in which LEDs start to glow from LSB port bit and MSB port bit
both. When reaching at the mid only two LEDs should glow for some time and the
process repeats. Verify your result on the trainer.
Solution:

void main() {

trisd=0x00;

portd=0;

while(1){

portd=0x81;

delay_ms(1100);

portd=0xC3;

delay_ms(1100);

portd=0xE7;

delay_ms(1100);

portd=0x18;

delay_ms(2000);

portd=0;

Example 1
void main() {

trisb=0x00;

trisd=0xFF;

while(1){

if (portd.f0==1){

portb=5;

delay_ms(500);

} else{
portb=15; }

} }

TASK 2
Place 8 switches on PORTD and show the output as if first switch is one the
output at PORTB should be 1, If second switch is on output should be 2 (In
Binary). If third switch is on then output should be 3 that is (11) in binary.

Solution:
void main() {
trisd=0xff;
trisb=0x00;
portb=0;
while(1){
if(portd.f0==1){
portb=0x01;
delay_ms(1100);
}
if(portd.f1==1){
portb=0x02;
delay_ms(1100);
}
if(portd.f2==1){
portb=0x03;
delay_ms(1100);
}
if(portd.f3==1){
portb=0x04;
delay_ms(1100);
}
if(portd.f4==1){
portb=0x05;
delay_ms(1100);
}
if(portd.f5==1){
portb=0x06;
delay_ms(1100);
}
if(portd.f6==1){
portb=0x07;
delay_ms(1100);
}
if(portd.f7==1){
portb=0x08;
delay_ms(1100);
}
}
}

Task3:
Place 8 switches on PORTD and show the output as if first switch is one then RB0
should glow, If second switch is on RB0 and RB1 should glow. If third switch is on
then three LSB pins of PORTB should glow
void main() {
trisd=0xff;
trisb=0x00;
portb=0;
while(1){
if(portd.f0==1){
portb=0x01;
delay_ms(1100);
}
if(portd.f1==1){
portb=0x03;
delay_ms(1100);
}
if(portd.f2==1){
portb=0x07;
delay_ms(1100);
}
if(portd.f3==1){
portb=0x0f;
delay_ms(1100);
}
if(portd.f4==1){
portb=0x1f;
delay_ms(1100);
}
if(portd.f5==1){
portb=0x1f;
delay_ms(1100);
}
if(portd.f6==1){
portb=0x3f;
delay_ms(1100);
}
if(portd.f7==1){
portb=0x7f;
delay_ms(1100);
}

}
}

Task 4:
When pin4 of PORTA is 1 then all LEDs of PORTB ON after small delay PORTC ON
without turn off PORTB and at the end PORTD turn on along with previous ports,
after that all leds off and then check the status of button.

int i=0;
void main() {
trisd=0xff;
trisc=0x00;
trisb=0x00;
trisa=0x00;
portc=0;
portb=0;
porta=0;
while(1){
if(portd.f3==1){
portc=0xff;
delay_ms(800);
portb=0xff;
delay_ms(800);
porta=0xff;
delay_ms(800);
portc=0;
portb=0;
porta=0;

Task5:
Display last three digits of your ID when PIN 4 of PORTA is 1.
int i=0;
void main() {
trisd=0xff;
trisc=0x00;
trisb=0x00;
trisa=0x00;
portc=0;
portb=0;
porta=0;
while(1){
if(portd.f3==1){
portc=0x7f;
delay_ms(800);
portb=0x41;
delay_ms(800);
porta=0x7f;
delay_ms(800);
portc=0;
portb=0;
porta=0;

portc=0x79;
delay_ms(800);
portb=0x49;
delay_ms(800);
porta=0x77;
delay_ms(800);
portc=0;
portb=0;
porta=0;

portc=0x00;
delay_ms(800);
portb=0x00;
delay_ms(800);
porta=0xff;
delay_ms(800);
portc=0;
portb=0;
porta=0;

Potrebbero piacerti anche