求大神帮忙看看是哪里出错了,我调试了很久,B6引脚接75176的控制端口。具体程序和投文件在附件:
部分程序:#include <stdio.h>
#include "NUC1xx.h"
#include "DrvGPIO.h"
#include "DrvTIMER.h"
#include "DrvSYS.h"
#include "DrvCAN.h"
#include "DrvUART.h"
#define uint unsigned int
#define uchar unsigned char
// char GetChar(void) ;
STR_CANMSG_T rrMsg;
STR_CANMSG_T tMsg;
int flag,flag2,aa,a;
uint32_t uTimerEventNo[4];;
volatile uint32_t u32Timer0Cnt=0;
// void send(char ch);
// void SendChar(int ch);
// char GetChar(void) ;
void delayms(uint t)
{
uint i;
while((--t) != 0){
for(i = 0;i <125;i++); //i 从0加到125,在12M晶体下CPU大概耗时1毫秒
}
}
//void SendChar_ToUART1(int ch)
void get(void)
{
while(UART2->FSR.RX_EMPTY ==0) ;
UART2->DATA;
}
void send(char ch)
{
if(flag2 == 1)
{
while(UART2->FSR.TX_FULL == 1);
UART2->DATA = ch;
if(ch == '\n'){
while(UART2->FSR.TX_FULL == 1);
UART2->DATA = '\r';
}
}
if(flag2 == 2)
{
delayms(500);
while(UART1->FSR.TX_FULL == 1);
DrvGPIO_SetBit(E_GPB,6);
UART1->DATA = ch;
delayms(10);
// while(UART1->FSR.TE_FLAG==1);
// while(UART1->FSR.TX_EMPTY==0);
DrvGPIO_ClrBit(E_GPB,6);
if(ch == '\n'){
while(UART1->FSR.TX_FULL == 1);
// DrvGPIO_SetBit(E_GPB,6);
UART1->DATA = '\r';
// delayms(10);
}
}
if(flag2 == 0)
{
while(UART0->FSR.TX_FULL == 1);
UART0->DATA = ch;
if(ch == '\n'){
while(UART0->FSR.TX_FULL == 1);
UART0->DATA = '\r';
}
}
// DrvGPIO_ClrBit(E_GPB,6);
}
void Test_NormalMode_Tx()
{
tMsg.FrameType= DATA_FRAME;
tMsg.IdType = CAN_EXT_ID;
tMsg.Id = 0x12345;
tMsg.DLC = 8;
tMsg.Data[0] = 0x10;
tMsg.Data[1] = 0x11;
tMsg.Data[2] = 0x12;
tMsg.Data[3] = 0x13;
tMsg.Data[4] = 0x14;
tMsg.Data[5] = 0x15;
tMsg.Data[6] = 0x16;
tMsg.Data[7] = 0x17;
if(DrvCAN_SetTxMsgObj(MSG(1),&tMsg) < 0)
{
return;
}
DrvCAN_SetTxRqst(MSG(1));
}
void CAN_CallbackFn(uint32_t u32IIDR)
{
if(u32IIDR==1)
{
DrvCAN_ReadMsgObj(0,TRUE,&rrMsg);
}
if(u32IIDR==5+1)
{ flag=0;
DrvCAN_ReadMsgObj(5,TRUE,&rrMsg);
if(rrMsg.Data[0]==0x1)flag=1;
if(rrMsg.Data[0]==0x2)flag=2;
if(rrMsg.Data[0]==0x3)flag=3;
if(rrMsg.Data[0]==0x4)flag=4;
if(rrMsg.Data[0]==0x5)flag=5;
if(rrMsg.Data[0]==0x6)flag=6;
if(rrMsg.Data[0]==0x7)flag=7;
}
if(u32IIDR==31+1)
{
DrvCAN_ReadMsgObj(31,TRUE,&rrMsg);
}
}
void TMR0_Callback(uint32_t u32Param)
{
if (u32Param == 1)
{
++u32Timer0Cnt, DrvTIMER_GetIntTicks(E_TMR0);
}else
{
++u32Timer0Cnt;
}
}
void Test_NormalMode_Rx1()
{
if(DrvCAN_SetRxMsgObj(MSG(5),CAN_EXT_ID, 0x0,TRUE) < 0)
{
return;
}
/* INT Mode */
DrvCAN_EnableInt(CAN_CON_IE);
DrvCAN_InstallCallback(CALLBACK_MSG, (CAN_CALLBACK)CAN_CallbackFn);
}
void count()
{
DrvTIMER_Init();
/* Set all the default TIMER clock sources are from 12MHz */
DrvSYS_SelectIPClockSource(E_SYS_TMR0_CLKSRC, 0);
DrvTIMER_Open(E_TMR0, 1000, E_PERIODIC_MODE);
DrvTIMER_EnableInt(E_TMR0);
DrvTIMER_Start(E_TMR0); /* Start counting */
DrvTIMER_Delay(E_TMR0, 40);
DrvTIMER_Close(E_TMR0);
}
void count1()
{
int i;
for(i=0;i<40000;i++)
{ DrvGPIO_Open(E_GPA,0, E_IO_INPUT);
DrvGPIO_SetBit(E_GPB, 12) ;
DrvGPIO_ClrBit(E_GPB, 12) ;//开573
if(DrvGPIO_GetBit(E_GPA,0)==1) {aa=1;}
DrvGPIO_SetBit(E_GPB, 12) ;
DrvGPIO_Close(E_GPA,0);
if(aa==1) break;
}
}
/*can初始化*/
void can()
{
/* Select CAN Multi-Function */
DrvGPIO_InitFunction(E_FUNC_CAN0);
DrvCAN_Init();
DrvCAN_Open(20);
Test_NormalMode_Rx1();
}
void can0()
{
/* Select CAN Multi-Function */
DrvGPIO_InitFunction(E_FUNC_CAN0);
DrvCAN_Init();
DrvCAN_Open(20);
}
void u()
{
/*串口配置部分*/
/* Step 1. GPIO initial */
SYS->GPBMFP.UART1_RX =1;
SYS->GPBMFP.UART1_TX =1;
/* Step 2. Enable and Select UART clock source*/
UNLOCKREG();
SYSCLK->PWRCON.XTL12M_EN = 1;
SYSCLK->CLKSEL0.HCLK_S=0;
LOCKREG();
SYSCLK->APBCLK.UART1_EN = 1;//Enable UART clock
SYSCLK->CLKSEL1.UART_S = 0; //Select 12Mhz for UART clock source
SYSCLK->CLKDIV.UART_N = 0; //UART clock source = 12Mhz;
/* Step 3. Select Operation mode */
UART1->FCR.TFR =1; //Reset Tx FIFO
UART1->FCR.RFR =1; //Reset Rx FIFO
UART1->FCR.RFITL = 0;//Set Rx Trigger Level -1byte FIFO
UART1->LCR.PBE = 0;//Disable parity
UART1->LCR.WLS = 3;//8 data bits
UART1->LCR.NSB = 0;//Enable 1 Stop bit
/* Step 4. Set BaudRate */
UART1->BAUD.DIV_X_EN = 1;
UART1->BAUD.DIV_X_ONE = 1;
UART1->BAUD.BRD = 12000000 / 1200 -2;// //波特率1200
}
int main(void)
{
// STR_UART_T sParam;
// /* SYSCLK =>12Mhz*/
// UNLOCKREG();
// SYSCLK->PWRCON.XTL12M_EN = 1;
// /* Waiting for 12M Xtal stalble */
// DrvSYS_Delay(5000);
// /* Run 48Mhz */
// DrvSYS_Open(48000000);
// /* Set UART Pin */
// DrvGPIO_InitFunction(E_FUNC_UART0);
// DrvGPIO_InitFunction(E_FUNC_UART1);
// DrvGPIO_InitFunction(E_FUNC_UART2);
// /* UART Setting */
// sParam.u32BaudRate = 1200;
// sParam.u8cDataBits = DRVUART_DATABITS_8;
// sParam.u8cStopBits = DRVUART_STOPBITS_1;
// sParam.u8cParity = DRVUART_PARITY_NONE;
// sParam.u8cRxTriggerLevel= DRVUART_FIFO_1BYTES;
/*原版*/
UNLOCKREG();
/* Enable External 12M Xtal */
DrvSYS_SetOscCtrl(E_SYS_XTL12M, ENABLE);
DrvGPIO_Open(E_GPB,6,E_IO_OUTPUT);
while(1)
{
can();
while(1)
{
if(flag==1){
u(); //开uart1
// DrvUART_Open(UART_PORT1,&sParam);
flag2=2;
send(0x2);
send(0x2);
send(0x3);
send(0x4);
send('a');
send('b');
send('c');
send('d');
flag2=0;
flag=0;
DrvUART_Close(UART_PORT1);
can();}
}
}
}
|