Browsing this Thread:
2 Anonymous Users
|
Re: 我寫的TLC2543的驅動程序
|
|
新會員
Joined
: 2007/4/18 12:29 最後登入時間
: 2007/6/30 16:19
Group:
註冊會員
Level : 1 HP : 0 / 15 MP : 2 / 769 EXP : 60
|
可能是晶振的問題。板子外接10MHz晶體振盪器,TLC2543時鐘要求4MHz。這該如何實現,在程序裏延時可以麽?
發表於: 2007/4/26 18:36
|
|
|
我寫的TLC2543的驅動程序
|
|
新會員
Joined
: 2007/4/18 12:29 最後登入時間
: 2007/6/30 16:19
Group:
註冊會員
Level : 1 HP : 0 / 15 MP : 2 / 769 EXP : 60
|
#define io_clk PORTAbits.RA0 #define io_clk_dir TRISAbits.TRISA0 #define ad_data_in PORTAbits.RA1 #define ad_data_in_dir TRISAbits.TRISA1
#define ad_data_out PORTAbits.RA2 #define ad_data_out_dir TRISAbits.TRISA2 #define ad_cs PORTAbits.RA3 #define ad_cs_dir TRISAbits.TRISA3 #define ad_eoc PORTAbits.RA4 #define ad_eoc_dir TRISAbits.TRISA4
#define port_out 0 #define port_in 1
void ad_setup(); unsigned int ad_setgetchannel(unsigned char channel);
unsigned int ad_data;
void main(void) { ad_setup(); while(1) { ad_data = ad_setgetchannel(0); Nop(); Nop(); } }
//call this once to set it up void ad_setup() { ad_data_in_dir = port_out; ad_data_out_dir = port_in; io_clk_dir = port_out; ad_cs_dir = port_out; ad_eoc = port_in; ad_cs = 1; }
unsigned int ad_setgetchannel(unsigned char channel) { signed char i; unsigned int data = 0x0; unsigned int ch_config;
i=0; do {} while( ad_eoc == 0); io_clk = 0; ad_cs = 0; / for (i=0;i<12;i++) { data <<=1; data |=ad_data_out;
if (channel&=0x80) ad_data_in =1; else ad_data_in = 0;
io_clk=1; channel <<= 1; io_clk=0; } ad_cs = 1; return data; }
請幫我看下有什麽問題麽?在watch窗口裏看到ad_data值總是零。我用的18f452。spi接口另有用処所以用軟件模擬了spi。
發表於: 2007/4/26 16:52
|
|
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.