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

Adc Week 10 Code

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Adc Week 10 Code

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

E:\esdlab\week 10\adcweek10.

c
1 #include <reg51.h>
2
3 #define input P2 // Input port to read the values of ADC
4 #define output P0 // Output port, connected to LEDs
5
6 sbit wr = P1^1; // Write pin. It is used to start the conversion
7 sbit rd = P1^0; // Read pin. It is used to extract the data from internal register to the output
pins of ADC
8 sbit intr = P1^2; // Interrupt pin. This is used to indicate the end of conversion. It goes low
when conversion is complete
9
10 void delay(unsigned int msec); // The delay function provides delay in msec
11 void adc(); // Function to read the values from ADC and display on the LEDs
12
13 void main() {
14 input = 0xff; // Declare port 2 as input port
15 while (1) {
16 adc();
17 }
18 }
19
20 void delay(unsigned int msec) {
21 unsigned int i, j;
22 for (i = 0; i < msec; i++) {
23 for (j = 0; j < 1275; j++);
24 }
25 }
26
27 void adc() {
28 rd = 1;
29 wr = 0;
30 delay(1);
31 wr = 1;
32 while (intr == 1);
33 rd = 0;
34 output = input;
35 delay(1);
36 intr = 1;
37 }
38

Page 1

You might also like