Docsity

Embedded and Real Time Systems Assignment 03, Assignments of Embedded Systems

Partial preview of the text

Download Embedded and Real Time Systems Assignment 03 and more Assignments Embedded Systems in PDF only on Docsity!

12/11/2019 E&RTS

Assignment 4

Submitted By: -

Syed Saqib Iqbal ( 16 - SE- 37 )

Submitted to: -

Mam Huma Ayub

University Of Engineering and Technology Taxila

Question 1: -

Write a C program to toggle bit 3 and bit 7 of PORTB and output of code must

be shown in proteus simulation using LEDs at pin 3 and 7 of PORTB.

Code: - #include <avr/io.h> int main(void) { /* Replace with your application code */ DDRB=0xFF; while (1) { PORTB=PORTB | 0b10001000; PORTB=PORTB & 0b01110111; } return 0; } OUTPUT: -

return 0; } OUTPUT: - Proteus Simulation: -

Question 3: -

Write a program to convert ASCII digits of โ€˜2โ€™ and โ€˜9โ€™ to packed BCD and display

them on PORTA.

Code: -

#include <avr/io.h> int main(void) { /* Replace with your application code */ unsigned char bcdbyte; unsigned char w='2'; unsigned char z='9'; DDRA=0xFF; w=w & 0x0F; w=w<<4; z=z & 0x0F; bcdbyte=w | z; PORTA=bcdbyte; return 0; } OUTPUT: -

Question 5: -

Write a C program to send your First and Last name to EEPROM.

Code: -

#include <avr/io.h> int main(void) { /* Replace with your application code */ while (EECR & (1<<EEWE)); EEDR= 'Ukasha Javed'; EECR |= (1<<EEMWE); EECR |= (1<<EEWE); return 0; }

OUTPUT: -

Question 6: -

Write a C program to take an input from PORTC bit 5 and send it PORTD bit 2.

Code: -

#include <avr/io.h> int main(void) { /* Replace with your application code */ DDRB=DDRB & 0b11011111; DDRD=DDRD | 0b00000100; while (1) { if ( PINB & 0b00100000) PORTD =PORTD | 0b00000100; else PORTD=PORTD & 0b0111111; } return 0; }

OUTPUT : -