Question

In: Computer Science

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.

Solutions

Expert Solution

 

To make port as a input with pullups enabled and read data from port 0

DDRA = 0x00;

PORTA = 0xFF;

To make port B as a tri stated input

DDRB = 0x00;

PORTB = 0x00;

To make lower nibble of port 0 as a output, higher nibble as a input with pullups enabled.

DDRA = 0x0F;

PORTA = 0xF0;

Blink LED on PB0 at a rate of 1Hz.

#include <mega16.h>
#include <delay.h>

void main()
{
    DDRB = 0xFF;         //PB as output
    PORTB= 0x00;         //keep all LEDs off

    while(1)
    {
        PORTB &= 0b11111110;       //turn LED off
        delay_ms(500);   //wait for half second
        PORTB |= 0b00000001;       //turn LED on 
        delay_ms(500);   //wait for half second
    };        
}

Blink LEDs on Port B with different patterns according to given input.

– Kit : use SW0, SW1
– No Kit : Connect a 2 micro-switches between pin PC0,PC2 and ground. So that when you press the switch pin is pulled low.

#include <mega16.h>
#include <delay.h>

//declare global arrays for two patterns
unsigned char p1[4] = { 0b10000001,
                        0b01000010,    
                        0b00100100,
                        0b00011000 };

unsigned char p2[4] = { 0b11111111,
                        0b01111110,    
                        0b00111100,
                        0b00011000 };
void main()
{
unsigned char i;                //loop counter

    DDRB = 0xFF;                //PB as output
    PORTB= 0x00;                //keep all LEDs off

    DDRC = 0x00;                //PC as input
    PORTC |= 0b00000011;        //enable pull ups for
                                //only first two pins

    while(1)
    {
        //# if SW0 is pressed show pattern 1
        if((PINC & 0b00000001)==0)                                           
        {
            for(i=0;i<3;i++)
            {
                PORTB=p1[i];    //output data
                delay_ms(300);  //wait for some time
            }
            PORTB=0;            //turn off all LEDs
        }

        //# if SW1 is pressed show pattern 2
        if((PINC & 0b00000010)==0)           
        {
            for(i=0;i<3;i++)
            {
                PORTB=p2[i];    //output data
                delay_ms(300);  //wait for some time
            }
            PORTB=0;            //turn off all LEDs
        }

    };        

Related Solutions

Port = 0x0055 A) Port &= 0xff0; B) Port |= 15;   C) Port = Port ^...
Port = 0x0055 A) Port &= 0xff0; B) Port |= 15;   C) Port = Port ^ 0x0005; D) Port = ( ( Port &~(0x000f) ) | 0x0020 );   Please explain how each logical opperator works and write out the results.
Write in C++ and insert comments. Input two values a and b 0 may be used...
Write in C++ and insert comments. Input two values a and b 0 may be used for False 1 may be used for True Write a program that will print the truth table for the logical operator and give the results for the specific input a, b. The following logical operators should be coded. ● conjunction (AND) ● disjunction (OR) ● conditional Statement (If a then b) ● exclusive OR (XOR) ● biconditional operation (p iff q) Example for conjunction...
Please write the code in c++ Write a function with one input parameter that is a...
Please write the code in c++ Write a function with one input parameter that is a vector of strings. The function should count and return the number of strings in the vector that have either an 'x' or a 'z' character in them. For example, when the function is called, if the vector argument contains the 6 string values, "enter", "exit", "zebra", "tiger", "pizza", "zootaxy" the function should return a count of 4. ("exit", "zebra", "pizza", and "zootaxy" all have...
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...
Write code in C please. #1 Write a function multiples() which will take an integer input...
Write code in C please. #1 Write a function multiples() which will take an integer input and it will print out all the multiples of this number starting from 2 but not including itself. For example, multiples(10) will print 2, 5 and multiples(100) will print 2, 4, 5, 10, 20, 25, 50 #2 Write and test a Fibonacci() function that uses a loop instead of recursion to calculate Fibonacci numbers.
in C please! Write a code that asks user for input N and calculates the sum...
in C please! Write a code that asks user for input N and calculates the sum of the first N odd integers. There should be a "pure" method that calculates the sum separately that Main method should call when printing the output.
this is a python code: QUESTION 1: Input floating point numbers for a, b, c, d...
this is a python code: QUESTION 1: Input floating point numbers for a, b, c, d and e. calculate the following and display the result.  Mathematical expression ab means a * b in programming context. QUESTION 2: You are sleep expert for a baby that is having struggle sleeping every night. You are to ask the mother of the child "How many oz of milk the child drank ?" Based on the amount of milk, you will have to determine...
in c++ QUESTION 4: Write the code to do the following: -read input from the keyboard...
in c++ QUESTION 4: Write the code to do the following: -read input from the keyboard by displaying the message on the screen to ask and read the following information: * customer ID (string) * customer name (string)                                                        * balance (float) -open output file customer .txt to write -Write to the output file customer.txt the following information:                 Customer ID – customer name – balance For example: 1561175753 - James Smith – 1255.25 -close file QUESTION 5: -create one notepad...
C++ code please: Write a program that first gets a list of integers from input. The...
C++ code please: Write a program that first gets a list of integers from input. The input begins with an integer indicating the number of integers that follow. Then, get the last value from the input, which indicates how much to multiply the array by. Finally, print out the entire array with each element multiplied by the last input. Assume that the list will always contain less than 20 integers. Ex: If the input is 4 4 8 -4 12...
Please code C# 10. Write a program that allows a user to input names and corresponding...
Please code C# 10. Write a program that allows a user to input names and corresponding heights (assumed to be in inches). The user can enter an indefinite number of names and heights. After each entry, prompt the user whether they want to continue. If the user enters true, ask for the next name and height. If the user enters false, display the name of the tallest individual and their height. Sample run: “Name?” James “Height?” 50 “Continue?” True “Name?”...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT