

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Batteries
To LED
// Name: James Conrad – 10/10/ // Function: when sw1 is pressed, turn the green LEDs on // If the thermister value is above 511 light the yellow LED // If the light sensor value is above 511 light the red LED // Inputs: sw1, 2 ADC; Outputs: LEDs Setup a switch (input) Setup LEDs (output, turn off) Setup thermister and light sensor ADC (sweep) Start continually reading thermister, light sensor While (1) { If (sw1 pressed) Turn on the green LED Else turn off green LED; If (thermister>511) Turn on the yellow LED; Else turn off yellow LED; If (light sensor>511) Turn on the red LED Else turn off red LED; }
adcon0=0x18; // perform repeated A/D conversions - sweep adcon1=0x28; // sweep pins 0-3 (to get pins 0 and 1, but no more) adcon2=0x01; // sample and hold adst=1; // <- start measuring!
5 points: set up reg0 with correct values
5 points: set up reg1 with correct values 5 points: set up reg2 with correct values
5 points: start sampling (adst or adcon bit set)
No extra points for writing the entire code package. I only asked for a few lines.