首页 > 代码库 > 2416 呼吸灯 效果
2416 呼吸灯 效果
#include <stdint.h> #include <stdbool.h> #include <raw_api.h> #include <lib_string.h> #include <2416_reg.h> #include <pwm.h> #include <irq.h> #include <timer.h> #include <pwm.h> #include <rsh.h> #include "command.h" static struct{ uint16_t hwLevelMax; uint16_t hwLevelNow; bool bIncreasing; }m_tBreathLed; #define SET_RELOAD(CNT) do{ TCNTB1_REG = (CNT);}while(0) #define SET_LEVEL_MAX(CNT) do{ m_tBreathLed.hwLevelMax = (CNT);}while(0) #define SET_TIMER_COMPARE(CNT) do{ TCMPB1_REG = (CNT);}while(0) void irq_breathled(void) { //clear pending //copy from pwm.c //line 57 SRCPND_REG |= ( 0x01 << 11); INTPND_REG |= ( 0x01 << 11); if(m_tBreathLed.bIncreasing){ if(m_tBreathLed.hwLevelNow >= m_tBreathLed.hwLevelMax){ m_tBreathLed.bIncreasing = false; // Uart_Printf("led_loop\n"); }else{ m_tBreathLed.hwLevelNow++; } }else{ if(m_tBreathLed.hwLevelNow <= 0){ m_tBreathLed.bIncreasing = true; }else{ m_tBreathLed.hwLevelNow--; } } SET_TIMER_COMPARE(m_tBreathLed.hwLevelNow); } void set_config(uint16_t hwBreathLedSpeedLevel) { TCON_REG |= (0x1 << 9); SET_RELOAD(hwBreathLedSpeedLevel); SET_LEVEL_MAX(hwBreathLedSpeedLevel); SET_TIMER_COMPARE(hwBreathLedSpeedLevel/2); TCON_REG &= ~(1<<9); TCON_REG |= (0x1<<8); } void breathled_init(void) { //set the GPB1 10 to enable the tout1 GPBCON_REG &= ~(0x3<<2); GPBCON_REG |= (0x2<<2); TCON_REG &= ~(0xF << 8); //clear the register of TIM1 //it will be config when finish //all config //TCON_REG &= TCFG0_REG &= ~(0xFF); TCFG1_REG &= ~(0xF0); //timer_1_ISRInit from raw-os //file: Pwm.c //Line: 124 INTMOD_REG = 0x00000000; PRIORITY_MODE_REG = 0x00000000; INTMSK_REG &= ~(0x1 << 11); //reset the bit 11 to restart the register_irq(11,irq_breathled); //ISR_REGISTER[11] = irq_breathled; TCFG0_REG |= 15; //Prescaler = 15 TCFG1_REG |= 0x10; //divide value = http://www.mamicode.com/1/4> 因为移植了cli 所以有类似teminal的效果整体程序再说了
视频地址:
http://v.youku.com/v_show/id_XNzQxMTg1Nzgw.html
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。