1. THÔNG BÁO TUYỂN ADMIN DIỄN ĐÀN 2013
    Tìm kiếm nhà trọ - Ở ghép
    THÔNG BÁO BÁN ÁO SPKT.NET CHO THÀNH VIÊN DIỄN ĐÀN


    HÃY TÌM KIẾM Ở ĐÂY TRƯỚC KHI ĐẶT CÂU HỎI
    {xen:phrase loading}

vd2

Thảo luận trong 'Kỹ thuật Điện - Điện tử' bắt đầu bởi Trandinhluong, 25 Tháng chín 2011.

  1. Trandinhluong New Member

    Số bài viết: 54
    Đã được thích: 0
    Điểm thành tích: 0
    /***********************************************************************************
    FILE NAME main.c
    DESCRIPTION Main Program

    This is the main tutorial code. This code will call three functions to demonstrate
    Port pin control (FlashLEDs), Interrupt usage (TimerADC) and C variable
    initialisation (Statics_Test). Code is also included to drive the optional LCD
    module.

    Please refer to the tutorial manual for more information on the program flow.

    Copyright : 2005 Renesas Technology Europe Ltd.
    Copyright : 2005 Renesas Technology Corporation.
    All Rights Reserved

    ***********************************************************************************/

    /***********************************************************************************
    Revision History
    DD.MM.YYYY OSO-UID Description
    07.07.2005 RTE-MAB First Release
    ***********************************************************************************/

    /**********************************************************************************
    System Includes
    ***********************************************************************************/

    /**********************************************************************************
    User Includes
    ***********************************************************************************/
    /* rsk1582def.h provides common defines for widely used items. */
    #include "rsk1582def.h"
    #include "lcd.h"
    #include "FlashLEDs.h"
    #include "main.h"
    #include "interrupts.h"
    #include "timeradc.h"
    #include "iodefine.h"


    /**********************************************************************************
    Global variables
    ***********************************************************************************/
    /* Global initialised variable*/
    char ucStr[] = " \0";
    /* Constant Data for replacement */
    const char ucReplace[] = " \0";
    /* Global changed by pressing switches */
    unsigned volatile char gucKeyPressed = 0x00;
    /* Initial value of the counter */
    unsigned volatile char count = 0xFF;
    // global variable
    int i;
    unsigned char a,tt;
    /**********************************************************************************
    User Program Code
    ***********************************************************************************/

    /**********************************************************************************
    Function Name: Main
    Description: Main function
    Parameters: none
    Return value: none
    ***********************************************************************************/
    void Main(void)
    {
    InitialiseDisplay();
    DisplayString(LCD_LINE1," ");
    Statics_Test();
    while(1)
    {




    bd1:tt=3;
    goto bd2;
    BD: tt=0;

    bd2:
    while (tt == 0)
    {

    a=0xfd;
    PI.DR.BYTE = a;

    if (key() == 0)
    {
    InitialiseDisplay();
    DisplayString(LCD_LINE1," led2 ");
    DisplayString(LCD_LINE2," ");
    Statics_Test();
    tt=1;
    }
    }
    while (tt == 1)
    {

    a=0xfb;
    PI.DR.BYTE = a;

    if (key() == 1)
    {
    InitialiseDisplay();
    DisplayString(LCD_LINE1," led12 ");
    DisplayString(LCD_LINE2," flash ");
    Statics_Test();
    tt=2;
    }
    }
    while (tt == 2)
    {

    a=0xf9;
    PI.DR.BYTE = a;
    delay_timer();
    a=0xff;
    PI.DR.BYTE = a;
    delay_timer();
    if (key() == 0)
    {
    InitialiseDisplay();
    DisplayString(LCD_LINE1," ");
    Statics_Test();
    tt=3;
    }
    }
    while (tt == 3)
    {
    a=0xff;
    PI.DR.BYTE = a;


    if (key() == 1)
    {
    InitialiseDisplay();
    DisplayString(LCD_LINE1," led1 ");
    DisplayString(LCD_LINE2," ");
    Statics_Test();
    goto BD;
    }
    }




    }
    }
    /**********************************************************************************
    End of function main
    ***********************************************************************************/

    /**********************************************************************************
    Function Name: Statics_Test
    Description: Displays an initialised string, then modifies it, a character
    at a time, displaying it at each stage.
    Finally NICKNAME is displayed.
    Parameters: none
    Return value: none
    ***********************************************************************************/
    void Statics_Test(void)
    {
    unsigned short uiCount;

    DisplayString(LCD_LINE2,ucStr);

    /*
    At this point please right click on the 'ucSTR' variable and select 'Instant Watch'
    A dialog will be displayed showing the current value of the variable.
    Select 'Add' in the dialog and a new 'Watch Window' will open.
    Step through the following code to see that the initialised data is being overwritten
    with the different data.
    */
    for (uiCount=0; uiCount<5; uiCount++)
    {
    ucStr[uiCount] = ucReplace[uiCount];
    DisplayString(LCD_LINE2,ucStr);
    }
    ucStr[uiCount] = '\0';

    /* Reset the LCD display */
    // DisplayString(LCD_LINE2,"flash");
    }
    /**********************************************************************************
    End of function Statics_Test
    ***********************************************************************************/
    void delay_timer(void)
    {
    unsigned long i;
    unsigned long j;

    for(i=0; i<100; i++)
    {
    for(j=0; j<40000; j++);

    }
    }
    /////////////////////////////
    unsigned char key(void)
    {
    if (SW2 == 0)
    {
    while (SW2 == 0)
    return 0;
    }
    if (SW1 == 0)
    {
    while (SW1 == 0)
    return 1;
    }

    }

Chia sẻ trang này