|
|
View previous topic :: View next topic |
Author |
Message |
lboghy
Joined: 04 Jun 2008 Posts: 23
|
LCD code using PIC16F193x |
Posted: Thu Jul 28, 2011 4:43 am |
|
|
Can anyone help me. I have a demo board with PIC16f1937 and LCD on it without any documentation about it. I don't know which kind of driver to build or to use for this LCD. All I know is that has 14 pins, the bias voltage is 3.072 volts, is 1/4, the clock should be 31 KHz.
Thank you. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Thu Jul 28, 2011 8:25 am |
|
|
quick ideas...
1) Since it's a demo board, 1st contact the manufacture, the distributor, reseller or wherever you bought it.
2) Google the info to see what's 'on the Web'.
3)Post the info about the board(make/model/mfr) here maybe someone has knowledge about it |
|
|
lboghy
Joined: 04 Jun 2008 Posts: 23
|
demoboard name |
Posted: Fri Jul 29, 2011 6:21 am |
|
|
Hello, the demo board is dm164130-1.
I found on the net some functions but are for Microchip compiler not ccs.
Thank you. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jul 29, 2011 4:56 pm |
|
|
Try this code. I don't have this board, so I don't guarantee that it works.
I modified some existing code to work with the LCD on the F1 Evaluation
Platform board. I tried to follow the register settings in the Microchip
sample code. This code will only display the main digits. There is no
support for decimal points or symbols. I don't have any more time to
work on it today.
Code: |
#include <16LF1937.H>
#fuses INTRC_IO, NOWDT, BORV19, NOPUT, PLL_SW
#use delay(clock=32M)
// 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.
// The connection data was derived from the Microchip file,
// seven_seg.h, which is in the sample code for the F1 board
// on the Microchip website.
//
// Digit segments A B C D E F G DP
// b7 b6 b5 b4 b3 b2 b1 b0
#define DIGIT3 COM0+2, COM0+4, COM2+4, COM3+2, COM2+2, COM1+2, COM1+4, COM3+1
#define DIGIT2 COM0+5, COM0+10, COM2+10, COM3+5, COM2+5, COM1+5, COM1+10, COM3+4
#define DIGIT1 COM0+12, COM0+16, COM2+16, COM3+12, COM2+12, COM1+12, COM1+16, COM3+10
// 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 = 0x7A6
#bit seg_4bc = LCDDATA6.1 // 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 clear_lcd(void)
{
#byte LCDDATA0 = 0x7A0;
#byte LCDDATA1 = 0x7A1;
#byte LCDDATA2 = 0x7A2;
#byte LCDDATA3 = 0x7A3;
#byte LCDDATA4 = 0x7A4;
#byte LCDDATA5 = 0x7A5;
#byte LCDDATA6 = 0x7A6;
#byte LCDDATA7 = 0x7A7;
#byte LCDDATA8 = 0x7A8;
#byte LCDDATA9 = 0x7A9;
#byte LCDDATA10 = 0x7AA;
#byte LCDDATA11 = 0x7AB;
LCDDATA0 = 0;
LCDDATA1 = 0;
LCDDATA2 = 0;
LCDDATA3 = 0;
LCDDATA4 = 0;
LCDDATA5 = 0;
LCDDATA6 = 0;
LCDDATA7 = 0;
LCDDATA8 = 0;
LCDDATA9 = 0;
LCDDATA10 = 0;
LCDDATA11 = 0;
}
//===================================
void main()
{
int16 number;
setup_adc_ports(NO_ANALOGS); // This fixes a bug in CCS start-up code
setup_oscillator(OSC_INTRC | OSC_PLL_ON | OSC_8MHZ);
setup_timer_1(T1_EXTERNAL_SYNC | T1_ENABLE_T1OSC | T1_DIV_BY_1);
//delay_ms(5000); // What is the start-up delay time for T1OSC ?
clear_lcd();
// Setup for a 1:4 mux LCD and enable 10 specific segment pins.
setup_lcd(LCD_TYPE_B | LCD_MUX14 | LCD_BIAS13 | LCD_REF_ENABLED
| LCD_B_HIGH_POWER | LCD_TIMER1,
0, 0x131437);
lcd_contrast(7);
number = 1234;
printf(lcd_putc,"\f%4lu",number); // Always send 4 digits
while(1);
} |
|
|
|
lboghy
Joined: 04 Jun 2008 Posts: 23
|
code don't works |
Posted: Fri Jul 29, 2011 10:09 pm |
|
|
I put the code that sent but the 4.093 compiler don't recognize <lcd_contrast(7)>, on setup_lcd dont recognize LCD_TYPE_B , LCD_BIAS13, LCD_REF_ENABLED, LCD_B_HIGH_POWER and LCD_TIMER1.
Thank you. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jul 29, 2011 11:17 pm |
|
|
I compiled it with vs. 4.124. Maybe I'll look at it again with your verison
in a few days. I can't do it now. |
|
|
lboghy
Joined: 04 Jun 2008 Posts: 23
|
THANK YOU |
Posted: Sat Jul 30, 2011 10:52 am |
|
|
thank you very much |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jul 31, 2011 1:58 pm |
|
|
I looked at compiling the program with vs. 4.093. I was able to fix a few
things in the function parameters, etc., to make compile. But then I
looked at the .LST file, and it's incorrect for the lcd_symbol() function.
This is the function that sets or clears bits in the LCDDATAx registers in
the PIC, in order to turn lcd segments on or off. The bank select
registers are set incorrectly in vs. 4.093. The LCDDATAx registers are
in bank 15, but v4.093 selects bank 2. It's just totally wrong. Your
compiler version isn't going to work.
It might be easier to take the sample Hi-tech code for the F1 board
and convert it to CCS. You would have to write a lot of #byte and #bit
statements to do this. That's because the Hi-Tech lcd code writes directly
to PIC registers and bits in the registers.
Look at lcd.c, lcd.h, and seven_segment.h:
http://ww1.microchip.com/downloads/en/DeviceDoc/F1%20Release%201-4a.zip |
|
|
juinhooley
Joined: 02 Aug 2011 Posts: 10
|
|
Posted: Tue Aug 02, 2011 1:17 am |
|
|
Hi,
I compiled this code with version 4.124 and downloaded onto the F1 Evaluation Platform.
Segment a, d, e and f of digit 3 always stay off.
I know that the LCD display is good. It works with the microchip LCD_Demo_Code.
Any idea why? |
|
|
lboghy
Joined: 04 Jun 2008 Posts: 23
|
Thank you |
Posted: Tue Aug 02, 2011 1:45 pm |
|
|
Thank you for your prompt response.
So, I have 2 solutions:
- buy the last version of the CCS;
- work with Hitech functions.
Now I don't know which solution is better. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Aug 02, 2011 3:03 pm |
|
|
Quote: | Segment a, d, e and f of digit 3 always stay off.
|
Let's try to figure out why.
If we look at the lcd.c file in the Microchip F1 sample code, we see this:
Code: |
// Glass pin 7
#define A3 SEG2COM0
#define F3 SEG2COM1
#define E3 SEG2COM2
#define D3 SEG2COM3
|
These are the pins you're talking about. They are all on pin 7 of the LCD.
(The call the LCD the "glass"). The F1 board schematic shows that pin 7
connects to pin RA7 on the 16F1937.
So if those lcd segments aren't working, it could be that the physical
connection between the PIC pin and the LCD is bad. But you said the
board works with the Microchip sample code, so the connection is probably OK.
It could also be that the something isn't configured correctly with regard
to pin A7. Is it possible that you changed the INTRC_IO fuse to INTRC ? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Aug 02, 2011 3:25 pm |
|
|
Quote: | So, I have 2 solutions:
- buy the last version of the CCS;
- work with Hitech functions
|
3rd solution. Edit the HiTech code to make it be compatible with CCS,
by declaring all the registers and bits with #byte and #bit statements.
Example. In the test program below, I've added some of the #byte and
#bit statements necessary to define the symbols in the HiTech code so
it will compile with CCS.
If you have the full IDE version of the CCS compiler, you can probably
get the compiler to do most of the work for you. Go into the Device
Editor screen for your PIC and there should be a button to push, which
will generate the register addresses and maybe the bit structures.
I don't have the full IDE so I can't do this. I had to look at the PIC data
sheet to see the register addresses and the bit positions within the registers.
Code: |
#include <16LF1937.H>
#fuses INTRC_IO, NOWDT, BORV19, NOPUT, PLL_SW
#use delay(clock=32M)
#byte LCDPS = 0x792
#bit WFT = LCDPS.7
struct
{
int8 LP : 4;
int8 WA : 1;
int8 LCDA: 1;
int8 BIASMD: 1;
int8 WFT: 1;
}LCDPSbits;
#locate LCDPSbits = LCDPS
#byte T1CON = 0x18
#bit T1OSCEN=T1CON.3
#byte LCDSE0 = 0x798
#byte LCDSE1 = 0x799
#byte LCDSE2 = 0x79A
//-------------------------------------
void lcd_init(void)
{
// Configure LCDPS
// Wave form type A or B
// Bias Mode
// Prescaler
// 1:16 - 1:1
LCDPS = 0;
WFT = 1; // B type
LCDPSbits.LP = 0;
T1OSCEN = 1; // activate the 32khz oscillator for our clock source
/**********************************************/
/* User is responsible to enable the needed segments */
/* Replace the code in the next 3 lines for your glass */
/******************************************/
LCDSE0 = 0x37;
LCDSE1 = 0x14;
LCDSE2 = 0x13;
.
.
.
// etc.
}
//==========================
void main()
{
lcd_init();
while(1);
} |
|
|
|
juinhooley
Joined: 02 Aug 2011 Posts: 10
|
|
Posted: Wed Aug 03, 2011 6:48 pm |
|
|
I didn't have any INTRC fuse at all. These segments now work after setting the fuse to INTRC_IO.
Good hint. Thanks! |
|
|
|
|
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
|