• slider image 442
  • slider image 483
  • slider image 484
  • slider image 485
  • slider image 486
  • slider image 487
  • slider image 488
  • slider image 491
:::


Browsing this Thread:   1 Anonymous Users






Re: 請問要做shift的動作,最長變數可宣告幾個byte?
#5
資深會員
資深會員


查看用戶資訊
謝謝,我怕pic記憶體單word byte數問題不能用shift
這樣說來用c 語言不會有這種問題!?

我最後一個bit寫在迴圈之外,因為我先加再移,最後一bit會被移位
所以最後一bit寫到迴圈外,直接加
聽您這麼說,第一bit先移應該不影響,會更方便沒錯


發表於: 2006/7/14 17:01
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請問要做shift的動作,最長變數可宣告幾個byte?
#4
版主
版主


查看用戶資訊
因該是先將 anglr_data 的資料向左移一位後再加 DATAIN bit
才對。

發表於: 2006/7/14 10:05
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請問要做shift的動作,最長變數可宣告幾個byte?
#3
資深會員
資深會員


查看用戶資訊
請問一下,若只抓18個bit,下面這樣寫不對嗎?

#define DATAIN PORTCbits.RC4
#define NUM_DATAIN 18
unsigned long angle_data; // 32 bits

for ( i = 0; i< NUM_DATAIN-1 ; i++)
{
Delay10TCYx(2);
SPI_CLK = 1; //
Delay10TCYx(2);
SPI_CLK = 0; //
angle_data = ( angle_data + DATAIN ) << 1;//這行
}

Delay10TCYx(2);
SPI_CLK = 1; //
Delay10TCYx(2);
angle_data = ( angle_data + DATAIN ) << 1; //Get last bits 和這行
Delay10TCYx(4);
SPI_CSA = 1;

發表於: 2006/7/13 17:06
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請問要做shift的動作,最長變數可宣告幾個byte?
#2
版主
版主


查看用戶資訊
你要旋轉的資料長度超過 Long 而且還要有輸入的一個位元,
所以用C來寫會比較辛苦一點,建議用 In-Line Assembly 或利用 C18 所提供的Macro來寫,C18 的 Macro 指令在 H 檔裡有宣告過如下所示:

可以開一的陣列內含五個 unsigned char的buffer, 檢查輸入的位元是 1 還是 0 以設定 C flag ,再利用 RLCF 指令透過for迴圈轉 5 個 Byte (陣列裡) 總共要做39次就可以了。

/*-------------------------------------------------------------------------
 * Some useful macros for inline assembly stuff
 *-------------------------------------------------------------------------*/
#define Nop()    {_asm nop _endasm}
#define ClrWdt() {_asm clrwdt _endasm}
#define Sleep()  {_asm sleep _endasm}
#define Reset()  {_asm reset _endasm}

#define Rlcf(f,dest,access)  {_asm movlb f rlcf f,dest,access _endasm}
#define Rlncf(f,dest,access) {_asm movlb f rlncf f,dest,access _endasm}
#define Rrcf(f,dest,access)  {_asm movlb f rrcf f,dest,access _endasm}
#define Rrncf(f,dest,access) {_asm movlb f rrncf f,dest,access _endasm}
#define Swapf(f,dest,access) {_asm movlb f swapf f,dest,access _endasm }

發表於: 2006/7/13 14:22
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


請問要做shift的動作,最長變數可宣告幾個byte?
#1
資深會員
資深會員


查看用戶資訊
我想1個bit一個bit連續抓39bit,配合shift動作
不知道使用c18,變數可有辦法
宣告成unsigned long int,再配合shift來完成呢

這樣合乎c嗎?

發表於: 2006/7/13 13:47
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部







You can view topic.
不可以 發起新主題
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.
You cannot use topic type.
You cannot use HTML syntax.
You cannot use signature.
You cannot create PDF files.
You cannot get print page.

[進階搜尋]


:::

Microchip連結

https://www.facebook.com/microchiptechnologytaiwan/
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=13
https://mu.microchip.com/page/tmu
http://elearning.microchip.com.tw/modules/tad_link/index.php?cate_sn=1
https://page.microchip.com/APAC-PrefCenters-TW.html
http://www.microchip.com/
http://www.microchip.com/treelink
http://www.microchipdirect.com/
http://www.microchip.com.cn/newcommunity/index.php?m=Video&a=index&id=103
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=2
http://www.microchip.com.tw/Data_CD/eLearning/index.html
http://www.microchip.com.tw/RTC/RTC_DVD/
https://www.microchip.com/development-tools/
https://www.youtube.com/user/MicrochipTechnology
[ more... ]

教育訓練中心

!開發工具購買
辦法說明 [業界客戶] [教育單位]
----------------------------------
!校園樣品申請
辦法說明 [教師資格] [學生資格]
----------------------------------