#include <m8c.h>      // part specific constants and macros     
#include "PSoCAPI.h"    // PSoC API definitions for all User Modules   
void delay(unsigned int x);    //開始宣告delay副程式
void main(void)
{
    while(1)      //while 迴圈開頭
       {
        PRT0DR=0x10;   // LED 亮
        delay(1000);
        PRT0DR=0x00;    // LED 滅
        delay(1000);
       }
}
 

void delay(unsigned int x)
    {
        unsigned i;
        for(i=0;i<x;i++);
    }

 

 CUP_CLOCK 建議256慢一點才看的出來他的變化

CPU_CLOCK

 

我也要先設PORT_0_4 為Strong 用來驅動LED,驅動方式設為「strong」。

PORT4 

 

    程式說明:   

 PRT0DR 代表PSoC 之Port_0, PRT1DR 代表Port_1, PRT2DR 代表Port_2, 每個Port 有8個位元 0x10 之0x 代表16 進制的數字, 所以0x10=00010000 會使得Port_0_4=1, 點亮LED。

延遲副程式,delay(1000) 數字愈大延遲的時間愈長 主程式呼叫時會傳入數值x, 讓for 迴圈 做x 次運算, 以達到延遲時間的目的

如有不對的地方請多多指教及留言


 

arrow
arrow
    全站熱搜

    阿榮交流的天地 發表在 痞客邦 留言(0) 人氣()