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 on segmented LCD
Goto page Previous  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
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.?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

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

I assume you're looking at the chart on page 58 (page 62 in Acrobat
reader) in the PicDem Mechatronics Demonstration Board User's Guide:
http://ww1.microchip.com/downloads/en/DeviceDoc/51557C.pdf

Here's the Varitronix VIM-332 LCD data sheet:
http://www.varitronix.com/Product/LCD/VIM-332-DP(R0).pdf
Look at page 2. It shows the digit numbers. Digit #1 is on the right side.
Now look at page 3. It shows the segment letters. Segment "A" is at
the top of each digit.

Now look at the chart on page 58 of the Mechatronics User's Guide again.
Down near the bottom left corner, you can see segment "1A". Notice
that segment "1A" corresponds to "COM0" and "SEG22".
That's how we get the first item in this #define statement.
Code:
#define DIGIT1 COM0+22, COM0+23, COM2+23, COM3+22, COM2+22, COM1+22, COM1+23, COM3+21

Notice the next item above is "COM0+23". Go look in the chart in the
User's Guide for segment "1B". Notice that it is in the column for COM0
and it's in the row for SEG23. That's how the chart can be converted to
the CCS #define statements.

This only works for the digits. For individual feature symbols, such as
a "Diode" or "BATT", you have to turn them on/off individually, with lines
of code.
newpic



Joined: 09 Aug 2005
Posts: 32

View user's profile Send private message

PostPosted: Wed Sep 17, 2008 2:20 pm     Reply with quote

PCM Programmer,

Any sample code to turn on the battery icon?
You have mentioned that need individual lines to turn these. Can you give sample code?

Thank you
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Sep 17, 2008 3:29 pm     Reply with quote

To add support for the symbols, you need to do this:

1. Add #byte statements to your program that declare the addresses of
all the LCDDATA registers.

2. Add macros that allow individual bits of the LCDDATA registers to be
set or cleared. There will be one macro per symbol. The reason for
using macros instead of functions is that it takes only one line of source
code to write it, and it compiles to only 1 or 2 lines of ASM code.


Let's do the "Diode" symbol on the Mechatronics LCD.

First, look at the Varitronix LCD data sheet, and find the name that
they give to the "Diode" symbol. It's in the upper right corner of the
diagram on page 2. They call it "S2".
http://www.varitronix.com/Product/LCD/VIM-332-DP(R0).pdf


Now look at the Mechatronics User's Guide. Look at the table
on page 58 (page 62 in the Acrobat reader). This table shows
what bit of each LCDDATA register is assigned to each segment
or symbol on the Mechatronics LCD. You can see that "S2" is in
the 2nd column, and it's assigned to bit 0 of the LCDDATA5 register.
http://ww1.microchip.com/downloads/en/DeviceDoc/51557C.pdf

Now you have enough information to write the code.
First, look at the SFR register addresses in the 16F917 data sheet.
Create all the byte statements that declare the register addresses.
Code:

#byte LCDDATA0  = 0x110
#byte LCDDATA1  = 0x111
#byte LCDDATA2  = 0x112
#byte LCDDATA3  = 0x113
#byte LCDDATA4  = 0x114
#byte LCDDATA5  = 0x115
#byte LCDDATA6  = 0x116
#byte LCDDATA7  = 0x117
#byte LCDDATA8  = 0x118
#byte LCDDATA9  = 0x119
#byte LCDDATA10 = 0x11A
#byte LCDDATA11 = 0x11B 
 


Now write the macro for the diode symbol. The parameter 'x' will be
either TRUE or FALSE. In C, a "true" value is one that is non-zero.
So we can use a "conditional" test to check if 'x' is non-zero. If it is,
then set the LCDDATA5.0 bit. If 'x' is zero, then clear the bit:
Code:
#define display_diode(x) x ? bit_set(LCDDATA5, 0) : bit_clear(LCDDATA5, 0)

Then in your program, to turn on the Diode symbol, you would do this:
Code:
display_diode(TRUE);

To turn it off, you do this:
Code:
display_diode(FALSE);



In a similar way, you can do the "BATT" symbol. From the Mechatronics
data sheet table, you can see that it's assigned to LCDDATA3, bit 1.
So the macro would look like this:
Code:
#define display_batt(x)  x ? bit_set(LCDDATA3, 1) : bit_clear(LCDDATA3, 1)
newpic



Joined: 09 Aug 2005
Posts: 32

View user's profile Send private message

PostPosted: Fri Sep 19, 2008 1:30 pm     Reply with quote

It does not work. The diode will not turn on.

Here is my code.

Code:
#include <16F917.H>
#device ICD=TRUE ADC=10
#fuses INTRC_IO, NOWDT, NOPROTECT, NOBROWNOUT, PUT
#use delay(clock=8000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)




#define display_diode(x) x ? bit_set(LCDDATA5, 0) : bit_clear(LCDDATA5, 0)
#define display_batt(x) x ? bit_set(LCDDATA3, 1) : bit_clear(LCDDATA3, 1)



#byte LCDDATA3  = 0x113
#byte LCDDATA5  = 0x115




//===================================

void main()
{
   int16 number,result;
   float temp;
   setup_lcd(LCD_MUX14 | LCD_BIAS_PINS, 0);

 
   while(1)
   {

   
      display_diode(TRUE);
      delay_ms(5000);
      display_diode(FALSE);
      delay_ms(5000);


//      display_batt(TRUE);

   
      
   
   }
   
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Sep 19, 2008 2:12 pm     Reply with quote

That's because the segment drivers are not enabled for the symbols.
I didn't realize this. The CCS routines only turn on the segments
that are specified when the lcd_symbol() function is called. For the
symbols, we need to separately enable the segment drivers with
our own code.

I don't have a Mechatronics board to test, and Digikey and Mouser
(the two main Varitronix LCD distributors) don't sell the VIM-332 LCD.
So I depend upon you to test the code.


To turn on the segment drivers for the symbols, you need to add this
code above main().
Code:

#bit SEG0 = LCDSE0.0
#bit SEG1 = LCDSE0.1
#bit SEG16 = LCDSE2.0

#define enable_symbol_segments(x) SEG0 = x; SEG1 = x; SEG16 = x



Then in main(), add the following line after the call to setup_lcd().
Code:
enable_symbol_segments(TRUE);


This will turn on the 3 segment drivers for all symbols. According to
the table at the end of the Mechatronics User's Guide, the symbols are
all on SEG0, SEG1, or SEG16. So this should work.
newpic



Joined: 09 Aug 2005
Posts: 32

View user's profile Send private message

PostPosted: Wed Jan 19, 2011 8:57 pm     Reply with quote

I will try it.
pic_micro



Joined: 07 Feb 2011
Posts: 26

View user's profile Send private message

how to display diode symbol onMechatronic board
PostPosted: Mon Feb 07, 2011 3:26 pm     Reply with quote

Dear PCM:

I've tried your code per the above instruction, when compile, I got these errors.


Code:
Executing: "C:\CCS_PIC\PCM\PICC\Ccsc.exe" "ex3.c" +FM +DF +LN +T -A +M +Z +Y=9 +EA
*** Error 12 "C:\chai\CProjects\PICC Experiment\CCS\mechatronic\ex3\ex3.c" Line 24(2,5): Undefined identifier   ?
*** Error 48 "C:\chai\CProjects\PICC Experiment\CCS\mechatronic\ex3\ex3.c" Line 24(11,15): Expecting a (
*** Error 48 "C:\chai\CProjects\PICC Experiment\CCS\mechatronic\ex3\ex3.c" Line 24(13,19): Expecting a (
*** Error 12 "C:\chai\CProjects\PICC Experiment\CCS\mechatronic\ex3\ex3.c" Line 29(1,35): Undefined identifier   ?
*** Error 12 "C:\chai\CProjects\PICC Experiment\CCS\mechatronic\ex3\ex3.c" Line 36(29,30): Undefined identifier   SEG0
*** Error 12 "C:\chai\CProjects\PICC Experiment\CCS\mechatronic\ex3\ex3.c" Line 36(29,30): Undefined identifier   SEG1
*** Error 12 "C:\chai\CProjects\PICC Experiment\CCS\mechatronic\ex3\ex3.c" Line 36(29,30): Undefined identifier   SEG16
      7 Errors,  0 Warnings.
Halting build on first failure as requested.
BUILD FAILED: Mon Feb 07 16:18:18 2011


See my code below:

File Name: ex3.c


Code:
#include <mechatronic.h>

#bit SEG0 = LCDSE0.0
#bit SEG1 = LCDSE0.1
#bit SEG16 = LCDSE2.0

#define enable_symbol_segments(x) SEG0 = x; SEG1 = x; SEG16 = x

void main()
{
   unsigned int16 value;
   unsigned int temp;

   // initial lcd
   setup_lcd(LCD_MUX14 | LCD_BIAS_PINS, 0);
   enable_symbol_segments(TRUE);

   // setup adc
   setup_adc(ALL_ANALOG);
   setup_adc( ADC_CLOCK_INTERNAL );
   set_adc_channel(0);
   

   while(1)
   {
      
      delay_ms(1);
      value = read_adc();
   //   value = 1234;
      
   

      temp =  (value/2) - 50;

      display_diode(TRUE);
         delay_ms(5000);

      
      printf(lcd_putc,"\f%u",temp);   // Always send 4 digits
   }
}



File name: mechatronic.h


Code:
/*
File name mechatronic.h, it is an include file
*/

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

#include <mech_seg_driver.c>

#define SW2   PIN_A4
#define SW3   PIN_A5


#define   LED   PIN_D7

//#byte d_port = 0x08

#bit LED2 = 0x08.7



File name: mech_seg_driver.c>

Code:
/*
FILE NAME mech_seg_driver.c 
It is the LCD driver for LCD VIM-332-DP that mount on the
mechatronic board
*/

// 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


#define display_diode(x) x ? bit_set(LCDDATA5, 0) : bit_clear(LCDDATA5, 0)
#define display_batt(x) x ? bit_set(LCDDATA3, 1) : bit_clear(LCDDATA3, 1)


// 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 LCDDATA0  = 0x110
#byte LCDDATA1  = 0x111
#byte LCDDATA2  = 0x112
#byte LCDDATA3  = 0x113
#byte LCDDATA4  = 0x114
#byte LCDDATA5  = 0x115
#byte LCDDATA6  = 0x116
#byte LCDDATA7  = 0x117
#byte LCDDATA8  = 0x118
#byte LCDDATA9  = 0x119
#byte LCDDATA10 = 0x11A
#byte LCDDATA11 = 0x11B 


#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++;
}


Please help me..
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 Previous  1, 2, 3  Next
Page 2 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