// This function reads the value of Humidity and Temperature integral and decimal values // The data is sent serially with a 50us low signal from the sensor indicating that the // next bit is data, and depending on the width of the high signal, we get a '0' or '1' unsigned short Read() { uint8_t bit_cnt; uint8_t hum_int=0; for (bit_cnt=0;bit_cnt<8;bit_cnt++) { while(DHT==0); //50us of low signal for every data bit if (DHT==1) { waitMicrosecond(29); //29us of high means'0' else '1' hum_int |= (0x01*DHT); if (bit_cnt!=7) { hum_int <<=1; } } while(DHT==1); } return (hum_int); }
int main(void) { // uint8_t* udpData; uint8_t* tcpData; uint8_t p=0; uint16_t i=0; Seq_number=0xfb0983f7; Ack_number=0x00000; myport=0xb921; id=0x1229; uint8_t* http; // init controller initHw(); putsUart0("\r\nWeather forecast\r\n"); // init ethernet interface etherInit(ETHER_UNICAST | ETHER_BROADCAST | ETHER_HALFDUPLEX); etherSetIpAddress(192,168,137,199); // flash phy leds etherWritePhy(PHLCON, 0x0880); RED_LED = 1; waitMicrosecond(500000); etherWritePhy(PHLCON, 0x0990); RED_LED = 0; waitMicrosecond(500000); sendSynWeather(data); // message loop while (1) { if (etherKbhit()) { if (etherIsOverflow()) { RED_LED = 1; waitMicrosecond(100000); RED_LED = 0; } // get packet etherGetPacket(data, 1500); // handle arp request if (etherIsArp(data)) { etherSendArpResp(data); RED_LED = 1; // GREEN_LED = 1; waitMicrosecond(50000); RED_LED = 0; GREEN_LED = 0; } // handle ip datagram if (etherIsIp(data)) { if (etherIsIpUnicast(data)) { // handle icmp ping request if (etherIsPingReq(data)) { etherSendPingResp(data); GREEN_LED = 1; waitMicrosecond(50000); GREEN_LED = 0; } if(etherIsTcp(data)) { tcpData = etherGetTcpData(data); if(etherisHandshake1(data)) { etherRespondtoHandshake1(data); RED_LED = 1; //GREEN_LED=1; BLUE_LED=1; waitMicrosecond(100000); RED_LED = 0; //GREEN_LED=0; BLUE_LED=0; break; } } } } } } sendGETRequest(data); while(1) { if (etherKbhit()) { etherGetPacket(data, 1500); if(etherIsTcp(data)) { RED_LED = 1; //GREEN_LED=1; BLUE_LED=1; waitMicrosecond(100000); RED_LED = 0; //GREEN_LED=0; BLUE_LED=0; if(p<=7) { if(tcp_DataCount>0) etherRespondToData(data); } //if(p>=2) { //p=0; tcpData = etherGetTcpData(data); http=tcpData+9; if((*http==0x32))//|(*http==0x35)) { tcpData=tcpData+299; for(i=0;i<(tcp_DataCount-299);i++) { putcUart0(*tcpData); tcpData++; } if(*http==0x32) break; } //break; //sendFinRequest(data); } p++; } } } while(1); return 0; }