All About Circuits Forum  

Go Back   All About Circuits Forum > Software, Microcomputing, and Communications Forums > Programmer's Corner

Notices

Programmer's Corner Discussion forum for all aspects of programming and software engineering. Any software programming language welcome: C, C++, C#, Fortran, Java, Matlab, etc.

Reply   Post New Thread
 
Thread Tools Display Modes
  #21  
Old 06-01-2014, 12:19 AM
portreathbeach portreathbeach is offline
Member
 
Join Date: Mar 2010
Posts: 94
Default

OK. Finally the i2c LCD adaptor has turned up and I've got it working. I am now programming in C and it's been a steep learning curve.

The pinout actually is:

PCF8574 -- LCD
-----------------
P0 -------- RS
P1 -------- R/W
P2 -------- En
P3 -------- LED on/off
P4 -------- Data pin 4
P5 -------- Data pin 5
P6 -------- Data pin 6
P7 -------- Data pin 7

ErnieM, we were discussing how to send the data to the module, you can simply send the i2c start condition, send the address and then high nibble, with enable high, then again with enable low, then the low nibble. It clocks in on the falling edge of the enable bit. You can keep sending data to it without having to send the stop condition after each byte. It really is a nice bit of gear.


However I'm a little bit stumped on something. I have a real time clock module and the LCD module both running on the i2c bus. I am reading the RTC module and storing the data in raw_seconds, raw_minutes and raw_hours. Each of these variables hold the tens in the high nibble and the units in the low nibble.

If I put them into variables like seconds_tens, second_units, minutes_tens.....etc. and want to display them on the LCD, how can I do this?

Originally I thought I would use my 'lcd_write_chars' function and simply pass it one of the variables with 0x30 added to it to give it the correct ascii code, but the compiler says: illegal conversion of integer to pointer

I Googled how I could achieve what I want and came across 'itoa', but I cant get this to work either. If I do this:

Code:
        char buf[];
        itoa(buf,seconds_units,16);
        lcd_wr_chars(buf);
Select All
I get the seconds counting up from 0 to 9 etc.

If I try this:
Code:
        char buf[];
        itoa(buf,seconds_tens,16);
        lcd_wr_chars(buf);

        char buf[];
        itoa(buf,seconds_units,16);
        lcd_wr_chars(buf);
Select All
I get 131 displayed and then 10 seconds later I get 232, and another 10 seconds later I get 333 etc.

I know it's something to do with the array, but I'm not sure what to do.

Is there an easier way to do what I want to do?

I thought that writing the program to send the commands over i2c to the LCD adaptor and getting it to toggle the pins correctly was going to be tricky, but it proved to be OK, even in C which I've only been on for a weeks. I never expected it to be so tricky to simply convert a few variables to ascii.

Again, thanks for any help you can give
Reply With Quote
  #22  
Old 06-01-2014, 12:36 AM
MMcLaren's Avatar
MMcLaren MMcLaren is offline
Senior Member
 
Join Date: Feb 2010
Location: Michigan, USA
Posts: 639
Default

Sounds like the clock data may be "packed bcd". If so, could this be useful?

Code:
    seconds_tens = (raw_seconds >> 4) | '0'    // ascii '0'..'5'
    seconds_ones = (raw_seconds &= 15) | '0'   // ascii '0'..'9'
Select All
My PIC 4-Digit Single-Chip 24-Hour Clock project and my PIC 4-Digit 99-Minute Timer project both use packed BCD variables. They're written in BoostC so not sure if that would be much help.

Good luck on your project.

Cheerful regards, Mike

Last edited by MMcLaren; 06-01-2014 at 12:46 AM.
Reply With Quote
  #23  
Old 06-01-2014, 12:48 AM
portreathbeach portreathbeach is offline
Member
 
Join Date: Mar 2010
Posts: 94
Default

Yeah, that's what I do to get the two variables from the 'raw_seconds' byte.

When I make my Nixie clock, all I will do is copy those values to a port and use a bcd chip, but as for displaying them on the LCD, I need to convert them to an ascii character.
Reply With Quote
  #24  
Old 06-01-2014, 01:00 AM
MMcLaren's Avatar
MMcLaren MMcLaren is offline
Senior Member
 
Join Date: Feb 2010
Location: Michigan, USA
Posts: 639
Default

That's what OR'ing or adding '0' (0x30) is supposed to do;

binary 0..9 + 0x30 = 0x30 ('0') .. 0x39 ('9')...

Have you checked it out using the MPLAB Simulator?
Reply With Quote
  #25  
Old 06-01-2014, 01:18 AM
portreathbeach portreathbeach is offline
Member
 
Join Date: Mar 2010
Posts: 94
Default

Yeah, it does give the correct hex value for the character I want to display, but my function is declared as follows:

void lcd_wr_chars (const char *data);

If I write lcd_wr_chars ("Hello");

Hello is displayed.

If I write lcd_wr_chars (seconds_tens);

I get an integer to character error.


I've managed to solve it by doing this:

Code:
        char buf[1];
        itoa(buf,(raw_hours >> 4),10);
        lcd_wr_chars(buf);

        char buf[1];
        itoa(buf,(raw_hours &= 15),10);
        lcd_wr_chars(buf);
Select All
Reply With Quote
  #26  
Old 06-01-2014, 01:34 AM
MMcLaren's Avatar
MMcLaren MMcLaren is offline
Senior Member
 
Join Date: Feb 2010
Location: Michigan, USA
Posts: 639
Default

Ah, I see. I just use an "overload" function in my BoostC programs;

Code:
   void PutCMD(char pdata)        // lcd command (RS=0)
   { rs = 0; PutLCD(pdata);       // rs = 0, send command
   }                              //

   void PutDAT(char pdata)        // lcd data (RS=1) character
   { rs = 1; PutLCD(pdata);       // rs = 1, send data
   }                              //

   void PutDAT(rom char *data)    // lcd data (RS=1) const string
   { char ndx = 0; rs = 1;        //
     while(work = data[ndx++])    // while not end-of-string
       PutLCD(work);              //
   }                              //
Select All
Reply With Quote
  #27  
Old 06-01-2014, 02:00 AM
portreathbeach portreathbeach is offline
Member
 
Join Date: Mar 2010
Posts: 94
Default

Here's a strange one....

If I do this:
Code:
        char buf[1];
        itoa(buf,(raw_hours >> 4),10);
        lcd_wr_chars(buf);
        
        char buf[1];
        itoa(buf,(raw_hours &= 15),10);
        lcd_wr_chars(buf);
Select All
The units of the hours is always displayed as 0. I've run it through the simulator and it is 0 there too.

But if I do this:
Code:
        char h = raw_hours;
        char l = raw_hours;

        char buf[1];
        itoa(buf,(h >> 4),10);
        lcd_wr_chars(buf);
        
        char buf[1];
        itoa(buf,(l &= 15),10);
        lcd_wr_chars(buf);
Select All
It works fine. What is happening?
Reply With Quote
Reply   Post New Thread

Tags
, , , , ,


Related Site Pages
Section Title
Worksheet Microcontroller principles
Worksheet Digital communication
Worksheet Digital display circuits
Textbook Look-up tables : Principles Of Digital Computing
Video Lecture Representative System (Part 2) - Computer Hardware - Microprocessors
Video Lecture Representative System (Part 4) - Computer Software - Microprocessors
Textbook Introduction : Digital Communication
Textbook Parallel-in, parallel-out, universal shift register : Shift Registers
Textbook Serial-in, parallel-out shift register : Shift Registers
Textbook Serial-in/serial-out shift register : Shift Registers


Similar Threads
Thread Thread Starter Forum Replies Last Post
PIC 14-pin solderless breadboard adapter tracecom The Projects Forum 25 12-21-2013 04:15 PM
8 Pin PIC Solderless Breadboard Adapter tracecom The Projects Forum 1 04-29-2013 10:27 PM
PIC 16F59 + TQFP44 adapter PCB takao21203 The Flea Market 11 01-15-2013 12:16 PM
PIC Programming Adapter tracecom Embedded Systems and Microcontrollers 17 05-11-2012 08:29 AM
Project: PIC based Scalextric Lap Counter Crossie The Completed Projects Collection 6 03-11-2011 01:26 PM

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 05:05 AM.


User-posted content, unless source quoted, is licensed under a Creative Commons Public Domain License.
Powered by vBulletin
Copyright ©2000 - 2014, vBulletin Solutions, Inc.