打印
[PIC®/AVR®/dsPIC®产品]

使用中断作为延时在LED上递增计数

[复制链接]
390|7
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
huangcunxiake|  楼主 | 2024-3-11 23:07 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
#include <xc.h>
// PIC16F1719 Configuration Bit Settings
// For more on Configuration Bits, consult y**ice data sheet
// CONFIG1
#pragma config FOSC = ECH // External Clock, 4-20 MHz
#pragma config WDTE = OFF // Watchdog Timer (WDT) disabled
#pragma config PWRTE = OFF // Power-up Timer disabled
#pragma config MCLRE = ON // MCLR/VPP pin function is MCLR
#pragma config CP = OFF // Flash Memory Code Protection off
#pragma config BOREN = ON // Brown-out Reset enabled
#pragma config CLKOUTEN = OFF // Clock Out disabled.
#pragma config IESO = ON // Internal/External Switchover on
#pragma config FCMEN = ON // Fail-Safe Clock Monitor enabled
// CONFIG2
#pragma config WRT = OFF // Flash Memory Self-Write Protect off
#pragma config PPS1WAY = ON // PPS one-way control enabled
#pragma config ZCDDIS = ON // Zero-cross detect disabled
#pragma config PLLEN = OFF // Phase Lock Loop disable
#pragma config STVREN = ON // Stack Over/Underflow Reset enabled
#pragma config BORV = LO // Brown-out Reset low trip point
#pragma config LPBOR = OFF // Low-Power Brown Out Reset disabled
#pragma config LVP = OFF // Low-Voltage Programming disabled
// Interrupt function
void interrupt isr(void){
// only process Timer0-triggered interrupts
if(INTCONbits.TMR0IE && INTCONbits.TMR0IF) {
// static variable for permanent storage duration
static unsigned char portValue;
// write to port latches
LATD = portValue++; // RD[0:3] = LED[0:3]
LATB = (portValue++ >> 4); // RB[0:3] = LED[4:7]
// clear this interrupt condition
INTCONbits.TMR0IF = 0;
}
}
void main(void){
// Port D access
ANSELD = 0x0; // set to digital I/O (not analog)
TRISD = 0x0; // set all port bits to be output
// Port B access
ANSELB = 0x0; // set to digital I/O (not analog)
TRISB = 0x0; // set all port bits to be output
// Timer0 setup
OPTION_REG = 0xD7; // timer 0 internal clock, prescaler 1:256
INTCONbits.TMR0IE = 1; // enable interrupts for timer 0
ei(); // enable all interrupts
while(1);
return;
}


使用特权

评论回复
沙发
huangcunxiake|  楼主 | 2024-3-11 23:08 | 只看该作者
同时展示了配置字的用法。

使用特权

评论回复
板凳
盗铃何须掩耳| | 2024-3-13 09:51 | 只看该作者
在LED上递增是啥意思

使用特权

评论回复
地板
zhizia4f| | 2024-3-27 11:12 | 只看该作者
这操作溜啊,用中断当delay?

使用特权

评论回复
5
ex7s4| | 2024-3-27 12:24 | 只看该作者
写的还挺规矩的,支持楼主一波

使用特权

评论回复
6
y1n9an| | 2024-3-27 13:25 | 只看该作者
用的定时器中断吧这是

使用特权

评论回复
7
w2nme1ai7| | 2024-3-27 15:36 | 只看该作者
其实不如用STM32了,库函数很好搞的

使用特权

评论回复
8
cen9ce| | 2024-3-27 18:20 | 只看该作者
不错的,这逻辑思路都是可以的

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

189

主题

3407

帖子

9

粉丝