ts-7000
[Top] [All Lists]

[ts-7000] Re: how do I synchronize two (or more) digital output pins

To: <>
Subject: [ts-7000] Re: how do I synchronize two (or more) digital output pins
From: " [ts-7000]" <>
Date: 28 Aug 2014 07:57:24 -0700


sbus_poke16(0x6c, sbus_peek16(0x6c) & ~(1 << pinOffSet));

  -Read 16 bits  IO ports
  -Create a mask to clear  the corresponding bit .     (1<< n) is equivalent to ( 2 power n)  and the ~ is the complement.
     Ex:     ~(1<<(31-21)) =  0xBFF
  -And write it back.

The best way to deal using  fast access with multiple unorder DIO pins is to create a complement Mask of all the DIO you want to manipulate and a Lookup Table with all the possibilities.

Using the complement mask to knock off DIO bits and the Table to set them will be very effective.

This is an example  for a 4 bits LCD display. The DIOs don’t need to be in sequence, it could be any DIO.
Ex:


#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#define  NUMBER_OF_DIO  4

// set the TABLE_SIZE  to   2 power DIO_NUMBER
#define TABLE_SIZE   16

// specify you DIO (from 21 to 36) . The first will be the LSB.
int DIO[NUMBER_OF_DIO]= { 21,22,31,32};

unsigned short   Table[TABLE_SIZE];
unsigned short Mask;

void initTable(void)
{
  int loop;
  int bits;
  unsigned short _utemp;

  int TableSize= (long) powl(2,NUMBER_OF_DIO);

  // now let’s create the table
  for(loop=0;loop<TABLE_SIZE;loop++)
  {
      unsigned short utemp=0;
      for(bits=0;bits<NUMBER_OF_DIO;bits++)
        if(loop & (1<<bits))
           utemp|= 1<< (DIO[bits]-21);
      Table[loop]=utemp;
  }

 // and the Mask;
 Mask = ~Table[TABLE_SIZE-1];
}


// and the write function


void write4bits(unsigned char value)
{
  if(value >= TABLE_SIZE) return;
  sbus_poke16(0x6c,(sbus_peek16(0x6c) & Mask) | Table[value]);
}
 
This is just an example.


Daniel

Sorry about the previously deleted post. I didn't check the code first but now it is ok

__._,_.___

Posted by:



__,_._,___
<Prev in Thread] Current Thread [Next in Thread>
Admin

Disclaimer: Neither Andrew Taylor nor the University of NSW School of Computer and Engineering take any responsibility for the contents of this archive. It is purely a compilation of material sent by many people to the birding-aus mailing list. It has not been checked for accuracy nor its content verified in any way. If you wish to get material removed from the archive or have other queries about the archive e-mail Andrew Taylor at this address: andrewt@cse.unsw.EDU.AU