To: | <> |
---|---|
Subject: | [ts-7000] Re: how do I synchronize two (or more) digital output pins |
From: | " [ts-7000]" <> |
Date: | 28 Aug 2014 07:38:05 -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: #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; TableSize= pow(2,DIO_NUMBER); Table = alloc(TableSize * sizeof(unsigned short); // now let’s create the table for(loop=0;loop<TABLE_SIZE;loop++) { 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]; } // This is 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 __._,_.___ Posted by: __,_._,___ |
<Prev in Thread] | Current Thread | [Next in Thread> |
---|---|---|
|
Previous by Date: | RE: [ts-7000] how do I synchronize two (or more) digital output pins, 'Daniel Perron' djperron@optest.com [ts-7000] |
---|---|
Next by Date: | [ts-7000] Re: how do I synchronize two (or more) digital output pins, djperron@optest.com [ts-7000] |
Previous by Thread: | RE: [ts-7000] how do I synchronize two (or more) digital output pins, 'Daniel Perron' djperron@optest.com [ts-7000] |
Next by Thread: | [ts-7000] Re: how do I synchronize two (or more) digital output pins, djperron@optest.com [ts-7000] |
Indexes: | [Date] [Thread] [Top] [All Lists] |
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