Programming 8051 Microcontroller

Assembly Programming for ADC0804

	rd equ P1.0           ;Read signal P1.0
wr equ P1.1 ;Write signal P1.1
cs equ P1.2 ;Chip Select P1.2
intr equ P1.3 ;INTR signal P1.3

adc_port equ P2 ;ADC data pins P2
adc_val equ 30H ;ADC read value stored here

org 0H
start: ;Start of Program
acall conv ;Start ADC conversion
acall read ;Read converted value
mov P3,adc_val ;Move the value to Port 3
sjmp start ;Do it again

conv: ;Start of Conversion
clr cs ;Make CS low
clr wr ;Make WR Low
nop
setb wr ;Make WR High
setb cs ;Make CS high
wait:
jb intr,wait ;Wait for INTR signal
ret ;Conversion done

read: ;Read ADC value
clr cs ;Make CS Low
clr rd ;Make RD Low
mov a,adc_port ;Read the converted value
mov adc_val,a ;Store it in local variable
setb rd ;Make RD High
setb cs ;Make CS High
ret ;Reading done

Programming 8051 in C for ADC0804

#include <REGX51.H>     
#define adc_port P2 //ADC Port
#define rd P1_0 //Read signal P1.0
#define wr P1_1 //Write signal P1.1
#define cs P1_2 //Chip Select P1.2
#define intr P1_3 //INTR signal P1.3

void conv(); //Start of conversion function
void read(); //Read ADC function

unsigned char adc_val;

void main() {
while (1) { //Forever loop
conv(); //Start conversion
read(); //Read ADC
P3 = adc_val; //Send the read value to P3
}
}

void conv() {
cs = 0; //Make CS low
wr = 0; //Make WR low
wr = 1; //Make WR high
cs = 1; //Make CS high
while (intr); //Wait for INTR to go low
}

void read() {
cs = 0; //Make CS low
rd = 0; //Make RD low
adc_val = adc_port; //Read ADC port
rd = 1; //Make RD high
cs = 1; //Make CS high
}

This finishes our ADC tutorial along with interfacing of ADC0804. If you have any questions or doubts please post on forum.

Conversation

ajay_bhargav
Thu Jan 29 2015, 06:54 AM
@gaurav, please mail me message you're trying to post.
ExperimenterUK
Thu Jan 29 2015, 01:17 AM
bhagyesh.bhavasar/gaurav.k I can post with Firefox. Can you try other browsers ?
naqirizvi
Wed Jan 28 2015, 08:08 AM
the web theme is too much buggy and heavy , admin please change it to simple theme, so that user can browse quickly
naqirizvi
Wed Jan 28 2015, 08:07 AM
some one please share software name or ebooks related to avr
bhagyesh.bhavasar
Tue Jan 27 2015, 11:06 AM
i want to share my project but there is problem occurred during postng
bhagyesh.bhavasar
Tue Jan 27 2015, 05:58 AM
@ExperimentalUK i have used that purple button but same as previous it takes me to blank page
ExperimenterUK
Sun Jan 25 2015, 08:10 PM
This box is for chat. Post problems in a suitable forum
ExperimenterUK
Sun Jan 25 2015, 08:04 PM
@gaurav.k Use the purple "Post reply" button. Green buttons often present a fresh edit box.
ExperimenterUK
Sun Jan 25 2015, 07:33 PM
@avianash..we have no entry for avianash.. Are you sure that is your login name ?
Fri Jan 23 2015, 04:29 AM
lolokijuh
DJ Bakal tulungan mo ako s IC Tester

Downloads

Comments

sachinmm
Thu Jan 29 2015, 07:09 AM
nawfel
Sat Jan 17 2015, 07:27 AM
Rohi123
Sat Jan 10 2015, 11:00 AM
safakarici
Fri Jan 09 2015, 08:55 PM
Nikita_Pinjare
Thu Jan 08 2015, 03:10 PM
mayank058
Wed Jan 07 2015, 05:43 AM
Overeating
Tue Jan 06 2015, 05:56 AM
trancebreaker11
Sun Jan 04 2015, 07:42 AM

Online

Guests: 45, Members: 0 ...

most ever online: 182184
(Members: , Guests: 182184) on 06 Aug 2010: 05:37 AM

Members: 37574
Newest member: sachinmm
Forum Activity
sachinmm Avatar
Posted By sachinmm
Thu Jan 29 2015, 07:21 AM
hello sir, plz tell me the circuit diagram interfa...
ajay_bhargav Avatar
Posted By ajay_bhargav
Thu Jan 29 2015, 06:28 AM
Moreover I see the segment Anode is connected via ...
ajay_bhargav Avatar
Posted By ajay_bhargav
Thu Jan 29 2015, 06:20 AM
LCD tutorial is written for 8051, you need to chan...
ajay_bhargav Avatar
Posted By ajay_bhargav
Thu Jan 29 2015, 06:17 AM
did you try any data sharing websites like 4shared...
ajay_bhargav Avatar
Posted By ajay_bhargav
Thu Jan 29 2015, 06:16 AM
you need to vary your PWM from 0 to 100 and then 100 to 0... it will generate sinewave.
ExperimenterUK Avatar
Posted By ExperimenterUK
Thu Jan 29 2015, 01:06 AM
The code in http://www.8051projects.net/t37289/805...
Karan123 Avatar
Posted By Karan123
Wed Jan 28 2015, 05:01 AM
Hello,I have changed schematic according to this c...
naqirizvi Avatar
Posted By naqirizvi
Tue Jan 27 2015, 07:10 PM
Have you done anything with devices like the ATme...
naqirizvi Avatar
Posted By naqirizvi
Tue Jan 27 2015, 07:09 PM
I am using avr gcc compiler and avrstudio 4 .I am ...
naqirizvi Avatar
Posted By naqirizvi
Tue Jan 27 2015, 05:43 PM
I have read that tutorial I am using AVR GCC Compi...