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

📄 main1.c

📁 M16C290FC can
💻 C
字号:
/*""FILE COMMENT""****************************************************
*System Name : CAN DEMO PROGRAM1
*File Name   : main1.c
*Version     : 1.00
*Contens     : 
*Customer    : RSO
*Model       : 
*Order       : 
*CPU         : 
*Compiler    : NC30 Version 5.30 Release 02
*OS          : 
*Programmer  : 
*Note        : 
*            : 
**********************************************************************
* Copyright(C)2005, Renesas Technology Corp.
* Copyright(C)2005, Renesas Solutions Corp.
* All rights reserved.
*
**********************************************************************
*History        2005.07.1   Ver 1.00
*""FILE COMMENT END""************************************************/

#define DECLARE_MAIN

#include "sfr29.h"
#include "define1.h"
#include "declare1.h"

 /*""FUNC COMMENT""****************************************************
  *ID               :1.0
  *Description      :
  *--------------------------------------------------------------------
  *Include          :"sfr29.h"
  *                 :"define1.h"
  *                 :"declare1.h"
  *--------------------------------------------------------------------
  *Declaration      :void main(void)
  *--------------------------------------------------------------------
  *Function         :main
  *--------------------------------------------------------------------
  *Arguments        :Nothing
  *--------------------------------------------------------------------
  *Returns          :Nothing
  *--------------------------------------------------------------------
  *Input            :unsigned char error_num        ;error number
  *Ountput          :unsigned char error_num        ;error number
  *--------------------------------------------------------------------
  *Call functions   :cpu_initial()              ;Initialize CPU
  *                 :sw_led_initial()           ;Initialize switch and LED
  *                 :can_initial()              ;Initialize CAN
  *                 :ad_initial()               ;Initialize A/D conberter
  *                 :timer_initial()            ;Initialize timer
  *                 :led_mode_change()          ;Change LED mode
  *                 :led_pt_fnc()               ;Change LED lightning pattern
  *                 :led_fnc()                  ;LED dynamic lightning
  *                 :sw_fnc()                   ;Read switch port
  *                 :ad_fnc()                   ;A/D convert
  *                 :error_main_fnc()           ;Error function
  *--------------------------------------------------------------------
  *Note             :
  *--------------------------------------------------------------------
  *History          :
  *                 :
  *""FUNC COMMENT END""***********************************************/
void main(void)
{
    asm("fclr I");
    
    cpu_initial();
    sw_led_initial();
    can_initial();
    ad_initial();
    timer_initial();
    
    /* variable initial */
    error_num = NO_ERROR;           //set error flag "No error"
    
    tabsr = 0x03;                   //LED & SW timer
    asm("fset I");
    
    
    while(error_num == NO_ERROR){   //Error check
        if(ir_ta1ic == 1){          //TA1
            ta1ic = TA1_LVL;        //IR clear
            
            led_fnc();              //LED dynamic lightning
            sw_fnc();               //Switch function
            ad_fnc();               //A/D convert
        }
        
        if(ir_ta0ic == 1){          //TA0
            ta0ic = TA0_LVL;        //IR clear
            
            led_mode_change();      //Change LED mode
            led_pt_fnc();           //Change LED lightning pattern
        }
    }
    


/* ERROR */
    error_main_fnc();               //Error function

    while(1);
}

 /*""FUNC COMMENT""****************************************************
  *ID               :1.1
  *Description      :Initialize CPU
  *--------------------------------------------------------------------
  *Include          :"sfr29.h"
  *--------------------------------------------------------------------
  *Declaration      :void cpu_initial(void)
  *--------------------------------------------------------------------
  *Function         :Initialize main clock,processer mode and ports
  *--------------------------------------------------------------------
  *Arguments        :Nothing
  *--------------------------------------------------------------------
  *Returns          :Nothing
  *--------------------------------------------------------------------
  *Input            :Nothing
  *Ountput          :Nothing
  *--------------------------------------------------------------------
  *Call functions   :Nothing
  *--------------------------------------------------------------------
  *Note             :
  *--------------------------------------------------------------------
  *History          :
  *                 :
  *""FUNC COMMENT END""***********************************************/
void cpu_initial(void)
{
    while(pacr != 0x03){
        prcr = 0x04;
        pacr = 0x03;                //80pin
    }
    
    prcr = 0x03;
    
    /* clock,processer mode */
    cm1 = 0x20;
    cm2 = 0;
    pm0 = 0;
    pm1 = 0x08;
    cm0 = 0x08;
    pm2 = 0;
    
    /* port */
    p0  = 0x00;
    p1  = 0x00;
    p2  = 0x00;
    p3  = 0x00;
#if !_KD_
    p6  = 0x00;
#endif
    p7  = 0x00;
    p8  = 0x00;
    p9  = 0x00;
    p10  = 0x00;
    
    pd0 = 0x00;
    pd1 = 0x00;
    pd2 = 0x00;
    pd3 = 0x00;
#if !_KD_
    pd6 = 0x00;
#endif
    pd7 = 0x00;
    pd8 = 0x00;
    prcr = 0x07;
    pd9 = 0x00;
    pd10 = 0x00;

    prcr = 0;

    /* pull up control */
    pur0 = 0x00;
    pur1 = 0x00;
    pur2 = 0x00;
    
    /* port control */
    pcr = 0x00;
}

 /*""FUNC COMMENT""****************************************************
  *ID               :1.2
  *Description      :Initialize timer
  *--------------------------------------------------------------------
  *Include          :"sfr29.h"
  *                 :"define1.h"
  *--------------------------------------------------------------------
  *Declaration      :void timer_initial(void)
  *--------------------------------------------------------------------
  *Function         :Initialize TA0 and TA1
  *--------------------------------------------------------------------
  *Arguments        :Nothing
  *--------------------------------------------------------------------
  *Returns          :Nothing
  *--------------------------------------------------------------------
  *Input            :Nothing
  *Ountput          :Nothing
  *--------------------------------------------------------------------
  *Call functions   :Nothing
  *--------------------------------------------------------------------
  *Note             :
  *--------------------------------------------------------------------
  *History          :
  *                 :
  *""FUNC COMMENT END""***********************************************/
void timer_initial(void)
{
    tabsr = 0;                  //all timer stop
    onsf = 0;
    trgsr = 0;
    
    ta0mr = 0x01;               //ivent
    ta0tgl = 1;                 //count sorce:TA1
    ta0tgh = 1;                 //
    ta0 = DATA_CLWS_TM;         //
    ta0ic = TA0_LVL;
    
    ta1mr = 0x00;               //timer mode
    ta1 = DATA_TA1;             //
    ta1ic = TA1_LVL;
}


 /*""FUNC COMMENT""****************************************************
  *ID               :1.3
  *Description      :Error process
  *--------------------------------------------------------------------
  *Include          :"sfr29.h"
  *--------------------------------------------------------------------
  *Declaration      :void error_fnc(void)
  *--------------------------------------------------------------------
  *Function         :Timer,A/D converter and CAN module are stop.
  *                 :LED off
  *--------------------------------------------------------------------
  *Arguments        :unsigned char in_num              ;Error number
  *--------------------------------------------------------------------
  *Returns          :Nothing
  *--------------------------------------------------------------------
  *Input            :Nothing
  *Ountput          :unsigned char error_num           ;Error number
  *--------------------------------------------------------------------
  *Call functions   :Nothing
  *--------------------------------------------------------------------
  *Note             :
  *--------------------------------------------------------------------
  *History          :
  *                 :
  *""FUNC COMMENT END""***********************************************/
void error_fnc(unsigned char in_num)
{
    asm("fclr I");
    
    tabsr = 0;                  //all timer stop
    adcon0 = 0;                 //AD stop
    reset_c0ctlr = 1;           //CAN reset
    
    p0 = 0x03;                  //LED OFF
    
    error_num = in_num;         //Set error number
}

 /*""FUNC COMMENT""****************************************************
  *ID               :1.4
  *Description      :Error process
  *--------------------------------------------------------------------
  *Include          :"sfr29.h"
  *--------------------------------------------------------------------
  *Declaration      :void error_main_fnc(void)
  *--------------------------------------------------------------------
  *Function         :Display error number
  *--------------------------------------------------------------------
  *Arguments        :Nothing
  *--------------------------------------------------------------------
  *Returns          :Nothing
  *--------------------------------------------------------------------
  *Input            :unsigned char error_num        ;Error number
  *                 :unsigned char led_count        ;LED counter
  *                 :unsigned char led_data[]       ;LED display data
  *Ountput          :unsigned char led_count        ;LED counter
  *                 :unsigned char led_data[]       ;LED display data
  *--------------------------------------------------------------------
  *Call functions   :sw_led_initial()               ;Initialize switch and LED
  *                 :led_fnc()                      ;LED dynamic lightning
  *--------------------------------------------------------------------
  *Note             :
  *--------------------------------------------------------------------
  *History          :
  *                 :
  *""FUNC COMMENT END""***********************************************/
void error_main_fnc(void)
{
    unsigned char in_led_on_off = 0;
    unsigned char i;
    
    asm("fclr I");
    
    tabsr = 0;                  //all timer stop
    adcon0 = 0;                 //AD stop
    reset_c0ctlr = 1;           //CAN reset
    
    sw_led_initial();
    
    ta0mr = 0x01;               //ivent
    ta0tgl = 1;                 //count sorce:TA1
    ta0tgh = 1;                 //
    ta0 = 250 - 1;              //
    ta0ic = 0x00;
    
    ta1mr = 0x00;               //timer mode
    ta1 = 2000000/50 -1;        //2ms
    ta1ic = 0x00;
    
    led_count = 0;
    led_data[1] = LED_TBL[0x0e];        //Set error number
    led_data[0] = LED_TBL[error_num];   //
    
    tabsr = 0x03;               //TA0,TA1 start
    
    while(1){
        if(in_led_on_off == 1){
            if(ir_ta1ic == 1){
                ta1ic = 0x00;
                
                led_fnc();
            }
        }
        
        if(ir_ta0ic == 1){      //LED flashing
            ta0ic = 0;
            
            if(in_led_on_off == 0){
                in_led_on_off = 1;  //LED ON
            }
            else{
                in_led_on_off = 0;  //LED OFF
                p0 = 0x03;
            }
        }
    }
}


⌨️ 快捷键说明

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