📄 icc17-1.c
字号:
#include <iom16v.h>
#include <macros.h>
#define uchar unsigned char
#define uint unsigned int
uchar col,row,cbyte; /*列x,行(页)y,输出数据 */
uchar const STR[16]="t1: / t2: / ";
uint year=0;
uchar month=0,date=0,hour=0,minute=0,second=0;
uchar set_hour1=0,set_minute1=0;
uchar set_hour2=0,set_minute2=0;
uchar temp;
uchar ReceverCnt=0,ReceverEndFlag=0,Flag=0;
uchar a[12],b[4],c[4],d[2];
uchar e[4];
uchar temh,teml;
uchar sign;
uchar Flag_1820Error=0;
#include"head.h"
#include"lcd.c"
#include"display_time.c"
#include"recever.c"
#include"ds18b20.c"
/*----------------ATMEGA16L初始化子函数。-----------------------*/
void m16_init(void)
{
PORTA=0x00;
DDRA=0xff;
PORTB=0x80;
DDRB=0xff;
DDRC=0xff;
PORTC=0xff;
PORTD = 0x7f; //36
DDRD = 0x82;
timer1_init();
uart0_init();
}
/***********************************/
void uart0_init(void) //40
{ //41
UCSRB = 0x00; //42
UCSRA = 0x82; //43
UCSRC = 0x06; //44
UBRRL = 0x67; //45
UBRRH = 0x00; //46
UCSRB = 0x98; //47
} //48
/******************************/
void timer1_init(void)
{
CLI();
TCCR1B = 0x00; //stop
TCNT1H = 0xE1; //setup
TCNT1L = 0x7C;
TCCR1A = 0x00;
TCCR1B = 0x05; //start Timer
TIMSK = 0x04;
SEI();
}
/*************主函数*************/
void main(void)
{
uchar loop,tempday;
m16_init();
lcd_init();
display_tu(1);
Delay_nms(3000);
display_tu(0);
Delay_nms(3000);
lcd_init();
display_chinese();
Delay_nms(5000);
lcd_init();
//***********************************/
display_hz(4,0,0,1,nian);
display_hz(8,0,0,1,yue);
display_hz(12,0,0,1,ri);
display_hz(4,2,0,1,shi);
display_hz(8,2,0,1,fen);
display_hz(12,2,0,1,miao);
/**********************************/
col=0;row=4;Putstr(STR,16);
/***********************************/
for(loop=0;loop<5;loop++)
{display_hz(2*loop,6,loop,1,temperature);}
display_hz(14,6,0,1,du);
/***********************************/
for(;;)
{
if(Flag_1820Error==0)read_temperature();
tempday=conv(year,month);
if(second>59){second=0;minute++;}
if(minute>59){minute=0;hour++;}
if(hour>23){hour=0;date++;}
if(date>tempday){date=1;month++;}
if(month>12){month=1;year++;}
if(year>9999)year=0;
dis_time();
//----------------------------------
if(d[0]==1)
{
if((hour==set_hour1)&&(minute==set_minute1))Led_On;
}
//----------------------------------
if(d[1]==1)
{
if((hour==set_hour2)&&(minute==set_minute2))Led_Off;
}
//----------------------------------
if(ReceverEndFlag>0)
{
ReceverEndFlag=0;
uart0_send(0x4f);
uart0_send(0x4b);
mov();
}
}
}
/*************************************/
void Delay_1ms(void) //1mS延时子函数
{ uint i;
for(i=1;i<(uint)(xtal*143-2);i++)
;
}
//====================================
void Delay_nms(uint n) //n*1mS延时子函数
{
uint i=0;
while(i<n)
{Delay_1ms();
i++;
}
}
/***************************************/
#pragma interrupt_handler timer1_ovf_isr:9
void timer1_ovf_isr(void)
{
TCNT1H = 0xE1; //reload counter high value
TCNT1L = 0x7C; //reload counter low value
second++;
}
/**************************************130***********/
#pragma interrupt_handler uart0_rx_isr:12
void uart0_rx_isr(void)
{
CLI();
temp=UDR;
Flag=1;
Rece();
SEI();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -