⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 基于MC908QY4的LIN从站通信例程
💻 C
字号:
#include <hidef.h> /* for EnableInterrupts macro */
#include <MC68HC908QY4A.h> /* include peripheral declarations */
#include "LINdriver.h"
#include "Board.h"

unsigned char MsgSend[2];
unsigned char MsgRcvd [2];
unsigned char Ret;
unsigned char MsgTest[2];


void Timer0_init(void){
  TCH0H=0x80;
  TCH0L=0x00;
  TSC0_MS0A=1;
  TSC0_MS0B=0;
  TSC0_TOV0=1;
  TSC0_ELS0A=0;
  TSC0_ELS0B=1; 
  
}

void LED_display (void)
{
    Ret = LIN_GetMsg (ID_RECEIVE, MsgRcvd);	 //收到数据后的状态,1反转
}        



void LIN_response (void)
{
    
		unsigned char key;
		
    key=0x00;
    key|=SWITCH2;
    key<<=1;
    key|=SWITCH1;
    
	
    ADSCR = Sensor1_CH;            /* ADC single convers on TEMP_CH         */
		//ADSCR_AIEN=1;
    while (!ADSCR_COCO);        /* wait for switching the ADC source     */

    MsgSend[0] = ADRL;           /* save current measured temperature     */
		MsgSend[1] = ADRL;
		
		
    Ret = LIN_PutMsg (ID_SEND, MsgSend);    /* LIN response to ID_SEND   */
}


void main(void) {
  
    CONFIG1 = 0x09;             /* disable COP                          */
    CONFIG2 = 0x00;             /* default (int. osc.)                  */

    DDRA=0x00;									/* Port A Input,SW1@3,SW2@2             */
    DDRB = 0xFC;                /* enable port B outputs                */
                                /* LEDs:B3-6, MC33399 enable:B7, TX: B2 */
    PTB_PTB7 = 1;               /* enable MC33399                       */

    SIGN_LED1=0x01;
    SIGN_LED2=0x01;
		SIGN_LED3=0x01;
		SIGN_LED4=0x00;
		
    
    TSC = 0x00;                 /* timer prescaler /1                   */
		Timer0_init();
    //TSC_TOIE=1;
    //TSC0_CH0IE=1;
    //TSC_TOF = 0;                /* start timer                          */

    //ADSCR_AIEN=1;
    ADCLK = 0x40;              /* ADC clock rate = 4                   */
                                /* cannot be faster then aprox          */
                                /* 1.2 MHz.                             */

    OSCTRIM = 0;                /* trim to max. frequency               */

    EnableInterrupts; /* enable interrupts */

    LIN_Init();                 /* initialise LIN drivers               */
  
  /* include your code here */
		for(;;){
		  
		  
		  if(LinState == Sending) SIGN_LED2=0x00;// 发送2亮
		  else SIGN_LED2=0x01;
		  if(LinState == ReceiveId)   SIGN_LED3=0x00;//接受3亮
		  else SIGN_LED3=0x01;
		  if(LinState == Unsyncronized) SIGN_LED1=0x00;// 非同步状态1亮
		  else SIGN_LED1=0x01;
		  if(ChecksumERROR==1) SIGN_LED4=0x00;
		  else SIGN_LED4==0x01;
		  
		  
		  if (TSC_TOF)            /* is overflow flag set?                */
        {
            TSC_TOF = 0;        /* yes, clear it                        */
            LED_display ();     /* update LEDs on PTB                   */
            LIN_response ();    /* send LIN response msg.               */
        } 
		  
		  
		}

}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -