






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This is the Lab report 2 of Microprocessor and interfacing of Comsats University Islamabab.
Typology: Study Guides, Projects, Research
1 / 11
This page cannot be seen from the preview
Don't miss anything!







This lab is about what type of circuit are used to make the microcontroller. Learn to program (download code to program memory of) a microcontroller using Arduino board. To understand and use digital I/O ports of AVR microcontroller. This lab is about what type of ARDUINO we use in lab and their specification.
.INCLUDE <M328PDEF.INC> /This header file tells the assembler to include the m328Pdef.inc file which you downloaded / LDI R18, 0XFF / R18=0XFF/ OUT DDRB, R18 /* DDRB=R18/ LDI R21, 3 / R21=3 / LOOP: LDI R16, 10 / R16=10 / LDI R20, 0 / R20=0 / AGAIN: ADD R20, R21 / R20=R20+R21 / OUT PORTB, R20 / PORTB=R20 / DEC R16 / R16=R16-1 / BRNE AGAIN / It will run the Fuction again & again until the value of R16 comes to zero as we are givinga Decrement in R16 / RJMP LOOP / and when will it come to zero this Jumber function take it again to "LOOP"*/ Figure 2.3: Proteous Simulation of task 2 Task 3:
#include <avr/io.h> #define F_CPU 16000000UL #include <util/delay.h> int main() { DDRB = 0xff; DDRD = 0x00; PORTD = 0x00; while(1) { char x; x = PIND; if (x==0x00) { PORTB = 0x00; } else if (x == 0x01) { PORTB = 0x01; } else if (x == 0x02) { PORTB = 0x02; } else if (x == 0x04) { PORTB = 0x04; } else if (x == 0x08) { PORTB = 0x08; } else if (x == 0x10) { PORTB = 0x10; } else if (x == 0x20) { PORTB = 0x20; } else if (x == 0x03) { PORTB = 0x03; } else if (x == 0x05) { PORTB = 0x05; } else if (x == 0x3F) { PORTB = 0x3F; } _delay_ms(10); } }
In the reverse Code we have to turn on the Opposite leds of the Given input if the opposite port e.g., we turn the first switch ON then instead of first led all LED will turn ON. #include <avr/io.h> #define F_CPU 16000000UL #include <util/delay.h> int main() { DDRB = 0xff; DDRD = 0x00; PORTD = 0x00; while(1) { char x; x = PIND; if (x==0x00) { PORTB = 0xFF; } else if (x == 0x01) { PORTB = 0xFE; } else if (x == 0x02) { PORTB = 0xFD; } else if (x == 0x04) { PORTB = 0xFB; } else if (x == 0x08) { PORTB = 0xF7; } else if (x == 0x03) { PORTB = 0xFC; } else if (x == 0x05) { PORTB = 0xFA; } else if (x == 0x3F) { PORTB = 0x00; } _delay_ms(10); } }
Figure 2.5: Proteous Simulation of task 3(the opposite Leds is/are turning “ON” on switching on the Pin of opposite PORT)
Figure 2.6: Proteous Simulation of Post Task(the Same Led is/are turning “ON” on switching on the Pin of opposite PORT)
In this lab we learn and understand the minimal circuit required to start using a microcontroller. We got introduction about microcontroller hardware Arduino UNO. We studied about its circuit diagram and its ports, also we burnt some hex files on it to analyze them on hardware using microcontroller. We learn how to program a memory of a microcontroller using Arduino board. We also understand and use digital I/O ports of AVR microcontroller. In 1st^ task the code is simple just to make a LED to Blink. In 2nd^ in Lab task, we just coded a different thing that we use a switch to control our input and show the same form of input on output. And we also have to repeat the Code but this with inverse output. In post lab I repeated the 2nd^ task but this time by using Arduino on Proteous Simulation. Also, we learn the basic port connection this lab to the hardware on simulation like as on Arduino UNO/NANO. Simulation is very important before performing any hardware task, it gives you the idea how it will be designed. Performing on hardware will cost you very high. That’s why we used the simulation method before the implementation of our actual hardware.