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

📄 main.c

📁 本程序实现在M16C上的AD转换
💻 C
📖 第 1 页 / 共 2 页
字号:
/*""FILE COMMENT""*************************************************************
*  System Name : This program is only for education.
*  File Name   : main.c
*  Contents    : Practice 8-A sample  interrupt control -int0(sw9) interrupt-
*  Model       : OAKS16-LCD Board
*  CPU         : M16C/60 Serials
*  Compiler    : M16C/60 NC30 COMPILER V.4.00 Release 2 - Entry
*  OS          : NON
*  Programer   : RENESAS Semiconductor Training Center
*  Note        : OAKS16-M30620FCAFP(M16C/62group,16MHz)
*******************************************************************************
* COPYRIGHT(C) 2004 RENESAS TECHNOLOGY CORPORATION ALL RIGHTS RESERVED 
*               AND RENESAS SOLUTIONS CORPORATION ALL RIGHTS RESERVED
*******************************************************************************
* History      : ---
*""FILE COMMENT END""*********************************************************/

/*===== include file =====*/
#include "defs.h"                       /* user defining file               */
#include "intr_i0.h"                    /* definition file for interrupt   */
                                        /* (assembly language)              */
#include "target.h"                     /* definition fot M16C/62 group    */

/*(Question)*/
/*#include "____.h"*/                   /*assembly language program defining file fot LCD */
#include "lcd1.h"                       
/*#include "______.h"*/                 /* definition file for character operation   */
#include "strutl.h"                     

/*===== macro definition =====*/
/*--- instruction definition of LCD ---*/
#define CMD_CLEAR               0x01    /* 00000001                         */
                                        /* clear all display+move cursor to home */
#define CMD_HOME                0x02    /* 00000010                         */
                                        /* move cursor to home+shift elimination */
#define CMD_ENTRY_DEC           0x04    /* 00000100                         */
                                        /* cursor's moving direction(decrement) */
#define CMD_ENTRY_DEC_SHIFT     0x05    /* 00000101                         */
                                        /* cursor's moving direction               */
                                        /* (decrement) + display shift      */
#define CMD_ENTRY_INC           0x06    /* 00000110                         */
                                        /* cursor's moving direction               */
                                        /* (increment)                 */
#define CMD_ENTRY_INC_SHIFT     0x07    /* 00000111                         */
                                        /* cursor 偺moving direction               */
                                        /* (increment) + display shift    */
#define CMD_DISP_DS             0x08    /* 00001000                         */
                                        /* no display(all display OFF + cursor OFF + */
                                        /* blink OFF)                     */
#define CMD_DISP_EN             0x0c    /* 00001100                         */
                                        /* display(all display ON + cursor OFF +    */
                                        /* blink OFF)                     */
#define CMD_DISP_EN_CUR         0x0e    /* 00001110                         */
                                        /* display(all display ON + cursor ON +     */
                                        /* blink OFF)                     */
#define CMD_DISP_EN_CUR_BLINK   0x0f    /* 00001111                         */
                                        /* display(all display ON + cursor ON +     */
                                        /* blink ON)                      */
#define CMD_MOVE_CUR_LEFT       0x10    /* 00010000                         */
                                        /* cursor left-shift                 */
#define CMD_MOVE_CUR_RIGHT      0x14    /* 00010100                         */
                                        /* cursor right-shift                 */
#define CMD_MOVE_SRC_LEFT       0x18    /* 00011000                         */
                                        /* source left-shift                   */
#define CMD_MOVE_SRC_RIGHT      0x1c    /* 00011100                         */
                                        /* source right-shift                   */
#define CMD_FUNC_D4_N2_F7       0x28    /* 00101000                         */
                                        /* interface data lenght 4 bit    */
#define CYCLICTIME  100          /* to count the set time(100ms)   */                                        /* 2-line, 5亊7 dots            */

/*===== macro definition =====*/


/*===== prototype declaration =====*/
void main(void);                        
//static void abc();
static void init_ta0(void); 
static void init_ad(void);                            
static void init_lcd(void);                /* LCD initialization           */
static BOOL is_busy(void);
            /* judge busy flag state (check whether or not to be able to write LCD)    */
static void set_cursol(int x, int y);      /* set display position          */
static void write_lcd(const char *msg);    /* write the selected character to LCD   */
static char read_creg(void);               /* read command from LCD     */
static void write_creg(char data);         /* write command to LCD       */
static char read_dreg(void);               /* read data from LCD       */
static void write_dreg(char data); 
static void disClock(void );        /* write data to LCD       */
static void disClock2(void );
/*===== variable declaration =====*/
#define DISP_LEN    2               /* number to be displayed                     */
#define DISP_TOP_X  0               /* display start positon X                    */
#define DISP_TOP_Z  1 
#define DISP_TOP_Y  0               /* display start positon Y                    */
#define DISP_LEN2    1 
#define FALSE 0
#define TRUE 1
char    DispLCD,DispLCD2,DispLCD3;        /* the value to be displayed on LCD      */
char    Disp;
char    DispLCDBuff[DISP_LEN+1];   /* buffer to save the character to be displayed */
char    num,num2,num3;
char    temp,temp2,temp3;
char Count = 0;
char TimeFor1s = CYCLICTIME;
int TimePass;
/*""FUNC COMMENT""*************************************************************
* ID              : ---
* Function name   : void main(void)
* Feature         : as long as depressing SW9, make SingleLED to be set left-shift.
*                 : initial display is to turn on LED1. turn on LED1 again 
*                 : after turned LED8 on (all processing is done in interrupt program).
* Argument        : NON
* Return value    : NON
* Called function : init_int0()               ; INT0 initialization
* Causion         : NON
* History         : ---
*""FUNC COMMENT END""*********************************************************/
void main(void)
{
     
    /* Port initialization */
	int ResultAD0; 
//	int Level; 
//	const static char LevelMeter_Pattern[]={
 //       0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8
//    };
	/* Port initialization */
//    p2  = 0xff;                             /* seit SingleLED to off  */
//    pd2 = 0xff;                             /* set Port P2 to output  */
    
	init_lcd();                
    init_ta0();
    init_ad();
    /* interrupt enable */
    ei();

    /* dead loop (all the processing is done in interrupt program) */
    while(1){ 
        if(TimePass==TRUE)
           { TimePass=FALSE;
		ResultAD0 = 0x3ff & ad0;
             Count++;
               num=Count%60;
               num2=(Count/60)%60;
               num3=(Count/3600)%24;
               disClock( );
		
//		    Level = (int)((((5.0 / 1024) * ResultAD0) - (5.0 / 2048)) + 0.5);
            temp3=(int)((5.0 / 1024) * ResultAD0);
			temp3=temp3%10;
            temp2=(int)(((5.0 / 1024) * ResultAD0)*10);
			temp2=temp2%10;
            temp=(int)(((5.0 / 1024) * ResultAD0)*100);
			temp=temp%10;
		   
           disClock2();

            /*--- output voltage according to display pattern ---*/
   //         p2 = LevelMeter_Pattern[Level] ^ 0xff;

		
		
		
		}
    }
}



/*""FUNC COMMENT""*************************************************************
* ID               : ---
* Function name    : void init_int0(void)
* Feature          : INT0(sw9) initialization
* Argument         : NON
* Return value     : NON
* Called function  : NON
* Causion          : INT0(sw9) is used as interrupt.  
* History          : ---
*""FUNC COMMENT END""*********************************************************/
///////////////////////////////////////////////////////////////////////////
void abc(void)
{
           TimeFor1s--;
            if( TimeFor1s == 0 ){           /* passed 1s?             */
                TimeFor1s = CYCLICTIME;     /* initialize 1s counter    */
                TimePass=TRUE;
    		}




}

/******************************************************************************
    end of file
******************************************************************************/
/*(Question)*/
static void init_lcd(void)
{
    _lcd1__initial();                   /* LCD control port initialization */

    /*--- initializing after reset LCD ---*/
    _lcd1__wait(150);                   /* wait for 15ms in order to make VCC stable */
    _lcd1__wr_nibble_creg(0x03);        /* function set 8bit(0x03)   */

    /*___________(__);*/                /* wait for 4.1ms         */
    _lcd1__wait(41);                    /*                         */
    _lcd1__wr_nibble_creg(0x03);        /* function set 8bit(0x03)   */

    /*___________(_);*/                 /* wait for 0.1ms             */
    _lcd1__wait(1);                    
    _lcd1__wr_nibble_creg(0x03);        /* function set 8bit(0x03)   */

    /*___________(_);*/                 /* wait for 0.1ms    */
    _lcd1__wait(1);                    
    _lcd1__wr_nibble_creg(0x02);        /* function set 4bit(0x02)   */
    /*___________(_);*/                 /* wait for 0.1ms    */
    _lcd1__wait(1);                    
    write_creg(CMD_FUNC_D4_N2_F7);      /* interface data length 4 bit    */
                                        /* 2-line, 5亊7 dot                */

    _lcd1__wait(1);                     /* wait for 0.1ms            */
    write_creg(CMD_DISP_DS);            /* display off                         */
    
    /*while(_______());*/               /* check busy flag      */
    /*write_creg(_________);*/          /* clear display                       */
    while(is_busy());                   
    write_creg(CMD_CLEAR);              
    
    /*while(_______());*/               /* check busy flag          */
    /*write_creg(______________);*/     /* entry mode, increment  */
    while(is_busy());                  
    write_creg(CMD_ENTRY_INC);         
    
    /*while(_______());*/               /* check busy flag          */
    /*write_creg(___________);*/        /*display on, cursor off, blink off */
    while(is_busy());                   
    write_creg(CMD_DISP_EN);           
}


/*""FUNC COMMENT""*************************************************************
* ID               : ---
* Function name    : static void set_cursol(int x, int y)
* Feature          : set cursor position (internal display buffer)
* Argument         : int x;  X-coordinate (left 0x0 - right 0xf)
*                  : int y;  Y-coordinate (up 0x0 - down 0x1)
* Return value     : NON
* Called function  : is_busy();
*                  : write_creg();
* Causions         : NON
* History          : 
*""FUNC COMMENT END""*********************************************************/

/*(Question)*/
static void set_cursol(int x, int y)
{
    /*while(_______());*/               /* check busy flag           */
    /*write_creg(____ | y*____ + x);*/  /* the address of the second line is 0x40乣0x4f  */
    while(is_busy());                   
    write_creg(0x80 | y*0x40 + x);      
}


/*""FUNC COMMENT""*************************************************************
* ID              : ---
* Function name   : static void write_lcd(const char *msg)
* Feature         : write displayed character-string to LCD

⌨️ 快捷键说明

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