Programming 8051 Micro Controller 3
Programming 8051 Micro Controller 3
rd equ P1.0 wr equ P1.1 cs equ P1.2 intr equ P1.3 adc_port equ P2 adc_val equ 30H org 0H start: acall conv acall read mov P3,adc_val sjmp start conv: clr cs clr wr nop setb wr setb cs wait: jb intr,wait ret read: clr cs clr rd mov a,adc_port mov adc_val,a setb rd setb cs ret
;Read signal P1.0 ;Write signal P1.1 ;Chip Select P1.2 ;INTR signal P1.3 ;ADC data pins P2 ;ADC read value stored here ;Start of Program ;Start ADC conversion ;Read converted value ;Move the value to Port 3 ;Do it again ;Start of Conversion ;Make CS low ;Make WR Low ;Make WR High ;Make CS high ;Wait for INTR signal ;Conversion done ;Read ADC value ;Make CS Low ;Make RD Low ;Read the converted value ;Store it in local variable ;Make RD High ;Make CS High ;Reading done
#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(); void read(); //Start of conversion function //Read ADC function
unsigned char adc_val; void main(){ while(1){ conv(); read(); P3 = adc_val; } } void conv(){ cs = 0; wr = 0; wr = 1; cs = 1; while(intr); } void read(){ cs = 0; rd = 0; adc_val = adc_port; rd = 1; cs = 1; } //Forever loop //Start conversion //Read ADC //Send the read value to P3