Question: #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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!