PIC32MZ tutorial -- Blinky LED
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 second
LED OFF
Delay second
It uses Timer1 to control the delay time. So first I implement the three Timer1 functions.
/**
<p><b>Function: TMR1_Open</b></p> <p><b>Summary: Initialization of Timer </b></p> <p><b>Description: TMR1 on; 0.08 microsecond every tick </b></p> <p><b>Remarks: Pre-scale 1:8; PB 100MHz; PR1 0xFFFF</b></p>
*/
void TMR1_Open(void)
{
T1CON = 0x8010;
PR1 = 0xFFFF;
}
// Comment a function definition and leverage automatic documentation
/**
<p><b>Function: TMR1_Write</b></p> <p><b>Summary: Write TMR1</b></p> <p><b>Description: Write a value to TMR1</b></p> <p><b>Remarks: the value is range of 0~65535</b></p>
*/
void TMR1_Write(unsigned int value)
{
TMR1 = value & 0xFFFF;
}
/**
<p><b>Function: TMR1_Read</b></p> <p><b>Summary: Read TMR1</b></p> <p><b>Description: Read the value from TMR1</b></p> <p><b>Remarks: the value is range of 0~65535</b></p>
*/
unsigned int TMR1_Read(void)
{
return (TMR1 & 0xFFFF);
}
Second I finish the delay function, the implemention is like below
/**
<p><b>Function: Delay_1S </b></p> <p><b>Summary: Delay using TMR1</b></p> <p><b>Description: Delay one second </b></p> <p><b>Remarks: call TMR1_Open first </b></p>
*/
void Delay_1S(void)
{
unsigned int count = ;
unsigned int ticks = ;
while (count--)
{
TMR1_Write();
while (TMR1_Read() < ticks)
{
; // do nothing
}
}
}
Actually we are also able to do that like below
/**
<p><b>Function: Delay_1S </b></p> <p><b>Summary: Delay using TMR1</b></p> <p><b>Description: Delay one second </b></p> <p><b>Remarks: call TMR1_Open first </b></p>
*/
void Delay_1S(void)
{
unsigned int count = ;
unsigned int ticks = ;
while (count--)
{
TMR1_Write();
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 <proc/p32mz2048ech144.h>
#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 ()
{
LED_SETON();
Delay_1S();
LED_SETOFF();
Delay_1S();
}
}
PIC32MZ tutorial -- Blinky LED的更多相关文章
- PIC32MZ tutorial -- External Interrupt
In my older blog "PIC32MZ tutorial -- Key Debounce", I shows how to acheive key debounce w ...
- PIC32MZ tutorial -- OC Interrupt
In my previous blog "PIC32MZ tutorial -- Output Compare", I shows how to apply Output Comp ...
- PIC32MZ tutorial -- Output Compare
Output Compare is a powerful feature of embedded world. The PIC32 Output Compare module compares the ...
- PIC32MZ tutorial -- Change Notification
In my last post I implement "Key Debounce" with port polling, port polling is not very eff ...
- PIC32MZ tutorial -- Key Debounce
Today I accomplish a application on PIC32MZ EC Starter Kit. The feature of application is to light u ...
- PIC32MZ tutorial -- Timer Interrupt
An interrupt is an internal or external event that requires quick attention from the controller. The ...
- PIC32MZ tutorial -- Hello World
Today I implement "Hello World" on PIC32MZ EC starter kit. The application of "Hello ...
- PIC32MZ tutorial -- UART Communication
At this moment, I accomplish the interface of UART communication for PIC32MZ EC Starter Kit. This in ...
- PIC32MZ tutorial -- Watchdog Timer
Watchdog is a very necessary module for embedded system. Someone said that embedded system operates ...
随机推荐
- html第一阶段总结
html格式汇总 <!doctype html><!-- html5格式声明 --> <html lang="en"><!-- 语言,en ...
- UWP/Win10新特性系列—UserConsentVerifier
在UWP开发中,微软提供了新的用户许可验证方式-指纹(生物识别).Pin.密码验证.在爆料的新型Win10 Mobile移动设备中,会增加虹膜识别等先进的用户身份识别技术,微软现在统一了身份验证的AP ...
- MYSQL基本操作语句
0.修改密码:mysqladmin -u root -p password 123456 导出数据库:mysqldump -u root -p yunpay>yunpay.sql 导入数据库:m ...
- CSS值得关注的那些事?
CSS值得关注的那些事? CSS层叠样式表的出现,使得样式表现层与HTML结构层分离,CSS样式与HTML结构层次清晰,一目了然.给我们前端开发者带来诸多的便利,然而,在实际前端开发中,还是有相当多的 ...
- 億万笑者 - Radwimps
億万笑者 作曲:野田洋次郎 作词:野田洋次郎 明日に希望を持った者だけに 絶望があるんだ何かを信じた者だけに 裏切りはあるんだ勇者だけに与えられた 名誉の負傷とでも言うのかそれにしてはずいぶんと 割に ...
- 关于 MAXScript 如何获取当前max版本
用到了 GetFileVersion 相关文档在此:http://docs.autodesk.com/3DSMAX/16/ENU/MAXScript-Help/index.html?url=files ...
- .net framework 4.0 从 GAC 卸载 程序集
.net framework 4.0 的 GAC 目录: C:\Windows\Microsoft.NET\assembly\GAC_MSIL 要卸载,仍然使用 gacutil 命令,不要带扩展名: ...
- php和js一起实现倒计时功能
里获取的php服务端的时间 纯JS是获取客服端时间! <?php //php的时间是以秒算.js的时间以毫秒算 date_default_timezone_set('PRC'); //date_ ...
- Network Address Translation(转载)
Network Address Translation 来源:http://alexanderlaw.blog.hexun.com/9791596_d.html 地址转换用来改变源/目的 ...
- MyEclipse Spring 学习总结一 Spring IOC容器
一.Spring IOC容器---- Spring AllicationContext容器 程序的结构如下: 1.首先在MyEclipse 创建创建Java Project 2.创建好后,添加spin ...