The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
Formatting a truth table?
Discuss Formatting a truth table? in the C Programming forum on Dev Shed. Formatting a truth table? C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

November 4th, 2012, 03:34 PM
|
|
Contributing User
|
|
Join Date: Oct 2011
Posts: 43
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];
}
|

November 4th, 2012, 04:45 PM
|
 |
Contributed User
|
|
|
|
|
> fsm(Reset,I0,I1,&Out0,&Out1);
How do you expect I0 and I1 to change for the next loop iteration?
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|