Continue to Site

Welcome to

Welcome to our site! is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Usage of PORTB in EasyPic5 Development Board by RTC and LCD

Not open for further replies.


Junior Member level 2
May 16, 2011
Reaction score
Trophy points
Activity points

I'm working on a project that uses RTC PCF8583 and a 2x16 LCD and I'm testing it in EasyPic5 development board. Both of them will need PortB to be able to work because the LCD is automatically connected to portB and RTC PCF8583 SCL and SDA are at RB0 and RB1.

Does anyone know how to fix this problem?

Any help will be greatly appreciated. Thanks.

I'm look right at an EasyPIC5 and there is no RTC module on the main board.

I believe the RTC is a separate module. In which case it can be relocated to another free port on the left side of the board.

Unless you have a different version of the EasyPIC5?

Yes, it's a separate module. However, the SCL and SDA pins of PIC18F4550 is at PORTB and the pins of the LCD of the EasyPic5 DevBoard are also located in PORTB. My hunch is that this is the problem why the LCD doesn't display the data from the RTC.

I must state first that I have no knowledge of I2C working principles, so I'm assuming here that no data will be send from RTC before the command is given.
In that case it should be doable since LCD interface is always in high impedance mode (RW pulled low on board). Just make sure E pin is low when accessing RTC.
And You'll have to toggle RB0 & RB1 direction (in for serial, out for lcd).

You might wanna try first connecting RTC to portC and use software I2C to make sure that the data is properly processed.

Bjuric is correct.

You should be able to toggle the direction of RB0 and RB1 while ensuring the port pin tied to the LCD E line is held low. If you post or upload your code, we should be able to make a few changes to allow for the LCD's proper operation.


I tried connecting the RTC to PORTC but only the text "Date" and "Time" appear in the LCD. The date and time from the RTC is not displayed in the LCD.

Please check our code:

char seconds, minutes, hours, day, month, year; // Global date/time variables

// Software I2C connections
sbit Soft_I2C_Scl at RB1_bit;
sbit Soft_I2C_Sda at RB0_bit;
sbit Soft_I2C_Scl_Direction at TRISB1_bit;
sbit Soft_I2C_Sda_Direction at TRISB0_bit;
// End Software I2C connections

// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections

//--------------------- Reads time and date information from RTC (PCF8583)
void Read_Time() {

Soft_I2C_Start(); // Issue start signal
Soft_I2C_Write(0xA0); // Address PCF8583, see PCF8583 datasheet
Soft_I2C_Write(2); // Start from address 2
Soft_I2C_Start(); // Issue repeated start signal
Soft_I2C_Write(0xA1); // Address PCF8583 for reading R/W=1

seconds = Soft_I2C_Read(1); // Read seconds byte
minutes = Soft_I2C_Read(1); // Read minutes byte
hours = Soft_I2C_Read(1); // Read hours byte
day = Soft_I2C_Read(1); // Read year/day byte
month = Soft_I2C_Read(0); // Read weekday/month byte
Soft_I2C_Stop(); // Issue stop signal


//-------------------- Formats date and time
void Transform_Time() {
seconds = ((seconds & 0xF0) >> 4)*10 + (seconds & 0x0F); // Transform seconds
minutes = ((minutes & 0xF0) >> 4)*10 + (minutes & 0x0F); // Transform months
hours = ((hours & 0xF0) >> 4)*10 + (hours & 0x0F); // Transform hours
year = (day & 0xC0) >> 6; // Transform year
day = ((day & 0x30) >> 4)*10 + (day & 0x0F); // Transform day
month = ((month & 0x10) >> 4)*10 + (month & 0x0F); // Transform month

//-------------------- Output values to LCD
void Display_Time() {

Lcd_Chr(1, 6, (day / 10) + 48); // Print tens digit of day variable
Lcd_Chr(1, 7, (day % 10) + 48); // Print oness digit of day variable
Lcd_Chr(1, 9, (month / 10) + 48);
Lcd_Chr(1,10, (month % 10) + 48);
Lcd_Chr(1,15, year + 48); // Print year variable (start from year 2010)

Lcd_Chr(2, 6, (hours / 10) + 48);
Lcd_Chr(2, 7, (hours % 10) + 48);
Lcd_Chr(2, 9, (minutes / 10) + 48);
Lcd_Chr(2,10, (minutes % 10) + 48);
Lcd_Chr(2,12, (seconds / 10) + 48);
Lcd_Chr(2,13, (seconds % 10) + 48);

//------------------ Performs project-wide init
void Init_Main() {

TRISB = 0;
SPPCON = 0x00;
INTCON = 0x00;
ADCON1 = 0x0F;

Soft_I2C_Init(); // Initialize Soft I2C communication
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear LCD display
Lcd_Cmd(_LCD_CURSOR_OFF); // Turn cursor off

Lcd_Out(1,1,"Date:"); // Prepare and output static text on LCD
Lcd_Out(1,12,"201"); // start from year 2010

//----------------- Main procedure
void main() {

Init_Main(); // Perform initialization

while (1) { // Endless loop
Read_Time(); // Read time from RTC(PCF8583)
Transform_Time(); // Format date and time
Display_Time(); // Prepare and display on LCD

Have you ran it through the debugger to see if in fact the data is retrieved from the RTC and assigned to the storage variables?

Also do you have pull up resistors on the I2C lines and disabled any LEDs or other devices sharing the I2C lines.

I'll take a look at the code. I may have a similar RTC laying around here, is so I can reproduce your design and see what happens at this end.

I tried connecting the RTC to PORTC
Than you need to change this part:
// Software I2C connections
sbit Soft_I2C_Scl at RB1_bit;
sbit Soft_I2C_Sda at RB0_bit;
sbit Soft_I2C_Scl_Direction at TRISB1_bit;
sbit Soft_I2C_Sda_Direction at TRISB0_bit;
// End Software I2C connections
To reflect new config. Something like:
// Software I2C connections
sbit Soft_I2C_Scl at [B]RC1_bit[/B];
sbit Soft_I2C_Sda at [B]RC0_bit[/B];
sbit Soft_I2C_Scl_Direction at [B]TRISC1_bit[/B];
sbit Soft_I2C_Sda_Direction at [B]TRISC0_bit[/B];
// End Software I2C connections

i got the habit of looking at the config first. Don't ask why. Oh, all the hours wasted.... ironic LOL

we've done that also but it still didn't work :(

Hmm... From first few post I'm getting the idea that You're using the RTC module that plugs into the port (the one with the dip switch).

According to this picture (grabbed it from the aforementioned RTC datasheet)

The SCL signal can only go to pins 0, 2 or 3, and SDA to 1, 3 or 4.
That means that in this init part:
sbit Soft_I2C_Scl at RC1_bit;
sbit Soft_I2C_Sda at RC0_bit;
sbit Soft_I2C_Scl_Direction at TRISC1_bit;
sbit Soft_I2C_Sda_Direction at TRISC0_bit;
the pin assignment should go the other way around:
sbit Soft_I2C_Scl at RC0_bit;
sbit Soft_I2C_Sda at RC1_bit;
sbit Soft_I2C_Scl_Direction at TRISC0_bit;
sbit Soft_I2C_Sda_Direction at TRISC1_bit;
With switches P4 for SCL on RC0, and P1 for SDA on RC1, turned "on".


I changed the pins as suggested but still there's no display of the date and time, just the text "date" and "time". I agree with you that the problem might be with pin configurations but I still don't know which configuration is wrong. The codes work well with PIC16F877A but when I use the pic I'm supposed to use, PIC18F4550, there seems to be a problem. We are using the EasyPic5 Development Board to test this.

It starting to sound like a configuration issue, due to the fact the program functions correctly with the PIC16F877A, but not with the PIC18F4550. It appears from your code listing you are setting the "fuses" through the MikroC IDE.

Have you check the settings for the configuration register?

Can you post those settings?

I was just about to say that lol.

I've noticed in MikroC project config there is "CCP2 mux" which selects RC1 by default. It probably disables data on that pin.
There's also a "Low power Timer1 Osc enable" seting, that timer uses on RC0 and RC1.

You might try changing the pins or even port. Or do some simple debugging like turning on LEDs on some unused pins when entering a routine, and turn of before exiting. Just to make sure the program is not stuck. Might even be a good idea to remove RTC and make a small program to switch LEDs on he pins that You wanna use for software I2C. Just to make sure some internal circuitry has not taken over that port.


    Points: 2
    Helpful Answer Positive Rating
to check if we have the configurations right, we tried first to make each of the ports function as general IO pins. for port A, we set ADCON1 = 0x0F making the pins digital, for port B, it requires SPPCON and INTCON set to 0x00. however, we find it difficult to set ports C and D. we tried the same thing like disabling all the registers attached to these ports, but still it doesn't work.

Did You set correct MHz value in project settings. I haven't used USB PIC, but i guess PLL is ON by default. So the oscillator value in project settings should be 4*osc. If this is wrong, the I2C speed and LCD communication delays are miscalculated by the compiler.

This is the only difference I can think of right now, that would make the code work on P16 and not on P18 (besides the possibility of wrong internal circuitry setting)

Btw. RC4 and RC5 are input only.
Also if You use soft I2C, disable the serial module.

Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to