|
楼主 |
发表于 2010-3-19 11:58:17
|
显示全部楼层
回1楼:
我的延时时间是1S。
2楼说的VL是什么?
完整的代码:
#ifndef __DS18B20_H_
#define __DS18B20_H_
#define CONVERT_T 200
extern unsigned char ConvertTime;
extern void ds18b20_rst(void);
extern void ds18b20_write_comm(unsigned char val);
extern unsigned char ds18b20_read(void);
extern void ds18b20_run(void);
extern void ds18b20_Convert(void);
extern void ds18b20_read_t(void);
#endif
DS18B20.C上面已有我就不帖了
#include <avr/interrupt.h>
#include <avr/io.h>
#include "Port.h"
#include "SEG_MPX4_CA.h"
#include "softRtc.h"
#include "key.h"
#include "ht1381.h"
#include "ds18b20.h"
// 内部函数声明
static void timer0_COMP_Init(void);
#define BUZZER_TIME 6
unsigned char ucBuzzer_time;
// Fosc:7.3728MHz
//TIMER0 initialize - prescale:256
// WGM: COMP
// desired value: 10KHz
void timer0_COMP_Init(void)
{
TCCR0 = 0;
TCNT0 = 0;
OCR0 = 3; // TOP 值
TCCR0 |= (1 << WGM01); // timer0 ctc
TCCR0 |= (1 << COM00); // 比较匹配发生时OC0 取反
TCCR0 |= (1 << CS02); // clkI/O/256 ( 来自预分频器)启动定时器计数
ucBuzzer_time = BUZZER_TIME;
}
void BUZZER_ON(void)
{
timer0_COMP_Init();
}
void BUZZER_OFF(void)
{
TCCR0 = 0;
}
void timer2_CTC_Init(void)
{
TCNT2 = 0;
OCR2 = 144; // TOP 值
TCCR2 |= (1 << WGM21); // Timier2 CTC
// clkI/O/256 ( 来自预分频器)启动定时器计数
TCCR2 |= (1 << CS22)|(1 << CS21);
TIMSK |= (1 << OCIE2); // 使能比较匹配中断
}
// 比较匹配中服
ISR(TIMER2_COMP_vect)
{
ShowLed();
if (++Keytick >= KEY_TICK)
{
Keytick = 0;
KeyScan();
}
if (--ucBuzzer_time <= 0)
{
BUZZER_OFF();
}
--ReadTime;
--ConvertTime;
}
(原文件名:QQ截图未命名.jpg)
仿真是OK,就是在实际中不行。
#include <avr/interrupt.h>
#include <avr/io.h>
#include <util/delay.h>
#include "SEG_MPX4_CA.h"
#include "Port.h"
#include "PortConf.h"
#include "System.h"
#include "softRtc.h"
#include "key.h"
#include "ht1381.h"
#include "ds18b20.h"
// 数码管是共阳极
// SEG线硬件连接方法定义(某位为 '1' 表示与数码管相对应的引脚相连)
int main(void)
{
cli();
PortConf();
KeyInit();
timer2_CTC_Init();
BUZZER_ON();
DisplayState =0x00;
ReadTime = HT1381_READ_EN;
bUpdateDisplayEn = 0;
sei(); //re-enable interrupts
while(1)
{
KeyPress();
if (bUpdateDisplayEn)
{
if (ReadTime == 0)
{
ReadTime = HT1381_READ_EN;
time.hour = ht1381_receive(0x85);
time.minute = ht1381_receive(0x83);
Updata_time(time.hour, time.minute);
}
}
if (ConvertTime == 0)
{
ConvertTime = CONVERT_T;
ds18b20_run();
}
}
return 0;
} |
|