1. 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.
    Dismiss Notice

How to use Interrupt in PIC16F877A in C..??

Discussion in 'Microcontrollers' started by koolguy, Jan 14, 2013.

  1. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,147
    Likes:
    907
    Location:
    Rochdale UK
    I have changed my Simulation to 16x32 leds.... Its working brilliantly... I'm making a few animations to show it off....
     
  2. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    I have changes the sacnning from down left to rigt but the animation is not working it is hanging at starting only and scrolling is flickering/vibrating
     
  3. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    Hi,
    I want to write more lines but when i do this some overlapping occur due to which scrolling doesn't work well how to chose the value of x and y??

     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,147
    Likes:
    907
    Location:
    Rochdale UK

    69 letters.... Eight pixels.... = 552 shifts.... This cannot be done with a char... You need to change to a signed int so the count will work...
     
  6. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    Then x will be 32 only??
     
  7. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    i am confused with x and y.......
     
  8. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,147
    Likes:
    907
    Location:
    Rochdale UK
    Each character is eight pixels wide so the whole string is 552 pixels so to scroll the whole string (using my code) you need to start at 32 and scroll to -520...
     
  9. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    so, x will be always 32???
    and y will be 8x character
     
  10. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,147
    Likes:
    907
    Location:
    Rochdale UK
    I use x=32 as this is just "off screen" the text then comes onto the screen at "x=31"

    Y=0 as its the top left pixel...
     
  11. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    Ok, if we have more character like 50 then we have to 400 value of x or y?? i have seen at large character it overlap!
     
  12. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,147
    Likes:
    907
    Location:
    Rochdale UK
    Yes because the code I posted was for smaller strings.... If you change x and y to signed int's you can use strings up to 127 characters long...
     
  13. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    then how to make it for bigger??

    if i want to make this column scanning code to your row scanning then how to do convert/send buffer data??

    Code (text):
    #include<pic.h>
    __CONFIG(LVP_OFF & BOREN_OFF & PWRTE_ON & WDTE_OFF & FOSC_HS);
    #define _XTAL_FREQ 20000000
    #define DAD PORTB
    #define RST RD7
    #define CLK RC3
    #define DATA RC4
     
     
     
    char displayPointer=0;
    extern const char  font[];
     
    unsigned char buffer[32]; // buffer for screen
     
    void interrupt ISR()        // This just swaps the buffer to the display
        {
        if(TMR2IF)              // make sure its the timer interrupt.
            {
            PORTB = 0;                  // clear old data first
            if(displayPointer == 0 )    // 1st frame..
                DATA = 1;               // Data = 1 on the first clock
            CLK = 1;
            __delay_us(10);             // Clock the shift registers
            CLK = 0;
            DATA = 0;
            PORTB = buffer[displayPointer];  // Move budffer line by line      
            if(++displayPointer==31)        //  24 LED columns
                displayPointer = 0;         // back to first..
            }
        TMR2IF = 0;
        }
     
    void display(const char* str)
        {
        int addr;
        char x, y;
        while(*str != 0)                    // while there is still characters
            {
            addr = (int) *str++ - 0x20;     // get character
        //  DAD=addr;
     addr *=5;
    //DAD=addr;
            for(y=0;y<5;y++)                // 5x8 font so 5 columns
                {
                buffer[31] = font[addr++];  // put it in buffer
     
        for(x=0;x<32;x++)
                    {
                    buffer[x] = buffer[x+1];    // shift all the columns <--
                    //DAD=buffer[x];
    __delay_ms(4);              // so you can see it
                    }
                }
            buffer[31] = 0;                     // This is the scpace between
            for(x=0;x<32;x++)                   // the characters.. Or they will be too close
                {
                buffer[x] = buffer[x+1];        //  shift the space in
                __delay_ms(5);
                }                           // NOTE!!! your array is 28 not 24 like mine
            }  
        }
     
     
    void main(void)
        {
        ADCON1 = 0x6;
        T2CON = 0x1e;  
        PR2 = 50;                           // timer preload value
        TMR2IE = 1;                         // enable timer 2 interrupt
        PEIE = 1;                           // enable peripheral interrupt
        GIE = 1;                            // enableglobal interrupt
        TRISB = 0;                          // Port B as output...
        TRISC = 0; 
    RST=1;                      // Port C as ouput...
        while(1)
            {
            display("WELCOME     ");   // Here's the message
            }
        }   // End main
     
  14. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,147
    Likes:
    907
    Location:
    Rochdale UK
    Do you not read my posts


    You have two complete sets of code.... One I posted ages ago that gives column scanning... The other is row scanning...

    You don't understand the code at all, do you??? When I see that you are trying to output to PORTB in the display routine, just shows that this concept is more advanced than you can handle... You need to get your head around the interrupt and how it drives the display.... Until then you are not going to get my code working on your hardware..
     
  15. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    OK, if i will change it to signed long then we can display more right?
    and x will be always 32, y will be dependable on number of character then if by some mistake less character are there but y is more than it then what will happen?
     
  16. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,147
    Likes:
    907
    Location:
    Rochdale UK
    Y is not important at all Its ALWAYS 0....

    X is 32 because there are 32 LEDs in a row..... If there were 8 matrices it would be 64 as there will be 64 LEDs in the row
     
  17. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    then here the value of y should be changed?? according to number of character?

    Code (text):
    for(y = 0;y < 300 ;y++)
     
  18. tvtech

    tvtech Well-Known Member Most Helpful Member

    Joined:
    Mar 27, 2010
    Messages:
    3,166
    Likes:
    348
    Location:
    South Africa
    To Ian Rogers

    You have 10X the patience of JOB from the Bible. I really don't know how you do it.

    Your mental health and sanity could be at risk.

    Kindest regards,

    A worried and concerned Doctor.
     
  19. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,147
    Likes:
    907
    Location:
    Rochdale UK
    I see your confusion.... In MY code

    Code (C):

    void displaystring(void)                // this routine prints through the screen buffer
        {                                   // moving one pixel at a time
        signed char x=32,y=0;               // I made these signed so I could print
        for(y = 0;y  < 96 ;y++)             // to nowhere so I could produce the scrolling effect
            {
            clr();                          // Clear the display buffer
            strput("HELLO WORLD!!",x--,0);  // adjust the scrolling string
            Blit();                         // pass to screen buffer
            __delay_ms(80);                 // time to view
            }
        }
     
    Y in this function is just a counter The function strput( char*, x, y); The y in the function is fixed at 0..

    13 characters... so this will scroll 96 times...
     
  20. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    If i will use 13 character and 200 times then what will happens??
     
  21. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,147
    Likes:
    907
    Location:
    Rochdale UK
    It will just scroll past completely. In my example the last two charcaters "!!" stay on the screen.
     

Share This Page