智能车制作
标题:
串口 G128
[打印本页]
作者:
yahui123
时间:
2012-3-27 17:22
标题:
串口 G128
请问下 我这程序有什么问题 我接不到数据
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
// 函数声明
void SCI0_Init(void);
void SCI0_BR(void);
void SCI0_SendByte(char ch);
void Service_WD(void);
void SetBusClock_40MHz(void);
// 全局变量
char SCI_Flag = 0;
char SCI_Rev = 0;
void main(void) {
/* put your own code here */
SetBusClock_40MHz();
SCI0_BR();
SCI0_Init();
作者:
yahui123
时间:
2012-3-27 17:23
EnableInterrupts;
SCI0_SendByte(0x01);
SCI0_SendByte(0x02);
SCI0_SendByte(0x03);
for(;;) {
_FEED_COP(); /* feeds the dog */
if(SCI_Flag==1) {
SCI_Flag = 0;
SCI0_SendByte(SCI_Rev);
}
} /* loop forever */
/* please make sure that you never leave main */
}
void Service_WD(void)
{
CPMUARMCOP = 0x55;
CPMUARMCOP = 0xAA;
}
/*************总线频率40M***********/
void SetBusClock_40MHz(void)
{
CPMUOSC_OSCE = 1; /* enable ext osc */
CPMUSYNR = 0xc0 | 0x04; /* VCOFRQ[7:6], SYNDIV[5:0] */
CPMUREFDIV = 0xc0 | 0x01; /* REFFRQ[7:6], REFDIV[3:0] */
CPMUPOSTDIV = 0x00; /* POSTDIV = 0 FPLL = FVCO */
while(!CPMUFLG_LOCK); /* wait for VCO to stabilize*/
_FEED_COP();
CPMUCLKS_PLLSEL = 1; /* Switch clk to use PLL */
}
//串口初始化
void SCI0_Init(void)
{
SCI0CR1 = 0x00; /* 8 Data Bits, 1 Start Bit, 1 Stop Bit, No Parity */
SCI0CR2 = 0x2C; /* 使能接收中断;使能 Tx,Rx */
/* SCIASR1, SCIACR1, SCIACR2, SCISR1, SCISR2, SCIDRH & SCIDRL left at default values */
}
//串口波特率设置
void SCI0_BR(void)
{
/* Set the Baud Rate */
SCI0BDH = 0x01;
SCI0BDL = 0x04; //波特率 9600
}
//串口发送字节
void SCI0_SendByte(char ch)
{
/* check SCI transmit data register is empty */
while(SCI0SR1_TDRE == 0);
SCI0DRL = ch;
}
//串口中断
#pragma CODE_SEG __NEAR_SEG NON_BANKED
void interrupt VectorNumber_Vsci0 SCI0_ISR(void)
{
SCI0CR2_RIE=0;
while(SCI0SR1_RDRF == 0);
SCI_Rev = SCI0DRL;
SCI_Flag = 1;
SCI0CR2_RIE = 1;
}
#pragma CODE_SEG DEFAULT
作者:
流水青云
时间:
2012-3-29 00:30
我也有问题。。
作者:
yahui123
时间:
2012-3-29 16:22
流水青云 发表于 2012-3-29 00:30
我也有问题。。
问题已解决 是自己的硬件问题 换了硬件就好了
欢迎光临 智能车制作 (http://111.231.132.190/)
Powered by Discuz! X3.2