Browsing this Thread:
1 Anonymous Users
|
請問
|
|
新會員
Joined
: 2006/6/14 11:34 最後登入時間
: 2012/5/2 17:44
Group:
註冊會員
Level : 1 HP : 0 / 8 MP : 1 / 456 EXP : 34
|
最近再寫一個A/D後存值--->再經由rs232傳到PC, 可是我發現我傳的筆數是陣列值的1/4,之後我有查看一下, array_index的變數都是一次加四(0,4,8,12.......), 可是我現在一直找不到原因, 不知道大大們,可以給我一些建議嗎?? 由於這是我第一次使用dspic所以有很多設定不清楚。 以下是我寫的程式。
#include "p30f3014.h" #include <stdio.h>
#define counter 1000 unsigned int array_index=0; unsigned int array1[counter] __attribute__((persistent,aligned(32))); char flag=0,count=0;
void put(char cc) { U1TXREG=cc; while(!U1STAbits.TRMT) ; } void getAD() { ADCON1bits.FORM = 0;//0000 dddd dddd dddd ADCON1bits.SSRC = 7; ADCON1bits.ASAM = 1;//1自動 0手動 ADCON2bits.VCFG = 0; ADCON2bits.BUFM = 0; ADCON3bits.ADRC = 0; ADCON3bits.SAMC =1;//11 samping時間 ADCON3bits.ADCS =7;//4/7 ADCHSbits.CH0SA =0; ADCSSL =1; ADPCFG =0xFFFE; ADCON1bits.ADON = 1; /////////////////////////////////////// ADCON1bits.DONE=0; ADCON1bits.SAMP=1; while(ADCON1bits.DONE==0) ; array1[array_index]=ADCBUF0; array_index=array_index+1; if(array_index==counter) { flag=1; array_index=0; } } int main(void) { TRISD=0xFF00; LATDbits.LATD0=1; U1BRG=38; U1MODE=0x8000; U1STAbits.UTXEN=1; while(1) { if(flag==0) getAD(0); if(flag==1) { if(array_index<counter) { LATDbits.LATD0=0; put(array1[array_index]>>8); put(array1[array_index]); array_index=array_index+1; } else { LATDbits.LATD0=1; flag=2; } }
}
}
發表於: 2006/6/16 10:39
|
|
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.