电脑桌面
添加小米粒文库到电脑桌面
安装后可以在桌面快捷访问

ADS7816驱动程序(1602显示51单片机四线串口传输数据)

ADS7816驱动程序(1602显示51单片机四线串口传输数据)_第1页
1/7
ADS7816驱动程序(1602显示51单片机四线串口传输数据)_第2页
2/7
ADS7816驱动程序(1602显示51单片机四线串口传输数据)_第3页
3/7
1.主函数 #include #include #include"1602.h" #define uchar unsigned char #define uint unsigned int sbit led=P1^0; sbit DCLK=P2^1; sbit Dout=P2^2; sbit CE= P2^3; void delay(uint z) //延时 Z MS 子函数 { uint x,y; for(x=z;x>0;x--) for(y=110;y>0;y--); } uchar code display[]={'0','1','2','3','4','5','6','7','8','9'}; void init() //AD 初始化 { DCLK=1; Dout=1; CE=1; } unsigned int readADS() //读取 AD 值,SPI { unsigned int back_up=0; unsigned char i=0; bit data1=0; Dout=1; DCLK=0; _nop_(); _nop_(); _nop_(); _nop_(); CE=1; _nop_(); _nop_(); _nop_(); _nop_(); 1 CE=0; //sample DCLK=1; _nop_(); _nop_(); _nop_(); _nop_(); DCLK=0; _nop_(); _nop_(); _nop_(); _nop_(); DCLK=1; _nop_(); _nop_(); _nop_(); _nop_(); DCLK=0; _nop_(); _nop_(); _nop_(); _nop_(); DCLK=1; _nop_(); _nop_(); _nop_(); _nop_(); for(i=0;i<12;i++) { DCLK=0; _nop_(); _nop_(); data1=Dout; //read data if(data1) { back_up|=(0x0800>>i); } DCLK=1; _nop_(); _nop_(); 2 } CE=1; //close transfer return back_up; } void main() { unsigned long int temp=0; unsigned long int ad=0; unsigned char wa=0,qi=0,ba=0,sh=0,ge=0; LCD_init(); LCD_cls(); init(); ad=readADS(); LCD_write_string(0,0,"ADS7816 TEST:"); while(1) { delay(100); led=0; delay(100); led=1; delay(100); ad=readADS(); wa=ad/10000; qi=ad%10000/1000; ba=ad%10000%1000/100; sh=ad%10000%1000%100/10; ge=ad%10000%1000%100%10/1; LCD_write_char(0,1,display[wa]); //显示二进制对于十进制 LCD_write_char(1,1,display[qi]); LCD_write_char(2,1,display[ba]); LCD_write_char(3,1,display[sh]); LCD_write_char(4,1,display[ge]); temp=ad*1221; LCD_write_char(6,1,display[temp/1000000]); LCD_write_char(7,1,'.'); LCD_write_char(8,1,display[temp%1000000/100000]); LCD_write_char(9,1,display[temp%1000000%100000/10000]); LCD_write_char(10,1,display[temp%1000000%100000%10000/1000]); LCD_write_char(11,1,display[tem...

1、当您付费下载文档后,您只拥有了使用权限,并不意味着购买了版权,文档只能用于自身使用,不得用于其他商业用途(如 [转卖]进行直接盈利或[编辑后售卖]进行间接盈利)。
2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。
3、如文档内容存在违规,或者侵犯商业秘密、侵犯著作权等,请点击“违规举报”。

碎片内容

ADS7816驱动程序(1602显示51单片机四线串口传输数据)

确认删除?
VIP
微信客服
  • 扫码咨询
会员Q群
  • 会员专属群点击这里加入QQ群
客服邮箱
回到顶部