View previous topic :: View next topic |
Author |
Message |
Futterama
Joined: 17 Oct 2005 Posts: 98
|
PIC16F916 and LCD driver module problem |
Posted: Thu Jan 26, 2006 4:23 am |
|
|
Hello forum,
I am trying to make the LCD driver module, in the PIC16F916, work.
I'm having trouble getting anything on the segment pins.
I have the PIC on a breadboard with 2 LEDs blinking, just to make sure the PIC is running.
I'm measuring the segment outputs with my scope - both compared to GND and the common pin.
I'm trying to use the PICs registers directly, avoiding any builtin functions in CCS because I would like to be in complete control (doing it the hard way = my own way ).
Here is my code in the .c file:
Code: | #include "916-LCDtest.h"
#byte RC = 0x07
#bit TRISC3 = 0x87.3
#bit TRISC4 = 0x87.4
// LCD registers
// LCDCON - Liquid Display Control Register
//#byte LCDCON = 0x107
#bit LMUX0 = 0x107.0 // Commons Select bits
#bit LMUX1 = 0x107.1 // Commons Select bits
#bit CS0 = 0x107.2 // Clock Source Select bits
#bit CS1 = 0x107.3 // Clock Source Select bits
#bit VLCDEN = 0x107.4 // LCD Bias Voltage Pins Enable bit (1=on, 0=off)
#bit WERR = 0x107.5 // LCD Write Failed Error bit (Read) (1=error, 0=no error)
#bit SLPEN = 0x107.6 // LCD Driver Enable in Sleep mode bit (1=off, 0=on)
#bit LCDEN = 0x107.7 // LCD Driver Enable bit (1=on, 0=off)
// LCDPS - LCD Prescaler Select Register
//#byte LCDPS = 0x108
#bit LP0 = 0x108.0 // LCD Prescaler Select bits
#bit LP1 = 0x108.1 // LCD Prescaler Select bits
#bit LP2 = 0x108.2 // LCD Prescaler Select bits
#bit LP3 = 0x108.3 // LCD Prescaler Select bits
#bit WA = 0x108.4 // LCD Write Allow Status bit (Read) (1=allowed, 0=not allowed)
#bit LCDA = 0x108.5 // LCD Active Status bit (Read) (1=on, 2=off)
#bit BIASMD = 0x108.6 // Bias Mode Select bit
#bit WFT = 0x108.7 // Waveform Type Select bit (1=Type-B, 0=Type-A)
// LCDSEn - LCD Segment Registers
//#byte LCDSEn = 0x11C // 0x11D 0x11E
#bit SEG0EN = 0x11C.0 // Segment Enable bits
#bit SEG1EN = 0x11C.1 // Segment Enable bits
#bit SEG2EN = 0x11C.2 // Segment Enable bits
#bit SEG3EN = 0x11C.3 // Segment Enable bits
#bit SEG4EN = 0x11C.4 // Segment Enable bits
#bit SEG5EN = 0x11C.5 // Segment Enable bits
#bit SEG6EN = 0x11C.6 // Segment Enable bits
#bit SEG7EN = 0x11C.7 // Segment Enable bits
#bit SEG8EN = 0x11D.0 // Segment Enable bits
#bit SEG9EN = 0x11D.1 // Segment Enable bits
#bit SEG10EN = 0x11D.2 // Segment Enable bits
#bit SEG11EN = 0x11D.3 // Segment Enable bits
#bit SEG12EN = 0x11D.4 // Segment Enable bits
#bit SEG13EN = 0x11D.5 // Segment Enable bits
#bit SEG14EN = 0x11D.6 // Segment Enable bits
#bit SEG15EN = 0x11D.7 // Segment Enable bits
// LCDDATAx - LCD Data Registers
//#byte LCDDATAx = 0x110 // 0x11A 0x11B
#bit LCDDAT0 = 0x110.0 // Pixel On bits
#bit LCDDAT1 = 0x110.1 // Pixel On bits
#bit LCDDAT2 = 0x110.2 // Pixel On bits
#bit LCDDAT3 = 0x110.3 // Pixel On bits
#bit LCDDAT4 = 0x110.4 // Pixel On bits
#bit LCDDAT5 = 0x110.5 // Pixel On bits
#bit LCDDAT6 = 0x110.6 // Pixel On bits
#bit LCDDAT7 = 0x110.7 // Pixel On bits
// LCDIF - LCD Interrupt Flag bit
#bit LCDIF = 0x0D.4
void main()
{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
// Set LCD prescaler to 1:16
LP0 = 1;
LP1 = 1;
LP0 = 1;
LP0 = 1;
// Enable segment 0
SEG0EN = 1;
SEG1EN = 0;
SEG2EN = 0;
SEG3EN = 0;
SEG4EN = 0;
SEG5EN = 0;
SEG6EN = 0;
SEG7EN = 0;
SEG8EN = 0;
SEG9EN = 0;
SEG10EN = 0;
SEG11EN = 0;
SEG12EN = 0;
SEG13EN = 0;
SEG14EN = 0;
SEG15EN = 0;
// Enable COM0 (Static drive)
LMUX1 = 0;
LMUX0 = 0;
// Set Type-A waveform
WFT = 0;
// Set Static Bias mode
BIASMD = 0;
// Set clock source to FOSC/8192
CS1 = 0;
CS0 = 0;
// Disable LCD Driver in sleep mode
SLPEN = 1;
// Set SEG0 on
LCDDAT0 = 1;
LCDDAT1 = 0;
LCDDAT2 = 0;
LCDDAT3 = 0;
LCDDAT4 = 0;
LCDDAT5 = 0;
LCDDAT6 = 0;
LCDDAT7 = 0;
// Clear LCD Interrupt Flag
LCDIF = 0;
// Disable LCD Bias Voltage Pins
VLCDEN = 0;
// Enable LCD Driver
LCDEN = 1;
TRISC3 = 0;
TRISC4 = 0;
while(1)
{
RC = RC | 0b00011000; // Set 2 bits high
delay_ms(50);
RC = RC & ~0b00011000; // Set 2 bits low
delay_ms(800);
}
}
|
Here is my code in the .h file:
Code: | #include <16F916.h>
#device adc=8
#fuses NOWDT,INTRC_IO, NOPUT, NOPROTECT, NOMCLR, NOCPD, BROWNOUT, NOIESO, NOFCMEN, NODEBUG
#use delay(clock=8000000)
|
If you have a simple example with the CCS builtin functions, please post that also, I just wanna make the LCD module work right now.
Regards,
Futterama
Last edited by Futterama on Tue Jan 31, 2006 1:24 am; edited 1 time in total |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jan 26, 2006 11:20 am |
|
|
Quote: | RC = RC & !0b00011000; // Set 2 bits low |
The '!' symbol is a logical NOT operator. Because your constant
value is non-zero, the '!' operator will convert it to zero.
So you are ANDing 'RC' with 0x00.
You should use the bit-wise inversion operator '~' instead. |
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Thu Jan 26, 2006 12:05 pm |
|
|
That's a classic! |
|
|
Futterama
Joined: 17 Oct 2005 Posts: 98
|
|
Posted: Thu Jan 26, 2006 2:37 pm |
|
|
Thanks for the comments, but it really doesn't solve my problem, and I wrote a comment: "Please ignore the rest, it's only blinking LEDs".
But thanks anyway, I'll correct this.
But what about the LCD module? |
|
|
drh
Joined: 12 Jul 2004 Posts: 192 Location: Hemet, California USA
|
|
Posted: Fri Jan 27, 2006 9:36 am |
|
|
Are the multiplex and bias setting correct for the LCD you are using? _________________ David |
|
|
Futterama
Joined: 17 Oct 2005 Posts: 98
|
|
Posted: Tue Jan 31, 2006 1:22 am |
|
|
drh wrote: | Are the multiplex and bias setting correct for the LCD you are using? |
Yes, the display uses static drive, so I set it up like this:
Multiplex type: "Static (only COM0 used)" - LMUX1 = 0, LMUX0 = 0
Bias type: "Static Bias (2 voltage levels: VSS and VDD)" - BIASMD = 0
I just updated the code I posted, to include some comments. |
|
|
Futterama
Joined: 17 Oct 2005 Posts: 98
|
|
Posted: Tue Jan 31, 2006 3:56 am |
|
|
Well, I found my problem.
My bias voltage pin was left onconnected, and it should be connected to Vdd.
Case closed |
|
|
Guest Guest
|
|
Posted: Thu Apr 06, 2006 2:00 am |
|
|
Can you tell me which LCD ( hardware ) do you use in this example ?
I need some HW suggestions for my project.. |
|
|
Futterama
Joined: 17 Oct 2005 Posts: 98
|
|
|
|