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

Fri Nov 28 2014, 06:31 AM
babar
aoa ,, i need a project for 8051 microcontroler can some one plz give me the pdf form of this project android control robot
Fri Nov 28 2014, 06:30 AM
babar
hi
ExperimenterUK
Thu Nov 20 2014, 06:00 PM
@Mehboob.. I don't think you can do that.
Sat Nov 15 2014, 06:41 AM
Mehboob
Pls can you send me code in c of PWM generation using UART/serial port in 8051.
Fri Nov 14 2014, 02:51 PM
mohammad aqil
NEED A BOOK ON MICROPROCESSOR AND INTERFACING BY D.V.HALL. RIGHT NOW, I SHALL BE VERY THANK FULL TO U....
Thu Nov 13 2014, 02:15 PM
m
please code hex project avr blood pressure monitor
Thu Nov 13 2014, 05:56 AM
Lambo
hi mate, whats the ajay-bhargav? tell us more pls
ExperimenterUK
Wed Nov 12 2014, 12:56 AM
@tmtm000.. have you been able to join ?
ExperimenterUK
Wed Nov 12 2014, 12:54 AM
@Alice..become a member,then send a PM to ajay_bhargav the site owner.
Tue Nov 11 2014, 03:58 AM
Abhishek Bansal
Thanks a lot for your informative tutorials!

Downloads

Comments

PsySc0rpi0n
Thu Nov 27 2014, 02:00 PM
hanifnoor
Thu Nov 27 2014, 09:42 AM
dpkraju
Wed Nov 26 2014, 02:18 PM
sankalp_s
Tue Nov 25 2014, 05:13 PM
dodul
Mon Nov 24 2014, 10:08 PM
VikiPeter
Tue Nov 18 2014, 09:13 AM
gentlboy
Sun Nov 16 2014, 11:13 PM
philipeastbourne
Wed Nov 12 2014, 05:32 AM

Online

Guests: 70, Members: 0 ...

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

Members: 37552
Newest member: PsySc0rpi0n
Forum Activity
PsySc0rpi0n Avatar
Posted By PsySc0rpi0n
Fri Nov 28 2014, 07:05 AM
Good morning. Thanks for replying. The problem in ...
ajay_bhargav Avatar
Posted By ajay_bhargav
Fri Nov 28 2014, 04:44 AM
You can read status of pin before starting the gam...
ajay_bhargav Avatar
Posted By ajay_bhargav
Fri Nov 28 2014, 04:37 AM
As ExperimenterUK (Phil) said, searching for speci...
ajay_bhargav Avatar
Posted By ajay_bhargav
Fri Nov 28 2014, 04:31 AM
[Topic moved to AVR Discussion Forum]
ajay_bhargav Avatar
Posted By ajay_bhargav
Fri Nov 28 2014, 04:29 AM
If you have worked on normal C language then Embed...
PsySc0rpi0n Avatar
Posted By PsySc0rpi0n
Thu Nov 27 2014, 02:30 PM
Hi...I'm new in forum and with programming 8051 co...
hanifnoor Avatar
Posted By hanifnoor
Thu Nov 27 2014, 09:45 AM
while(msg_array[i]!='\0') { if(msg_array[i]=...
rearthur2003 Avatar
Posted By rearthur2003
Thu Nov 27 2014, 05:23 AM
there are two types of diodes ir rx which is coat...
rearthur2003 Avatar
Posted By rearthur2003
Thu Nov 27 2014, 05:19 AM
First you will need to let us know what IDE you pl...
engr1931 Avatar
Posted By engr1931
Thu Nov 27 2014, 05:18 AM
yes sir! i only know assembly, and still in proces...