Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

What am i doing wrong? stp16cp05 led driver.

Status
Not open for further replies.

vedo35

Member
Hello friends i am trying to learn led drive with STP16CP05 spi led driver. I did a lot of thing but i coudnt success to led on-of or blink. I am using CCS. Anybody can help for me? Here is my source code. Thanks for all your help or idea.

C:
#include <16F887.h>
#FUSES NOWDT
#FUSES NOMCLR
#FUSES NOCPD
#FUSES NOBROWNOUT
#FUSES XT
#use delay(clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
/////////////////////////////////////////////////////////////////////////////////
#define SDI PIN_C0
#define CLK PIN_C1
#define LE PIN_C2
int i, data;

void counting()
    {
    output_low(SDI);
    for (i=0; i<data; ++i)
        {
        output_low(CLK);
        delay_ms(100);
        output_high(CLK);
        delay_ms(100);
        }
    printf("%2x", data);
    }

void Send16Bit(unsigned int16 data16bit )
    {
    unsigned int16 i;
    for(i=0x8000;i>0;i>>=1)
        {
        if(i&data16bit)output_high(SDI);
        else output_low(SDI);
        output_high(CLK);
        delay_us(1);
        output_low(CLK);
        }
    output_high(LE);
    delay_us(5);
    output_low(LE);

    }
unsigned int16 led_data;


led_data(b01000100000000001);
Send16Bit(led_data );

void Main()
    {
    output_high(SDI);
    delay_ms(100);
    output_high(CLK);
    delay_ms(100);
    output_low(CLK);
    while(true)
        {
        if(kbhit())
            {
            data=getc();
            counting();
            }
        }
    }
 
Last edited by a moderator:
Thank you ian for your reply. When i put in main function i get error message

*** Error 53 "stp16cp05.c" Line 47(5,13): Expecting function name
cant recognize led_data function.


void Main()
{
led_data(b01000100000000001);
Send16Bit(led_data );
output_high(SDI);
delay_ms(100);
output_high(CLK);
delay_ms(100);
output_low(CLK);
while(true)
{
if(kbhit())
{
data=getc();
counting();
}
}
}
 
Ok... Where are these two functions.... You need to create the functions if you want to use them...

Maybe it's a variable..
C:
unsigned int led_data = 01000100000000001;
Send16Bit(led_data );

Or a definition

C:
#define led_data  01000100000000001
...
while(1)
{..
Send16Bit(led_data );
 
Ian really thanks a lot last code that you wrote. Can you please obviously write again how i will write and to which line?
 
Unfortunately I don't use mikroC... so anything I write will need "adjusting" to your compiler.

Something like this...
C:
#include <16F887.h>
#FUSES NOWDT
#FUSES NOMCLR
#FUSES NOCPD
#FUSES NOBROWNOUT
#FUSES XT
#use delay(clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
/////////////////////////////////////////////////////////////////////////////////
#define SDI PIN_C0
#define CLK PIN_C1
#define LE PIN_C2
int i, data;

void counting()
    {
    output_low(SDI);
    for (i=0; i<data; ++i)
        {
        output_low(CLK);
        delay_ms(100);
        output_high(CLK);
        delay_ms(100);
        }
    printf("%2x", data);
    }

void Send16Bit(unsigned int16 data16bit )
    {
    unsigned int16 i;
    for(i=0x8000;i>0;i>>=1)
        {
        if(i&data16bit)output_high(SDI);
        else output_low(SDI);
        output_high(CLK);
        delay_us(1);
        output_low(CLK);
        }
    output_high(LE);
    delay_us(5);
    output_low(LE);

    }
unsigned int16  led_data;


void Main()
    {
    output_high(SDI);
    delay_ms(100);
    output_high(CLK);
    delay_ms(100);
    output_low(CLK);
    while(true)
        {
        led_data = b01000100000000001;
        Send16Bit(led_data );
        if(kbhit())
            {
            data=getc();
            counting();
            }
        }
    }
 
So, can i connect external clock generator like 555 . I just connect that pin direct to Gnd.
Sorry my compiler used old source code too thats why i got those error code.. now i have only one error code
*** Error 12 "stp16cp05-new.c" Line 57(20,38): Undefined identifier b01000100000000001
1 Errors, 0 Warnings.
 
So, can i connect external clock generator like 555 . I just connect that pin direct to Gnd.
Should be okay.... But if the power isn't an issue just ground it... You can do that for testing anyway!!
Sorry my compiler used old source code too thats why i got those error code.. now i have only one error code
*** Error 12 "stp16cp05-new.c" Line 57(20,38): Undefined identifier b01000100000000001
1 Errors, 0 Warnings.
Change b01000100000000001 to a hex value 0x4401... see if that works I don't know your compilers binary suffix..
 
Ian it woooorrkkkkkssss.. :D:p:) Thank you very very muchhh. I can even change the led situations. I dont know why not accepting b01000100000000001 but accepting hex value 0x4401. Very strange. now i changed to CCC0 led like i wanted 1100110011000000. By the way OE connected to GND. Only works like that otherwise not working. My mcu is 16f877. I had to delete also #FUSES NOMCLR line otherwise complier gives error. somebody told u cant make mclr off because pull-up true? Any way like this works perfect.
Ian A lot of tulips sending to you from netherlands :). So if somebody needs to this code down. Helps with Ian:

#include <16F877.h>
#FUSES NOWDT
#FUSES NOCPD
#FUSES NOBROWNOUT
#FUSES XT
#use delay(clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
/////////////////////////////////////////////////////////////////////////////////
#define SDI PIN_C0
#define CLK PIN_C1
#define LE PIN_C2
int i, data;
void counting()
{
output_low(SDI);
for (i=0; i<data; ++i)
{
output_low(CLK);
delay_ms(100);
output_high(CLK);
delay_ms(100);
}
printf("%2x", data);
}
void Send16Bit(unsigned int16 data16bit )
{
unsigned int16 i;
for(i=0x8000;i>0;i>>=1)
{
if(i&data16bit)output_high(SDI);
else output_low(SDI);
output_high(CLK);
delay_us(1);
output_low(CLK);
}
output_high(LE);
delay_us(5);
output_low(LE);
}
unsigned int16 led_data;

void Main()
{
output_high(SDI);
delay_ms(100);
output_high(CLK);
delay_ms(100);
output_low(CLK);
while(true)
{
led_data = 0xCCC0;
Send16Bit(led_data );
if(kbhit())
{
data=getc();
counting();
}
}
}
 

Attachments

  • STP16CP05 development board.jpg
    STP16CP05 development board.jpg
    56.2 KB · Views: 345
Ian hello again. After that i tried some kind of other ideas, like one or some of or all are blinking leds. which codes i need? and to which line i have to put that code?

Thanks again for helps:
 
i am trying to do, for example led 1,3 and 5 500ms blinking, led 4 and 8 800ms blinking or something like that. or all are blinking in 500ms .
 
Use Timer0 to give a 100mS interval..

Then setup a bit of logic to monitor the state of the LED's... For instance.. A mask for each time the timer overflows..

ie.. Something like this...
C:
if(T0IF)
   {
   LED_STAGE++;
   T0IF = 0;
   }
if(LED_STAGE == 1) Ledbuffer &= MASK1;
if(LED_STAGE == 2) Ledbuffer &= MASK2;
if(LED_STAGE == 3) Ledbuffer &= MASK3;
if(LED_STAGE == 4) Ledbuffer &= MASK4;
 
Thanks ian , between which line i have to put up code that u gave me? I put after
Send16Bit(led_data );

line giving error.
 
Last sittuation of code like up.
in the command :

led_data = 0xCCC0; (led burns like this 1100110011000000 )
this time i want to make like this : led_data=0x8B0D (1000101100001101 )
for example if we say one and zeros up side from left to right i want first bit 1 will be blink 5.bit 1 will be blink and 14. and 16. bit 1 will be blink . to which lines which and what codes we have to write?


C:
#include <16F877.h>
#FUSES NOWDT
#FUSES NOCPD
#FUSES NOBROWNOUT
#FUSES XT
#use delay(clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
/////////////////////////////////////////////////////////////////////////////////
#define SDI PIN_C0
#define CLK PIN_C1
#define LE PIN_C2
int i, data;
void counting()
    {
    output_low(SDI);
    for (i=0; i<data; ++i)
        {
        output_low(CLK);
        delay_ms(100);
        output_high(CLK);
        delay_ms(100);
        }
    printf("%2x", data);
    }
   
void Send16Bit(unsigned int16 data16bit )
    {
    unsigned int16 i;
        for(i=0x8000;i>0;i>>=1)
        {
        if(i&data16bit)output_high(SDI);
        else output_low(SDI);
        output_high(CLK);
        delay_us(1);
        output_low(CLK);
        }
    output_high(LE);
    delay_us(5);
    output_low(LE);
    }
   
unsigned int16 led_data;

void Main()
    {
    output_high(SDI);
    delay_ms(100);
    output_high(CLK);
    delay_ms(100);
    output_low(CLK);
    while(true)
        {
        led_data = 0xCCC0;
        Send16Bit(led_data );
            if(kbhit())
            {
            data=getc();
            counting();
            }
        }
    }
 
Last edited by a moderator:
Try and use code tags... Its a lot easier to read with the indentations... I've done it for you use the little cog symbol to insert your code...

If you want all the LED's to blink at the same time.... Well that's easy just clear the LED_data every other 200mS or so...

What's the purpose of the "counting" function?
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top