?? 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;
USB_Packet.USB_Packet_struct.start = 0xAB;
USB_Packet.USB_Packet_struct.CAN_frame_num = 0;
USB_Packet.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 + -