#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2011
    Posts
    43
    Rep Power
    3

    Formatting a truth table?


    I'm trying to create a PIC controller which is basically a table lookup (a requirement is to implement the fsm()). The table that should be displayed is :
    https://www.dropbox.com/s/f04okc0cbp65rjq/Capture1.PNG


    My output is this :https://www.dropbox.com/s/ijj69ksrrvadkar/Capture.PNG


    Code:
    #include <stdio.h>
    
    void fsm(char Reset,char I0, char I1,  char *Out0, char *Out1);
    
    int main(int argc, char *argv[])
    {
        char I1,I0,Reset, Out1, Out0, i;
    
    
    
        printf("PIC Microcontroller\n\n");
        printf("Operations with Reset=0\n\n");
        printf("R   I0  I1  Out0    Out1\n\n");
    
        Reset=0;
        I0=0;
        I1=0;
        Out0=0;
        Out1=0;
    
        for(i=0;i<16;i++)
        {
            printf("%1d %1d %1d %1d %1d", Reset, I0, I1, Out0, Out1);
            fsm(Reset,I0,I1,&Out0,&Out1);
            printf("%1d %1d %1d %1d",I0,I1,Out0,Out1);
        }
    
        printf("\n\n\n");
    }
    
    void fsm(char Reset,char I0, char I1,  char *Out0, char *Out1)
    {
    
        static char I0table[] = {0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1};
        static char I1table[] = {0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1};
        static char Out0table[] = {1,1,1,1,0,1,0,1,1,0,1,0,0,0,0,0};
        static char Out1table[] = {0,1,0,1,0,0,1,1,1,0,1,0,1,0,1,0};
    
        int index=(Reset<<4)+(I0<<3)+(I1<<2)+(*Out0<<1)+*Out1;
    
        I0=I0table[index];
        I1=I1table[index];
        *Out0=Out0table[index];
        *Out1=Out1table[index];
    }
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,379
    Rep Power
    1871
    > fsm(Reset,I0,I1,&Out0,&Out1);
    How do you expect I0 and I1 to change for the next loop iteration?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper

IMN logo majestic logo threadwatch logo seochat tools logo