Circuit 11, PWM ADC
Not much to say here. It uses the same ADC code to read back the potentiometer signal and then uses that value for the PWM output via OCR0B. While simple, the code is good to go though.
Circuit 12, LCD: 4 Bit mode
Back to using the shift register, but with a 4x20 LCD screen! The wiring in this one is…. Complex. Can you spot the error? (haha) While I do have normal wire, I figured using the wires they gave me would be faster to build, so I decided to not cut/strip my own. Interesting to note that the LCD screen used push in headers for the pins. I didn’t know that they were a thing and is quite awesome. It’s a very tight fit and required using pliers to get the pins in. The potentiometer is there to control the display contrast.
The code is split into two files, main and the LCD initialization/control files. Main calls for the LCD to initialize, clears the display, and prints some code (the letter “A” in this case). The LCD code is much more complex and thankfully there are some good comments on what each part is doing. It has code for sending a 1, 0, clearing the display, and initializing it. They have also included two characters in the code, A and ス (J su?). The one thing not really explained in their documents is the need to send a one before the nibbles for each 4-bit portion of the character codes. I’m sure it’s in the datasheet, but haven’t read that yet. Adding character data is laborious if doing it by a series of 1’s and 0’s though. I’m sure arrays or loops of some kind would help a lot!
Overall, pretty easy to understand, just need to know the commands from the datasheet and what is important to call for setup. Interfacing is easy then.
Circuit 13, LCD: 8 Bit mode, Count in base 4
Had a funny moment of getting garbage text on the screen when I first downloaded the code. Turns out there was more changes to the wiring between 4-bit and 8-bit mode than I first thought. The code that they implement here is a 3-digit, 4-bit counter (in the form of k, j, i) on the display. It then resets when it gets to 333. To do the counting, they use the timer overflow interrupt like before.
The extra was a little confusing to me. The idea was to display numbers without the use of variables. Someone commented on how they did it. I get how it was implemented, but never would have really thought of doing it that way.
Circuit 14, LCD: 8 Bit mode, Count in base n
This one is interesting. They made the code very flexible by using a way that I’ve already thought of doing it like (but didn’t know how to implement it). Arrays! That being said, it makes some good sense. Again, using timer overflow to trigger a counter, which you can then specify a base to count in 2 to 10. From there it coverts it and then passes it off to a function which displays the numbers on the display. Also included is a display shift. One thing confusing about the shift is that the lines aren’t in order. It seems like line 3 of the display follows line 1 in the address space.
The extra confused me a lot. I couldn’t find a good description of the cursor position codes in the datasheet. After some digging online, I understand it. And I found where it exists in the datasheet (under setting the DDRAM address).
Circuit 15, LCD: Banner
This code just scrolls text across the screen. It’s honestly not very good. I think what is missing is a complete clearing of the display before it shifts the text over. They do have code to clear the display, but after the text shifts you can see the previous text for a little longer (maybe 150-250ms). I think this is more of a hardware problem and larger resistors could be used to drain the LCD sooner. The way they move the text is interesting. The clear the display, move the cursor home, then print spaces to move the text back. I think addressing the cursor directly would yield better results overall.