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

NOT USE SPI CONNECTION TO 74LS164

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







NOT USE SPI CONNECTION TO 74LS164
PostPosted: Sat Feb 10, 2007 12:17 pm     Reply with quote

hi! every teachers.
today i start learn different connect to 74ls164.
and not application spi mode. so i use direct control mode.
but i try written a sample . now still can't find question position.
hope every teacher can tell me ,where is error?
thanks.
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>
void write_expanded_outputs(BYTE* eo) {
BYTE i;
output_low(PIN_C3);
for(i=1;i<=8;++i) { // Clock out bits from the eo array
if(((*(eo))&0x80)==0)
output_low(PIN_C1);
else
output_high(PIN_C1);
shift_left(eo,1,0);
output_high(PIN_C3);
output_low(PIN_C3);
}
}

void init74164(void)
{
output_low(PIN_C2);
DELAY_MS(100);
output_high(PIN_C3);
//output_high(PIN_C1);


lcd_init();
delay_ms(100);
}


void main()
{
unsigned int da;

char a[]={0x80,0xeb,0x4c,0x49,0x2b,0x19,0x38,0x8b,0x08,0x0b};
init74164();
da=0xf7;
lcd_gotoxy(1,1);printf(lcd_putc,"\ftest=%4u",a[0]);
write_expanded_outputs(A[0]);
delay_ms(3000);
//WHILE(1);
while(1);
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sat Feb 10, 2007 5:31 pm     Reply with quote

Hard to say where the error is when you don't give more details. How is your hardware connected? What is the error? What results do you get, and what are you expecting to see?

One error I spotted at a quick glance is that you are passing write_expanded_outputs() a character, while it expecting the _address_ of a character.

Change
Code:
 write_expanded_outputs(A[0]);
to
Code:
 write_expanded_outputs(&A[0]);
whung.john
Guest







sorry, i have not explain hardware connected.
PostPosted: Sun Feb 11, 2007 1:51 am     Reply with quote

ckielstra wrote:
Hard to say where the error is when you don't give more details. How is your hardware connected? What is the error? What results do you get, and what are you expecting to see?

One error I spotted at a quick glance is that you are passing write_expanded_outputs() a character, while it expecting the _address_ of a character.

Change
Code:
 write_expanded_outputs(A[0]);
to
Code:
 write_expanded_outputs(&A[0]);


hi.senior .
sorry i have not to explain clearly.
First ,i connect to chip(74ls164),because 74ls164 have 3 address pin must connected.
so i connected method follow as:
clock pin =>pin_c3
serial input pin=>pin_c1
clear pin =>pin_c2
and 74lS164 output area pin connected a 8 number led display.

hope u can suggest me ,how can i modify that my sample program error.
thank u very much.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sun Feb 11, 2007 5:31 am     Reply with quote

Check init74164(), you set the Clear pin low but never high again.
whung.john
Guest







modified program and issue a question
PostPosted: Wed Feb 14, 2007 8:29 am     Reply with quote

ckielstra wrote:
Check init74164(), you set the Clear pin low but never high again.


hi.sir .
i modified program.follow as
issue display number 1 to 9.and stop not display.
please teach me ,where id the program have error ?

#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資料
//74164_CLEAR = PIN_C4 清除74164內資料 可任何PIN腳位


void write_74164(BYTE* eo) {
BYTE i;
// output_low(PIN_C3);
for(i=1;i<=8;++i) { // Clock out bits from the eo array
if(((*(eo))&0x80)==0)
output_low(PIN_C1);
else
output_high(PIN_C1);
shift_left(eo,1,0);
output_high(PIN_C3);
output_low(PIN_C3);
}
}


void init74164(void)
{
output_low(PIN_C2); //清除74164資料
DELAY_MS(100);
output_high(PIN_C2); //清除74164資料
output_low(PIN_C3); //clock l
output_high(PIN_C3);//clock h




delay_ms(100);
}


void main()
{
unsigned int da,i;

char a[]={0x80,0xeb,0x4c,0x49,0x2b,0x19,0x38,0x8b,0x08,0x0b,0xff};

init74164();
lcd_init();

da=0xf7;

lcd_gotoxy(1,1);printf(lcd_putc,"\ftest=%4u",a[0]);

while(1)
{
for (i=0;i<11;i++)
{
write_74164(&A[i]);
delay_ms(500);

}
write_74164(&A[10]);
}

}
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Feb 14, 2007 10:46 am     Reply with quote

First, when posting code, please use the 'Code' buttons in order to preserve the layout of your code. Easier reading will get you quicker and better answers.

The 74164 clocks data in at the rising edge. In init74164() you have
Code:
output_low(PIN_C3); //clock l
output_high(PIN_C3);//clock h
This has two problems,
1) You are clocking in undefined data.
2) You leave the clock signal at a high level.

Code:
//!//74164CLK = PIN_C3 SCK=CLOCK
//74164_DO = PIN_C5 output資料
//74164_CLEAR = PIN_C4 清除74164內資料 可任何PIN腳位
These pin descriptions are not equal to the connections from your previous post.
Make life easier to yourself by creating subtitute names for the pin numbers:
Code:
#define CLK_74164    PIN_C3
#define D0_74164     PIN_C1
#define CLR_74164    PIN_C2


I remember someone else having similar problems a few weeks ago. I don't know where you got your code from, but it is a modifed version from the CCS 74595.c example. Problem with this CCS code is that it is destructive, once a character is displayed the value is set to all zeroes and fails the next time.
The easiest solution is to change the write_74164() function to not get an address as parameter, but to pass the value to be displayed.

Code:
#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.C>

#define CLK_74164   PIN_C3
#define D0_74164    PIN_C1
#define CLR_74164   PIN_C2


void write_74164(BYTE eo)
{
  int8 i;

  for (i=0; i<8; i++) // Clock out bits from the eo array
  {
    if ((eo & 0x80) == 0)
      output_low(D0_74164);
    else
      output_high(D0_74164);

    shift_left(&eo,1,0);
    output_high(CLK_74164);
    output_low(CLK_74164);
  }
}


void init74164(void)
{
  // Initialize clock line
  output_low(CLK_74164);
 
  // Clear all outputs
  output_low(CLR_74164);
  output_high(CLR_74164);
}


void main()
{
  const char a[]={0x80,0xeb,0x4c,0x49,0x2b,0x19,0x38,0x8b,0x08,0x0b,0xff};
  int8 i;

  init74164();
  lcd_init();

  lcd_gotoxy(1,1);printf(lcd_putc,"\ftest=%4u",a[0]);

  while(1)
  {
    for (i=0; i<11; i++)
    {
      write_74164(a[i]);
      delay_ms(500);

    }
  }
}


Note the character array a[] is a never changing constant. I changed 'char a[]' to 'const char a[]', this moves the array from RAM to ROM, saving both in ROM and RAM usage.
whung.john
Guest







thanks u very much.if i must connected 2 74ls164?
PostPosted: Fri Feb 16, 2007 11:46 am     Reply with quote

ckielstra wrote:
First, when posting code, please use the 'Code' buttons in order to preserve the layout of your code. Easier reading will get you quicker and better answers.

The 74164 clocks data in at the rising edge. In init74164() you have
Code:
output_low(PIN_C3); //clock l
output_high(PIN_C3);//clock h
This has two problems,
1) You are clocking in undefined data.
2) You leave the clock signal at a high level.

Code:
//!//74164CLK = PIN_C3 SCK=CLOCK
//74164_DO = PIN_C5 output資料
//74164_CLEAR = PIN_C4 清除74164內資料 可任何PIN腳位
These pin descriptions are not equal to the connections from your previous post.
Make life easier to yourself by creating subtitute names for the pin numbers:
Code:
#define CLK_74164    PIN_C3
#define D0_74164     PIN_C1
#define CLR_74164    PIN_C2


I remember someone else having similar problems a few weeks ago. I don't know where you got your code from, but it is a modifed version from the CCS 74595.c example. Problem with this CCS code is that it is destructive, once a character is displayed the value is set to all zeroes and fails the next time.
The easiest solution is to change the write_74164() function to not get an address as parameter, but to pass the value to be displayed.

Code:
#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>

#define CLK_74164   PIN_C3
#define D0_74164    PIN_C1
#define CLR_74164   PIN_C2


void write_74164(BYTE eo)
{
  int8 i;

  for (i=0; i<8; i++) // Clock out bits from the eo array
  {
    if ((eo & 0x80) == 0)
      output_low(D0_74164);
    else
      output_high(D0_74164);

    shift_left(&eo,1,0);
    output_high(CLK_74164);
    output_low(CLK_74164);
  }
}


void init74164(void)
{
  // Initialize clock line
  output_low(CLK_74164);
 
  // Clear all outputs
  output_low(CLR_74164);
  output_high(CLR_74164);
}


void main()
{
  const char a[]={0x80,0xeb,0x4c,0x49,0x2b,0x19,0x38,0x8b,0x08,0x0b,0xff};
  int8 i;

  init74164();
  lcd_init();

  lcd_gotoxy(1,1);printf(lcd_putc,"\ftest=%4u",a[0]);

  while(1)
  {
    for (i=0; i<11; i++)
    {
      write_74164(a[i]);
      delay_ms(500);

    }
  }
}


Note the character array a[] is a never changing constant. I changed 'char a[]' to 'const char a[]', this moves the array from RAM to ROM, saving both in ROM and RAM usage.



ckielstra:
thanks u very much. i can from taiwan get u suggest.
i am very happy.
the night ,i modified my bad program . and hard to learn .
i get a good medtod from u description suggest.
but i tested finish.
next tested homework ,i hope to connected 2 74ls164.
but i dont know how modified .and first area.
can u suggest me? again get me a clew.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Fri Feb 16, 2007 12:51 pm     Reply with quote

We are not here to do your homework. This sounds hard, but that's how the world is. If we give you the solution right now than you will not learn how to solve problems like these. I already have enough colleagues who can't think by themselves.

Please try to think of a solution yourself first. Than when you can't get it to work post your code and we will try to help 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