日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當(dāng)前位置:首頁(yè) > 單片機(jī) > 單片機(jī)
[導(dǎo)讀]  Today I finish the "Blinky LED" application on PIC32MZ starter kit. This application let LED1 blink with 0.5HZ frequency. The pseudo code is like LOOP: LED ON Delay 1 second LED OFF D

  Today I finish the "Blinky LED" application on PIC32MZ starter kit. This application let LED1 blink with 0.5HZ frequency. The pseudo code is like


LOOP:

LED ON

Delay 1 second

LED OFF

Delay 1 second

  It uses Timer1 to control the delay time. So first I implement the three Timer1 functions.



/**

Function: TMR1_Open


Summary: Initialization of Timer


Description: TMR1 on; 0.08 microsecond every tick


Remarks: Pre-scale 1:8; PB 100MHz; PR1 0xFFFF

*/

void TMR1_Open(void)

{

T1CON = 0x8010;

PR1 = 0xFFFF;

}

// Comment a function definition and leverage automatic documentation

/**

Function: TMR1_Write


Summary: Write TMR1


Description: Write a value to TMR1


Remarks: the value is range of 0~65535

*/

void TMR1_Write(unsigned int value)

{

TMR1 = value & 0xFFFF;

}

/**

Function: TMR1_Read


Summary: Read TMR1


Description: Read the value from TMR1


Remarks: the value is range of 0~65535

*/

unsigned int TMR1_Read(void)

{

return (TMR1 & 0xFFFF);

}


  Second I finish the delay function, the implemention is like below



/**

Function: Delay_1S


Summary: Delay using TMR1


Description: Delay one second


Remarks: call TMR1_Open first

*/

void Delay_1S(void)

{

unsigned int count = 12500;

unsigned int ticks = 1000;

while (count--)

{

TMR1_Write(0);

while (TMR1_Read() < ticks)

{

; // do nothing

}

}

}


  Actually we are also able to do that like below



/**

Function: Delay_1S


Summary: Delay using TMR1


Description: Delay one second


Remarks: call TMR1_Open first

*/

void Delay_1S(void)

{

unsigned int count = 1000;

unsigned int ticks = 12500;

while (count--)

{

TMR1_Write(0);

while (TMR1_Read() < ticks)

{

; // do nothing

}

}

}


  I prefer to the second one. I believe the second one has higher accuracy than the first one.


  In the end, I finish the main function. In last blog, I already show how to implement LED_SETON. This time, we will the same LED_SETON funtion, and more, we need to implement LED_SETOFF. That's easy once you have read my last blog. If you don't know yet, please look at below.



#include

#include "Delay.h"

#include "ConfigurationBits.h"


#define LED_IOCTL() TRISHCLR = (1<<0)

#define LED_SETON() LATHSET = (1<<0)

#define LED_SETOFF() LATHCLR = (1<<0)

#define LED_OPEN() ANSELH &= 0xFFFFFFFE


void main(void)

{

TMR1_Open();

LED_OPEN();

LED_IOCTL();

while (1)

{

LED_SETON();

Delay_1S();

LED_SETOFF();

Delay_1S();

}

}



本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請(qǐng)聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請(qǐng)及時(shí)聯(lián)系本站刪除( 郵箱:macysun@21ic.com )。
換一批
延伸閱讀
關(guān)閉