Differences

This shows you the differences between two versions of the page.

Link to this comparison view

pm:prj2025:iotelea:ana_maria.ailiesei [2025/05/27 23:58]
ana_maria.ailiesei [Software Design]
pm:prj2025:iotelea:ana_maria.ailiesei [2025/05/28 00:35] (current)
ana_maria.ailiesei [Bibliography and Sources]
Line 251: Line 251:
     }     }
     ​     ​
-    ​ 
-== Documentation for I2C communication with the LCD == 
-This was the hardest part because I couldn'​t really find any code on any forum to help me with this. Here is the information i found in the datahseet [[https://​cdn.sparkfun.com/​assets/​9/​5/​f/​7/​b/​HD44780.pdf] | HD44780 Datasheet]. 
- 
-In the Table 6 Instructions I found the addr4esses for the commands 0x01 (clear), 0x02 (home), 0x06 (entry-mode),​ 0x0C (display ON), 0x28 (function set 4-bit / 2-line). In figure 24 - 4 bit interface we can see how we have to initialise the lcd so that we can communicate in 4 bit mode. In the  Interfacing to the MPU section we see that the 4 bits of data must be sent twice, In figure 9 is explained how The nibble you put on DB7-DB4 is latched into the Instruction Register. The IR holds commands such as Function Set, Display On/Off, or an address for DDRAM/​CGRAM. Data register (DR) read 1 1 You read the Data Register, which is a one-byte buffer in front of DDRAM/​CGRAM. After the read, the controller automatically prefetches the next byte to DR. 
- 
- 
- 
- 
 == GPIO == == GPIO ==
 Initializing the buttons: Initializing the buttons:
Line 285: Line 276:
       joystickButtonPinInterrupt = true;       joystickButtonPinInterrupt = true;
   }   }
 +  ​
 +  ​
 +=== Documentation for the I2C communication with the LCD ===
 +== Why those hex commands? ==
 +
 +0x01 Clear Display, 0x02 Return Home, 0x06 Entry-Mode Set, 0x0C Display ON/OFF, 0x28 Function Set – their op-codes and bit-fields are listed in Table 6 "​Instructions"​ of the datasheet. ​
 +
 +The Function Set constant 0x28 is 0010 1000b => DL = 0 (4-bit), N = 1 (2-line), F = 0 (5x8 font). You must send this after forcing the controller into 4-bit mode so it knows the final interface width.
 +
 +== Power-up initialisation (Figure 24 flow) ==
 +<​code>​
 +0x30 -> 0x30 -> 0x30 -> 0x20
 +</​code>​
 +Send the "0x30 three times" handshake (still in 8-bit mode) and finally 0x20 to drop DL=0. This is the exact 4-bit initialisation sequence shown in Figure 24 "4-Bit Interface Initializing by Instruction"​ (under Initializing by Instruction). ​
 +
 +== 4-bit write cycle (Figure 9) ==
 +In 4-bit mode each byte is split: high nibble first, low nibble second. Figure 9 labels the bus cycles:
 +
 +| RS | R/W | Cycle name | Purpose |
 +| 0 | 0 | IR write | Latch a command or address into the Instruction Register |
 +| 1 | 1 | DR read | Fetch data from DDRAM/CGRAM via Data Register |
 +
 +See Figure 9 "4-Bit Transfer Example"​ for the two Enable pulses per byte. 
 +
 +== What the bit-flags in lcd_send_half() do ==
 +
 +| Bit mask | PCF8574 pin → LCD | Why it’s set |
 +| 0xF0 | P4-P7 -> DB4-DB7 | Carry the nibble you’re transmitting |
 +| 0x01 | P0 -> RS | 0 = command, 1 = data (selects IR or DR) |
 +| 0x00 | P1 → R/W kept low | We only write; reads would need a separate read routine |
 +| 0x04 | P2 -> E | Toggling E high->​low latches the nibble; kept >450 ns with delayMicroseconds(2) |
 +| 0x08 | P3 -> LED+ | Turns the backpack back-light on |
   ​   ​
  
Line 324: Line 347:
 <​html>​ <​html>​
   <iframe width="​560"​ height="​315"​   <iframe width="​560"​ height="​315"​
-     ​src="​https://​www.youtube.com/​embed/​rlgCxp-0uKw?​si=nVdr1mpfgMVzz8b_"+     ​src="​https://​www.youtube.com/​embed/​1_WvuHkVgRU"
      ​title="​YouTube video player"​ frameborder="​0"​ allow="​accelerometer;​ autoplay; clipboard-write;​ encrypted-media;​ gyroscope; picture-in-picture;​ web-share"​ referrerpolicy="​strict-origin-when-cross-origin"​ allowfullscreen>​      ​title="​YouTube video player"​ frameborder="​0"​ allow="​accelerometer;​ autoplay; clipboard-write;​ encrypted-media;​ gyroscope; picture-in-picture;​ web-share"​ referrerpolicy="​strict-origin-when-cross-origin"​ allowfullscreen>​
   </​iframe>​   </​iframe>​
Line 347: Line 370:
  
 [[https://​www.flipkart.com/​tumtafa-best-quality-labyrinth-game-ball-in-a-maze-round-wooden-kids-adults-party-fun-games-board/​p/​itm10a21ca18e84c?​pid=BDGGGSTBHPG2E3WZ |Ball maze photo]] [[https://​www.flipkart.com/​tumtafa-best-quality-labyrinth-game-ball-in-a-maze-round-wooden-kids-adults-party-fun-games-board/​p/​itm10a21ca18e84c?​pid=BDGGGSTBHPG2E3WZ |Ball maze photo]]
 +
 +[[https://​cdn.sparkfun.com/​assets/​9/​5/​f/​7/​b/​HD44780.pdf | HD44780 Datasheet]]
  
  
pm/prj2025/iotelea/ana_maria.ailiesei.1748379486.txt.gz · Last modified: 2025/05/27 23:58 by ana_maria.ailiesei
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0