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

Improper display segments

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



Joined: 27 Jun 2017
Posts: 71

View user's profile Send private message

Improper display segments
PostPosted: Wed Sep 06, 2017 10:28 am     Reply with quote

Hello,

I am using PIC16F1939 to interface 7 segment LCD (3 digits). I have interfaced the LCD with the pic using the Internal register Ladder. I am observing the strange problem.

When i manually change counts for digits 1,2,3 then everything is displayed as input inserted, but when i put count=11 (which is null) the lcd displays erratic segments instead of turning all segments off.

Any suggestions as to why this is happening.
Code:

#include <16F1939.h>
#fuses HS ,NOVCAP, MCLR, NOWDT, PUT, NOIESO, BROWNOUT, NOFCMEN,PLL_SW,WRT,CPD
#use delay(crystal=20MHz, clock=20MHz)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

//====================================================================================================|
//====================================================================================================|
//                                 LCD Configuration                                                  |
//====================================================================================================|
// Digit segments  A           B         C          D           E         F         G          DP
//                 b7          b6        b5         b4          b3        b2        b1         b0
#define DIGIT3  COM0+11,   COM1+11,   COM2+11,   COM3+11,   COM2+10,   COM0+10,   COM1+10,   COM3+10
#define DIGIT2  COM0+17,   COM1+17,   COM2+17,   COM3+17,   COM2+18,   COM0+18,   COM1+18,   COM3+18
#define DIGIT1  COM0+19,   COM1+19,   COM2+19,   COM3+19,   COM2+20,   COM0+20,   COM1+20,   COM3+20
//       ComX+Y is combination of Backplan0-3 and Segment0-SegmentXX
//=====================================================================================================|
//           character          0    1    2    3    4    5    6    7    8    9  Null
//byte const Digit_Map[11]   = {0xFD,0x61,0xDB,0xF3,0x67,0xB7,0xBF,0xE1,0xFF,0xF7,0x01}; //Decimal

byte const Digit_Map_1[11] = {0xFC,0x60,0xDA,0xF2,0x66,0xB6,0xBE,0xE0,0xFE,0xF6,0x00}; //no Decimal

//===================================================================================================//
//                          Segments Initilization                                                   //
// Seg23 Seg22  ...  Seg12 Seg11 Seg10 Seg9 Seg8 Seg7 Seg6 Seg5 Seg4 Seg3 Seg2 Seg1 Seg0             //
//  0/1   0/1   0/1   0/1   0/1   0/1  0/1  0/1   0/1  0/1 0/1   0/1 0/1  0/1  0/1   0/1             //
//  if bit_SegX is 1, SegX is set as Segment Output. Otherwise                                       //
//===================================================================================================//

#define Segments 0x1E0C00        // Initilize LCD SegmentX

//============================================================================//

int count3 = 0;// after decimal
int count2=0;   // 1st digit
int count1=0;   // 2nd digit

//============================================================================//

void Display()
{
   
   lcd_symbol (Digit_Map_1[count3], DIGIT3);
   lcd_symbol (Digit_Map_1[count2], DIGIT2);
   lcd_symbol (Digit_Map_1[count1], DIGIT1);
         
}
//============================================================================//
void main()
{
       set_tris_a (0xC9); //set RA-0,3,5,6,7 as inputs
       set_tris_b (0xCF);
       set_tris_c (0x80);
       set_tris_d (0x0C);
       set_tris_e (0x08);
       
       setup_comparator (NC_NC_NC_NC);

       enable_interrupts (INT_TIMER0);
   
       enable_interrupts(GLOBAL);
       
       // set segments, contrast, internal resistor ladder
       setup_lcd(LCD_MUX14|LCD_HALT_IDLE|LCD_FOSC|LCD_VOLTAGE3 |LCD_REF_ENABLED |LCD_REF_VDD|LCD_A_HIGH_POWER |LCD_B_MED_POWER|LCD_A_CLOCK4,3, Segments);
       count1 = 8;
       count2 = 8;
       count3 = 8;
   
       Display ();
       delay_ms (1000);
       printf("hello started");
       
       while (TRUE) 
       {
            count1=11;
            count2=11;
            count3=11;
            Display();
       }
   
}


Using CCS PCWH 5.072 compiler.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Sep 06, 2017 11:16 am     Reply with quote

Quote:
byte const Digit_Map_1[11] = .....;

count1=11;
count2=11;
count3=11;

lcd_symbol (Digit_Map_1[count3], DIGIT3);
lcd_symbol (Digit_Map_1[count2], DIGIT2);
lcd_symbol (Digit_Map_1[count1], DIGIT1);


Your digit array is declared with 11 elements total.
What index should you use to access the last element in the array ?
POPE19



Joined: 27 Jun 2017
Posts: 71

View user's profile Send private message

PostPosted: Wed Sep 06, 2017 11:47 am     Reply with quote

Got it thanks!! Silly mistake Rolling Eyes
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