/*##########################################################*/
/*   SD工作室-微處理機[ATmel-ATmega xx 系列]軟體程式教材[C語言]     */
/*   開發軟體程式工具  : ICC AVR C編譯器                                               */
/*                               : ATMEL CodeVision AVR C編譯器                       */
/*                               : ATMEL AVR Studio  IDE                                    */
/* Chip: Amega32A                                                                               */
/* O.S.C : 16MHz                                                                                   */
/*  範例名稱:Amega32A I/O Ports 控制應用練習[LED 左/右 交換掃描]       */
/*##########################################################*/


//-------------------------------------------------------
//---- Incude Link Head Files
//-------------------------------------------------------
// ICC-AVR application builder : 2013/11/20 上午 03:38:19
// Target : M32
// Crystal: 16.000Mhz


#include <iom32v.h>
#include <macros.h>

//-----------------------------------------------
//---- Define MACRO ---------------------
//-----------------------------------------------
#define uint unsigned int
#define uchar unsigned char

/*=============================*/
/*      函數功能: 延遲時間副函數             */
/*=============================*/
void Delay_ms(uint xms)
{
        int i,j;
        for(i=0;i<xms;i++)
       { for(j=0;j<1140;j++) ; }
}

/*==============================*/
/*      函數功能: PortC 初始化副函數     */
/*==============================*/
//1.PortC定義為:輸出埠
//2.PortC初始值為(Bit7~Bit0):1111 1111 (0xFF)
void port_init(void)
{
       DDRC=0xFF;
       PORTC=0xFF;
}

/*==========================*/
/*      函數功能: 主函數                    */
/*==========================*/
void main(void)
{
    uchar temp;
    uchar i;
    port_init();
    while(1)
   {
         for(i=0;i<8;i++)                //LED 左移
        {
              PORTC=0xFF;            /* LED 輸出 ALL OFF */
              temp=1<<i;
              PORTC=PORTC&(~temp);
              Delay_ms(500);
             //Delay_ms(1);
         }
         for(i=8;i>0;i--)                 //LED右移
        {
              PORTC=0xFF;           /* LED 輸出 ALL OFF */
              temp=1<<i;
              PORTC=PORTC&(~temp);
              Delay_ms(500);
              //Delay_ms(1);
        }
    } 
}
/*********************************<< END >>*******************************/

arrow
arrow
    文章標籤
    [C語言] 微處理機[ATmel-ATmega
    全站熱搜
    創作者介紹
    創作者 ysy168twIQ 的頭像
    ysy168twIQ

    ysy168twIQ的部落格

    ysy168twIQ 發表在 痞客邦 留言(0) 人氣()