本文包含原理图、PCB、源代码、封装库、中英文PDF等资源
您需要 登录 才可以下载或查看,没有账号?注册会员
×
ADC0832转换程序一下是源代码:
C语言源代码:
- #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;
- //此程序A TO D为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);
- }
- //主程序
- void main(void)
- {
- uchar ad;
- while(1)
- {
- ad=read_adc();
- P0=ad;
- }
- }
复制代码
汇编源代码:- 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处理主程序
- CLR A
- MOV R7,A
- CLR CS
- SJMP adc_wait ;;判断A/D是否准备好?
- 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处理子程序
- 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
- ;==========================================================================
- ;主程序
- start:
- LCALL adc0832
- MOV P0,R7
- SJMP start
- END
复制代码 |