ADC0832 assembly language code program CLK bit P1.6 DATA_I bit P1.4 DATA_O bit P1.5 CS bit P1.2 org 0000h ajmp start org 0020h adc0832: ;;A/D processing main program CLR A MOV R7,A CLR CS SJMP adc_wait ;;Judge whether A/D is ready? wait_loop: JNB DATA_O,adc_process adc_wait: SETB CLK NOP NOP CLR CLK NOP NOP SJMP wait_loop adc_process: CLR A ;;A/D processing subroutine MOV R6,A pro_loop: SETB CLK NOP NOP CLR CLK NOP NOP MOV A,R7 ADD A,ACC MOV R7,A MOV C,DATA_O CLR A RLC A ORL A,R7 MOV R7,A INC R6 CJNE R6,#08H,pro_loop SETB CS RET ;Main program start: LCALL adc0832 MOV P0,R7 SJMP start END #include\"reg51.h\" #include\"intrins.h\" #define uchar unsigned char #define nop() _nop_(); sbit clk=P1^6; sbit data_i=P1^4; sbit data_o=P1^5; sbit cs=P1^2; //This program A TO D is CH1 uchar read_adc(void) { uchar i,ch=0; cs=0; clk=1; nop(); nop(); clk=0; nop(); nop(); for (;data_o==1;) { clk=1; nop(); nop(); clk=0; nop(); nop(); } for (i=0; i<8; i++) { clk=1; nop(); nop(); clk=0; nop(); nop(); ch=(ch<<1)|data_o; } cs=1; return(ch); } //Main program void main(void) { uchar ad; while(1) { ad=read_adc(); P0=ad; } }
You Might Like
Recommended ContentMore
Open source project More
Popular Components
Searched by Users
Just Take a LookMore
Trending Downloads
Trending ArticlesMore