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

📄 main.c

📁 本程序实现在M16C上的AD转换
💻 C
📖 第 1 页 / 共 2 页
字号:
* Argument        : const char *msg;     displayed character-string
* Return value    : NON
* Called function : is_busy();
*                 : write_dreg();
* Causions        : 
* History         :
*""FUNC COMMENT END""*********************************************************/

/*(Question)*/
static void write_lcd(const char *msg)
{
    /*for( ; '\0' != ____; msg++){*//*repeat to read the given character-string until '\0'*/
    /*    while(_______());       *//* check busy flag               */
    /*    write_dreg(____);       *//* write LCD data register          */
    /*}                           */
    for( ; '\0' != *msg; msg++){    
        while(is_busy());          
        write_dreg(*msg);           
    }
}


/*""FUNC COMMENT""*************************************************************
* ID              : ---
* Function name   : static BOOL is_busy(void)
* Feature         : check busy flag to make sure be able to write LCD
* Argument        : NON
* Return value    : BOOL(int) TRUE ; unwritable
*                 :           FALSE; writable
* Called function : read_creg(); read instruction register 
* Causions        : NON
* History         : 
*""FUNC COMMENT END""*********************************************************/

/*(Question)*/
static BOOL is_busy(void)
{
    /* if(____ & _________()){ */       /* check busy flag    */
    /*     return TRUE;        */       /*please call the instruction register  */
    /* }                       */       /*   read function ( read_creg() )     */
    /* else{                   */
    /*     return FALSE;       */
    /* }                       */

    if(0x80 & read_creg()){             /* if(BusyFlag)          */
        return TRUE;                   
    }                                   
    else{
        return FALSE;
    }
}


/*""FUNC COMMENT""*************************************************************
* ID              : ---
* Function name   : static char read_creg(void)
* Feature         : read Command-Register 
* Argument        : NON
* Return value    : char  ; read value (only low-order(8bit) is valid )
* Called function : _lcd1__rd_nibble_creg(); read instruction (assembly language function)
* Causions        : NON
* History         :
*""FUNC COMMENT END""*********************************************************/

/*(Question)*/
static char read_creg(void)
{

    char command;
    
    /* in order to read/write LCD register, it is necessary to contro bus. */
    /* here, we write an assembly language function to perform bus control,*/
    /* and then realized the register access.         */
     
    /*command  = _____________________() << 4;*//* interface length 4bit     */
    /*command |= _____________________();     */
    command  = _lcd1__rd_nibble_creg() << 4;    
    command |= _lcd1__rd_nibble_creg();
    return command;
}


/*""FUNC COMMENT""*************************************************************
* ID              : ---
* Function name   : static void write_creg(char data)
* Feature         : write Command-Register 
* Argument        : char data;  written value (only low-order(8bit) is valid乯
* Return value    : NON
* Called function : _lcd1__wr_nibble_creg(); write instruction(assembly language function)
* Causions        : NON
* History         :
*""FUNC COMMENT END""*********************************************************/

/*(Question)*/
static void write_creg(char data)
{
    /* in order to read/write LCD register, it is necessary to contro bus. */
    /* here, we write an assembly language function to perform bus control,*/
    /* and then realized the register access.         */

    /*_____________________(data>>4 & 0x000f);*//* interface length 4bit    */
    /*_____________________(data    & 0x000f);*/
    _lcd1__wr_nibble_creg(data>>4 & 0x000f);    
    _lcd1__wr_nibble_creg(data    & 0x000f);
}


/*""FUNC COMMENT""*************************************************************
* ID              : ---
* Function name   : static char read_dreg(void)
* Feature         : read Data-Register 
* Argument        : NON
* Return value    : char ;    read value (only low-order(8bit) is valid)
* Called function : _lcd1__rd_nibble_dreg(); read data (assembly language function)
* Causions        : NON
* History         :
*""FUNC COMMENT END""*********************************************************/
static char read_dreg(void)
{
    char data;

    /* in order to read/write LCD register, it is necessary to contro bus. */
    /* here, we write an assembly language function to perform bus control,*/
    /* and then realized the register access.         */

    /*data  = _____________________() << 4;*/   /* interface length 4bit     */
    /*data |= _____________________();     */
    data  = _lcd1__rd_nibble_dreg() << 4;       
    data |= _lcd1__rd_nibble_dreg();
    return data;
}


/*""FUNC COMMENT""*************************************************************
* ID               : ---
* Function name    : static void write_dreg(char data)
* Feature          : write Data-Register 
* Argument         : char data ;  written value (only low-order(8bit) is valid)
* Return value     : NON
* Called function  : _lcd1__wr_nibble_dreg(); write data (assembly language function)
* Causions         : NON
* History          :
*""FUNC COMMENT END""*********************************************************/
static void write_dreg(char data)
{
    /* in order to read/write LCD register, it is necessary to contro bus. */
    /* here, we write an assembly language function to perform bus control,*/
    /* and then realized the register access.         */

    /*_____________________(data>>4 & 0x000f);*//* interface length 4bit     */
    /*_____________________(data    & 0x000f);*/   
    _lcd1__wr_nibble_dreg(data>>4 & 0x000f);    
    _lcd1__wr_nibble_dreg(data    & 0x000f);
}
//////////////////////////////////////////////////////////////////////////////
void init_ta0(void)
{
    ta0mr = 0x80;                   /* setting timer A0 mode register         */
                                    /* 10000000                             */
                                    /* ||||||++---- timer  mode            */
                                    /* |||||+------ pulse is not output        */
                                    /* |||++------- gate function not availble  */
                                    /* ||+--------- timer mode       */
                                    /* ++----------  count source is f32       */
                                    /*              (f(XIN)=16MHz:2兪s))    */
    ta0 = 7499;                     /* setting timer A0 register (20ms)         */
                                    /* 49999 = (100ms / 2兪s) -1              */
    ta0ic =0x01;               /* clearign timer A0 interrupt request  bit     */
    ta0s = SET;                     /* setting timer A0 count to start           */
}
//////////////////////////////////////////////////////////////////////////
static void init_ad(void)
{
    /*----- setting A-D converter -----*/
    adcon2 = 0x01;                  /* setting A-D control register2    */
                                    /* 00000001                         */
                                    /* |||||||+---sample & hold      */
                                    /* +++++++----亊                    */

    adcon0 = 0x88;                  /* setting A-D control register0    */
                                    /* 10001000                         */
                                    /* |||||+++---AN0                   */
                                    /* |||++------repeat mode        */
                                    /* ||+--------0=S/W trigger      */
                                    /* |+---------0=AD conversion disabled,
                                                  1=start */
                                    /* +----------0=fad/4,1=fad/2       */

    adcon1 = 0x28;                  /* setting A-D control register1    */
                                    /* 00101000                         */
                                    /* ||||||++---invalid               */
                                    /* |||||+-----repeat mode           */
                                    /* ||||+------0=8bit,1=10bit        */
                                    /* |||+-------0=fad/2or/4,1=fad     */
                                    /* ||+--------1=Vref connected      */
                                    /* ++---------not use               */
    adst = SET;                     /* setting AD conversion started    */
                                    /*   (bit6 of A-D control register0)*/
}

////////////////////////////////////////////////////////////////////////////
static void disClock(void )
{
       
       
        set_cursol( DISP_TOP_X, DISP_TOP_Y );  
        
        /* set display position     */
        DispLCD3=num3;
        STRUTL__d2s( DispLCD3, DispLCDBuff, DISP_LEN );    /* generate display character-string   */
        write_lcd( DispLCDBuff ); 


        Disp=0xa;
        STRUTL__x2s( Disp, DispLCDBuff, DISP_LEN2 );    /* generate display character-string   */
        write_lcd( DispLCDBuff ); 

        DispLCD2=num2;
        STRUTL__d2s( DispLCD2, DispLCDBuff, DISP_LEN );    /* generate display character-string   */
        write_lcd( DispLCDBuff ); /* write to LCD          */

        Disp=0xa;
        STRUTL__x2s( Disp, DispLCDBuff, DISP_LEN2 );    /* generate display character-string   */
        write_lcd( DispLCDBuff ); 
    	
        DispLCD=num;
        STRUTL__d2s( DispLCD, DispLCDBuff, DISP_LEN );    /* generate display character-string   */
        write_lcd( DispLCDBuff ); 
        
    	
    	


}
/////////////////////////////////////////////////////////////////////////////////////////////////////
static void disClock2(void )
{
       
       
        set_cursol( DISP_TOP_X, DISP_TOP_Z);  
        
        /* set display position     */
        DispLCD3=temp3;
        STRUTL__d2s( DispLCD3, DispLCDBuff, DISP_LEN2 );    /* generate display character-string   */
        write_lcd( DispLCDBuff ); 


        Disp=0xa;
        STRUTL__x2s( Disp, DispLCDBuff, DISP_LEN2 );    /* generate display character-string   */
        write_lcd( DispLCDBuff ); 

        DispLCD2=temp2;
        STRUTL__d2s( DispLCD2, DispLCDBuff, DISP_LEN2 );    /* generate display character-string   */
        write_lcd( DispLCDBuff ); /* write to LCD          */

       /* Disp=0xa;
        STRUTL__x2s( Disp, DispLCDBuff, DISP_LEN2 );    /* generate display character-string   */
       // write_lcd( DispLCDBuff ); 
    	
        DispLCD=temp;
        STRUTL__d2s( DispLCD, DispLCDBuff, DISP_LEN2 );    /* generate display character-string   */
        write_lcd( DispLCDBuff ); 
        
    	
    	


}

⌨️ 快捷键说明

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