"); //-->
代码
//头文件: #include "pic16f877.h" #include "stdio.h" //变量定义: #define CLK RC3 #define DIN RC4 #define DOUT RC5 #define ADCS RC0 int getdata; void Output_Control(char TempChar) { unsigned char Mask = 0x10; unsigned char Count; for(Count = 0;Count<5;Count++)//5次循环,第一次循环DIN为Start,第二次DIN为选择差分或单端,后3次DIN分别是0,0,0选择通道 { DIN = 0; if(TempChar&Mask) { DIN = 1; } CLK = 1; Mask >>= 0x01; CLK = 0; } } int Input_Data(void) { unsigned char Count; unsigned int Mask = 0x8000; unsigned int Result = 0x0000; CLK = 1; CLK = 0; for(Count = 0;Count <13;Count++) { if(DOUT) { Result|=Mask; } CLK = 1; Mask >>= 0x01; CLK = 0; } Result >>= 0x03; Result &= 0x0FFF; return(Result); } //void display(int da);//定义显示函数,参数为显示内容,只显示两位十六进制 void delay(unsigned int timer) { while(timer--); } float v; float r; float t; //主函数,C语言的入口函数: void main(void) { TRISB=0; TRISD=0; //TRISC=0XD7; TRISC=0XE6; SSPCON=0; ADCS = 1; while(1) { ADCS = 0; Output_Control((char)0x18); getdata=Input_Data(); ADCS = 1; //v=0.5*getdata/4096.0;//5v除以运放放大倍数10,得出0.5 //r=v*500.0;//根据仿真取电压表的几个值绘出曲线,得出斜率为500,r为电位器的阻值,不包含R8 //t=r/0.3908;//PT100: R=100*(1+A*t),A=0.00390802,所以t=(R-100)/0.3908 PORTB=(unsigned char)(getdata>>8); PORTD=(unsigned char)(getdata&0XFF); delay(5000); } }
仿真效果图
*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。