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.

LED display code.

Status
Not open for further replies.

koolguy

Active Member
Hi,

I have written this code working fine, but i have issue with its shifting that is low frame rate and i want to shift the charter to 2 pixel not 1 as here...
when i make buffer[x]=buffer[x+2] charter get stretch which is not to be done ....


C:
#include <htc.h>
__CONFIG(LVP_OFF & BOREN_OFF & PWRTE_ON & WDTE_OFF & FOSC_HS);
#define _XTAL_FREQ 20000000
#define DAD PORTB
#define RST RC5
#define CLK RC3
#define DATA RC4
extern const char Font2[];
void blit(void), clear(void);
unsigned char leds[66];
unsigned char buffer[33];
unsigned char pow[] = {0,1,2,4,8,16,32,64,128};
display(char *str);
int data( int p);

char b;

main (){
    TRISC=0B00000000;
    TRISB=0B00000000;
    RST=0;

    clear();        
    display(" LED      ");

    while(1){
        for(char d=0;d<50;d++){
            buffer[31]=leds[d];
            for(char z=0;z<32;z++){
                buffer[z]=buffer[z+1];
                blit();//for displaying function

            }
        }
    }
}
display(char *str){
    int addr;                                                    
    int z;
    while(*str!=0){
        addr = ((int)*str++ - 0x20);
        addr *= 5;
        int y=0;
        for(z=0;z<5;z++){
            leds[z] = Font2[addr+y];
            y++;
        }
        addr = ((int)*str++ - 0x20);
        addr *= 5;
        int y=0;
        for(z=6;z<11;z++){
            leds[z] = Font2[addr+y];
            y++;
        }
        addr = ((int)*str++ - 0x20);
        addr *= 5;
        int y=0;
        for(z=12;z<17;z++){
            leds[z] = Font2[addr+y];
            y++;
        }
        addr = ((int)*str++ - 0x20);
        addr *= 5;
        int y=0;
        for(z=18;z<23;z++){
            leds[z] = Font2[addr+y];
            y++;
        }
        addr = ((int)*str++ - 0x20);
        addr *= 5;
        int y=0;
        for(z=24;z<29;z++){
            leds[z] = Font2[addr+y];
            y++;
        }
        addr = ((int)*str++ - 0x20);
        addr *= 5;
        int y=0;
        for(z=30;z<35;z++){
            leds[z] = Font2[addr+y];
            y++;
        }
        addr = ((int)*str++ - 0x20);
        addr *= 5;
        int y=0;
        for(z=36;z<41;z++){
            leds[z] = Font2[addr+y];
            y++;
        }
        addr = ((int)*str++ - 0x20);
        addr *= 5;
        int y=0;
        for(z=42;z<47;z++){
            leds[z] = Font2[addr+y];
            y++;
        }
        addr = ((int)*str++ - 0x20);
        addr *= 5;
        int y=0;
        for(z=48;z<53;z++){
            leds[z] = Font2[addr+y];
            y++;
        }
        addr = ((int)*str++ - 0x20);
        addr *= 5;
        int y=0;
        for(z=54;z<59;z++){
            leds[z] = Font2[addr+y];
            y++;
        }
        addr = ((int)*str++ - 0x20);
        addr *= 5;
        int y=0;
        for(z=60;z<65;z++){
            leds[z] = Font2[addr+y];
            y++;
        }
    }
}

void blit(void){
    char u=-1;
    b=0b00000001;
    for(int r=0;r<8;r++){
        DAD=pow[r];
        __delay_ms(1);
        RST=0;
        RST=1;
        u++;
        for(int a=0;a<32;a++){
            DAD=0;
            RST=1;
            char t,n;
            n=buffer[a];
            n>>=u;
            t=(n & b);
            DATA=t;

            CLK=1;
            __delay_us(1);
            CLK=0;
        }   
    }
}

void clear(void){
    for(char x=0;x<80;x++){
        leds[x]=0;

    }
}
 
Last edited by a moderator:
I want scrolling of x = x+2 i.e. twice in one frame but but doing so in code is stretching the Character scrolling which is error x=x+1 is fine but speed is very low and low frame rate plaese tell should be done?
 
If you remember our last visit to this... I had it all on an interrupt... As this is confusing you we'll need to it without...

The problem with NON interrupt routines, its hard to adjust speed without major overhaul of the code... To speed up the character moving you have to move ALL the pixels at once, hence this is why I double buffered the output.

If you want fast moving graphics you'll need to implement the interrupt timer as before... The physical cycle through your code is the slowest part.. If you need more processing speed you could move to the pic18f4520 ( pin compatable) and will run at 40Mhz... Or just learn the interrupt..
 
You wrote that code? haha. Honestly, if you say from where did you copy that code, you could get some help.
 
Last edited:
You wrote that code? haha. Honestly, if you say from where did you copy that code, you could get some help.
Please!!

Most of the code we have done together!! Its a working model and that's a damn good sign..
 
If you remember our last visit to this... I had it all on an interrupt... As this is confusing you we'll need to it without...

The problem with NON interrupt routines, its hard to adjust speed without major overhaul of the code... To speed up the character moving you have to move ALL the pixels at once, hence this is why I double buffered the output.

If you want fast moving graphics you'll need to implement the interrupt timer as before... The physical cycle through your code is the slowest part.. If you need more processing speed you could move to the pic18f4520 ( pin compatable) and will run at 40Mhz... Or just learn the interrupt..

the main problem is shifting x+2 time is not working for this i was shifting x+2 working good in that i was using only one buffer where font was saved and the problem was i have to re write and clear the font pixel saved buffer.
 
I am working one more 16x~60 so, i want to connect two white Led per shift register output ..
so, connecting in // where take more current so, i want to connect in series but 74hc164 work on 5V so, how to connect is there any chip..????
 
The two led per pin must have atlaest 20ma to give brightness more current will be also fine.
b'coz display from can't be see in dim.
 
hi ritesh
If you mean connect two White LED's in series to a HC164 pin powered by 5V , its not possible.

E.

EDIT:

This IC will replace a HC164
 

Attachments

  • TPIC6595.pdf
    185.1 KB · Views: 216
Status
Not open for further replies.

Latest threads

Back
Top