Question

In: Computer Science

Q1- Write code in C language(Atmel atmega32 avr microcontroller) (a)-Switches are connected to Port C and...

Q1- Write code in C language(Atmel atmega32 avr microcontroller)
(a)-Switches are connected to Port C and Port B and LED’s with PORTD. Write a code to read input from
PortB and C and perform following.
Addition of both inputs, Subtraction, Multiplication, Division, And, Or, Nor,Xor.


(b)- A switch is connected to PD0 and LED’s to Port B and Port C. Write a code to perform following:
When switch is 0 send your roll number to Port B.
When Switch is 1, toggle PortC 20 times.

Solutions

Expert Solution

Ans:

Code(a):

#include <inttypes.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>
#include <util/delay.h>
int main()
{
DDRB = 0;       // make portB input
   DDRC = 0;       //make portC input
   DDRD = 0xff;       // make portD output
  
while (1)
{

   PORTD = PINB + PINC ;       // Addition
   _delay_ms(2000);                   // 2 second delay
   PORTD = PINB - PINC ;       //Subtraction
   _delay_ms(2000);                   // 2 second delay
   PORTD = PINB * PINC ;       //Multiplication
   _delay_ms(2000);                   // 2 second delay
   PORTD = PINB / PINC ;           //Division
   _delay_ms(2000);                   // 2 second delay
   PORTD = PINB & PINC ;       //And
   _delay_ms(2000);                   // 2 second delay
   PORTD = PINB | PINC ;           //Or
   _delay_ms(2000);                   // 2 second delay
   PORTD = ~ PORTD ;               //Nor
   _delay_ms(2000);                   // 2 second delay
   PORTD = PINB ^ PINC ;       //Xor
   _delay_ms(2000);                   // 2 second delay

}
return 0;
}

//diagram(a)

Code(b):

#include <inttypes.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>
#include <util/delay.h>
int main()
{ int i;
DDRD = 0xFE;       // make portD0 input
   DDRC = 0xFF;       //make portC input
   DDRB = 0xff;       // make portB output
   PORTC =0 ;
while (1)
{

   if(PIND & 0x01){


   for( i; i<40; i++){
           PORTB =0 ;
           PORTC =~PORTC ; //toggle PortC 20 times.
           _delay_ms(500);   //delay 0.5 second
      
           if((PIND & 0x01)==0){
           PORTB =0x55 ;         // here id number is 55 (you put your number in PORTB = 0x_ _ )
           i= 0;
           while((PIND & 0x01)==0);
           }

   }
   }

   else{
       PORTB =0x55 ;         // here id number is 55 (you put your number in PORTB = 0x_ _ )
       i= 0;
       }

   }
return 0;
}

//diagram(b)


Related Solutions

write a program for the microcontroller-msp430fr6989 using code composer studio not assembly language. write a code...
write a program for the microcontroller-msp430fr6989 using code composer studio not assembly language. write a code that transmits a single character and lights the red LED upon receiving that character. The board will "talk" to itself. The green LED should turn on whenever a message is sent and the LCD will display the message being received.
1. An LED is connected to PORTB.5 of ATmega328 microcontroller. Write a C Program that toggles...
1. An LED is connected to PORTB.5 of ATmega328 microcontroller. Write a C Program that toggles LED after 0.5 Seconds. Assume XTAL = 16MHz. To generate this delay use Timer 1 CTC (Clear Timer on Compare match) mode Programming. 2. Write a program to generate a square wave of frequency of 250 Hz with 50% duty cycle on PORTB.5. Assume XTAL = 16MHz. Use Timer 2 Normal Mode Programming. 3. Write a program using 16-bit timer to generate a square...
Write the C code required to configure pin 0 on port B to be an input...
Write the C code required to configure pin 0 on port B to be an input with the pullup resistor enabled.
Write a code fragment in C language that tests the value of an integer num1. If...
Write a code fragment in C language that tests the value of an integer num1. If the value is 10, square num1. If it is 9, read a new value into num1. If it is 2 or 3, multiply num1 by 99 and print out the result. Implement your code using SWITCH statements
Write an assembly language program for 8051 microcontroller to find the sum of the following series,...
Write an assembly language program for 8051 microcontroller to find the sum of the following series, 1, -2, +3, -4, +5, -6,..., up to 100 terms. Store lower byte in R0 and higher byte in R1.
A PIC C code for Interfacing Ultrasonic sensor using PIC C 18F8722 microcontroller  
A PIC C code for Interfacing Ultrasonic sensor using PIC C 18F8722 microcontroller  
Please write code for C language Problem: Write a couple of functions to process arrays. Note...
Please write code for C language Problem: Write a couple of functions to process arrays. Note that from the description of the function you have to identify what would be the return type and what would be part of the parameter. display(): The function takes an int array and it’s size and prints the data in the array. sumArray(): It takes an int array and size, and returns the sum of the elements of the array. findMax(): It takes an...
1. IN C LANGUAGE: Write a code that makes the MSP430 blink the red LED and...
1. IN C LANGUAGE: Write a code that makes the MSP430 blink the red LED and the green LED at the same time. The two LEDs should be on at the same time and then off at the same time
An LCD 16x2 display is used for PIC16F1619, if Port C is connected to 8 data...
An LCD 16x2 display is used for PIC16F1619, if Port C is connected to 8 data pins of the LCD. Pin4 and 5 of port A are connected to EN and RS respectively. RW is tied to the ground. Write a C code to set up 2 lines, 5x8 matrix, 8-bit mode and force the cursor to the beginning of the first line.
Write a code of digital alarm clock 8051 microcontroller using pin AT89S52
Write a code of digital alarm clock 8051 microcontroller using pin AT89S52
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT