UNIT 5
Unit 5
• LCD interfacing
• Keyboard interface
• SPI protocol
• Ds1306 RTC interfacing and programming
• Relay and opto isolator
• Stepper motor interfacing
• DC motor interfacing
• PWM motor control with CCP
LCD
LCD operation
LCD pin Description
LCD pin Description
LCD command instruction
Lcd address
KEYBOARD INTERFACTNG
(a) key press detection,
(b) key identification.
There are two ways by which the PIC 18 can
perform key press detection:
(1) the interrupt method.
(2) the scanning method.
Interrupt Method of KEY Press Detection
• The rows are connected to PORTB Low (RB3-RB0) and the
columns are connected to PORTB High (RB7-RB4), which is the
PORTB-Change interrupt.
• Any changes on the RB7-RB4 pins will cause an interrupt
indicating a key press.
STEP1
• To make sure that the preceeding key has been released, 0s
are output to all rows at once, and the columns are read and
checked repeatedly until all the columns are HIGH.
• When all columns are found to be HIGH, the program waits
for a short amount of time before it goes to the next stage of
waiting for a key to be pressed.
STEP2
• To see if any key is pressed, the columns are
connected to the PORTB-Change interrupt.
• Therefore, any key press will cause an interrupt
and the microcontroller will execute the ISR.
• The ISR must do two things:
– (a) ensure that the first key press detection was
not erroneous due to spike noise,
– (b) wait 20 ms to prevent the same key press from
being interpreted as multiple key presses
STEP3
• To detect which row the key press belongs to, the
microcontroller grounds one row at a time, reading the
columns each time.
• If it finds that all columns are HIGH, this means that the
key press cannot belong to that row; therefore, it
grounds the next row and continues until it finds the
row the key press belongs to.
• Upon finding the row that the key press belongs to, it
sets up the starting address for the look-up table holding
the scan codes (or the ASCII value) for that row and goes
to the next stage to identify the key.
STEP4
• To identify/ the key press, the microcontroller
rotates the column bits, one bit at a time, into
the carry flag and checks to see if it is LOW.
• Upon finding the zero, it pulls out the ASCII
code for that key from the look-up table;
otherwise, it increments the pointer to point
to the next element of the look-up table.
Scanning method for key press detection
• Another method for key press detection is by scanning.
• In this method, to detect a pressed key, the microcontroller grounds
all rows by providing 0 to the output latch, then it reads the
columns.
• If the data read from the columns are equal to 1111, no key has
been pressed and the process continues until a key press is
detected.
• If one of the column bits has a zero, however, this means that a key
press has occurred.
• After a key press is detected, the microcontroller will go through
the process of identifying the key.
• Starting with the top row, the microcontroller grounds it by
providing a LOW to the first row only; then it reads the columns.
Scanning method for key press detection
• If the data read is all 1s, no key in that row is activated
and the process is moved to the next row.
• It grounds the next row, reads the columns, and checks
for any zero.
• This process continues until the row is identified.
• After identification of the row in which the key has
been pressed, the next task is to find out which
column the pressed key belongs to.
• This should be easy since the microcontroller knows at
any time which row and column are being accessed.
SPI protocol
SPI read and write protocol
Step to write data to an SPI device
Step to read data to an SPI device
Ds1306 RTC interfacing and programming
Register of Ds 1306
Address map of ds1306
Time and date address location and modes
SSPCON1-SSP CONTROL REGISTER 1
SSPSTAT-SSP STATUS REGISTER
RELAYS
Optoisolator
Optoisolator
LED – Transmitter Photosensor receiver
Interfacing a Optoisolator
Optoisolator
STEPPER MOTOR
Unipolar
Controlling stepper motor via optoisolator
Dc Motor Interfacing AND PWM
DC Motor Interfacing and PWM
Bidirectional control
DC motor control with CCP
DC Motor control with CCP