初级会员

- 积分
- 50
- 金钱
- 50
- 注册时间
- 2014-4-1
- 在线时间
- 0 小时
|

楼主 |
发表于 2014-4-24 12:57:05
|
显示全部楼层
回复【2楼】Badu_Space:
---------------------------------
现在是可以了,但貌似效果相反了,
#include "timer.h"
#include "led.h"
#include "usart.h"
#include "stm32f10x_lib.h"
#include "sys.h"
uchar k_num[3];
uchar l_s_num[3];
uchar n_2; //秒数
u8 sta=1;
void TIM3_IRQHandler(void)
{
//sta=1;
if(TIM3->SR&0X0001)//溢出中断
{
n_2--;
if(n_2<1)
{
if(sta==1)
{
//STMFLASH_Read(FLASH_SAVE_ADDR,(u16*)sta,SIZE);
sta=0;
n_2=0;
}
//TIM3->CR1&=0<<0;
else
{
sta=1;
}
TIM3->CR1&=0xfe; //使能定时器3
}
}
TIM3->SR&=~(1<<0);//清除中断标志位 //sta=0;
//TIM3->CR1&=0<<0; //关闭中断
}
void Timerx_Init(u16 arr,u16 psc)
{
RCC->APB1ENR|=1<<1;//TIM3时钟使能
TIM3->ARR=arr; //设定计数器自动重装值//刚好1ms
TIM3-> SC=psc; //预分频器7200,得到10Khz的计数时钟
//这两个东东要同时设置才可以使用中断
TIM3->DIER|=1<<0; //允许更新中断
TIM3->DIER|=1<<6; //允许触发中断
TIM3->CR1|=0x01; //使能定时器3
MY_NVIC_Init(3,3,TIM3_IRQChannel,2);//抢占1,子优先级3,组2
}
int main(void)
{
//u8 t9=0;
u8 a[64]; //接收缓冲,最大64个字节.
//sta=1;
volatile int menu;
u32 led_count=0;
Stm32_Clock_Init(9); //72M
delay_init(72); //延时初始化
LED_Init();
uart_init(72,38400);
Max7219_port();
Init_Max7219();
//IWDG_Init(4,625*4);
while(1)
{
//IWDG_Feed();
if(led_count<1000000)
{
LEDB=1;
led_count++;
}
else if(led_count>2000000)
{
led_count=0;
}
if(sta==1)
{
delay_ms(100);
LEDBON();
delay_ms(100);
max7219_standby();
delay_ms(3000);
clear();
delay_ms(300);
Timerx_Init(5000,7199);
n_2=2*5;
//TIM3->CR1&=0<<0;
//sta=0;
//如果直接显示数码管的数字
//Write_Max7219(1,0x7E);
//
sta=0;
}
现在的效果是执行一次standby(),然后灭5秒,之后再执行standby(),一直这样执行,我想要的效果就是,n_2的变量定义的时间是运行standby()的时间,也就是说,n_2=2*100,那standby()执行100秒,之后中断定时器,这样要怎么改下 |
|