#include"reg51.h" #include"intrins.h" ***it rs=P1^0; ***it rw=P1^1; ***it en=P1^2; ***it CS=P1^3; ***it clk=P1^4; ***it DI=P1^5; ***it DO=P1^7; ***it B0=B^0; void w1602c(unsigned char dat) { char n; ACC=dat; rs=0; rw=0; en=0; P3=dat; P1 &=~0x40; P1 |=dat & 0x40; n=5; while(n--); en=1; n=8; while(n--) en=0; } void w1602d(unsigned char dat) { char n; ACC=dat; rs=1; rw=0; en=0; P3=dat; P1 &=~0x40; P1 |=dat & 0x40; n=5; while(n--); en=1; n=8; while(n--) en=0; } unsigned char rADC0832() { char i; CS=1; _nop_(); CS=0; //exchange clk=0; _nop_(); DI = 1; _nop_(); clk=1; //NO.1.Pulse DI=1 _nop_(); clk=0; _nop_(); clk=1; _nop_(); clk=0; //NO.2.Pulse DI=1 _nop_(); clk=1; _nop_(); clk=0; //NO.3.Pulse DI=0 DI=0; _nop_(); clk=1; _nop_(); clk=0; //NO.3.Pulse DI=0 for(i=0;i<8;i++) { B=B<<1; clk=1; B0 = DO; clk=0; } return B; } void main() { unsigned char temp; w1602c(0x38); w1602c(0x06); w1602c(0x0c); w1602c(0x01); while(1) { temp =rADC0832()-1; w1602c(0x80); w1602d(0x30+temp/100); w1602d(0x30+(temp%100)/10); w1602d(0x30+temp%10); } } 电桥放大电路 |
更多回帖