5V0
5V0
R1
8.2K
R2
8.2K
R7
PUSHBUTTON
F3
10K
RO TARY ENCODER
1
2
3
4
5
6
U1
2
3
4
5
27
28
6
RA0
RA1
RA2/INDX
RA3/QEA
RB6/PGC
RB7/PGD
RA4/QEB
ICSP CONNEC TOR
1
2
3
4
5
6
1
2
3
4
5
6
R5
100
C8
100nF
R6 1K
1 MCLR
RS
D5
D4
D7
E
D6
21
22
23
24
25
26
11
12
13
14
15
16
17
18
RB0
RB1
RB2
RB3
RB4
RB5
RC0
RC1/CCP2
RC2/CCP1
RC3/INT0
RC4/INT1
RC5/INT2
RC6/TX
RC7/RX
10 OSC2
C7
20pF
Y1
20MHz
9 OSC1
C6
20pF
5V0
5V0
BACKLITE
LED2
RW
LED1
5V0
7
20 AVDD VDD
R9
470
R10
470
8
19 AVSS VSS
C2
1uF
C3
LED2
PIC18F2431
D7
D5
D6
D4
C1
0.1uF
NHD-0208BZ-FL-YBW
1
2
3
4
5
6
7
8
9
10
11
12
13
14
GND
VCC
VO
RS
R/W
E
D0
D1
D2
D3
D4
D5
D6
D7
5V0
RW
RS
E
R8
33
SCHEMATIC 1.
The PIC18F2431 is
really intended for
motor control. We
have adapted it for
use as a human
interface device
that can run an
additional
application.
LCD BACKLIGHT LED
5V0
R4
10K
Q1
high nibble of PORTB was not available as I wanted to
include a programmer/debugger portal in this design. I also
considered losing the UART if I tied the high nibble of the
LCD I/O to the high nibble of PORTC. So, I crammed as
much of the LCD interface onto the PORTB I/O pins.
If you don’t have any plans for reading the LCD’s
internal SRAM, you can reclaim RC3. Just be sure to wire
the LCD’s R/W pin to ground. Don’t need a back light on
you LCD? If not, you can recover RC1 too. The LEDs are
here for example. That leaves all of PORTC for your optical
encoder design. If you’re really pushed for I/O, you can also
recover the MCLR pin as RE3.
The C2-C5 bypass capacitor arrangement isn’t very clear
in Schematic 1. Capacitors C2 and C3 are physically
attached between the AVDD and AVSS pins, while C4 and
C5 lie in parallel between the VDD and VSS pins.
The LCD back light requires a maximum of 80 mA of
current depending on the current-limiting resistor value you
choose. That’s way too much current for a PIC18F2431 I/O
pin to absorb. So, I opted to drive the LCD back light with a
MOSFET. Doing this allows the PIC18F2431 to control the
LCD back light and eliminates the need to worry about the
relatively high LCD back light current requirement. I wrote a
four-bit LCD driver that consists of an LCD init function, a
character/command write function, and a cursor locate
function. Here are the base LCD definitions and macros:
//***********************************************
//* LCD DEFINITIONS
//***********************************************
#define databus LATB
#define lcdcntrl LATB
#define E 0x10
#define RS 0x20
#define RW LATC3
#define clrRW RW = 0
#define setRW RW = 1
46 SERVO 07.2010