#include"iom48v.h"
#include"macros.h"
unsigned char duanxuan[10]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
unsigned char wei_number[4]={0};
#pragma interrupt_handler move_led: 17
unsigned int count=0,raw_count=0,raw=0;
unsigned char move_wei=0,i=0,j=0,xianshi=1,up_Addr=50;down_Addr=60;
unsigned int up_line=0,down_line=0;
void move_led()
{
if(xianshi==1)
count=raw_count;
if(xianshi==2)
count=up_line;
if(xianshi==3)
count=down_line;
TCNT0=195;
wei_number[0]=count/1000;
wei_number[1]=count%1000/100;
wei_number[2]=count%100/10;
wei_number[3]=count%10;
move_wei++;
if(move_wei==4)
{
move_wei=0;
}
PORTD=duanxuan[wei_number[move_wei]];
if(move_wei==2)
PORTD&=~BIT(7);
PORTB|=0x0F;
PORTB&=~BIT(move_wei);
}
void delay_ms(unsigned int k)
{
unsigned int m,n;
for(m=0;m<k;m++)
{
for(n=0;n<80;n++);
}
}
void ADC_read()
{
ADCSRA|=0b01000000;
while(!ADIF);//等待转换结束
ADCSRA|=BIT(4);
raw=ADC;
raw_count=(unsigned int)(((unsigned long)raw*500/1023));
}
void key_scan()
{
if(!(PINC&BIT(0)))
xianshi=1;
if(!(PINC&BIT(1)))
xianshi=3; //下限
if(!(PINC&BIT(2)))
xianshi=2;
if(!(PINC&BIT(3)))
{
if(xianshi==3)
{
down_line+=1;
if(down_line>=up_line)
down_line=up_line-1;
EEprom_write(down_Addr,down_line>>8);
EEprom_write(down_Addr+1,down_line);
delay_ms(100);
}
if(xianshi==2)
{
up_line+=1;
if(up_line>=400)
up_line=400;
EEprom_write(up_Addr,up_line>>8);
EEprom_write(up_Addr+1,up_line);
delay_ms(100);
}
}
if(!(PINC&BIT(4)))
{
if(xianshi==3)
{
down_line-=1;
if(down_line<=100)
down_line=100;
EEprom_write(down_Addr,down_line>>8);
EEprom_write(down_Addr+1,down_line);
delay_ms(100);
}
if(xianshi==2)
{
up_line-=1;
if(down_line>=up_line)
up_line=down_line+1;
EEprom_write(up_Addr,up_line>>8);
EEprom_write(up_Addr+1,up_line);
delay_ms(100);
}
}
}
void led_shine()
{
if(up_line<raw_count)
{
PORTB&=~BIT(5);
}
else if(up_line>=raw_count)
{
PORTB|=BIT(5);
}
if(down_line>raw_count)
{
PORTB&=~BIT(6);
}
else if(down_line<=raw_count)
{
PORTB|=BIT(6);
}
if(raw_count>down_line&&raw_count<up_line)
PORTB|=BIT(4);
else
PORTB&=~BIT(4);
}
void IO_init()
{
DDRB=0xFF; //PB0-3数码管位选;PB4-6接LED
PORTB=0xFF;
DDRD=0xFF; //PD口接数码管段选
PORTD=0xFF;
DDRC=0x00; //PC0-2接按键,加减上下限
PORTC=0xFF;
}
void EEprom_write(unsigned int Address,unsigned char Data)
{
CLI();
while(EECR&(1<<EEWE));
EEAR=Address;
EEDR=Data;
EECR|=(1<<EEMPE);
EECR|=(1<<EEPE);
SEI();
}
unsigned int EEprom_read(unsigned int Address)
{
CLI();
while(EECR&(1<<EEWE));
EEAR=Address;
EECR|=(1<<EERE);
return EEDR;
SEI();
}
void T0_init() //4ms
{
TCCR0A=0x00;
TCCR0B=0b00000011; //64分频
TCNT0=195; //4ms
TIMSK0=0x01;
}
void ADC_init()
{
ADMUX=0x45;//选参考电压为AVCC,通道5
ADCSRA=0xC0;//使能ADC,并启动转
}
void main()
{
CLI(); //关闭全局中断
IO_init();
T0_init();
ADC_init();
up_line=(EEprom_read(up_Addr)<<8);
up_line+=EEprom_read(up_Addr+1);
down_line=(EEprom_read(down_Addr)<<8);
down_line+=EEprom_read(down_Addr+1);
SEI();
while(1)
{
delay_ms(10);
ADC_read();
key_scan();
led_shine();
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
abcd.rar_温度报警_系统温度
共92个文件
130623155052:1个
130616172832:1个
130623155218:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 36 浏览量
2022-09-24
19:18:40
上传
评论
收藏 116KB RAR 举报
温馨提示
基于eeprom的温度报警系统,可设定上下限温度
资源推荐
资源详情
资源评论
收起资源包目录
abcd.rar (92个子文件)
单片机综合实验
ADC.prj 1KB
_iom48v.h 15KB
ADC.mak 483B
ADC.lst 30KB
ADC.dbg 3KB
ADC.SRC 51B
ADC.o 13KB
BACKUP
ADC.c.130623135150 2KB
ADC.c.130623143418 2KB
ADC.c.130623133318 2KB
ADC.c.130623142146 2KB
ADC.c.130623143930 2KB
ADC.c.130623155218 4KB
ADC.c.130623133448 2KB
ADC.c.130623141530 2KB
ADC.c.130616172808 2KB
ADC.c.130623141658 2KB
ADC.c.130623142752 2KB
ADC.c.130616172832 2KB
ADC.c.130623153916 3KB
ADC.c.130623155052 4KB
ADC.c.130623162110 4KB
ADC.c.130623140208 2KB
ADC.c.130623140036 2KB
ADC.c.130623133806 2KB
ADC.c.130623154800 3KB
ADC.c.130623152250 3KB
ADC.c.130623145148 3KB
ADC.c.130616164950 1019B
ADC.c.130623152646 3KB
ADC.c.130616172120 1KB
ADC.c.130623153050 3KB
ADC.c.130623153554 3KB
ADC.c.130623152210 3KB
ADC.c.130623140304 2KB
ADC.c.130623155006 3KB
ADC.c.130616164752 0B
ADC.c.130616173806 2KB
ADC._c 3KB
ADC.c.130616171612 2KB
ADC.c.130623144912 3KB
ADC.c.130616171228 1KB
ADC.c.130623144930 3KB
ADC.c.130623152724 3KB
ADC.c.130616172854 2KB
ADC.c.130623144834 3KB
ADC.c.130623140018 2KB
ADC.c.130623162006 4KB
ADC.c.130623153248 3KB
ADC.c.130616173640 2KB
ADC.c.130623143034 2KB
ADC.c.130623134334 2KB
ADC.c.130623142638 2KB
ADC.c.130623141608 2KB
ADC.c.130623133410 2KB
ADC.c.130623133914 2KB
ADC.c.130616171828 2KB
ADC.c.130623155516 4KB
ADC.c.130616173832 2KB
ADC.c.130616170716 1KB
ADC.c.130623145206 3KB
ADC.c.130616172742 2KB
ADC.c.130616171734 2KB
ADC.c.130623152420 3KB
ADC.c.130623162338 3KB
ADC.c.130616172536 2KB
ADC.c.130623153850 3KB
ADC.c.130616170324 1KB
ADC.c.130623144128 2KB
ADC.c.130623132938 2KB
ADC.c.130623140434 2KB
ADC.c.130623140158 2KB
ADC.c.130623135610 2KB
ADC.c.130623162122 3KB
ADC.c.130623133056 2KB
ADC.c.130623152544 3KB
ADC.c.130623142434 2KB
ADC.c.130616171442 1KB
ADC.c.130623152214 3KB
ADC.c.130623155430 4KB
ADC.c.130623152438 3KB
ADC.c.130623140216 2KB
ADC.c.130623142016 2KB
ADC.c.130616165020 1KB
ADC.c.130623141322 2KB
ADC.c.130616172046 1KB
ADC.c 3KB
ADC.mp 3KB
ADC.hex 5KB
ADC.cof 8KB
ADC.lis 41KB
ADC.lk 8B
共 92 条
- 1
资源评论
朱moyimi
- 粉丝: 61
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功