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 ...
随机推荐
- CSS特性: 继承 和 层叠
在css中也存在着继承关系,与面向对象的编程语言不同,css的继承很简单,而且主要指的是在CSS盒模型中,外围的盒子的样式会被内部所包含的盒子所继承.具体来了解一下. HTML元素之间存在一个”树型“ ...
- Android 学习第10课,Android的布局
Android的布局 线性布局
- H5版定点投篮游戏(1)--物理模型抽象
前言: 前几天目睹了大学同学开了个微店, 算是间接体验微信公众平台的使用. 觉得非常便捷和方便, 于是自己也想捣鼓一个. 公众号取名: "木目的H5游戏世界", 定位做成一个, 个 ...
- netfilter-IPv4实现框架分析(一)
基于Linux-2.6.30版本,具体实现net\ipv4\netfilter目录下,入口文件为net\ipv4\netfilter\iptable_filter.c,入口/出口函数为模块的init函 ...
- EXTJS信息提示框的注意事项
1.申明html:弹出框不完整 申明xhtml 2.当非必须参数不需要设定,而后续需要设置参数时,可设置为null. Ext.onReady(){ function(){ Ext.Message.pr ...
- Streaming replication slots in PostgreSQL 9.4
Streaming replication slots are a pending feature in PostgreSQL 9.4, as part of the logical changese ...
- 我终于搞清楚为什么谷歌地图获取到的联通3G基站与大家手头的基站表不同了
我终于搞清楚这个问题了,大家使用谷歌地图手机版.MobileTrack以及网优用的FieldTest获取到的WCDMA基站Cellid为什么不是大家手头的CellTrack91或基站表里的数字了... ...
- Mac 下 Intellij IDEA 2016.1.2+maven+jetty+ JRebel 6.4.3 破解+spring mvc
准备阶段: Intellij IDEA 2016.1.2 (官方下载,作者下载的是社区版): JRebel for IntelliJ插件安装,可选择在线安装,在线安装的是最新版,我选择本地安装, 下 ...
- Jquery数组操作
jQuery的数组处理,便捷,功能齐全. 最近的项目中用到的比较多,深感实用,一步到位的封装了很多原生js数组不能企及的功能. 最近时间紧迫,今天抽了些时间回过头来看 jQuery中文文档 中对数组的 ...
- C#后台程序重启IIS,发邮件通知
应用场景:IIS网站挂掉,系统自动重启IIS,通知相关联系人: 主要代码: 监控类 public class monitoringiis { EmailSend send = new EmailSen ...