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 support@ccsinfo.com

PIC16F628A+74HC595+ULN2003A 7 segment

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



Joined: 17 Feb 2012
Posts: 11

View user's profile Send private message

PIC16F628A+74HC595+ULN2003A 7 segment
PostPosted: Mon Apr 09, 2012 3:54 am     Reply with quote

Hello sir.

I need to counter with 3 digit of 7 segment (12V, Anode) . I used 74HC595 + ULN2003 but i don't know how to fix ten, hundreds position
my circuit as below
sbo sbobet

This is my code


Code:
#include <16F628a.h>
#fuses HS,NOLVP,NOWDT,NOPROTECT,PUT
#use delay (clock = 4000000)
#fuses HS,NOWDT,NOPROTECT,NOLVP   

#TYPE long=32                     
#include <74595.c>

void main()
{
BYTE  data[10] ={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0X7D,0x07,0x7F,0x6F};
int i;

set_tris_b(0x00);

while(true)
  {
   for(i=0; i<10; i++)
     {
      write_expanded_outputs (&data[i]);
      delay_ms(50);
     }
  }

}


Help me, please


Last edited by matsuo on Mon Apr 09, 2012 7:45 am; edited 3 times in total
temtronic



Joined: 01 Jul 2010
Posts: 9162
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Apr 09, 2012 5:26 am     Reply with quote

First help. Do NOT POST CCS code ! It's in the rules and you'll get a polite warning, first time. If you continue to post CCS code, you'll be banned from posting....it's in the rules...

Second, try using the 'search' option on this forum. You're not the first one wanting to do this project,so answers will be here.

Third, try Googling '74595 PIC C code' or similar...again, you're not the first to do it!

fourth, ...
Code:

#fuses HS,NOLVP,NOWDT,NOPROTECT
#use delay (clock = 4000000) // Crytal = 20MHz
//#use fast_io(b)
// --------- untested code ---------
//#define LOAD  pin_b0  // 16F628 pin 6
//#define CLOCK pin_b1  // 16F628 pin 7
//#define DATA  pin_b2  // 16F628 pin 8

#fuses HS,NOWDT,NOPROTECT,NOLVP   
#use delay(clock=20000000)       
...

delete the
Code:

#fuses HS,NOLVP,NOWDT,NOPROTECT
#use delay (clock = 4000000) // Crytal = 20MHz
//#use fast_io(b)
 

lines of code !

Probably 'leftover' from another attempt, but confusing to us and perhaps the compiler !!

5th. Have you got 0,1,2,....9 working correctly ? It's always good to start small, expand on your working code.Far easier to debug small sectins of code!!

6th. always add 'PUT' to the #FUSES options.The small delay in PowerUpTimer will ensure the PIC gets 'organized' properly on every power up.
matsuo



Joined: 17 Feb 2012
Posts: 11

View user's profile Send private message

PostPosted: Mon Apr 09, 2012 7:31 am     Reply with quote

Thanks for your advice Embarassed
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Apr 09, 2012 11:09 am     Reply with quote

Look at this CCS example file:
Quote:

c:\program files\picc\examples\ex_zmd.c

It writes a number to three 7-segment displays. It uses the 74595.c
driver. So it's similar to your project.

Look at this routine in the ex_zmd.c file:
Code:

void lcd_putd(int16 num)

It displays 'num' as 3 digits on the 7-segment displays. (It really should
be called "led_putd", because the displays use leds). But look at the
first part of the routine. They use division and modulus operators to
break up the number into 3 separate digits, which they put into an array.

Then in later code, they check if the digit is a leading 0, and if so, they will
display a blank, instead of a 0. When they finally have the array setup
with the correct data (blank or the 7-segment digit code), then they call
the write_expanded_outputs() routine.

I think this is the information that you want. Hopefully it will solve your
problem.
matsuo



Joined: 17 Feb 2012
Posts: 11

View user's profile Send private message

PostPosted: Tue Apr 10, 2012 1:47 am     Reply with quote

Actually. I need to make counter board as my picture
My condition

Target display (top) (setting)
Actual display (mid) (input)
Different display (bottom) (Target-Actual)

exp. target display = 100
Actual display = 10
Different display= -90

but don't know to write code follow my condition
somebody can help me or not?

Thanks

My diagram


My code

Code:
#include <16F628a.h>
#fuses HS,NOLVP,NOWDT,NOPROTECT,PUT
#use delay (clock = 12000000)

#define Latch2 pin_b5 
#define Shift2 pin_b6 
#define DATA2  pin_b7

#define Latch pin_b4
#define Shift pin_b1 
#define DATA  pin_b2 

#define Latch3 pin_a0
#define Shift3 pin_a1 
#define DATA3  pin_a3


int1 i=0;

//------------ Interrup fuction------------//
#INT_EXT
void Isr_ext(void)
{
     i =~ i; // change from 0 to 1
   
 
}
///--------------------------------------------//
void display_digit(unsigned int16 ds1)
{
  unsigned int16 digit[4],i,loop_digit,dis;

/*****************************************************
*    Constants
******************************************************/
char num_led[17] = {0x3F,0x06,0x5B,0x4F,0x66,
                     0x6D,0x7D,0x07,0x7F,0x6F,
                     0x77,0x7C,0x39,0x5E,0x79,
                     0x50,0x80};

  digit[0] = num_led[ds1%10];
  digit[1] = num_led[(ds1/10)%10];
  digit[2] = num_led[(ds1/100)%10];
  digit[3] = num_led[(ds1/1000)%10];

  output_low(Shift);
  output_high(Latch);

  for(loop_digit=0;loop_digit<4;loop_digit++)

    {
     dis = digit[loop_digit];
     for(i=0;i<8;i++)
     {
         if((dis&0x80)==0)
         output_low(Data);
     else
         output_high(Data);
         dis=dis<<1;
         output_high(Shift);
         output_low(Shift);
       }
    }    // loop digit

    output_low(Latch);
    output_high(Latch);
}

///--------------------------------------------//
void display2_digit(unsigned int16 ds1)
{
  unsigned int16 digit[4],i,loop_digit,dis;

/*****************************************************
*    Constants
******************************************************/
char num_led[17] = {0x3F,0x06,0x5B,0x4F,0x66,
                     0x6D,0x7D,0x07,0x7F,0x6F,
                     0x77,0x7C,0x39,0x5E,0x79,
                     0x50,0x80};

  digit[0] = num_led[ds1%10];
  digit[1] = num_led[(ds1/10)%10];
  digit[2] = num_led[(ds1/100)%10];
  digit[3] = num_led[(ds1/1000)%10];

  output_low(Shift2);
  output_high(Latch2);

  for(loop_digit=0;loop_digit<4;loop_digit++)

    {
     dis = digit[loop_digit];
     for(i=0;i<8;i++)
     {
         if((dis&0x80)==0)
         output_low(Data2);
     else
         output_high(Data2);
         dis=dis<<1;
         output_high(Shift2);
         output_low(Shift2);
       }
    }    // loop digit

    output_low(Latch2);
    output_high(Latch2);
}
///--------------------------------------------//
void display3_digit(unsigned int16 ds2)
{
  unsigned int16 digit2[4],i2,loop_digit2,dis2;

/*****************************************************
*    Constants
******************************************************/
char num_led2[17] = {0x3F,0x06,0x5B,0x4F,0x66,
                     0x6D,0x7D,0x07,0x7F,0x6F,
                     0x77,0x7C,0x39,0x5E,0x79,
                     0x50,0x80};

  digit2[0] = num_led2[ds2%10];
  digit2[1] = num_led2[(ds2/10)%10];
  digit2[2] = num_led2[(ds2/100)%10];
  digit2[3] = num_led2[(ds2/1000)%10];

  output_low(Shift3);
  output_high(Latch3);

  for(loop_digit2=0;loop_digit2<4;loop_digit2++)

    {
     dis2 = digit2[loop_digit2];
     for(i2=0;i2<8;i2++)
     {
         if((dis2&0x80)==0)
         output_low(Data3);
     else
         output_high(Data3);
         dis2=dis2<<1;
         output_high(Shift3);
         output_low(Shift3);
       }
    }    // loop digit

    output_low(Latch3);
    output_high(Latch3);
}

void main()
{
enable_interrupts(GLOBAL); // Open Enable interrupt all
enable_interrupts(INT_EXT); // Open external interrupt
ext_int_edge(H_TO_L); //check Falling Edge
int16 counter = 0;
int16 counter2 = 100;
int16 counter3;
   while ( TRUE )
   {

  if(i==1)
 

   {
      counter++;
     
   
   }

display_digit( counter2);
display2_digit( counter  );
counter3=(counter2-counter);
   
display3_digit( counter3);
}
}
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Tue Apr 10, 2012 2:58 am     Reply with quote

You've been directed towards loads of helpful code.

PCM programmer has kindly outlined the steps you need to take.

Several things strike me.

(1) You're not showing current limiting resistors for your LEDs.
(2) Your diagram has groups of three displays, Your code has four.
(3) You writing out roughly the same code for each of the three groups.

I suggested in a previous thread of yours that you read the CCS forum guidelines.

Tell us what you can do, and what you can't.

Mike
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