|
|
View previous topic :: View next topic |
Author |
Message |
Guest
|
|
Posted: Tue Sep 16, 2008 1:04 pm |
|
|
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
|
|
Posted: Tue Sep 16, 2008 1:30 pm |
|
|
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
|
|
Posted: Wed Sep 17, 2008 2:20 pm |
|
|
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
|
|
Posted: Wed Sep 17, 2008 3:29 pm |
|
|
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
|
|
Posted: Fri Sep 19, 2008 1:30 pm |
|
|
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
|
|
Posted: Fri Sep 19, 2008 2:12 pm |
|
|
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
|
|
Posted: Wed Jan 19, 2011 8:57 pm |
|
|
I will try it. |
|
|
pic_micro
Joined: 07 Feb 2011 Posts: 26
|
how to display diode symbol onMechatronic board |
Posted: Mon Feb 07, 2011 3:26 pm |
|
|
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.. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Feb 07, 2011 3:54 pm |
|
|
Add the 3 lines (in bold) above the #bit lines, as shown below:
Quote: |
#byte LCDSE0 = 0x11C
#byte LCDSE1 = 0x11D
#byte LCDSE2 = 0x11E
#bit SEG0 = LCDSE0.0
#bit SEG1 = LCDSE0.1
#bit SEG16 = LCDSE2.0 |
|
|
|
pic_micro
Joined: 07 Feb 2011 Posts: 26
|
special symbol on mechatronic LCD |
Posted: Mon Feb 07, 2011 7:41 pm |
|
|
It works.
Can you explain the following? I just want to understand see if I can put others symbols on the LCD
#byte LCDSE0 = 0x11C
#byte LCDSE1 = 0x11D
#byte LCDSE2 = 0x11E
0x11C, etc. are these the addresses?
Thanks in advance. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
pic_micro
Joined: 07 Feb 2011 Posts: 26
|
How to display the DP (decimal point) on the mechatronic LCD |
Posted: Mon Feb 07, 2011 10:26 pm |
|
|
PCM,
Thanks so much,
I would like to ask you one more question, how about the DP
Any suggestion? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Feb 07, 2011 11:58 pm |
|
|
Why don't you try to write the code for the DP's. |
|
|
pic_micro
Joined: 07 Feb 2011 Posts: 26
|
display DP on mechatronic board |
Posted: Tue Feb 08, 2011 12:33 pm |
|
|
FILE NAME: mech_seg_driver.c
Code: | /*
FILE NAME mech_seg_driver.c
I increase the Digit_Map to 11 and I add 0x01 to represent DP
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
// special symbols
#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)
#define display_volt(x) x? bit_set(LCDDATA3, 0) : bit_clear(LCDDATA3,0)
#define display_ohm(x) x ? bit_set(LCDDATA9, 0) : bit_clear(LCDDATA9, 0)
#define display_satellite(x) x ? bit_set(LCDDATA2, 0) : bit_clear(LCDDATA2, 0)
#define display_minus(x) x ? bit_set(LCDDATA6, 1) : bit_clear(LCDDATA6, 1);
#define display_AC(x) x ? bit_set(LCDDATA9, 1) : bit_clear(LCDDATA9, 1);
#define display_m(x) x ? bit_set(LCDDATA8, 0) : bit_clear(LCDDATA8, 0);
#define display_A(x) x ? bit_set(LCDDATA0, 0) : bit_clear(LCDDATA0, 0);
#define display_K(x) x ? bit_set(LCDDATA6, 0 ) : bit_clear(LCDDATA6, 0);
#define display_M(x) x ? bit_set(LCDDATA11, 0 ) : bit_clear(LCDDATA11, 0);
#define display_RC(x) x ? bit_set(LCDDATA0, 1 ) : bit_clear(LCDDATA0, 1);
#define display_RH(x) x ? bit_set(LCDDATA3, 2 ) : bit_clear(LCDDATA3, 2);
#define display_DH(x) x ? bit_set(LCDDATA0, 2 ) : bit_clear(LCDDATA0, 2);
// 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 DP
byte const Digit_Map[11] = {0xFC,0x60,0xDA,0xF2,0x66,0xB6,0xBE,0xE0,0xFE,0xE6,0x01};
#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
#byte LCDSE0 = 0x11C
#byte LCDSE1 = 0x11D
#byte LCDSE2 = 0x11E
#bit SEG0 = LCDSE0.0
#bit SEG1 = LCDSE0.1
#bit SEG16 = LCDSE2.0
#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++;
}
|
FILENAME main.c
I can display the dp into the LCD with the "lcd_symbol(0x01, DIGIT1); " but I am out of ideal how to implement it into the void lcd_putc(char c) function.
Code: | #include <mechatronic.h>
#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);
while(1)
{
/*
value = 1234;
display_diode(FALSE);
if(value < 600)
{
output_high(LED);
output_low(LED2);
display_batt(TRUE); // Batt symbol
display_volt(TRUE); // V symbol
display_ohm(FALSE); // Ohm symbol
display_satellite(TRUE); // Satellite symbol
display_minus(TRUE); // - sign symbol
display_AC(TRUE); // AC symbol
display_m(TRUE); // m symbol
display_A(TRUE); // A symbol
display_K(TRUE); // K symbol
display_M(TRUE); // M symbol
display_RC(TRUE); // RC symbol
display_RH(TRUE); // RH symbol
display_DH(TRUE); // DH symbol
display_diode(TRUE); // diode symbol
}
if(value >600)
{
output_high(LED2);
output_low(LED);
display_batt(FALSE);
display_volt(FALSE);
display_ohm(TRUE);
}
*/
// printf(lcd_putc,"\f%4lu",value); // Always send 4 digits
lcd_symbol(0x01, DIGIT1); // display s2dp
lcd_symbol(0x01, DIGIT2); // display s3dp
lcd_symbol(0x01, DIGIT3); // display s4dp
/* I can display the dp into the LCD with the above lines, but I don't know now to map or use it without the "lcd_symbol(0x01, DIGIT1); "
*/
}
}
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Feb 08, 2011 3:08 pm |
|
|
Quote: | I can display the dp into the LCD with the above lines, but I don't
know now to map or use it without the "lcd_symbol(0x01,DIGIT1); |
You were able to make code to display all the other symbols, as shown
below. Try to do the same thing for the 2DP, 3DP, and 4DP symbols:
Code: | // special symbols
#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) |
Quote: | but I am out of ideas how to implement it into the void lcd_putc(char c) function. |
You're giving lcd_putc() a sequence of ASCII numbers, one character at a
time, for example, "1.234". So clearly at some point, the lcd_putc()
routine will get the '.' character as a parameter. You need to add code to
lcd_putc() to handle it. Add an "if" (or "else if") statement for it. Make
sure you don't increment the lcd_pos variable if you are handling the
decimal point. |
|
|
|
|
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
|