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

Signal noise when use LCD driver (pic16f946) !

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
aka211



Joined: 24 May 2010
Posts: 15

View user's profile Send private message

Signal noise when use LCD driver (pic16f946) !
PostPosted: Thu Jun 17, 2010 2:52 am     Reply with quote

Hi everyone,
I'm using pic16f946 and a 7-segment LCD, I config the LCD as below:
Code:

/////////////////////////////////////////////////////////////////////////////////////////
//                                 LCD Configuration                                   //
/////////////////////////////////////////////////////////////////////////////////////////
// Digit segments    A        B        C        D        E        F        G        DP
//                   b7       b6       b5       b4       b3       b2       b1       b0
#define DIGIT6    COM0+22, COM1+22, COM2+22, COM3+22, COM2+21, COM0+21, COM1+21
#define DIGIT5    COM0+24, COM1+24, COM2+24, COM3+24, COM2+23, COM0+23, COM1+23
#define DIGIT4    COM0+26, COM1+26, COM2+26, COM3+26, COM2+25, COM0+25, COM1+25
#define DIGIT3    COM0+33, COM1+33, COM2+33, COM3+33, COM2+27, COM0+27, COM1+27
#define DIGIT2    COM0+31, COM1+31, COM2+31, COM3+31, COM2+32, COM0+32, COM1+32
#define DIGIT1    COM0+29, COM1+29, COM2+29, COM3+29, COM2+30, COM0+30, COM1+30
//                  BAT      RF       Re.       Us.      V        A        kW       h
#define SYMBOL    COM3+21, COM3+23, COM3+25, COM3+27, COM3+28, COM2+28, COM1+28, COM0+28 
#define COMMON    COM3+32, COM3+30
#define SYMBOL2   COM0+35, COM1+35, COM2+35, COM3+35
//
//         character         0    1    2    3    4    5    6    7    8    9   
byte const Digit_Map[10] = {0xFC,0x60,0xDA,0xF2,0x66,0xB6,0xBE,0xE0,0xFE,0xF6};
byte const Symbol_Map[10] = {0x00,0x80,0x40,0x20,0x10,0x08,0x04,0x13,0x80,0x40};
byte const Symbol_Map2[3] = {0x00,0xc0,0xd0};
#define BLANK 0
#define DASH 11
/////////////////////////////////////////////////////////////////////////////////////////

byte lcd_pos;

void lcd_putc(char c)
{
   byte 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 : lcd_symbol(segments,DIGIT6); break; // fill  100000s place
        case 2 : lcd_symbol(segments,DIGIT5); break; // fill   10000s place
        case 3 : lcd_symbol(segments,DIGIT4); break; // fill    1000s place
        case 4 : lcd_symbol(segments,DIGIT3); break; // fill     100s place
        case 5 : lcd_symbol(segments,DIGIT2); break; // fill      10s place
        case 6 : lcd_symbol(segments,DIGIT1); break; // fill       1s place
      }
   }
   lcd_pos++;
}

void lcd_symbol(char s)
{
byte symbols;   
if((s>='0')&&(s<='7'))
   {
   symbols=Symbol_Map[s-'0'];
   lcd_symbol(symbols,SYMBOL);
   }
else symbols=BLANK;
}

void lcd_symbol2(char s2)
{
byte symbols2;   
if((s2>='0')&&(s2<='2'))
   {
   symbols2=Symbol_Map2[s2-'0'];
   lcd_symbol(symbols2,SYMBOL2);
   }
else symbols2=BLANK;
}

void lcd_common(char co)
{
byte commons;
if((co=='0')||(co=='8')||(co=='9'))
   {
   commons=Symbol_Map[co-'0'];
   lcd_symbol(commons,COMMON);
   }
else commons=BLANK;
}

But there's much noise, other ports can't be controlled.
They're all twinkling very fast and continuosly.
I just do a simple work: display a number on LCD and export a pulse to RB3 to drive a LED (active low, flash 3s). But it still don't work. LCD display OK, but LED not flash.
I use internal osc 4 Mhz.
Where's the problem, plz tell me. Thanks alot !
Here's my code :

Code:

#include <16F946.h>
#include <def_16f946.h>
#include <7_lcd.c>
#fuses INTRC,NOWDT,PUT
#use delay(clock=4000000)

int8 mode;
long long id1,id2;
long sym2,sym,com;
float diennang,cosphi,dienap,dongdien;

void program1();
void program2();
void program3();
void program4();

void main()
{
trisb=0x00;
rb3=1;
mode=1;
setup_oscillator( OSC_4MHZ );
setup_lcd(LCD_MUX14|LCD_STOP_ON_SLEEP,2);
dienap=220.67;
dongdien=12.328;
cosphi=1;
id1=0;
id2=12;
diennang=dienap*dongdien*cosphi;
write_eeprom(10,id2);

while(1)
   {
   switch(mode)
      {
      case 0: program1();
      case 1: program2();
      }
   }
}

void program1()
   {
   sym2=2;
   sym=0;
   com=0;
   printf(lcd_symbol2,"\f%1lu",sym2);
   printf(lcd_symbol,"\f%1lu",sym);
   printf(lcd_common,"\f%1lu",com);
   printf(lcd_putc,"\f%06lu",id1);
   rb3=0;
   delay_ms(3000);
   rb3=1;
   delay_ms(3000);
   mode=2;
   }
   
   void program2()
   {
   sym2=1;
   sym=7;
   com=8;
   printf(lcd_symbol2,"\f%1lu",sym2);
   printf(lcd_symbol,"\f%1lu",sym);
   printf(lcd_common,"\f%1lu",com);
   printf(lcd_putc,"\f%6lu",(int16)(diennang/10));
   rb3=0;
   delay_ms(3000);
   rb3=1;
   delay_ms(3000);
   mode=2;
   }
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jun 17, 2010 8:36 pm     Reply with quote

1. Comment out all the LCD code. Does the LED now blink correctly ?

2. Did you buy the LCD board or did you build it by yourself ?
If you bought it, post a link to the webpage for the board. If you built it,
did you put ceramic 100 nF capacitors between the Vdd pins of the PIC
and ground ? Did you use a voltage regulator (7805, etc). for the +5
volts ? Did you put a 10 uF (or larger) Tantalum capacitor on the output
of the voltage regulator, from +5v to ground ?

3. What is your compiler version ?
aka211



Joined: 24 May 2010
Posts: 15

View user's profile Send private message

PostPosted: Thu Jun 17, 2010 9:35 pm     Reply with quote

PCM programmer wrote:
1. Comment out all the LCD code. Does the LED now blink correctly ?

2. Did you buy the LCD board or did you build it by yourself ?
If you bought it, post a link to the webpage for the board. If you built it,
did you put ceramic 100 nF capacitors between the Vdd pins of the PIC
and ground ? Did you use a voltage regulator (7805, etc). for the +5
volts ? Did you put a 10 uF (or larger) Tantalum capacitor on the output
of the voltage regulator, from +5v to ground ?

3. What is your compiler version ?


1. LED blinks as it likes, I can't control it.

2.I built it, and put 100nF ceramic capacitors between the Vdd pins of the PIC
and ground. Yes, i used 7805 for 5V. I used 100uF Tantalum capacitor on the output of the voltage regulator, from +5v to ground.
3. I use CCS_PCWHD_v4.93.

rb3 and some other pins (not used for LCD) blink continuosly at frequency of ~250Hz, VH~2V, VL~1V.

The LCD have 6 digits, 2 comons, and some symbols.


Last edited by aka211 on Thu Jun 17, 2010 9:49 pm; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jun 17, 2010 9:46 pm     Reply with quote

Try this simple test program. Compile it and run it. What happens ?
Code:

#include <16F946.h>
#fuses INTRC_IO, NOWDT, NOPROTECT, BROWNOUT, PUT
#use delay(clock=4000000)

//===============================
void main()
{

while(1)
  {
   output_high(PIN_B3);
   delay_ms(500);
   output_low(PIN_B3);
   delay_ms(500);
  }
}
aka211



Joined: 24 May 2010
Posts: 15

View user's profile Send private message

PostPosted: Thu Jun 17, 2010 9:54 pm     Reply with quote

I've tried, it works correctlly. When I don't include the "7_lcd.c", it works as i like. I think the problem is the lcd driver.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jun 17, 2010 10:06 pm     Reply with quote

Do you mean that you just added the #include line for the 7_lcd.c file
as shown below, and then the program fails ?
Is the 7_lcd.c file the same as the code that you posted in an earlier post ?
Code:

#include <16F946.h>
#fuses INTRC_IO, NOWDT, NOPROTECT, BROWNOUT, PUT
#use delay(clock=4000000)

#include "7_lcd.c"

//===============================
void main()
{

while(1)
  {
   output_high(PIN_B3);
   delay_ms(500);
   output_low(PIN_B3);
   delay_ms(500);
  }
}
aka211



Joined: 24 May 2010
Posts: 15

View user's profile Send private message

PostPosted: Thu Jun 17, 2010 10:14 pm     Reply with quote

When i #include <7_lcd.c> and setup_lcd(LCD_MUX14|LCD_STOP_ON_SLEEP,2);
the program fails.
Quote:
#include <16F946.h>
#fuses INTRC_IO, NOWDT, NOPROTECT, BROWNOUT, PUT
#use delay(clock=4000000)
#include <7_lcd.c>
//===============================
void main()
{

setup_lcd(LCD_MUX14|LCD_STOP_ON_SLEEP,2);
while(1)
{
output_high(PIN_B3);
delay_ms(500);
output_low(PIN_B3);
delay_ms(500);
}
}

Include but not setup_LCD, or setup but not include, it still works.
Quote:
Is the 7_lcd.c file the same as the code that you posted in an earlier post ?

Yes, the same.

This is how it shows on oscilloscope. Yellow is COM0 pin, blue is RB3. Volts/div=2V. Time/div=5ms
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jun 17, 2010 10:55 pm     Reply with quote

The compiler is setting bit 3 of the LCDSE0 register = '1'. This makes
pin B3 into an analog pin. That's why the LED won't work properly.

I'll continue this tomorrow.
aka211



Joined: 24 May 2010
Posts: 15

View user's profile Send private message

PostPosted: Fri Jun 18, 2010 12:11 am     Reply with quote

Thanks alot PCM, so how can I config the pins not used for LCD as analog pins?
See u tomorrow,

This is my LCD:
aka211



Joined: 24 May 2010
Posts: 15

View user's profile Send private message

PostPosted: Fri Jun 18, 2010 2:04 am     Reply with quote

I know where the problem is. It the line
setup_lcd(LCD_MUX14|LCD_STOP_ON_SLEEP,2);
I dont config the segments used for LCD ( the full syntax: setup_lcd (mode, prescale, [segments]); )

But I don't know what to write in the [segments]. In PIC16C924.h there are these defines :
Quote:

#define SEG0_4 1
#define SEG5_8 2
#define SEG9_11 4
#define SEG12_15 8
#define SEG16_19 16
#define SEG20_26 32
#define SEG27_28 64
#define SEG29_31 128
#define ALL_LCD_PINS 255


but in PIC16F946 there aren't these. So how can I define the segments correctly ? Ex, why define SEG0_4 1 ?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jun 18, 2010 2:21 pm     Reply with quote

I don't think the setup_lcd() function can handle all six bytes to control
enabling/disabling the segments in the 16F946. So as a work-around, I
wrote the following short function to load the segment registers.

Add this function above main():
Code:

void setup_lcd_segments(int8 se5, int8 se4, int8 se3, int8 se2, int8 se1, int8 se0)
{
#byte LCDSE0 = 0x11C 
#byte LCDSE1 = 0x11D
#byte LCDSE2 = 0x11E
#byte LCDSE3 = 0x19C
#byte LCDSE4 = 0x19D
#byte LCDSE5 = 0x19E

LCDSE0 = se0;
LCDSE1 = se1;
LCDSE2 = se2;
LCDSE3 = se3;
LCDSE4 = se4;
LCDSE5 = se5;
}


Then call the function as shown below:
Code:

void main()
{
setup_lcd(LCD_MUX14 | LCD_STOP_ON_SLEEP, 2);

// Enable the segments that are connected to the LCD.
// This function loads the Segment Enable registers
// with the bitmasks specified below.  The segments
// are determined by looking at the schematic of the
// PIC to LCD connections. In each byte, a '1' means
// the segment is Enabled ("On").  A '0' means it's Off.
// This function must be called after the setup_lcd() function.
setup_lcd_segments(0x00,   // Segs 41-40 = off
                   0x03,   // Segs 39-34 = off, 33-32 = On
                   0xFF,   // Segs 31-24 = On
                   0xE0,   // Segs 23-21 = On, 20-16 = off
                   0x00,   // Segs 15-8 = off
                   0x00);  // Segs 7-0 = off

Or if you didn't want to do this, you could just put in the #byte statements
and set the 6 LCDSEn registers in main() with 6 lines. But I like functions.
aka211



Joined: 24 May 2010
Posts: 15

View user's profile Send private message

PostPosted: Sat Jun 19, 2010 10:44 pm     Reply with quote

Thanks PCM, I'll try. My internet line had problem so i couldn't be online these days. I'll try and tell you the result.
Best wishes, PCM
aka211



Joined: 24 May 2010
Posts: 15

View user's profile Send private message

PostPosted: Sun Jun 20, 2010 8:09 pm     Reply with quote

It's great PCM, it works well. Thank you very much.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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