《ADC0832简单应用c程序》由会员分享,可在线阅读,更多相关《ADC0832简单应用c程序(11页珍藏版)》请在金锄头文库上搜索。
1、#include #include #include #define uchar unsigned char#define uint unsigned int#define led_wei 0xefff#define led_duan 0xf7ff sbit ADCLK =P16; /时钟接口sbit ADDO =P35; /数据输出接口sbit ADDI =P17; /数据输入接口sbit ADCS =P15; /使能接口uchar buff = 0;uint data i;uchar code seg=0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80
2、,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e;void disp(uchar n)uchar dis0,dis1;dis0=ndis1=(nXBYTEled_wei=0xfe;/for(i=0;i 1;ADCLK = 1;_nop_();_nop_();if(ADDO)temp2|=0x80; ADCLK = 0; /形成下降沿 _nop_();_nop_();/if(temp1 = temp2)return temp1;unsigned int Adc0832(unsigned char channel)uchar i=0;uchar j;uint dat=0;uc
3、har ndat=0;if(channel=0)channel=2;if(channel=1)channel=3;ADDI=1;_nop_();_nop_();ADCS=0;/拉低 CS 端_nop_();_nop_();ADCLK=1;/拉高 CLK 端_nop_();_nop_();ADCLK=0;/拉低 CLK 端,形成下降沿 1_nop_();_nop_();ADCLK=1;/拉高 CLK 端ADDI=channel_nop_();_nop_();ADCLK=0;/拉低 CLK 端,形成下降沿 2_nop_();_nop_();ADCLK=1;/拉高 CLK 端ADDI=(channel1)_nop_();_nop_();ADCLK=0;/拉低 CLK 端,形成下降沿 3ADDI=1;/控制命令结束 _nop_();_nop_();dat=0;for(i=0;i=1;ADCS=1;/拉低 CS 端ADCLK=0;/拉低 CLK 端ADDO=1;/拉高数据端,回到初始状态dat=8;dat|=ndat;return(dat); /return ad datamain()uchar n;uint i,m;while(1)m=Adc0832(1);disp(m);