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

Code to drive a serial 3-digit 7-segment

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



Joined: 09 Sep 2003
Posts: 52

View user's profile Send private message MSN Messenger

Code to drive a serial 3-digit 7-segment
PostPosted: Mon Nov 15, 2004 11:09 am     Reply with quote

I have a serial 7-segment display(3-digit). I've tried to use the CCS SPI
subroutine to drive the display, but i does not work.
The spec stated that the display integrated with a M5450 MOS to take a serial data. Start with "1" and follow by 35 data bit.

Anybody has any suggestion what should I do to get it to work?

Here is the display P/N: LTM8522Y

http://www.radiobox.ru/pdfa/lt/9-205.pdf

Here is my code.

Code:


#include <16f877.h>
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) 


#include <input.c>
#define    CS   (PIN_B0)
#define      enable   output_low
#define      disable   output_high

void main()
{
   byte value,cmd,spi;
   setup_spi(SPI_MASTER | SPI_H_TO_L | SPI_CLK_DIV_16);
   output_high(CS);                     //Enable the POT
   
   while(true)
   {
          
         enable(CS);                  //Enable POT
         SPI_WRITE(0X13);            //Data byte   
         
         disable(CS);                  //Disable POT
                  
      
      }

}
Ttelmah
Guest







PostPosted: Mon Nov 15, 2004 11:28 am     Reply with quote

Unfortunately, the device _requires_ 36bits to be clocked out. Hence the SPI routnes (which send 8), cannot be used (if the required number of bits was a multiple of 8, you could use the SPI, by sending multiple bytes). This is why your example won't work (since the chip does nothing till it sees 36 bits).
If you look at the 'examples', there are a couple that use manual 'bit banging' to send data. You are going to have to do something like this, and extend it to send 36 bits. Do you want to drive the extra output pins?. If so, then the data will have to come from an array (since the largest 'type' in CCS, is only 32bits long). Otherwise you could use a int32, and just ignore the extra bits.

Best Wishes
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Mon Nov 15, 2004 1:03 pm     Reply with quote

Very simple to do. Take a look at the 74595.C example. Your code will be very similar to that. However, you will have to stop after 36 clocks.

Original code:
Code:
#IFNDEF EXP_OUT_ENABLE

#define EXP_OUT_ENABLE  PIN_B0
#define EXP_OUT_CLOCK   PIN_B1
#define EXP_OUT_DO      PIN_B2
#define NUMBER_OF_74595 1

#ENDIF


void write_expanded_outputs(BYTE* eo) {
  BYTE i;

  output_low(EXP_OUT_CLOCK);
  output_low(EXP_OUT_ENABLE);

  for(i=1;i<=NUMBER_OF_74595*8;++i) {  // Clock out bits from the eo array
    if((*(eo+(NUMBER_OF_74595-1))&0x80)==0)
      output_low(EXP_OUT_DO);
    else
      output_high(EXP_OUT_DO);
   shift_left(eo,NUMBER_OF_74595,0);
   output_high(EXP_OUT_CLOCK);
   output_low(EXP_OUT_CLOCK);
  }
  output_high(EXP_OUT_ENABLE);
}


Here is one modification:
Code:
// Pass an address to an array to this function
// The data will be destroyed in the array
// Digit 1 Segment A is bit0 of the first element
void write_outputs(BYTE* eo) {
  BYTE i;

  output_low(EXP_OUT_CLOCK);
  output_low(EXP_OUT_ENABLE);

  // Output the leading '1'
  output_high(EXP_OUT_DO);
  output_high(EXP_OUT_CLOCK);
  output_low(EXP_OUT_CLOCK);

  for(i=1;i<=35;++i) {  // Clock out bits from the eo array
    if((*eo)&0x01)==0)
      output_low(EXP_OUT_DO);
    else
      output_high(EXP_OUT_DO);
   shift_right(eo,5,0);
   output_high(EXP_OUT_CLOCK);
   output_low(EXP_OUT_CLOCK);
  }
  output_high(EXP_OUT_ENABLE);
}


There are lots of ways to modify the code. Some destroy the orginal data others do not. You could do bit tests on the array which would preserve the orginal data. A lot depends on what the rest of the program is doing and how you want it to function. I'll leave that up to you.
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