📄 main._c
字号:
//ICC-AVR application builder : 2008-8-2 15:50:57
// Target : M16
// Crystal: 8.0000Mhz
#include <iom16v.h>
#include <macros.h>
#include "lm1602.h"
#include "ds18b20.h"
byte flag10ms = 0;
void port_init(void)
{
PORTA = 0x00;
DDRA = 0xE0;
PORTB = 0x00;
DDRB = 0xFF;
PORTC = 0x00; //m103 output only
DDRC = 0x00;
PORTD = 0x00;
DDRD = 0x00;
}
//TIMER1 initialize - prescale:64
// WGM: 0) Normal, TOP=0xFFFF
// desired value: 10mSec
// actual value: 10.000mSec (0.0%)
void timer1_init(void)
{
TCCR1B = 0x00; //stop
TCNT1H = 0xFB; //setup
TCNT1L = 0x1E;
TCCR1A = 0x00;
TCCR1B = 0x03; //start Timer
}
#pragma interrupt_handler timer1_ovf_isr:9
void timer1_ovf_isr(void)
{
static unsigned char cnt =0;
//TIMER1 has overflowed
TCNT1H = 0xFB; //reload counter high value
TCNT1L = 0x1E; //reload counter low value
cnt++;
if(cnt>=50)
{
cnt = 0;
flag10ms = 1;
}
}
//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
timer1_init();
MCUCR = 0x00;
GICR = 0x00;
TIMSK = 0x04; //timer interrupt sources
SEI(); //re-enable interrupts
//all peripherals are now initialized
}
//
void main(void)
{
unsigned int *temp_data;
init_devices();
LcdInit();
DisString(0, 1, "DS18B20 test");
//insert your functional code here...
while(1)
{
if(flag10ms)
{
flag10ms =0;
if(ReadTemperature(temp_data))
{
LCD_Dis_Temperature(1,1,*temp_data); //温度数据转换和显示函数
}
else
{
DisString(1,1,"DS18B20 Error!");
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -