• slider image 514
  • slider image 516
  • slider image 517
  • slider image 518
  • slider image 519
:::


Browsing this Thread:   2 Anonymous Users






Re: 請教C18的寫法
#5
高級會員
高級會員


查看用戶資訊
找到解決的方法了,謝謝指點。
typedef union{
unsigned char Byte;
   
struct{
      
unsigned b0:1;
      
unsigned b1:1;
      
unsigned b2:1;
      
unsigned b3:1;
      
unsigned b4:1;
      
unsigned b5:1;
      
unsigned b6:1;
      
unsigned b7:1;
   }
bits;
}
_out;


_out out;
#define out_byte out.Byte
//---------------------------------------------------
#define out_bits out.bits
//---------------------------------------------------

BYTE SPI(BYTE outdata){
    
out_byte=outdata;
}


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


Re: 請教C18的寫法
#4
高級會員
高級會員


查看用戶資訊
typedef    unsigned char    BYTE;
...................................
BYTE _out;
union {
  
struct {
    
unsigned b0:1;
    
unsigned b1:1;
    
unsigned b2:1;
    
unsigned b3:1;
    
unsigned b4:1;
    
unsigned b5:1;
    
unsigned b6:1;
    
unsigned b7:1;
  };
out=0;
..............................................
BYTE SPI(BYTE);
..............................................
BYTE SPI(BYTE outdata){
//    out=outdata;   <== compiler說型態錯誤,那要如何把outdata的資料放入out 比較方便?
    
}

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


Re: 請教C18的寫法
#3
資深會員
資深會員


查看用戶資訊
C18沒辦法直接那樣定義, 只能換個方式達到你要的

ex.
#define DB0 PORTDbits.RD0
#define DB1 PORTDbits.RD1


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


Re: 請教C18的寫法
#2
版主
版主


查看用戶資訊
Hi-Tech C & CCS 都可以用特定的指令bit來定義單一位元或I/O 腳位,但C18只能用位元結構的方式定義位元,詳細用法請參考W410 workshop教材或C18裏的H檔裡的宣告

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


請教C18的寫法
#1
高級會員
高級會員


查看用戶資訊
這是截取CC5X 部份的程式碼,宣告pin腳的部份還ok, 不知道c18能不能寫到那麼簡明?

#pragma bit CS @ PORTC.2    // output for chip select CS
#pragma bit SCK @ PORTC.3    // clock output
#pragma bit SDO @ PORTC.5    // data output (PIC)
#pragma bit SDI @ PORTC.4    // data input (PIC)

char SPI(char out)  // software SPI function at about 620 kHz for a 20MHZ crystal
{
    
char in,i;
    for (
08i++)
    {
        
nop2();
        
SCK 0;          // falling edge of clock
        
nop();
        
SDO out.7;      // prepare data
        
nop();
        
out out<<1;     // shift output byte for next loop
        
nop2();
        
in in<<1;       // shift input data for next loop
        
SCK 1;          // rising edge of clock
        
nop();
        
in.0 SDI;       // read input data
    
}
    return 
in;
}



發表於: 2006/11/13 10:19
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... ]

教育訓練中心

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