• slider image 442
  • slider image 497
  • slider image 498
  • slider image 499
  • slider image 500
  • slider image 502
:::


Browsing this Thread:   1 Anonymous Users






訪客
CANbus & USART
#1
各位前輩大家好:

我是學習PIC的新手,目前所用晶片為PIC18F4620
並置於PICDEM Z這塊板子,主要使用於
CAN Bus與USART傳輸之設定
不過在編譯過程遭遇sprintf & sscanf之麻煩,
sprintf--->type qualifier mismatch in assignment
sscanf--->call of function without prototype
如此看來需要在額外定義此兩個指令或是?

希望各位前輩不吝嗇給予指教,謝謝!

unsigned char Key;
int i;
char data[50];

void PutrsUSART( const rom char *data );
void getsUSART ( char * buffer, unsigned char len );
void OpenPORTB ( unsigned char config);

//Checking busy or not
void USARTOut(char *data, char bytes){

for(i=0; i<bytes; i++){

while(BusyUSART());
WriteUSART(data[i]);
}
}
void Init_IO(void){

PORTA = 0; //PORTA initially all zeros
TRISA = 0xF8; //RA0 and RA1 outputs (LEDs)
TRISB = 0xFF; //PORTB all inputs (RB0 is interrupt, RB4 and RB5 are push buttons)

OpenUSART( USART_TX_INT_OFF // Set TXSTA Reg. =0b00100100
& USART_RX_INT_OFF // Set RCSTA Reg. =0b10010000
& USART_ASYNCH_MODE
& USART_EIGHT_BIT
& USART_CONT_RX
& USART_BRGH_HIGH,25 ); // Set SPBRG=103, Baud Rate = 9600
}

void initCAN(char *data, char bytes){

PutrsUSART("\r\r\r\r\r\r\r\r"); //clear CAN232 buffer
getsUSART(data,20);

PutrsUSART("C\r"); //close CAN channel
getsUSART(data,1);

PutrsUSART("X1\r"); //set auto poll
getsUSART(data,1);

PutrsUSART("s82EB\r"); //set CAN bit rate
getsUSART(data,1);

PutrsUSART("O\r"); //open CAN channel
getsUSART(data,1);

PutrsUSART("t010103\r"); //connect to videoray
getsUSART(data,2);
}

//SendCan function
int SendCAN(VideoRayCommandPacket c){

sprintf(data,"t010703%02x%02x%02x%02x%02x%02x\r",
c.StbdThruster,
c.PortThruster,
c.VertThruster,
c.Lights,
c.CtrlBits1,
c.CtrlBits2);

USARTOut(data,strlen(data));
}

//ReceiveCAN function
unsigned char DataType,HeadingLow,HeadingHigh,DepthLow,DepthHigh;

int ReceiveCAN(unsigned int *h,unsigned int *d){

int temp;

getsUSART(data,18);

sscanf(data,"t0186%2x%2x%2x%2x%2x",
&DataType,
&HeadingLow,
&HeadingHigh,
&DepthLow,
&DepthHigh);

USARTOut(data,strlen(data));
}
//********************************************************************//
//** Function to output an array of bytes to the USART (RS232 port) **//
//********************************************************************//
void main(void){

Init_IO();

while(initCAN == 0){

Command.VertThruster = 0;
Command.PortThruster = 0;
Command.StbdThruster = 0;
Command.Lights = 0;
Command.CtrlBits1 = 0;
Command.CtrlBits2 = 0;
}
while(1){

switch(Key){
case 'RB4': //up
if (RB4 == 1){
LED0 = 0x05; //RA0 LED ON
Delay10KTCYx(40);
Command.VertThruster = 100;
Command.CtrlBits2 = 0; //D6 = 0, Vertical up;
}else{
LED0 = 0x04; //RA0 LED OFF
}
break;

case 'RB5': //down
if (RB5 == 1){
LED1=0x06; //RA1 LED ON
Delay10KTCYx(40); // Waiting time instead of pressing button
Command.VertThruster = 100;
Command.CtrlBits2 = 0x40; //D6 = 1, Vertical down;
}else{
LED1=0x04; //RA1 LED OFF
}
break;
}
}
}
void PutrsUSART( const rom char *data ){
do{
while(!(TXSTA & 0x02));
TXREG = *data;
}while(*data++);
}

並於LED1=0x04; //RA1 LED OFF
此行出現重複定義之問題
但我想目的同LED0為何會有重複定義之問題呢?

謝謝,感激不盡!

Attach file:


Link only for registered users


Edited by bn10051 on 2009年07月09日 07:17:14
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... ]

教育訓練中心

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