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 support@ccsinfo.com

Help on segmented LCD
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Nov 26, 2007 1:53 am     Reply with quote

Here is a test program for the LCD on the PicDem Mechatronics
Demonstration Board.

I don't have the Mechatronics board, so I can't test this program.
But I believe it has a good chance to work. I looked at the ASM
source code for the Mechatronics board. I've tried to make the
program below be similar to that ASM code, in terms of setting up
the LCD and by using the internal oscillator at 8 MHz.

I'm using the CCS lcd_symbol() function to turn on the three digits
on the right side of the LCD. I followed the method shown in the
CCS example file, Ex_LCD92.c. At this time, I don't have any code
to turn on the left-most '1' digit, or the decimal points, or any of the
special segments such as the diode or "low battery" segments.


Code:
#include <16F917.H>
#fuses INTRC_IO, NOWDT, NOPROTECT, NOBROWNOUT, PUT
#use delay(clock=8000000)

// The LCD digits are numbered in the following way, 
// according to the Varitronix VIM-332-DP data sheet.
//            _    _    _
//        |  |_|  |_|  |_|
//        |  |_|  |_|  |_|
//                     
// Digit  4   3    2    1
//

// The CCS lcd_symbol() function will be used to display digits
// 1, 2, and 3. The following define statements tell the
// lcd_symbol() function which PIC pins are connected to the
// LCD segment pins.
// There is a table on page 58 of the PicDem Mechatronics
// Demonstration Board data sheet which lists the connections
// that are used to make these define statements.
//
// Digit segments  A        B        C        D        E        F        G        DP
//                 b7       b6       b5       b4       b3       b2       b1       b0
#define DIGIT3  COM0+3,  COM0+11, COM2+11, COM3+3 , COM2+3,  COM1+3,  COM1+11, COM3+2
#define DIGIT2  COM0+6,  COM0+21, COM2+21, COM3+6,  COM2+6,  COM1+6,  COM1+21, COM3+11
#define DIGIT1  COM0+22, COM0+23, COM2+23, COM3+22, COM2+22, COM1+22, COM1+23, COM3+21

// The following array tells the CCS lcd_symbol() function which
// segments to turn on, to display the numbers from 0 to 9.
//                            0    1    2    3    4    5    6    7    8    9
byte 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 LCDDATA6 = 0x116
#bit  seg_4bc = LCDDATA6.2   // Controls left-most digit ("1")

int8 lcd_pos; 

//-----------------------------------------------
void lcd_putc(char c)
{
int8 segments;

if(c == '\f')
  {
   lcd_pos = 0;
  }
else
  {
   if((c >= '0') && (c <= '9'))
      segments = Digit_Map[c - '0'];
   else
      segments = BLANK;

   switch(lcd_pos)
     {
      case 1:           // 1000's digit (left-most digit on lcd)
        if(c == '1')        // Is the top digit = 1 ?
           seg_4bc = 1;     // If so, display it
        else                // If it's not = 1, don't display it.
           seg_4bc = 0;   
        break;
   
      case 2: lcd_symbol(segments, DIGIT3); break; // 100's digit
      case 3: lcd_symbol(segments, DIGIT2); break; // 10's digit
      case 4: lcd_symbol(segments, DIGIT1); break; // 1's digit
     }
  }

lcd_pos++;
}

//===================================
void main()
{
int16 number;

setup_lcd(LCD_MUX14 | LCD_BIAS_PINS, 0);

number = 1234;

printf(lcd_putc,"\f%4lu",number);   // Always send 4 digits

while(1);


-------
Edit:
Updated the code so that it's the same as the code shown on page 2 of
this thread. The code above incorporates two bug fixes, and it adds the
ability to display the left-most digit.


Last edited by PCM programmer on Tue Sep 16, 2008 6:01 pm; edited 2 times in total
Sebastian20000



Joined: 09 Nov 2007
Posts: 12

View user's profile Send private message

PostPosted: Mon Nov 26, 2007 12:25 pm     Reply with quote

Hi,
I test the program today and it works!
Thanks a lot.

One further question:

I don´t understand the line: c - '0' in the array:

Code:
segments = Digit_Map[c - '0'];
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Nov 27, 2007 2:10 pm     Reply with quote

Quote:
I don´t understand the line: c - '0' in the array:

segments = Digit_Map[c - '0'];

The lcd_putc() function expects to receive an ASCII number from 0 to 9
as the input value. ASCII numbers '0' to '9' have hex values of 0x30
to 0x39.

The code needs to use the input value as an index into the Digit_Map
array. But to do this, it must subtract off the ASCII "bias" of 0x30.
In other words, input values of 0x30 to 0x39 need to be converted to
values of 0x00 to 0x09. Then you can use it as an index into an
array which has 10 elements in it.

You could write the code to subtract the ASCII bias as
Quote:
c - 0x30

but it's very common for programmers to write it as
Quote:
c - '0'

because it shows very clearly that you're working with ASCII characters,
and that the base value of your index is derived from the ASCII number '0'.
Guest








Help on LCD of Mechatronics Demo board
PostPosted: Fri Sep 12, 2008 9:32 am     Reply with quote

I just copy and paste the code above and when I compile. The following error encounter.

Quote:

Executing: "C:\CCS_PIC\PCM\PICC\Ccsc.exe" "lcd.c" +FM +DF +LN +T -A +M +Z +Y=9 +EA
*** Error 12 "C:\PICC Experiment\Mechantronic\lcd.c" Line 69(23,36): Undefined identifier LCD_BIAS_PINS
1 Errors, 0 Warnings.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Sep 12, 2008 10:01 am     Reply with quote

That constant is defined in all the 16F91x header files:
Quote:

c:\program files\picc\devices\16f913.h
#define LCD_BIAS_PINS 0x10

c:\program files\picc\devices\16f914.h
#define LCD_BIAS_PINS 0x10

c:\program files\picc\devices\16f916.h
#define LCD_BIAS_PINS 0x10

c:\program files\picc\devices\16f917.h
#define LCD_BIAS_PINS 0x10

If you don't have that #define statement, you're probably not using a
16F91x PIC. Or maybe you have a very old compiler version.
Guest








PostPosted: Fri Sep 12, 2008 10:13 am     Reply with quote

How to put all 4 digits on to the LCD.

e.g.

I want to output ADC channel 0 to the LCD, the min result = 0, the max= 1023.

What should I add to the code to do that?

Also anyone know the actual manf. # of the LCD so I can look at the datasheet.

Thanks..
dyeatman



Joined: 06 Sep 2003
Posts: 1922
Location: Norman, OK

View user's profile Send private message

PostPosted: Fri Sep 12, 2008 10:17 am     Reply with quote

According to the postings above it is:

Varitronix VIM-332

Here are the data sheets.

http://www.varitronix.com/LCDsearch.php?u=&query1=&page=6
Guest








PostPosted: Fri Sep 12, 2008 11:48 am     Reply with quote

I have PCM Ver 3.249
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Sep 12, 2008 12:17 pm     Reply with quote

In vs. 3.249 they didn't have the LCD_BIAS_PINS constant in the
16F917.H file. They added it later in vs. 4.xxx. All the rest of the
LCD constants in the .H file are the same in both versions.

Maybe during the weekend I'll look at it and see what's necessary
to add support for the 1st digit (which can only display '1').
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Sep 15, 2008 3:16 pm     Reply with quote

Quote:
How to put all 4 digits on to the LCD ?

I'm working on this problem.

I don't have the PicDem Mechatronics board, so I can't physcially test
the code. I have a question. When you run the driver and the test
program that I posted earlier in this thread, what does it display on
the LCD ? Post what you see.
Guest








PostPosted: Tue Sep 16, 2008 7:41 am     Reply with quote

If comment out like this

setup_lcd(LCD_MUX14, 0); // | LCD_BIAS_PINS, 0);

I can compile it and "432" show on the LCD instead of "234"
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Sep 16, 2008 11:13 am     Reply with quote

I always thought those digits were reversed, but the person I was working
with at the time, said everything was OK. I don't have the Mechatronics
board and you can't buy the VIM-332-DP LCD (apparently), so I could
never test it in hardware.

Your version of the compiler is missing this #define statement from
the 16F917.H file. Just add the following line to the program. Put it
in the area below the #use delay() statement, where the other #define
statements are located.
Code:
#define LCD_BIAS_PINS     0x10



The code below should work better. I've corrected the reversed digits
problem and I've added support for the left-most digit ("1").
Code:

#include <16F917.H>
#fuses INTRC_IO, NOWDT, NOPROTECT, NOBROWNOUT, PUT
#use delay(clock=8000000)

// The LCD digits are numbered in the following way, 
// according to the Varitronix VIM-332-DP data sheet.
//            _    _    _
//        |  |_|  |_|  |_|
//        |  |_|  |_|  |_|
//                     
// Digit  4   3    2    1
//

// The CCS lcd_symbol() function will be used to display digits
// 1, 2, and 3. The following define statements tell the
// lcd_symbol() function which PIC pins are connected to the
// LCD segment pins.
// There is a table on page 58 of the PicDem Mechatronics
// Demonstration Board data sheet which lists the connections
// that are used to make these define statements.
//
// Digit segments  A        B        C        D        E        F        G        DP
//                 b7       b6       b5       b4       b3       b2       b1       b0
#define DIGIT3  COM0+3,  COM0+11, COM2+11, COM3+3 , COM2+3,  COM1+3,  COM1+11, COM3+2
#define DIGIT2  COM0+6,  COM0+21, COM2+21, COM3+6,  COM2+6,  COM1+6,  COM1+21, COM3+11
#define DIGIT1  COM0+22, COM0+23, COM2+23, COM3+22, COM2+22, COM1+22, COM1+23, COM3+21

// The following array tells the CCS lcd_symbol() function which
// segments to turn on, to display the numbers from 0 to 9.
//                            0    1    2    3    4    5    6    7    8    9
byte 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 LCDDATA6 = 0x116
#bit  seg_4bc = LCDDATA6.2   // Controls left-most digit ("1")

int8 lcd_pos; 

//-----------------------------------------------
void lcd_putc(char c)
{
int8 segments;

if(c == '\f')
  {
   lcd_pos = 0;
  }
else
  {
   if((c >= '0') && (c <= '9'))
      segments = Digit_Map[c - '0'];
   else
      segments = BLANK;

   switch(lcd_pos)
     {
      case 1:           // 1000's digit (left-most digit on lcd)
        if(c == '1')        // Is the top digit = 1 ?
           seg_4bc = 1;     // If so, display it
        else                // If it's not = 1, don't display it.
           seg_4bc = 0;   
        break;
   
      case 2: lcd_symbol(segments, DIGIT3); break; // 100's digit
      case 3: lcd_symbol(segments, DIGIT2); break; // 10's digit
      case 4: lcd_symbol(segments, DIGIT1); break; // 1's digit
     }
  }

lcd_pos++;
}

//===================================
void main()
{
int16 number;

setup_lcd(LCD_MUX14 | LCD_BIAS_PINS, 0);

number = 1234;

printf(lcd_putc,"\f%4lu",number);   // Always send 4 digits

while(1);
}


Last edited by PCM programmer on Tue Sep 16, 2008 11:33 am; edited 1 time in total
Guest








PostPosted: Tue Sep 16, 2008 11:28 am     Reply with quote

Thanks...

It works like a champ!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Sep 16, 2008 11:36 am     Reply with quote

I added a comment in my post about adding the LCD_BIAS_PINS
definition to your program. That's in there because the demo program
from Microchip (written in MPASM) has the bias pins enabled. So
supposedly they think it's necessary.
Guest








PostPosted: Tue Sep 16, 2008 1:04 pm     Reply with quote

I try to understand the following

Can you explain how these work relate to LCD?

Quote:
#define DIGIT1 COM0+22, COM0+23, COM2+23, COM3+22, COM2+22, COM1+22, COM1+23, COM3+21


Sorry, I new to this. I try to compare your line above to the mapping worksheet that came with the demo board and still don't get it. Again what is COM0+22 and etc.?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2, 3  Next
Page 1 of 3

 
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