|
|
View previous topic :: View next topic |
Author |
Message |
Sebastian20000
Joined: 09 Nov 2007 Posts: 12
|
Help on segmented LCD |
Posted: Wed Nov 21, 2007 7:26 pm |
|
|
Hi,
I am using the CCS Compiler 4.042 and I am just rookie in programming.
I bought a test board from microchip.com which has an
lcd on board.
Now I just want to run this lcd. But I don´t know how to start.
Its a 39 segment display and my first idea is just to write a "hello world"
in this display.
Can anyone give me some hints how to start, or tell me some infomation links...
Sebastian |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Nov 21, 2007 7:31 pm |
|
|
Quote: | I bought a test board from microchip.com which
has an lcd on board. |
Post the name of the Microchip board. |
|
|
Sebastian20000
Joined: 09 Nov 2007 Posts: 12
|
|
Posted: Wed Nov 21, 2007 7:36 pm |
|
|
its called
PICDEM Mechatronics
Demonstration Board. |
|
|
Sebastian20000
Joined: 09 Nov 2007 Posts: 12
|
|
|
rberek
Joined: 10 Jan 2005 Posts: 207 Location: Ottawa, Canada
|
|
Posted: Thu Nov 22, 2007 11:12 am |
|
|
Why don't you look at the CD that comes with the board? It has all the user guides and several projects, including one that uses the LCD to make a digital clock (Project #4). It even has the MPLAB project with all the assembler code to make it go. If you're a beginner, that's a great place to start.
Even the link you provided has the PDF for the User Guide. |
|
|
Sebastian20000
Joined: 09 Nov 2007 Posts: 12
|
|
Posted: Thu Nov 22, 2007 12:02 pm |
|
|
Hi,
yes I know the project 4. But the project data on the cd are
.asm assembler files.
I want to program with "C" and not in assembler, therefore I bought CCS-Compiler. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Nov 22, 2007 5:43 pm |
|
|
I can look at the code later in the weekend, to see if it can easily be
translated to CCS LCD functions. Maybe on Sunday I can look at it. |
|
|
Sebastian20000
Joined: 09 Nov 2007 Posts: 12
|
|
Posted: Sat Nov 24, 2007 7:53 pm |
|
|
@pcm programmer
That would be nice. thx |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Nov 26, 2007 1:53 am |
|
|
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
|
|
Posted: Mon Nov 26, 2007 12:25 pm |
|
|
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
|
|
Posted: Tue Nov 27, 2007 2:10 pm |
|
|
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
but it's very common for programmers to write it as
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 |
Posted: Fri Sep 12, 2008 9:32 am |
|
|
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
|
|
Posted: Fri Sep 12, 2008 10:01 am |
|
|
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
|
|
Posted: Fri Sep 12, 2008 10:13 am |
|
|
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: 1939 Location: Norman, OK
|
|
|
|
|
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
|