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

use 74ls164 display led delay

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
whung.john
Guest







use 74ls164 display led delay
PostPosted: Sat Jan 27, 2007 10:26 am     Reply with quote

hi:
today ,my try 74ls164 and connected eight red led.
but i check 74ls164 to pic16f877 pin address.i had correct to display.
i try written a sample program. but every times changed display number ,always lose some value.
can tell me what error ,follow as

#include <16F877.h>
#use delay(clock=10000000)
#fuses NOWDT,HS,NOLVP,BROWNOUT
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
#include <LCD>
//74164CLK = PIN_C3 SCK=CLOCK
//74164_DO = PIN_C5 output data
//74164_CLEAR = PIN_C4 cear buffer

void init74164(void)
{
output_low(PIN_C4);
DELAY_MS(100);
output_high(PIN_C3);
output_high(PIN_C5);

setup_spi(SPI_MASTER|SPI_L_TO_H|SPI_CLK_DIV_4);
lcd_init();
delay_ms(100);
}


void main()
{
unsigned int da;

init74164();
da=0X0f; // here i changed area.
lcd_gotoxy(1,1);printf(lcd_putc,"\ftest=%4u",da);
spi_write(da);
WHILE(1);


}











// TODO: USER CODE!!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jan 28, 2007 3:24 pm     Reply with quote

The 74LS164 is not the best chip to use, because:

1. It doesn't have an output register. It's just a straight shift register.
Anytime you clock in new data, all the output pins will change state
on each of the 8 cycles of the clock. It's better to use a 74595-type
chip. It has an output register, and also CCS has a driver for it,
called 74595.c.

2. The minimum output voltage is only 2.4v. Some LEDs have a
forward voltage of 3.0v or more. They won't work with a drive
voltage of 2.4v. It's not high enough. For this reason, it's
better to use a chip that puts out CMOS levels. A CMOS chip
(74HCT series) will put out almost 5v for a high level output.
It's possible that your LEDs only have a forward drop of 2.0v.
There are many LEDs like that, so your circuit may work.

Anyway, let's suppose that you still want to use the LS164.

You're trying to use hardware SPI. With SPI, the most important
thing is how to select the correct SPI mode. If you don't use the
correct mode, the device may not operate or it may be flaky.

Here are ckielstra's SPI mode definitions. They use the CCS constants.
Code:

#define SPI_MODE_0_0  (SPI_L_TO_H | SPI_XMIT_L_TO_H)
#define SPI_MODE_0_1  (SPI_L_TO_H)
#define SPI_MODE_1_0  (SPI_H_TO_L)
#define SPI_MODE_1_1  (SPI_H_TO_L | SPI_XMIT_L_TO_H)


Look at your setup_spi() statement:
Code:

setup_spi(SPI_MASTER | SPI_L_TO_H | SPI_CLK_DIV_4);

From this, it's obvious that you're using SPI mode 1. But is it the
correct mode to run a 74LS164 ?

Here's the data sheet for the 74LS164:
http://focus.ti.com/lit/ds/symlink/sn74ls164.pdf
Here's another one:
http://pdf1.alldatasheet.com/datasheet-pdf/view/12631/ONSEMI/74LS164.html
This chip is basically obsolete. I wouldn't use it.
But if you look closely at the data sheets, you can see that data is
clocked into the chip on the rising edge of clock. What SPI mode
uses the rising edge of clock ? Also, the timing diagrams show the
idle state for the clock is a high level. Next, look at the diagram
on the following web site, which shows SPI modes:
http://www.totalphase.com/support/articles/article03/#modes
It shows that Mode3 samples on the rising edge and idles at a high level.
Based on that, your setup_spi() statement should be this:
Code:
setup_spi(SPI_MASTER | SPI_MODE_1_1 | SPI_CLK_DIV_4);

Mode 3 is represented in binary, as "1_1" in the constant above.
WHUNG.JOHN
Guest







DELAY QUESTION SOLVE
PostPosted: Wed Jan 31, 2007 6:28 am     Reply with quote

Very Happy
HI :
PROGRAMMER SIR ,glad that question can solve.
the question is leaded from 74164 spi command .
and u ready suggest accuracy.
i modify my program ,now my make sample model can working correct.
thanks.
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