• slider image 442
  • slider image 509
  • slider image 510
  • slider image 511
  • slider image 512
  • slider image 513
  • slider image 514
  • slider image 515
:::


Browsing this Thread:   1 Anonymous Users




(1) 2 »


Re: 請問結構的指標!
#13
資深會員
資深會員


查看用戶資訊
你好:
了解,Thanks.

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


Re: 請問結構的指標!
#12
資深會員
資深會員


查看用戶資訊
1. 既然用的是pic16f914,怎會又和C18扯上關係?
C18又不能用在PIC16F914上

2. 你的需求用union是不可能達到的,只能自己寫個程式轉換


這樣做如何?

uns16 *ip, num;
uns8 *p0,*p1;

num=0x1234;

ip=# //ip 指向0x1234
p0=(uns8*)ip; //p0 指向 0x34
p1=p0+1; //p1 指向 0x12

發表於: 2008/11/7 13:23

Edited by nicecookie on 2008年11月07日 16:39:53
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請問結構的指標!
#11
資深會員
資深會員


查看用戶資訊
大家好:
1.Hitec PICC用的是16F914,但我不知ram<256會怎樣(沒試過).
2.原本16 bits的指標,我想變成2個8 bits指標,
而且16 bits跟2個8 bits都要可以使用,所以我
想到用union
3.結果用C18卻發生8 bits不能使用的狀況!
而ptr0和ptr1應該顯示為8 bits但卻顯示16 bits,
所以我不知是何原因?
4.構想為ptr1為ram bank切換,而ptr0為offset.

感謝大家的回覆,煩請指正,Thanks.

發表於: 2008/11/7 12:43
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請問結構的指標!
#10
資深會員
資深會員


查看用戶資訊
很好奇
開版大用的是哪個PIC型號, 哪個C compilier ?



不知道對於ram小於256byte的 PIC
Hitech PICC 的指標是用1byte還是2byte ?

發表於: 2008/11/7 11:09
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請問結構的指標!
#9
資深會員
資深會員


查看用戶資訊
如前所述,指標存放的是變數的位址,要提醒的是: 如果指標只有 8 bit, 只能定址到 256 個地址的能力。

PIC 是 Harvard 架構,RAM 與 Program 存在於不同的空間,word size 不同,定址範圍也不相同,要分別考慮。 除非是一些容量很小的 PIC,否則 8 bit 的指標實在不夠用。

以 Hitech PICC (for PIC16 以下)為例,該編譯器所實作的指標如下:

3.4.11 Pointer Types

The format and use of pointers depend upon the range of processor selected. This is described in the
following sections.

3.4.11.1 Baseline Pointers
All pointers in the Baseline (12-bit PICs) range are 8-bits.
• RAM pointers point to RAM using the FSR index register.
• Const pointers point to ROM via a RETLW table.
• Function Pointers reference functions. A function is jumped to rather than called. A jump
table is used to return control to the calling function.

3.4.11.2 Midrange Pointers
All pointers for Midrange processors (14-bit PICs) are the same as for Baseline processors with the
following exceptions:
50
C Language Features Supported Data Types and Variables
RAM pointers are 8-bits and therefore can only access 256 bytes. A pointer which is unqualified
or has a bank 1 qualifier can point to any object in bank 0 or bank 1. If the pointer is
qualified as bank 2 or bank 3, then it can access any object in banks 2 or 3. At present, there
is no general purpose pointer that can read and write to all four banks.
Const pointers are 16-bits wide. They can be used to access either ROM or RAM. If the upper
bit of the const pointer is non-zero, it is a pointer into RAM. A const pointer may be used to
read from any RAM location in any bank, but writing to such locations is not permitted. If
upper bit is zero, it is a pointer able to access the entire ROM space. The ability of this pointer
to access both ROM and RAM is very useful in string-related functions where a pointer passed
to the function may point to a string in ROM or RAM.
• Function pointers reference functions. A function is called using the address assigned to the
pointer.

3.4.11.3 Highend Pointers
Highend processors (17Cxxx processors) differ in many ways from baseline and midrange processors
and this effects the way pointers have been implemented.
RAM banks in highend processors are 0xFF bytes long, so an 8-bit RAM pointer can only
access objects in one bank.
Thus a bank 0 RAM pointer can only access bank 0; a bank 1
RAM pointer can only access bank 1, etc...
Const pointers for highend processors are 16-bits wide. Const pointers on highend processors
work in the same way as they do for midrange processors.
Far pointers are 16-bits wide and can be used to access objects in any available bank of RAM.
These pointers are similar to const pointers; they differ in that they may be used to indirectly
read from, or write to, RAM locations. Far pointers can also access ROM locations as per
const pointers. The far qualifier is used to specify the larger pointer size.
• Function pointers reference function. A function is called using the address assigned to the
pointer

至於 PICC18, 可能也有一些類似情形,我手上沒裝,確實情形請到 C:\Program Files\HI-TECH Software 下找一下 manual 查查看。


另附網路上找到的一篇 Comparison of Hi-Tech PICC-18 and MPLAB C18:
http://www.xargs.com/pic/picc18-vs-c18.html

發表於: 2008/11/7 10:35
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請問結構的指標!
#8
版主
版主


查看用戶資訊
如果在 如果在 C18 下的 RAM 指摽會使用 FSR0 暫存器 (13-bit) 來當作 RAM 的指標。

uns8* A; 是宣告一個 A 的指標,是屬於指向 unsigned char 的指標。這點你好像誤會了。

發表於: 2008/11/7 8:11
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請問結構的指標!
#7
資深會員
資深會員


查看用戶資訊
謝謝指教,感恩.
我想我測試出來應該是:
ram_addr=0x500;
uns8* A;
A=&ram_addr;
雖然A是8 bits,但編譯器會強制變為16 bits,
所以0x05為不可變位址,而只能更改0x00~0xff,
這是我覺得奇怪的地方!反正就是只能這樣用了,
Thanks.

發表於: 2008/11/6 14:46
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請問結構的指標!
#6
資深會員
資深會員


查看用戶資訊
其實也不太明白你的需求

如果是要把 unsigned int* 指標
轉成 unsigned char* 的話
可以用強制型別轉換
但不知是否合你需求
我大概也只會這個了
用結構的話,偶不會~

ex.

unsigned char *p;
unsigned int *ip;
unsigned int ap[5];

ip=ap;
*ip=0x1234;

p=(unsigned char*)ip;
*p=0x78;
p++;
*p=0x56;

結果,原來的0x1234會被改成 0x5678

發表於: 2008/11/6 14:28
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請問結構的指標!
#5
資深會員
資深會員


查看用戶資訊
大家好:
設ram區塊在bank5(0x500),
而指標ptr為16 bits,
因此ptr++; //(0x502)
所以我想將指標ptr為16 bits,
能夠轉成2 bytes的指標,
我該如何讓ptr++; //(0x501)

煩請告知,Thanks.

發表於: 2008/11/6 14:06
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請問結構的指標!
#4
資深會員
資深會員


查看用戶資訊
你好:
謝謝指教.
剛剛我用HTC V9.6顯示是正常的,
ptr0和ptr1為byte.

不知為何C18有這問題呢?
Thanks.

發表於: 2008/11/6 9:46
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... ]

教育訓練中心

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