bc... [盗版]

timer.c ( File view )

  • By Karma_w 2015-06-09
  • View(s):16
  • Download(s):1
  • Point(s): 1
			#include "timer.h"
#include "led.h"
#include "usart.h"
//////////////////////////////////////////////////////////////////////////////////
//本程序只供学习使用,未经作者许可,不得用于其它任何用途
//Mini STM32开发板
//通用定时器 驱动代码
//正点原子@ALIENTEK
//技术论坛:www.openedv.com
//修改日期:2010/12/03
//版本:V1.0
//版权所有,盗版必究。
//Copyright(C) 正点原子 2009-2019
//All rights reserved
//////////////////////////////////////////////////////////////////////////////////

extern u8 volatile uart_rev_flag;	//接收完成标志
extern u16 uart_rev_count;	//ADU接收字节个数

//定时器3中断服务程序
void TIM3_IRQHandler(void)
{

	if(TIM3->SR&0x0001)//溢出中断
	{

		TIM3->SR&=~(1<<0);//清除中断标志位
		TIM3->SR&=~(1<<0);//清除中断标志位
		TIM3->CR1&=~(0x01);
		//uart_send_char(0x05);
		LED1=!LED1;
		
		//USART1->CR1&=~(1<<8);
		//USART1->CR1&=~(1<<5);
		
		uart_rev_flag=1;	//接收完成标志
		
	
}
	

}
//通用定时器中断初始化
//这里时钟选择为APB1的2倍,而APB1为36M
//arr:自动重装值。
//psc:时钟预分频数
//这里使用的是定时器3!
void Timerx_Init(u16 arr,u16 psc)
{

	RCC->APB1ENR|=1<<1;//TIM3时钟使能
 	TIM3->ARR=arr;  //设定计数器自动重装值//刚好1ms
	TIM3->PSC=psc;  //预分频器7200,得到10Khz的计数时钟
	//这两个东东要同时设置才可以使用中断
	TIM3->DIER|=1<<0;   //允许更新中断
	TIM3->DIER|=1<<6;   //允许触发中断

	TIM3->CR1|=0x01;    //使能定时器3
  	MY_NVIC_Init(1,3,TIM3_IRQChannel,2);//抢占1,子优先级3,组2

}

//TIM3 PWM部分
//正点原子@ALIENTEK
//2010/6/2

//PWM输出初始化
//arr:自动重装值
//psc:时钟预分频数
void PWM_Init(u16 arr,u16 psc)
{

	//此部分需手动修改IO口设置
	RCC->APB1ENR|=1<<1;       //TIM3时钟使能

	GPIOA->CRH&=0XFFFFFFF0;//PA8输出
	GPIOA->CRH|=0X00000004;//浮空输入

	GPIOA->CRL&=0X0FFFFFFF;//PA7输出
	GPIOA->CRL|=0XB0000000;//复用功能输出
	GPIOA->ODR|=1<<7;//PA7上拉

	TIM3->ARR=arr;//设定计数器自动重装值
	TIM3->PSC=psc;//预分频器不分频

	TIM3->CCMR1|=7<<12;  //CH2 PWM2模式
	TIM3->CCMR1|=1<<11; //CH2预装载使能

	TIM3->CCER|=1<<4;   //OC2 输出使能

	TIM3->CR1=0x8000;   //ARPE使能
	TIM3->CR1|=0x01;    //使能定时器3

}













			
...
Expand> <Close

Want complete source code? Download it here

Point(s): 1

Download
0 lines left, continue to read

File list

Tips: You can preview the content of files by clicking file names^_^
Name Size Date
01.97 kB
01.97 kB
01.97 kB
adc.c2.48 kB2015-06-03 11:04
adc.h693.00 B2011-01-12 21:19
01.97 kB
dma.c1.31 kB2010-06-07 16:30
dma.h378.00 B2010-06-07 16:30
01.97 kB
exti.c1.71 kB2011-01-12 20:50
exti.h628.00 B2011-01-12 20:51
01.97 kB
key.c1.73 kB2013-04-03 14:18
key.h839.00 B2011-01-12 20:46
01.97 kB
FONT.H15.78 kB2010-06-21 11:18
ILI93xx.c38.75 kB2012-10-25 23:18
LCD.h8.94 kB2012-10-25 22:28
01.97 kB
led.c910.00 B2013-04-03 14:18
led.h288.00 B2010-05-27 17:30
01.97 kB
FONT.H15.78 kB2010-03-19 17:16
oled.c6.70 kB2011-01-12 21:02
oled.h1.59 kB2011-01-12 21:02
01.97 kB
rtc.c7.75 kB2011-01-12 22:04
rtc.h1.35 kB2011-01-12 21:15
01.97 kB
timer.c2.10 kB2015-06-03 11:38
timer.h724.00 B2011-01-12 20:59
01.97 kB
wdg.c2.04 kB2011-01-12 20:56
wdg.h756.00 B2011-01-12 20:56
01.97 kB
wkup.c1.85 kB2011-01-12 21:18
wkup.h728.00 B2011-01-12 21:18
keilkilll.bat399.00 B2011-04-23 10:24
README.TXT377.00 B2012-07-19 22:20
01.97 kB
01.97 kB
delay.c2.02 kB2013-04-03 12:14
delay.h905.00 B2013-04-03 12:14
01.97 kB
cortexm3_macro.h2.17 kB2009-05-07 14:42
stm32f10x_conf.h6.05 kB2009-05-07 14:42
stm32f10x_it.h4.42 kB2012-12-18 12:35
stm32f10x_map.h27.63 kB2009-05-07 14:42
stm32f10x_nvic.h18.75 kB2009-05-07 14:42
stm32f10x_type.h3.31 kB2009-05-07 14:42
sys.c6.69 kB2013-04-03 12:13
sys.h3.78 kB2013-04-03 12:13
01.97 kB
usart.c3.35 kB2015-06-03 11:28
usart.h1,010.00 B2015-06-03 10:57
01.97 kB
adc.crf34.24 kB2015-06-03 11:04
adc.d298.00 B2015-06-03 11:04
adc.o39.02 kB2015-06-03 11:04
delay.crf31.84 kB2015-06-03 10:54
delay.d286.00 B2015-06-03 10:54
delay.o37.45 kB2015-06-03 10:54
ili93xx.crf80.82 kB2015-06-03 10:57
ili93xx.d592.00 B2015-06-03 10:57
ili93xx.o79.87 kB2015-06-03 10:57
JLinkLog.txt59.16 kB2015-06-03 11:43
JLinkSettings.ini578.00 B2013-04-03 14:19
key.crf34.17 kB2015-06-03 10:54
key.d332.00 B2015-06-03 10:54
key.o40.01 kB2015-06-03 10:54
led.crf33.41 kB2015-06-03 10:54
led.d298.00 B2015-06-03 10:54
led.o38.35 kB2015-06-03 10:54
modbus.c5.44 kB2015-06-03 11:38
modbus.crf40.08 kB2015-06-03 11:38
modbus.d478.00 B2015-06-03 11:38
modbus.h404.00 B2015-06-03 10:54
modbus.o47.92 kB2015-06-03 11:38
rtc.crf41.95 kB2015-06-03 10:57
rtc.d434.00 B2015-06-03 10:57
rtc.o48.63 kB2015-06-03 10:57
STM32F10x.d28.00 B2015-06-03 10:54
STM32F10x.lst34.54 kB2015-06-03 10:54
stm32f10x.o5.58 kB2015-06-03 10:54
STM32F10x.s11.04 kB2009-12-22 19:16
sys.crf35.34 kB2015-06-03 10:54
sys.d264.00 B2015-06-03 10:54
sys.o42.51 kB2015-06-03 10:54
TEST.axf37.47 kB2015-06-03 11:43
TEST.build_log.htm1.36 kB2015-06-03 11:44
test.c601.00 B2015-06-03 11:41
test.crf51.11 kB2015-06-03 11:41
test.d792.00 B2015-06-03 11:41
TEST.hex13.17 kB2015-06-03 11:43
TEST.htm43.73 kB2015-06-03 11:43
TEST.lnp339.00 B2015-06-03 11:43
TEST.map64.78 kB2015-06-03 11:43
test.o54.43 kB2015-06-03 11:41
TEST.Opt2.03 kB2013-04-03 14:21
TEST.plg249.00 B2014-03-16 19:17
TEST.sct479.00 B2014-02-21 11:13
TEST.tra1.38 kB2014-02-21 11:13
TEST.Uv23.21 kB2013-04-03 14:21
TEST.uvgui.Administrator69.44 kB2013-04-03 14:20
TEST.uvgui.wjc72.16 kB2015-06-03 11:44
TEST.uvgui.WuJiChao67.42 kB2014-03-16 19:17
TEST.uvgui_wjc.bak72.08 kB2015-06-03 11:42
TEST.uvgui_WuJiChao.bak67.35 kB2014-02-21 11:21
TEST.uvopt10.12 kB2015-06-03 11:44
TEST.uvproj16.86 kB2015-06-03 11:42
TEST_Target8.60 kB2015-06-03 11:43
TEST_uvopt.bak10.12 kB2015-06-03 11:42
TEST_uvproj.bak17.39 kB2015-06-02 14:35
timer.crf38.84 kB2015-06-03 11:38
timer.d462.00 B2015-06-03 11:38
timer.o43.37 kB2015-06-03 11:38
usart.crf38.59 kB2015-06-03 11:28
usart.d388.00 B2015-06-03 11:28
usart.o43.36 kB2015-06-03 11:28
wdg.crf34.45 kB2015-06-03 10:54
wdg.d330.00 B2015-06-03 10:54
wdg.o41.05 kB2015-06-03 10:54
wkup.crf34.14 kB2015-06-03 10:54
wkup.d378.00 B2015-06-03 10:54
wkup.o41.15 kB2015-06-03 10:54
...

timer.c (571.52 kB)

Need 1 point
Your Point(s)

Your Point isn't enough.

Get point immediately by PayPal

More(Debit card / Credit card / PayPal Credit / Online Banking)

Submit your source codes. Get more point

LOGIN

Don't have an account? Register now
Need any help?
Mail to: support@codeforge.com

切换到中文版?

CodeForge Chinese Version
CodeForge English Version

Where are you going?

^_^"Oops ...

Sorry!This guy is mysterious, its blog hasn't been opened, try another, please!
OK

Warm tip!

CodeForge to FavoriteFavorite by Ctrl+D