Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include // Bit-access function unsigned char SetBit(unsigned char x, unsigned char k, unsigned char b) { return (b ? x | (0x01 < < k)

#include

// Bit-access function unsigned char SetBit(unsigned char x, unsigned char k, unsigned char b) { return (b ? x | (0x01 << k) : x & ~(0x01 << k)); } unsigned char GetBit(unsigned char x, unsigned char k) { return ((x & (0x01 << k)) != 0); }

int main(void) { DDRA = 0x00; PORTA = 0xFF; // Configure port A's 8 pins as inputs DDRC = 0xFF; PORTC = 0x00; // Configure port B's 8 pins as outputs, // initialize to 0s

unsigned char button = 0x00; unsigned char fuel1 = 0x00; unsigned char fuel2 = 0x00; unsigned char fuel3 = 0x00; unsigned char fuel4 = 0x00; while(1) { fuel1 = PINA & 0x01; fuel2 = PINA & 0x02; fuel3 = PINA & 0x04; fuel4 = PINA & 0x08; button = PINA & 0x01; if (GetBit(button, 0x01)) { fuel1 = SetBit(fuel1, 0x01, 1); } else { fuel1 = SetBit(fuel1, 0x01, 0); } if (GetBit(button, 0x02)) { fuel2 = SetBit(fuel2, 0x02, 1); } else { fuel2 = SetBit(fuel2, 0x02, 0); } // ** code to be added here ** /

// port output PORTC = fuel1 << 4; PORTC = fuel2 << 3; PORTC = (fuel1 + fuel2) << 4; } }

this is for AVR studio using C programming and atmega1284

A car has a fuel-level sensor that sets PortsA3 to PortsA0 to a value between 0 (empty) and 15 (full). A series of LEDs connected to PortsC5 to PortsC0 should light to graphically indicate the fuel level. If the fuel level is 1 or 2, PortC5 lights. If the level is 3 or 4, PortC5 and Port C4 light.

I have the first 3 levels, but i don't know how to make it so that in level 4 two lights emit on port C ? please help

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Understand human resource planning in an academic setting.

Answered: 1 week ago

Question

2. What type of team would you recommend?

Answered: 1 week ago