智能车制作
标题:
麻烦大家帮助分析一下我想发送数据0到99,但收到的为100个0
[打印本页]
作者:
黄河浪
时间:
2012-3-30 09:41
标题:
麻烦大家帮助分析一下我想发送数据0到99,但收到的为100个0
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
void SCI0_Init(void);
void delay(void);
void SET_PLL(void);
void PWM_Init(void);
void SendChar(unsigned char text);
unsigned char loop_index;
void SCI0_Init(void)
{
SCI0BD=312.5;
SCI0CR1=0x00;
SCI0CR2=0x0c;
}
/*****************锁相环程序*****************/
void SET_PLL(void)
{ //设置锁相环时钟频率为48M
SYNR=2;
REFDV=1; //PLLCLK=2*OSCCLK*(SYNR+1)/(REFDV+1)
asm NOP;
asm NOP;
asm NOP;
while((CRGFLG&0X08)==0);//等待锁相环频率锁定
CLKSEL=0X80; //选定锁相环时钟
}
void SendChar(unsigned char text)
{ while (!(SCI0SR1&0x80));
SCI0DRH=0;
SCI0DRL =text;
}
void delay(void)
{
unsigned int loop_i,loop_j;
for(loop_i=0;loop_i<500;loop_i++)
{
for(loop_j=0;loop_j<500;loop_j++)
{
;
}
}
}
/*****************PWM初始化程序***************/
void PWM_Init(void)
{
PWME=0X00;//关闭所有PWM输出
PWMPRCLK=0X22;//24M/4=6M
PWMSCLA=0X06; //6M/(2*6)=0.5M
PWMSCLB=0X03; //6M/(2*3)=1M
PWMCTL=0X20; //通道2和通道2合并
PWMCLK=0X3C; //通道23,4,5选择clocksA
PWMPOL=0X3C; //PWM先输出高电平
PWMCAE=0X00; //左对齐
PWMPER23=10000;//周期为10ms
PWMDTY23=1500;//输出角度为0度
PWMPER4 = 100; //5KHz
PWMPER5 = 100; //5KHz
PWMDTY4 =30;//初始速度设置为0
PWMDTY5 =0;
PWME=0X3C;//开启PWM23,PWM4,PWM5
}
void main(void)
{
//unsigned char loop_index;
SCI0_Init();
PWM_Init();
for(loop_index=0;loop_index<100;loop_index++)
{
while(!SCI0SR1_TDRE)//等待发送缓冲区空
SCI0DRL=loop_index;
SendChar(SCI0DRL);
PWMDTY4 =15;
delay();
}
while(1)
{
}
}
欢迎光临 智能车制作 (http://dns.znczz.com/)
Powered by Discuz! X3.2