完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
本帖最后由 马永贵11 于 2016-4-13 21:23 编辑 仿真如图片所示,LED数码管不显示。程序如下 /*********************头文件***********************/ #include #include #include #include unsigned int wendu,shidu; unsigned char code table_h[20]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90, 0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10}; unsigned char code table_l[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; /********************************定义p1口******************/ ***it d1=P1^2; ***it d2=P1^3; ***it d3=P1^4; ***it Sp=P1^7; #define uchar unsigned char #define uint unsigned int void LED_init(void); void LED_xianshi(void); void delay_n10us(uint n); void LED_init(void) { d1=1; d2=1; d3=1; P0= 0xff; P2= 0xff; } /****************************LED显示***************/ void LED_xianshi(void) { uint i; uchar a,b,c,u,v,w; for(i=0;i<51;i++) { P0=0xff; P2=0xff; delay_n10us(200); a=(wendu/10); b=(wendu%10); c=wendu-10*a-b; u=(shidu/10); v=(shidu%10); w=shidu-10*u-v; d1=1; P0=table_h[a]; P2=table_l[a]; delay_n10us(1000); d2=0; d3=1; P0=table_h[c]; P2=table_l[w]; delay_n10us(1000); d3=0; } } /*************************延时**************************/ void delay_n10us(uint n) { uint i; for(i=n;i>0;i--) { _nop_();_nop_();_nop_();_nop_();_nop_();_nop_(); } } ***it SCK =P1^1; ***it DATA=P1^0; typedef union { unsigned int i; float f; } value; enum {TEMP,HUMI}; #define noACK 0 #define ACK 1 #define STATUS_REG_W 0x06 #define STATUS_REG_R 0x07 #define MEASURE_TEMP 0x03 #define MEASURE_HUMI 0x05 #define RESET 0xle void s_transstart(void); void s_connectionreset(void); char s_write_byte(unsigned char value); char s_read_byte(unsigned char ack); char s_measure(unsigned char*p_value,unsigned char*p_checksum,unsigned char mode); void calc_dht10(float*p_humidity,float*p_temperature); void s_transstrat(void) { DATA=1; SCK=0; _nop_(); SCK=1; _nop_(); DATA=0; _nop_(); SCK=0; _nop_();_nop_();_nop_(); SCK=1; _nop_(); DATA=1; _nop_(); SCK=0; } /****************复位*************/ void s_connectionreset(void) { unsigned char i; DATA=1; SCK=0; for(i=0;i<9;i++) { SCK=1; SCK=0; } s_transstart(); } /************************写字节*****************/ char s_write_byte(unsigned char value) { unsigned char i,error=0; for(i=0x80;i>0;i/=2) { if(i&value)DATA=1; else DATA=0; SCK=1; _nop_();_nop_();_nop_(); SCK=0; } DATA=1; SCK=1; error=DATA; _nop_();_nop_();_nop_(); SCK=0; DATA=1; return error; } /***************************读字节*********************/ char s_read_byte(unsigned char ack) { unsigned char i,val=0; DATA=1; for(i=0x80;i>0;i/=2) { SCK=1; if(DATA)val=(val|i); _nop_();_nop_();_nop_(); SCK=0; } if(ack==1)DATA=0; else DATA=1; _nop_();_nop_();_nop_(); SCK=1; _nop_();_nop_();_nop_(); SCK=0; _nop_();_nop_();_nop_(); DATA=1; return val; } /*************************************测量***********************/ char s_measure(unsigned char*p_value,unsigned char*p_checksum,unsigned char mode) { unsigned error=0; unsigned int i; s_transstart(); switch(mode){ case TEMP :error+=s_write_byte(MEASURE_TEMP);break; case HUMI :error+=s_write_byte(MEASURE_HUMI);break; default :break; } for(i=0;i<65535;i++)if(DATA==0)break; if(DATA)error+=1; *(p_value)=s_read_byte(ACK); *(p_value+1)=s_read_byte(ACK); *p_checksum=s_read_byte(noACK); return error; } void calc_dht10(float*p_humidity,float*p_temperature) { const float C1=-4.0; const float C2=+0.0405; const float C3=-0.0000028; const float T1=+0.01; const float T2=+0.00008; float rh=*p_humidity; float t=*p_temperature; float rh_lin; float rh_true; float t_C; t_C=t*0.01-40; rh_lin=C3*rh*rh+C2*rh+C1; rh_true=(t_C-25)*(T1+T2*rh)+rh_lin; if(rh_true>99)rh_true=99; if(rh_true<0.1)rh_true=0.1; *p_temperature=t_C; *p_humidity=rh_true; } uint long2string (uint INum,uchar chWord[]) //转成 { uint i=0; uint j=0; uint cnt=0; uchar chTemp; //依次取整数的末位,存入chWord while(INum!=0) { chWord='0'+INum%10; //转换为数字的ASCIIA码 i++; INum=INum/10; } cnt=i; //字符串最后一位加 chWord=' |