码迷,mamicode.com
首页 > 其他好文 > 详细

2416 呼吸灯 效果

时间:2014-07-22 08:25:33      阅读:229      评论:0      收藏:0      [点我收藏+]

标签:http   os   io   art   for   re   

#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 = 1/4

	TCON_REG	&= ~(0xF << 8);
	TCON_REG	|= (0xCD<<8);
}

//¹Ø±ÕPWM1Êä³öͨµÀ
void breathled_close(void)
{
		TCON_REG &= ~(0X1 << 8);
		INTMSK_REG |= (0X1 << 11);
}

int do_breathled(struct cmd_tbl_s *cmdtp, int flag, int argc, char * const argv[])
{
    char* pchLed;
    uint16_t hwSpeedLevel = 0;
//	int i;
//	for(i=0;i<argc;i++)
//	{		
//		Uart_Printf("%s\r\n",argv[i]);
//	}
    pchLed = argv[1];
    while((*pchLed <= ‘9‘)
        &&(*pchLed >= ‘0‘)){
        hwSpeedLevel *= 10;
        hwSpeedLevel += *pchLed-‘0‘;
        pchLed++;
    }
    Uart_Printf("Level:%d\r\n",hwSpeedLevel);
    set_config(hwSpeedLevel);	
    breathled_init();
	return 0;
}
因为移植了cli 所以有类似teminal的效果

整体程序再说了

视频地址:

http://v.youku.com/v_show/id_XNzQxMTg1Nzgw.html





2416 呼吸灯 效果,布布扣,bubuko.com

2416 呼吸灯 效果

标签:http   os   io   art   for   re   

原文地址:http://my.oschina.net/mummy108/blog/291293

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!