C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 4th, 2012, 03:34 PM
lisa92 lisa92 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2011
Posts: 43 lisa92 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 31 m 45 sec
Reputation Power: 2
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];
}

Reply With Quote
  #2  
Old November 4th, 2012, 04:45 PM
salem's Avatar
salem salem is online now
Contributed User
Click here for more information
 
Join Date: Jun 2005
Posts: 3,831 salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 153 Folding Title: Novice Folder
Time spent in forums: 2 Months 3 Weeks 2 Days 13 h 30 m 55 sec
Reputation Power: 1774
> 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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Formatting a truth table?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap