Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com 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.

[SOLVED] Mikroc for PCF8593 + PIC18F452 + LCD in Proteus showing unexpected character

Status
Not open for further replies.

rajib.das

Member level 3
Joined
Oct 23, 2013
Messages
54
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
415
Hello There
I am very new in C coding for MCUs
I am using PIC18F452 +PCF8593 + LM016L
Proteus 8.00
Mikro C pro pic


I am keep having LCD out like
Date:45.25.2003.
Time:mad:5:mad:5:mad:5


Please I Need serious help
Thanks

- - - Updated - - -



My functions are

Code:
// Software I2C connections
sbit Soft_I2C_Scl           at RC3_bit;
sbit Soft_I2C_Sda           at RC4_bit;
// Pin direction
sbit Soft_I2C_Scl_Direction at TRISC3_bit;
sbit Soft_I2C_Sda_Direction at TRISC4_bit;// End Software I2C connections

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

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

     //Soft_I2C_Init();           // Initialize Soft I2C communication
     //TRISC = 0;
     //PORTC = 0x18;
     //TRISC = 0x18;  // ----Making RC0 as Input of 5v--------

     Soft_I2C_Init();           // Initialize Soft I2C communication
}


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

     Soft_I2C_Start();               // Issue start signal
     Soft_I2C_Write(0xA0);           // Address PCF8593, see PCF8593 datasheet
     Soft_I2C_Write(2);              // Start from address 2
     Soft_I2C_Start();               // Issue repeated start signal
     Soft_I2C_Write(0xA1);           // Address PCF8593 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_Variable(void) {
     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
}
//------------------------SET TIME and DATE in CLOCK------------------------------
void Set_Clock_Time(void) {

   Delay_ms(1000);
   //Soft_I2C_Init();       // Initialize full master mode
   Soft_I2C_Start();      // Issue start signal
   Soft_I2C_Write(0xA0);  // Address PCF8583, see PCF8583 datasheet
   Soft_I2C_Write(0);     // Start from address 0 (configuration memory location)
   Soft_I2C_Write(0x80);  // Write 0x80 to configuration memory location (pause counter...)
   Soft_I2C_Write(0);     // Write 0 to cents memory location
   Soft_I2C_Write(0);     // Write 0 to seconds memory location
   Soft_I2C_Write(0x30);  // Write 0x30 to minutes memory location
   Soft_I2C_Write(0x12);  // Write 0x12 to hours memory location
   Soft_I2C_Write(0x18);  // Write 0x18 to year/date memory location
   Soft_I2C_Write(0x04);  // Write 0x04 to weekday/month memory location
   Soft_I2C_Stop();       // Issue stop signal

   Soft_I2C_Start();      // Issue start signal
   Soft_I2C_Write(0xA0);  // Address PCF8530
   Soft_I2C_Write(0);     // Start from address 0
   Soft_I2C_Write(0);     // Write 0 to configuration memory location (enable counting)
   Soft_I2C_Stop();       // Issue stop signal
}

//-------------------- Output Format to LCD -------------------------
void Display_Time_Format(void) {
     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_Chr(1,8,'.');
     //Lcd_Out(1,8,'.');
     Lcd_Chr(1,11,'.');
     //Lcd_Out(1,11,'.');
     Lcd_Chr(1,16,'.');
     Lcd_Out(2,1,"Time:");
     Lcd_Chr(2,8,':');
     //Lcd_Out(2,8,'.');
     Lcd_Chr(2,11,':');
     //Lcd_Out(2,11,'.');
     Lcd_Out(1,12,"201");       // start from year 2010}
}

//-------------------- Output values to LCD -----------------------------------
void Display_Time(void) {
     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);
}
 
Last edited by a moderator:

Thanks mathespbe for your time...
In my environment its not working .Its still showing @5:mad:5:mad:5..evertime I run. Any Idea how to fix it? My schematic is attached. thanks

- - - Updated - - -

@mathespbe I checked the data received on I2C.Decoded it and having the same weird unchanged result every time. thanks
 

i think the error in transform function and also post your I2C code because time and date wrong printed .
 

Hi try this.......

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
void Display_Time(void) {
     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)%10)  + 48);
     Lcd_Chr(2, 7, (hours % 10)   + 48);
     Lcd_Chr(2, 9, ((minutes / 10)%10) + 48);
     Lcd_Chr(2,10, (minutes % 10) + 48);
     Lcd_Chr(2,12, ((seconds / 10)%10) + 48);
     Lcd_Chr(2,13, (seconds % 10) + 48);
}


the problem is you are getting more than 30 in date more than 12 in month and more than 59 in time
 

LCD.gif

Thanks @Venkadesh_M
Your Segment did some changes like reformatted the time variables.
Actual problem was PCF8593 wasn't working like a real time Clock.it always starts from a same point and never updated.

I attached the new LCD output.
Its crazy!!!!!
 

Code:
//-------------------- Formats date and time----------------------
void Transform_Time_Variable(void) {
     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
}
 

thanks Man .Right now I am stuck with the weird output. I attached everything u asked for. Any help will be much appreciated. Thanks again.
 

Attachments

  • c code.zip
    4.9 KB · Views: 103
  • TEST PROTEUS.zip
    50.3 KB · Views: 87
  • LCD.gif
    LCD.gif
    26.3 KB · Views: 101
  • DATA SHEET FOR PIC18F452.pdf
    5.4 MB · Views: 129
  • PCF8593 by PHILLIPS.pdf
    197.3 KB · Views: 87

I don't have Proteus 8. It is better if you post Proteus .dsn file in 7.x format. Have you set Clock freq properly in Proteus. If not double click microcontroller and set Clock properly as in code and also disable WDT in Proteus. You are using PIC18F so LCD should use LATBx instead of RBx in lcd defines.
 

Hey Man
Thanks for Suggestions. I checked everything you asked to ...I am using Mikro c PIC compiler and include it's LCD.h file which basically performing LATD by default. I also checked both of my Proteus and Compiler's PIC Clock frequency are sitting at 8MHz and WDT are disabled.
and I am sorry that I don't know how to transform the Proteus projects from 8 to 7. I checked online couldn't find anything. So for your attention to my hardware connections I attached the schematic .Its not complicated and wont take long if u want to build it in 7.

Thanks
 

thanks Man .Right now I am stuck with the weird output. I attached everything u asked for. Any help will be much appreciated. Thanks again.

Hi there is no consecutive, write operations specified in the data sheet, I think you have to do them one by one.. And you are using inbuilt I2C but why putting soft I2C??
**Give gap between stop and start I2C....

Is that you got a successful write operation??

I didnt able to compile it can you attach the project file with hex...
 

Remove the 1k resistor in series with the RTC SDA line. Zip and post the mikroC project files. I can't create a new project and add all the files and compile.

**broken link removed**

**broken link removed**


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
void Initiate_LCD (void){
   TRISC = 0x00;
   PORTC = 0x00;
   LATC = 0x00;
   TRISD = 0x00;
   PORTD = 0x00;
   LATD = 0x00;
   
   Lcd_Init();                        // Initialize LCD
}

 
Last edited:

The reason Behind I am using Soft_I2C as I was following the example given in Mikro C ( for pic16.... and PCF8583) . I attached my project files .will be appreciated if you Do look. Thanks.
 

Attachments

  • 2_MyProject.zip
    76.6 KB · Views: 83
  • TEST PROTEUS.zip
    48.8 KB · Views: 77

https://www.ccsinfo.com/forum/viewtopic.php?p=125396


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// LCD module connections
sbit LCD_RS at LATD2_bit;
sbit LCD_EN at LATD3_bit;
sbit LCD_D4 at LATD4_bit;
sbit LCD_D5 at LATD5_bit;
sbit LCD_D6 at LATD6_bit;
sbit LCD_D7 at LATD7_bit;
 
sbit LCD_RS_Direction at TRISD2_bit;
sbit LCD_EN_Direction at TRISD3_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;
// End LCD module connections
 
// Software I2C connections
sbit Soft_I2C_Scl at RC3_bit;
sbit Soft_I2C_Sda at RC4_bit;
// Pin direction
sbit Soft_I2C_Scl_Direction at TRISC3_bit;
sbit Soft_I2C_Sda_Direction at TRISC4_bit;// End Software I2C connections
 
 
unsigned char seconds;
unsigned char minutes;
unsigned char hours;
unsigned char day;
unsigned char month;
unsigned char year;
 
unsigned char i;                              // Loop variable
 
void Display_Time_Format(void);
void Display_Time(void);
 
void Read_Clock_Time(void);
void Transform_Time_Variable(void);
void Set_Clock_Time(void);
 
void Read_Clock_Time(void) {
 
     I2C1_Start();               // Issue start signal
     I2C1_Wr(0xA0);           // Address PCF8593, see PCF8593 datasheet
     I2C1_Wr(2);              // Start from address 2
     I2C1_Start();               // Issue repeated start signal
     I2C1_Wr(0xA3);           // Address PCF8593 for reading R/W=1
 
     seconds = I2C1_Rd(1);     // Read seconds byte
     minutes = I2C1_Rd(1);     // Read minutes byte
     hours = I2C1_Rd(1);       // Read hours byte
     day = I2C1_Rd(1);         // Read year/day byte
     month = I2C1_Rd(1);       // Read weekday/month byte
     year = I2C1_Rd(0);
     I2C1_Stop();                // Issue stop signal
}
 
void Set_Clock_Time(void) {
 
   I2C1_Start();      // Issue start signal
   I2C1_Wr(0xA0);  // Address PCF8583, see PCF8583 datasheet
   I2C1_Wr(0);     // Start from address 0 (configuration memory location)
   I2C1_Wr(0x80);  // Wr 0x80 to configuration memory location (pause counter...)
   I2C1_Wr(0);     // Wr 0 to cents memory location
   I2C1_Wr(0);     // Wr 0 to seconds memory location
   I2C1_Wr(0x30);  // Wr 0x30 to minutes memory location
   I2C1_Wr(0x12);  // Wr 0x12 to hours memory location
   I2C1_Wr(0x18);  // Wr 0x18 to year/date memory location
   I2C1_Wr(0x04);  // Wr 0x04 to weekday/month memory location
   I2C1_Stop();       // Issue stop signal
 
   I2C1_Start();      // Issue start signal
   I2C1_Wr(0xA0);  // Address PCF8530
   I2C1_Wr(0);     // Start from address 0
   I2C1_Wr(0);     // Wr 0 to configuration memory location (enable counting)
   I2C1_Stop();       // Issue stop signal
}
 
 
//-------------------- Formats date and time----------------------
void Transform_Time_Variable(void) {
     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
}
 
void Display_Time_Format(void) {
     Lcd_Out(1,1,"Date:");      // Prepare and output static text on LCD
     Lcd_Chr(1,8,':');
     Lcd_Chr(1,11,':');
     Lcd_Out(1,12,"201");       // start from year 2010}
     //Lcd_Chr(1,16,'.');
     Lcd_Out(2,1,"Time:");
     Lcd_Chr(2,8,':');
     Lcd_Chr(2,11,':');
}
 
//-------------------- Output values to LCD -----------------------------------
void Display_Time(void) {
     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);
}
 
void main() {
 
     //-----------------Start LCD With test Messege------------------------
     TRISB = 0x00;
     PORTB = 0x00;
     LATB = 0x00;
     
     Lcd_Init();
     LCD_Cmd(_LCD_CLEAR);
     LCD_Cmd(_LCD_CURSOR_OFF);
 
     PORTD.F0 = 1;
     Delay_ms(10);
     PORTD.F0 = 0;
     
     I2C1_Init(1000000);
     Set_Clock_Time();
     
     while (1){                // Endless loop
 
           Read_Clock_Time();             // Rd time from RTC(PCF8583)
           Transform_Time_Variable();        // Format date and time
           
           Display_Time();          // Prepare and display on LCD
 
     }
}





Time transformation must be wrong.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
char seconds, minutes, hours, day, month, year;    // Global date/time variables
 
// Software I2C connections
sbit Soft_I2C_Scl           at RC3_bit;
sbit Soft_I2C_Sda           at RC4_bit;
sbit Soft_I2C_Scl_Direction at TRISC3_bit;
sbit Soft_I2C_Sda_Direction at TRISC4_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() {
 
  PORTB = 0x00;
  TRISB = 0x00;
  ANSEL  = 0;                // Configure AN pins as digital I/O
  ANSELH = 0;
  C1ON_bit = 0;              // Disable comparators
  C2ON_bit = 0;
  
  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_Chr(1,8,'.');
  Lcd_Chr(1,11,'.');
  Lcd_Chr(1,16,'.');
  Lcd_Out(2,1,"Time:");
  Lcd_Chr(2,8,':');
  Lcd_Chr(2,11,':');
  Lcd_Out(1,12,"201");       // start from year 2010
}
 
//----------------- Main procedure
void main() {
  Delay_ms(500);
   
  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
  }
}

 
Last edited:

Hi rajib.das;

The biggest mistake of your program is that it does not initialize the RTC. Thus, this will not start. Have to use the Set_Clock_Time() function too (only once, before the main loop starts) as the above jayanth's program.

I don't use Proteus 8, but - based on your attached screenshot - I recommend the followings:
- modify the properties (types) of both I2C pullup resistors to digital
- as jayanth wrote, remove the 1k resistor in series with the SDA line

zuisti
 
Last edited:

Attachments

  • RTC Read.rar
    39.7 KB · Views: 86
  • RTC Read rev1.rar
    56.6 KB · Views: 81
  • RTC Read rev2.rar
    56.9 KB · Views: 81
Last edited:

Thanks for the codes.
I tried first option with I2C1 in RC3 and RC4. Found different results. But the Clock is not updating .I attached the Image for your convenience. Thanks.

FYI my project Specs doesn't allow me to use any pin other than RC3:RC4 for RTC. So I could not test the second option.
 

Attachments

  • LCD.gif
    LCD.gif
    69.4 KB · Views: 100

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top