|
|
View previous topic :: View next topic |
Author |
Message |
louyueqing
Joined: 03 Jan 2018 Posts: 1
|
Interfacing PIC24FJ64GB002 with LCD |
Posted: Thu Jan 04, 2018 1:24 am |
|
|
PIC24FJ64GB002 with 1602 LCD circuit
This post shows how to interface LCD screen (16×2, 20x’4 ….) with PIC24FJ64GB002 microcontroller where the compiler used is CCS C.
The PIC24FJ64GB002 is a 16-bit microcontroller runs with 3.3V while is the LCD used in this example is 5V. It's datasheet is: http://www.kynix.com/uploadfiles/pdf8798/PIC24FJ64GB002-I2fSO_94644.pdf .The PIC24FJ64GB002 has some 5.5V tolerant input pins (RB5, RB7, RB8, RB9, RB10 and RB11), with this pins we can apply 5V to the microcontroller without any problem.
An other good thing with this microcontroller is the open drain outputs, each output pin can be configured to work as an open drain output.
In this project I used a serial-in parallel-out shift register to minimize number of pins used by the LCD because we don’t have enough 5.5V tolerant input pins to connect another 5V device. With the shift register the LCD will use only 3 pins which means we’ve gained at least 3 pins.
Hardware Required:
PIC24FJ64GB002 microcontroller
AMS1117 3V3 voltage regulator
16×2 LCD screen
74HC595 shift register (74HC164N and CD4094 also work)
100uF polarized capacitor
10uF polarized capacitor
4 x 0.1uF ceramic capacitor
4 x 10K ohm resistor
10K variable resistor
100 ohm resistor
5V power source
Breadboard
Jumper wires
Interfacing PIC24FJ64GB002 with LCD circuit:
pic24fj64gb002 LCD interfacing circuit
In this example the PIC24FJ64GB002 MCU runs with its internal oscillator.
The AMS1117 3V3 voltage regulator is used to supply the MCU with 3.3V from the 5V source.
The E (Enable) pin of the LCD screen is connected directly to pin RB7 (#16) of the microcontroller. The C (Clock) pin of the shift register is connected to pin RB8 (#17) of the microcontroller. The last shift register pin which named D (Data) is connected to pin RB9 (#18) of the microcontroller.
The three pins: RB7, RB8 and RB9 are 5.5V tolerant input pins and can be configured to be an open drain outputs. With the open drain outputs and 5V pull up resistors we get what our LCD needs (logic 0 of 0V and logic 1 of 5V).
Interfacing PIC24FJ64GB002 with LCD C code:
The C code below was tested with CCS C compiler version 5.051.
To be able to compile the code below a 3-wire LCD driver has to be added to the project folder. Download link might be found in the post below:
3-Wire LCD driver for CCS PIC C compiler
I used the command set_open_drain_b(value) to configure the open-drain output pins of the PIC24FJ64GB002 MCU. For example if I want pin RB0 to be an open-drain output I just write:
set_open_drain_b(1);
For pins RB7, RB8 and RB9 I used:
set_open_drain_b(0x380);
where 0x380 = 896 = 0b0000001110000000
Complete C code is below.
Code: | // Interfacing PIC24FJ64GB002 with LCD example CCS C code
// Internal oscillator used @ 8 MHz
// 3-Wire LCD module connections
#define LCD_DATA_PIN PIN_B9
#define LCD_CLOCK_PIN PIN_B8
#define LCD_EN_PIN PIN_B7
// End 3-Wire LCD module connections
#include <24FJ64GB002.h>
#fuses FRC NOWDT NOJTAG OSCIO SOSC_IO
#use delay(clock = 8M)
#include <3WireLCD.c> // 3-wire LCD source file
unsigned int8 i;
void main(){
output_b(0);
set_open_drain_b(0x380); // Configure RB7, RB8 and RB9 pins as an open-drain outputs
delay_ms(500); // Wait 1/2 second
lcd_initialize(); // Initialize LCD module
lcd_cmd(LCD_CLEAR); // LCD Clear
lcd_goto(3, 1); // Go to column 3 line 1
lcd_out("Hello world!");
delay_ms(1000); // Wait 1 second
while(TRUE){
for(i = 0; i < 200; ++i){
lcd_goto(7, 2); // Go to column 7 row 4
printf(lcd_out, "%3u", i); // Write i with 3 numbers max
delay_ms(500);
}
}
}
// Interfacing PIC24FJ64GB002 with LCD example CCS C code
// Internal oscillator used @ 8 MHz
// 3-Wire LCD module connections
#define LCD_DATA_PIN PIN_B9
#define LCD_CLOCK_PIN PIN_B8
#define LCD_EN_PIN PIN_B7
// End 3-Wire LCD module connections
#include <24FJ64GB002.h>
#fuses FRC NOWDT NOJTAG OSCIO SOSC_IO
#use delay(clock = 8M)
#include <3WireLCD.c> // 3-wire LCD source file
unsigned int8 i;
void main(){
output_b(0);
set_open_drain_b(0x380); // Configure RB7, RB8 and RB9 pins as an open-drain outputs
delay_ms(500); // Wait 1/2 second
lcd_initialize(); // Initialize LCD module
lcd_cmd(LCD_CLEAR); // LCD Clear
lcd_goto(3, 1); // Go to column 3 line 1
lcd_out("Hello world!");
delay_ms(1000); // Wait 1 second
while(TRUE){
for(i = 0; i < 200; ++i){
lcd_goto(7, 2); // Go to column 7 row 4
printf(lcd_out, "%3u", i); // Write i with 3 numbers max
delay_ms(500);
}
}
}
|
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9269 Location: Greensville,Ontario
|
|
Posted: Thu Jan 04, 2018 6:37 am |
|
|
NICE, especially for your first post !
There is an option to eliminate the 595 interface between the PIC and LCD that I've used for a few years.
Simply use 1 PIC pin, 2 caps, 1 diode and create a voltage doubler to supply 5 volts to the LCD VCC.
It allows you to use the 'standard' 4 bit mode LCD driver, fewer parts, smaller PCB, cheaper, etc.
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19587
|
|
Posted: Thu Jan 04, 2018 10:03 am |
|
|
Only problem is the 'main' is duplicated!.... |
|
|
empty
Joined: 13 Jan 2018 Posts: 15
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|