CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Help with 2.5 Digit 7-Segment LCD Code

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
temtronic



Joined: 01 Jul 2010
Posts: 9221
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Apr 19, 2013 5:34 am     Reply with quote

I used similar displays in the past(3/4" tall aka DMM size).When you read the datasheet you'll see it's direct drive(PIC i/o pin per segment is OK), but operating voltage is AC.
The COM terminal is supposed to be fed from an alternating source.Simply use a PWM output to feed it, or just toggle an I/O pin will do.Something around 100HZ should work fine.
If you just tie it to ground then over time you'll 'burn' the segments into the display,similar to CRTs and plasma displays.It could take months of use though, all depends on how long a segment is on for.So for 'test' purposes, it'd be OK to just ground COM,getting your program 'up and running'.

hth
jay
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Fri Apr 19, 2013 8:05 am     Reply with quote

Quote:
I used similar displays in the past(3/4" tall aka DMM size).When you read the datasheet you'll see it's direct drive(PIC i/o pin per segment is OK), but operating voltage is AC.
So:-

1) Mean DC voltage from any segment to common must be ~zero.
2) Common goes up and down with 50% duty. (Say @ 100Hz.)
3) Off segments go up and down in phase with common.
4) On segments go up and down out of phase with common.

Mike
dkw



Joined: 18 Apr 2013
Posts: 6

View user's profile Send private message

PostPosted: Fri Apr 19, 2013 9:24 am     Reply with quote

Thanks all for the help - I'm obviously new at this. Based on the comments, it seems it may be best to start over and use the static 7-segment LCD capabilities of the PIC.

PCM Programmer - I was searching for code to accomplish the above and came across code you posted several years ago. It compiles fine and I can modify for 2.5 vs 3 digits (I hope Smile ) . Are the +numbers (i.e.COM0+16) the segment it is connected to on the PIC? With this code, which pin would the COM from the LCD go to?

Code:

// Digit segments  A        B        C        D        E        F        G       
//                 b7       b6       b5       b4       b3       b2       b1       
#define DIGIT3  COM0+16, COM0+17, COM0+18, COM0+19, COM0+20, COM0+21, COM0+22
#define DIGIT2  COM0+8,  COM0+9,  COM0+10, COM0+11, COM0+12, COM0+13, COM0+14
#define DIGIT1  COM0+0   COM0+1,  COM0+2,  COM0+3,  COM0+4,  COM0+5,  COM0+6


//                            0    1    2    3    4    5    6    7    8    9
int8 const Digit_Map[10] = {0xFC,0x60,0xDA,0xF2,0x66,0xB6,0xBE,0xE0,0xFE,0xE6};


#define BLANK 0  // For a blank digit, don't turn on any segments.


#byte LCDDATA0 = 0x110
#byte LCDDATA1 = 0x111
#byte LCDDATA2 = 0x112


// These functions allow you to turn each decimal point On/Off.
#define display_DP2(x) x ? bit_set(LCDDATA0, 7) : bit_clear(LCDDATA0, 7)
#define display_DP3(x) x ? bit_set(LCDDATA1, 7) : bit_clear(LCDDATA1, 7)
#define display_DP4(x) x ? bit_set(LCDDATA2, 7) : bit_clear(LCDDATA2, 7)


int8 lcd_pos = 1;

//-----------------------------------------------
// This function was revised to add decimal points.

void lcd_putc(char c)
{
int8 segments;

if(c == '\f')
  {
   lcd_pos = 1;
   return;
  }

if(c == '.')
  {
   switch(lcd_pos)
     {
      case 1:
        display_DP4(TRUE);
        display_DP3(FALSE);
        display_DP2(FALSE);
        break;

      case 2:
        display_DP4(FALSE);
        display_DP3(TRUE);
        display_DP2(FALSE);
        break;

      case 3:
        display_DP4(FALSE);
        display_DP3(FALSE);
        display_DP2(TRUE);
        break;
     }
  }

if(isamong(c, " 0123456789"))
  {
   if(c == ' ')
      segments = BLANK;
   else
      segments = Digit_Map[c - '0'];

   switch(lcd_pos)
     {
      case 1: lcd_symbol(segments, DIGIT3); break; // 100's digit
      case 2: lcd_symbol(segments, DIGIT2); break; // 10's digit
      case 3: lcd_symbol(segments, DIGIT1); break; // 1's digit
     }

   lcd_pos++;
  }

}

//---------------------------
void clear_lcd(void)
{
LCDDATA0 = 0;
LCDDATA1 = 0;
LCDDATA2 = 0;
}


//===================================
void main()
{
// Setup for a static LCD and enable all 24 segment pins.
setup_lcd(LCD_STATIC, 0, 0xFFFFFF);
clear_lcd();

lcd_putc("\f1.23");

while(1);
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Apr 19, 2013 2:21 pm     Reply with quote

Two things.

First, it would have been a courtesy to post a link to where you got
that code. Then I wouldn't have had to go search for it.
(Since you only posted a fragment of it). This is it:
http://www.ccsinfo.com/forum/viewtopic.php?t=32774&start=40

2nd thing, you want to know what pin is COM0 on the PIC.
A good place to start would be, you know, the 16F914 data sheet.
Go to Google, type in PIC16F914 and you'll get a link to it.
Download the PDF, and look at the pin diagram which is always in
the first few pages. Find the pin that's labeled COM0.
dkw



Joined: 18 Apr 2013
Posts: 6

View user's profile Send private message

PostPosted: Fri Apr 19, 2013 3:36 pm     Reply with quote

With all due respect, I asked what where the common pin was attached - not where COM0 was on the PIC. I understand that had I had more knowledge I would have known that the common was supposed to go to COM0 - Pin 37.

I also asked if the + numbers after the COMO references in the code represented the pins on the pic so that I can map the segments. Since you didn't answer this, I'm assuming this is the case? I don't really appreciate the tone of your comments as I may not have much knowledge but I'm not lazy and have spent many hours with the datasheets.

Thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Apr 19, 2013 4:31 pm     Reply with quote

My tone was caused by the company owner constantly bringing out more
cups of hot coffee and placing them in front of me all morning.
I apologize for that.

This post explains that the COMx+YY numbers are the segments:
http://www.ccsinfo.com/forum/viewtopic.php?t=32774&start=22
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Sat Apr 20, 2013 1:34 am     Reply with quote

Quote:
4) You've got TWO LCD pins connected to RD6!
5) You've got the LCD segments wired in different order for the separate digits.
6) You could create a driver for the second digit, but you're making it difficult.

What I was getting at here was:-

a) Dedicate a complete port to each digit.
b) Wire both digit segments in the same order.
c) Conversion to segment data then MUCH simpler.
d) Conversion for each digit almost identical (just a different port).

Mike
dkw



Joined: 18 Apr 2013
Posts: 6

View user's profile Send private message

PostPosted: Tue Apr 23, 2013 7:09 pm     Reply with quote

Thanks all for your help! Got everything working. I can post the code if anyone wants; however, I ended up using the compiler that I started working with (thought it might be considered bad form to post it on a dedicated forum).

Again, thank you. I have only been at this a short while and owe all my (very limited) knowledge to helpful people on forums like this.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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