📄 main._c
字号:
//ICC-AVR application builder : 2005-11-2 16:28:30
// Target : 8515
// Crystal: 4.0000Mhz
#include <io8515v.h>
#include <macros.h>
#include <162-1302.h>
#include <function.h>
uchar temh_d;
uchar teml_d;
uchar temm_d;
void port_init(void)
{
PORTA = 0x00;
DDRA = 0xFF;
PORTB = 0xFF;
DDRB = 0xFF;
PORTC = 0xFF;
DDRC = 0xFF;
PORTD = 0x00;
DDRD = 0x00;
} //call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
MCUCR = 0x00;
GIMSK = 0x00;
TIMSK = 0x00;
SEI(); //re-enable interrupts
//all peripherals are now initialized
}
/******************************************************
主程序
******************************************************/
void main(void)
{
uchar s,i,th,tl;
uchar temh,teml,a,count,temm;
init_devices();
init_1302();
init_1302();
init_lcd() ;
init_lcd() ;
init_time();
while(1)
{
LCD_set_xy(0,0);
for(i=0;i<9;i+=2)
{
s=read_data(0x81+i);
tl=s&0x0f;
th=(s>>4);
LCD_write_char(th+48);
LCD_write_char(tl+48);
LCD_write_char(':');
}
s=read_data(0x8b);
tl=s&0x0f;
LCD_write_char(tl+48);
a=init_1820(); //复位18b20
if(a==0x01)
{
LCD_write_string(0,1,"wrong"); //初始化失败
}
else
{
LCD_write_string(0,1,"temper is");//初始化成功
}
write_1820(0xCC); // SKIP THE ROM
write_1820(0x44); //启动温度转换
for(i=0;i<200;i++) //每次转换需要延时200ms以上
delay(200);
a=init_1820(); //复位18b20
write_1820(0xCC); //SKIP THE ROM
write_1820(0xBE); //读寄存器命令
teml=read_1820(); //读低字节数据
temh=read_1820(); //读高字节数据
temm=teml;
temm&=0x0F;
teml>>=4;
temh<<=4;
count=teml|temh;
temh_d=count/10;
temm_d=(temm*6)/10;
teml_d=count%10;
delay(200);
LCD_set_xy(10,1);
LCD_write_char(temh_d+48);
LCD_set_xy(11,1);
LCD_write_char(teml_d+48);
LCD_set_xy(12,1);
LCD_write_char('.');
LCD_set_xy(13,1);
LCD_write_char(temm_d+48);
LCD_write_string(14,1,"`c");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -