0% found this document useful (0 votes)
19 views

Lab Report Problem

This lab report problem involves reading sensor values using an ADC and comparing the values to thresholds. It initializes ports and registers for analog to digital conversion. It takes ADC readings of two sensors, compares each value to a threshold, and performs different actions depending on whether the value is above or below the threshold, including blinking an LED a certain number of times.

Uploaded by

miro1993
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Lab Report Problem

This lab report problem involves reading sensor values using an ADC and comparing the values to thresholds. It initializes ports and registers for analog to digital conversion. It takes ADC readings of two sensors, compares each value to a threshold, and performs different actions depending on whether the value is above or below the threshold, including blinking an LED a certain number of times.

Uploaded by

miro1993
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

I.

Lab Report Problem


void main() {
unsigned int temp;
unsigned int light;
unsigned int counter;
TRISA=0XFF;
TRISC=0X00;
TRISB=0X00;
TRISD=0X00;
ADCON1=0XC3;
ADCON0=0X80;
counter=0x00;
ADC_Init();
while(1){

//compare sensor 1 with the threshold

if (temp >> 512)


{
PORTD=0x00;
temp=ADC_Read(0);

//get 10bit result of ADC

PORTC=temp;

//lower bits to C

PORTB=temp>>8;

//higher bits to B

OPTION_REG= 0X25;

//PRESCALE TIMER0 1:64

while (counter < 100)


{TMR0 = 0x2A;

//Initialize by 42

while (INTCON == 0xA4)


{INTCON = 0xA0;
TMR0 = 0x2A;
counter ++;
}
Counter = 0x00;

//Initialize by 42

PORTD=0x01; //Read Sensor2


}
else if (light << 512)
{
light=ADC_Read(0);
PORTC=light;
PORTB=light>>8;
OPTION_REG= 0X25;

//PRESCALE TIMER0 1:64

while (counter < 100)


{ TMR0 = 0x2A;

//Initialize by 42

while (INTCON == 0xA4)


{INTCON = 0xA0;
TMR0 = 0x2A;
counter ++;
}
PORTD=0x00; //Read Sensor 1
}
}
}

//Initialize by 42

You might also like