📄 main.c
字号:
#include <hidef.h>
#include <string.h>
#include <math.h>
#include <mc9s12dp256.h>
#include "define.h"
#include "Initial.h"
#include "SCI_COM.h"
#include "soft.h"
#include "D12.h"
#include "Interrupt.h"
#include "CAN.h"
#include "my_APP.h"
#pragma CODE_SEG DEFAULT
//注意:TBDML中的设置:
//当在没有外部晶振的情况下,TBDML中的速度设置为6M;
//在D12加上之后,没有初始化的时候,速度是4.465M
void main(void)
{
unsigned char i = 0;
unsigned int i_st = 0;
UINT status = 0;
UINT j = 0;
UINT PB_data = 0;
Delay(5000);
CLKSEL = 0x80;//2倍频
// COPCTL = 0x07;// (* Page 289 *)看门狗
// Soft_Init();
//------------------------------------------------------------------------------------
Port_Init();
//------------------------------------------------------------------------------------
D12_SPD_0;
Set_LED(0xFF);//可以设置到0x41,芯片频率是24M,并口BDM可以下载,但是TBDML不能下载.
//设置到0x42,芯片频率正常,0x40,芯片保护.
D12_SetMode(0x02,0x42);
Delay(40000);
D12_SetMode(0x12,0x42);
if(D12_ReadChipID() != 0x1012)
{
Set_LED(0x55);
while(1);
}
RTIInit();
SCI_Initial(); //串口初始化
CAN0_Initial(); //CAN0初始化
CAN1_Initial(); //CAN0初始化
Write_To_SCI0("SCI0 -> PDIUSBD12 initial success!\n");
Write_To_SCI1("SCI1 -> PDIUSBD12 initial success!\n");
Set_LED(0x00);
//--------- 要发送的CAN数据初始化 ----------------
SendFrame.RemoteFlag = 0;
SendFrame.ExternFlag = 1;
SendFrame.ID = 0x12345;
SendFrame.Priority = 3;
SendFrame.DataLen = 8;
for(i=0;i<8;i++)
SendFrame.Data[i] = i;
for(i=0;i<2;i++)
{
USB_Packet[i].USB_Packet_struct.start = 0xAB;
USB_Packet[i].USB_Packet_struct.CAN_frame_num = 0;
USB_Packet[i].USB_Packet_struct.end = 0xCD;
}
//------------------------------------------------------
EnableInterrupts;//中断使能
Delay(10000);
while(1)
{
//实时中断控制的LED
if(RTI_count < 10)
RTI_LED_ON;
else if(RTI_count < 20)
{
RTI_LED_OFF;
}
else
{
if(USB_D12_OK == 1)
USB_LED_ON;
if(CAN0RIER & 0x01)
CAN0_RX_LED_ON;
if(CAN1RIER & 0x01)
CAN1_RX_LED_ON;
if(CAN_BTR0 == BTR0_125kbps)
{
LED2_OFF;
LED3_OFF;
}
else if(CAN_BTR0 == BTR0_250kbps)
{
LED2_ON;
LED3_OFF;
}
else if(CAN_BTR0 == BTR0_500kbps)
{
LED2_OFF;
LED3_ON;
}
else if(CAN_BTR0 == BTR0_1000kbps)
{
LED2_ON;
LED3_ON;
}
RTI_count = 0;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -