Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] I want to connect 80 inputs to micro controller

Status
Not open for further replies.
In case this helps, there is an IC called '1-of-8 data selector', 74LS151.

Also called '8-line to 1-line multiplexer'.

Apply a 3-bit address, and the output indicates the state of the corresponding input, high or low.

You would need ten of these, to scan 80 inputs one at a time, in succession. Maybe additional IC's too, since you'd need to build a branching network.
 

I wrote a sample function for that as follows
. please suggest me or advise
Code:
[COLOR=#333399][B]int[/B][/COLOR] a = [COLOR=#0000DD][B]2[/B][/COLOR]; [COLOR=#888888]// To check to times [/COLOR]
[COLOR=#008800][B]for[/B][/COLOR](i=[COLOR=#0000DD][B]0[/B][/COLOR]; i<[COLOR=#0000DD][B]80[/B][/COLOR]; i++) [COLOR=#888888]// 80 portscanning [/COLOR]
{ 
[COLOR=#008800][B]    if[/B][/COLOR](datapin) [COLOR=#888888]// checking wheter any of the inut is high [/COLOR]
    { 
       a[i] = [COLOR=#0000DD][B]1[/B][/COLOR]; [COLOR=#888888]// set high to the corresponding high pin
[/COLOR]
[COLOR=#008800][B]      if[/B][/COLOR](a==[COLOR=#0000DD][B]2[/B][/COLOR]) [COLOR=#888888]// checking whether the Pin tested first time if it is first time store the i value in temp[i][/COLOR]
         {
            temp[i] = a[i]; 
             a--; 
        }
        
         [COLOR=#008800][B]if[/B][/COLOR](a==[COLOR=#0000DD][B]0[/B][/COLOR]) [COLOR=#888888]// checking wheter the pin tested two times then return the i value [/COLOR]
     [COLOR=#008800][B]if[/B][/COLOR](temp[i]==a[i])
[COLOR=#008800][B]return[/B][/COLOR] i;     
     } 
}
 

You might make life a bit easier for yourself if you use a different name for the array ('a[]') and the flag variable ('a'). The compiler might be able to detect the different usage of the name but is more likely to assume they are the same variable and this will lead to all sorts of issues when you try to run it.
Also, you set the variable to 2 before you enter the loop that executes 80 times. Therefore the first pass through the loop (which i = 0) will eventually get the the "if( a == 2)" statement which will be true which will then drop the value of 'a' to 1.
As the only place where you decrement this value of 'a' is within the conditional statement, you never get to decrement the value again, in which case the "if(a == 0)" can never be true.
Also, if 'datapin' is not set (which according to your comment means that no input is high) then the for loop will simply loop again. It is therefore quite possible for the for loop to be executed 80 times (which 'datapin' still false) and you will fall out of the bottom of the function. As you have not shown the rest of the code it is hard to known what will happen then.
I suggest that you get a pencil and paper and work through the process that you are trying to perform to make sure that you get your logic straight before you try to code anything.
Susan
 
I believe, serial-in code has been posted a hundred times at Edaboard. But anyway

Code:
int8 sr;
int8 data[NBYTE];
int8 i,j;

SHLD = 0;
// optional delay
SHLD = 1;
for (j = 0, j < NBYTE; j++) {
{
  for (i = 0,  i < 8, i++) {
    sr = (sr << 1) | SI;
    CLK = 1;
    // optional delay    
    CLK = 0; 
  }
  data[j] = sr;
}

Use delays for fast processors as required. Use IO macros or built-in functions according to the used processor and compiler tool.

Hello sir Can you explain this portion as follows


sr = (sr << 1) | SI;
 

for example ,
if sr = 00000101 and SI =1;
(sr<<1) = 000001010

then (sr<<1)|SI;

=00001011 ?
isnt it ?
then how to save these value data[j] ?

please explain ?
 

maybe the cheapeast and easist option is to buy a 100 or 144 pin micro-controller like pic24ep512gu814 cost about 10$ per piece ,
 

for example ,
if sr = 00000101 and SI =1;
(sr<<1) = 000001010

then (sr<<1)|SI;

=00001011 ?
isnt it ?
The example numbers are correct.
then how to save these value data[j] ?
Exactly as in the post #36 and post #64 example. After shifting in 8 bits, store the result to data[j].
Code:
data[j] = sr;
 
data[j] = sr;
oh sorry my misunderstanding that array element cant have 8 bit digital value .
 

I want to check each bit in the data[j] ,.
that is the data[j] holding an 8 bit binary data .
How to check is it zero or one ?
 

is it correct the following code ?
Code:
for(i=0;i<8;i++)
  {
    b = i>>a[j]&&1;
      if(b==1)
        { 
          // bit is one 
         }
   }
 

Review your C text book for shift operation syntax.

i >> a[j] means i shifted a[j] times, I guess that's not what you want.

You can write
Code:
for(i=0;i<8;i++)
  if(a[j]>>i & 1)
    { 
      // bit is one 
    }

A small processor that can't perform multibit shift in an atomar instruction (e.g. 8051) will spent a lot of time doing the same shift again and again, also the a[j] indexing is repeated eight times. you can speed-up the operation by performing the action a bit different.

Code:
aa = a[j];
for(i=0;i<8;i++)
{
  if(aa & 1)
    { 
      // bit is one 
    }
  aa >>= 1;
 }
 
I tested this in a normal c compiler to find out the output as follows
Code:
#include<stdio.h>

int main()
{

int i ,j,b;
//int a[7];

for(i=0;i<8; i++)
  {
    b =00001111>>i&&1;
    
      if(b==1)
        { 
          printf(" the bit i %d is 0ne\n",i  );
         }
   }
}

and the output was Capture.PNG

why so ?
 

Code:
   b =00001111>>i&&1;
Multiple faults in a line.

00001111 is an octal literal according to C syntax rules
&& is a logical and operator, &&1 only asks if the left side is != 0
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top