void ADC_conv() { ADC_u8ReadCh_SSht(0 , &ADCREAD); // if(ADCREAD!=old_ADC) // old_ADC=ADCREAD ; if(ADCREAD-old_ADC > 5 && flag1==0) { old_ADC=ADCREAD ; Write_LCD(); } //else //{ if(ADCREAD<=132 && ADCREAD>124) { flg=2 ; } else if (ADCREAD>132) { count+=(old_ADC); if(count>1500) { step(); count=ADCREAD ; } flg=0 ; } else if (ADCREAD<=124) { c+=((255-old_ADC)) ; if(c>1500) { step(); c=ADCREAD ; } flg=1 ; } //} }
int main(void) { /* Ledstrips inits */ /* W5100 defines */ unsigned char sockstat; unsigned int rsize; char radiostat0[10], radiostat1[10]; int postidx, getidx; /* Initial variable used */ sockreg = 0; tempvalue = 0; ledmode = 0; Init_timer1(); Init_timers(); /*Init_shift();*/ OSCTUN = 21; PLLFBD = 38; /* M=40 */ CLKDIVbits.PLLPOST = 0; /* N1=2 */ CLKDIVbits.PLLPRE = 0; /* N2=2 */ /* Eraseleds();*/ /* even ledstrips have to be mirrored */ /* Mirror(patt); */ /* LCD inits */ Init_mcp(); Init_LCD(); Write_LCD(startup); /* W5100 inits */ Init_pin_SPI(); Init_SPI(); W5100_Init(gtw_addr,mac_addr,sub_mask,ip_addr); T_SPI_CS; SPI_CS = 1; Init_UART(); for (;;) { sockstat = SPI_Read(S0_SR); switch (sockstat) { case SOCK_CLOSED: if (socket(sockreg, MR_TCP, TCP_PORT) > 0) { /* Listen to Socket 0 */ if (listen(sockreg) <= 0) Delayms(1); } break; case SOCK_ESTABLISHED: /* Get the client request size */ rsize = recv_size(); if (rsize > 0) { /* Now read the client Request */ if (recv(sockreg, buf, rsize) <= 0) break; Putstr(buf); /* printf("%s",buf);*/ /* Check the Request Header */ getidx = strindex((char *) buf, "GET /"); postidx = strindex((char *) buf, "POST /"); if (getidx >= 0 || postidx >= 0) { /* Now check the Radio Button for POST request */ if (postidx >= 0) { if (strindex((char *) buf, "uBoard new color") > 0) ledmode++; } /* Create the HTTP Response Header */ strncpy((char *)buf,("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n" "<body style=\"background-color:FFFFFF;\">\r\n"),96); strcat((char *)buf,("[\n" " {\n" " \"id\": \"1\",\n" " \"name\": \"uBoard webboard\",\n" " \"ipaddr\": \"192.168.0.102\",\n" " \"subnetmask\": \"255.255.255.0\",\n" " \"gateway\": \"192.168.0.1\",\n" " \"adjustSpeedOfPattern\": \"int\",\n" " \"turnLedsOnOff\": \"boolean\"\n" " }\n" "]\n")); /* Now Send the HTTP Response */ if (send(sockreg,buf,strlen((char *)buf)) <= 0) break; /* TODO: add status */ LCD_Clear(); LCD_PutByte(ledmode); if (ledmode == 1) { strncpy(radiostat0,"",0); strncpy(radiostat1,("checked"),7); } else { strncpy(radiostat0,("checked"),7); strncpy(radiostat1,"",0); } /* Create the HTTP Radio Button Response */ strncpy((char *)buf,("<p><input type=\"radio\" name=\"radio\" value=\"0\" "),52); strcat((char *)buf,radiostat0); strcat((char *)buf,(">Turn off\r\n")); strcat((char *)buf,("<br><input type=\"radio\" name=\"radio\" value=\"1\" ")); strcat((char *)buf,radiostat1); strcat((char *)buf,(">Lounge mode\r\n")); strcat((char *)buf,("</strong><p>\r\n")); strcat((char *)buf,("<input type=\"submit\">\r\n")); strcat((char *)buf,("</form></span></body></html>\r\n")); /* Now Send the HTTP Remaining Response */ if (send(sockreg,buf,strlen((char *)buf)) <= 0) break; } /* Disconnect the socket */ disconnect(sockreg); } else Delayms(1); /* Wait for request */ break; case SOCK_FIN_WAIT: case SOCK_CLOSING: case SOCK_TIME_WAIT: case SOCK_CLOSE_WAIT: case SOCK_LAST_ACK: /* Force to close the socket */ close(sockreg); break; } } return 0; }