PIC Wi-Fi Interface 3

In the second Wi-Fi project I mentioned in passing that it would be fairly easy to port the design to the more modern 16F1847 that we used in for the graphics display project.  That would get us away from having to copy the command and message strings into limited RAM space and instead embed the strings in program memory.  It also allows for larger strings, including some HTML commands, but it is a little tricky because you have to pay close attention to which banks the registers are in.  That’s one of the basic drawbacks of assembly language versus higher level languages which take care of that automatically.  Still, I think the benefits of using assembly language for small projects like these outweigh the disadvantages.

Hardware

PIC WiFi Interface2

The schematic shown here is exactly the same as what was presented for the second Wi-Fi project except that the pin numbers are different for the 16F1847.  In particular, make sure that you notice that the power pins are not only in the middle of the chip but also on opposite sides from what we had with the 16F688.

Software

Two software listings are available below.  Initially I just modified the version in the previous project (leaving the strings in RAM) so that I could get the basic code updates in place.  That version is not included here.  For the most part the required changes were modifications of some register names and the addition of BANKSEL commands.  The BANKSEL commands were required because the serial port registers that are located in Bank0 of the 16F688 are now in Bank3 of the 16F1847.  Because we also need to check the PIR1 register (still located in Bank0) in those routines we need to switch between Bank0 and Bank3.  The issues I had in making those changes were mostly the result of just missing a couple of locations in the code where a BANKSEL was needed.

Once I had that version going I moved the strings that had been copied into RAM to a table defined in program memory (starting at address 1000H).  That is similar to what I did for defining the graphics data in the Graphics LCD project.  In this case, however, I used the DT (define table) directive for each of the strings instead of the DATA directive.  That allowed me to actually enter the data as strings, followed by the individual bytes for carriage return, line feed, and the end of data marker (0x00).  The directives DA (define ASCII) and DATA also allow entering strings but they won’t work for this application because they pack two 7-bit ASCII characters into each 14-bit program memory location.  The DT directive puts one character per memory location.  That’s what is needed for the MOVIW (move indirect to W) command to work because it only picks up the lower 8-bits of data from the addressed memory.

Circles Screen Shot

One of the listings below uses the same command and message strings that were used in the previous project so it acts exactly the same.  The other listing uses a more elaborate HTML directive just to provide an indication of what can be done with longer strings and the extra memory space provided by the 16F1847.    In this example HTML commands are used to draw two circles that represent the status of the Front and Back Sprinklers.  Red=off and green=on (a screen shot is shown above).  From what I’ve read online you may be able to send up to 2048 characters with a CIPSEND command.  The software example is currently limited to 255 characters because a single 8-bit RAM location is used to tally up the character count.  That’s it for this post.  Check out my other electronics projects.

ESP8266_Rcv SW