You are given the following schematic and timing diagram for reading and writing
ID: 2250097 • Letter: Y
Question
You are given the following schematic and timing diagram for reading and writing data to an 8-bit digital temperature sensor. Complete the function stub below, which sends an 8-bit value to the instruction register. Write your answer on the next page.
Keep it very simple, you do not need to make the code portable or make use of any user created #defines. Just write a straightforward function to accomplish the task.
Use the |=, &=, and << operators for all register configurations!
1 Read 0Write Read or Write RW Register Select RS 0=Instruction Register Execute Ta- 100 D7 D7 DS D5 D3 D2 D2 D1 D1 5V 5V VCC PA7O 07.0 ATMEGA32 peo ETemp Sensor PB1 RS GND P82Explanation / Answer
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay_basic.h>
#define SEVEN_SEGMENT_PORT PORTD
#define SEVEN_SEGMENT_DDR DDRD
unpredictable uint8_t digits[3];
void SevenSegment(uint8_t n,uint8_t dp)
{
/*
This capacity composes a digits given by n to the show
the decimal point is shown if dp=1
Note:
n must be under 9
*/
if(n<10)
{
switch (n)
{
case 0:
/.gfedcba
SEVEN_SEGMENT_PORT=0b00111111;
break;
case 1:
/.gfedcba
SEVEN_SEGMENT_PORT=0b00000110;
break;
case 2:
/.gfedcba
SEVEN_SEGMENT_PORT=0b01011011;
break;
case 3:
/.gfedcba
SEVEN_SEGMENT_PORT=0b01001111;
break;
case 4:
/.gfedcba
SEVEN_SEGMENT_PORT=0b01100110;
break;
case 5:
/.gfedcba
SEVEN_SEGMENT_PORT=0b01101101;
break;
case 6:
/.gfedcba
SEVEN_SEGMENT_PORT=0b01111101;
break;
case 7:
/.gfedcba
SEVEN_SEGMENT_PORT=0b00000111;
break;
case 8:
/.gfedcba
SEVEN_SEGMENT_PORT=0b01111111;
break;
case 9:
/.gfedcba
SEVEN_SEGMENT_PORT=0b01101111;
break;
}
if(dp)
{
/if decimal point ought to be shown
/make seventh piece high
SEVEN_SEGMENT_PORT|=0b10000000;
}
}
else
{
/This image in plain view tells that n was more prominent than 9
/so show can't deal with it
SEVEN_SEGMENT_PORT=0b11111101;
}
}
void Wait()
{
uint8_t I;
for(i=0;i<10;i++)
{
_delay_loop_2(0);
}
}
void Print(uint16_t num)
{
/*
This capacity breaks separated a given whole number into particular digits
also, thinks of them to the show cluster i.e. digits[]
*/
uint8_t i=0;
uint8_t j;
if(num>9999) return;
while(num)
{
digits[i]=num%10;
i++;
num=num/10;
}
for(j=i;j<4;j++) digits[j]=0;
}
void InitADC()
{
ADMUX=(1<<REFS0);//For Aref=AVcc;
ADCSRA=(1<<ADEN)|(7<<ADPS0);
}
uint16_t ReadADC(uint8_t ch)
{
/Select ADC Channel ch must be 0-7
ch=ch&0b00000111;
ADMUX|=ch;
/Start Single change
ADCSRA|=(1<<ADSC);
/Wait for change to finish
while(!(ADCSRA and (1<<ADIF)));
/Clear ADIF by keeping in touch with one to it
ADCSRA|=(1<<ADIF);
return(ADC);
}
void principle()
{
uint16_t adc_value;
uint8_t t;
/Prescaler = FCPU/1024
TCCR0|=(1<<CS02);
/Enable Overflow Interrupt Enable
TIMSK|=(1<<TOIE0);
/Initialize Counter
TCNT0=0;
/Port B[3,2,1,0] as out put
DDRB|=0b00001111;
PORTB=0b00000001;
/Port D
SEVEN_SEGMENT_DDR=0XFF;
/Turn off all portions
SEVEN_SEGMENT_PORT=0X00;
/Enable Global Interrupts
sei();
/Enable ADC
InitADC();
/Infinite circle
while(1)
{
/Read ADC
adc_value=ReadADC(0);
/Convert to degree Centrigrade
t=adc_value/2;
/Print to show
Print(t);
/Wait some time
Hold up();
}
}
ISR(TIMER0_OVF_vect)
{
/*
This interfere with benefit routine (ISR)
Updates the presentations
*/
static uint8_t i=0;
if(i==3)
{
/If on last show at that point come
/back to first.
i=0;
}
else
{
/Goto Next show
i++;
}
/Activate a show as indicated by I
PORTB&=(0b11110000);
PORTB|=(1<<i);
/Write the digit[i] in the ith show.
SevenSegment(digits[i],0);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.