高级会员
- 积分
- 792
- 威望
- 414
- 贡献
- 152
- 兑换币
- 0
- 注册时间
- 2010-11-21
- 在线时间
- 113 小时
|
5贡献
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
void SetBusCLK_80M()
{
CLKSEL=0X00; //disengage PLL to system
PLLCTL_PLLON=1; //turn on PLL
SYNR =0xc0 | 0x09; //后六位有效
REFDV=0x80 | 0x01; //后四位有效
POSTDIV=0x00; //PLL Clock=2*OSC*(1+SYNR)/(1+REFDV)=160MHz;
_asm(nop); //BUS Clock=80M
_asm(nop);
while(!(CRGFLG_LOCK==1)); //when pll is steady ,then use it;
CLKSEL_PLLSEL =1; //engage PLL to system;
}
void SCI_Init()
{
SCI0CR1 = 0x04; //9 bits, no parity
SCI0CR2_RE = 1; //Enable Rxd
SCI0CR2_TE = 1; //Enable Txd
SCI0CR2_RIE = 1; //Rxd interrupt
SCI0CR2_TCIE = 0; //Disable Txd interrupt
SCI0BDH = 0X02;
SCI0BDL = 0X08; //SCI baud rate=busclk/(16*SCI0BDL)
//busclk 8MHz, 9600bps, SCI0BD=0x34
//busclk 16MHz, 9600bps, SCI0BD=0x68
//busclk 24MHz, 9600bps, SCI0BD=0x9C
//busclk 32MHz, 9600bps, SCI0BD=0xD0
//busclk 48MHz, 9600bps, SCI0BD=0x138
//busclk 80MHz, 9600bps, SCI0BD=0x208
//busclk 80MHz, 38400bps, SCI0BD=0x82
//busclk 80Mhz, 115200bps, SCI0BD=0x2B
}
void SCI_Send_Data(byte data)
{
while( !(SCI0SR1 & 0x80) );
SCI0DRL = data;
}
void delay_us(int time) {
int i,j;
for(i=0;i<time;i++)
for(j=0;j<100;j++); //100
}
void send_pic()
{int n,j;
// rec_cmd=0;
DisableInterrupts;
delay_us(10);
SCI_Send_Data('p');
SCI_Send_Data('i');
SCI_Send_Data('c');
EnableInterrupts;
}
void main(void) {
/* put your own code here */
SetBusCLK_80M();
SCI_Init();
EnableInterrupts;
for(;;) {
send_pic();
_FEED_COP(); /* feeds the dog */
} /* loop forever */
/* please make sure that you never leave main */
}
做labvIEW通信的时候,用这个程序发送,SCI0DRL一直没有值。。不知道怎么回事,麻烦大家赐教下~~
谢谢谢谢谢~~~ 头疼shi我了。。。 |
|