PDA

View Full Version : hệ Thống báo cháy trong phòng


convitcon1t
23-09-2012, 09:17 AM
tình hình em mới học PIC,đang làm hệ thống thiết kế báo cháy đơn giàn,dùng CCS và dùng RTOS .em muốn ghi và đọc dữ liệu nhiệt độ vào EFROM để khi mất điện ta ko cần set lại , các bác xem giùm ^^, sao mà ko đọc hoặc ghi dc dữ liệu từ EF ROM ra,nhấn nút giá trị a ko tăng(em hiển thị giá trị a ra LCD)

#include <16F877A.h>
#include <def_16f877a.h>

#device pic16F877A*=16 ADC=8
const char code[10]={'0','1','2','3','4','5','6','7','8','9'} ;
const char t[4][21]={" HT DO NHIET DO ",
"NHIET DO PHONG: ",
" ",
" "};

int8 a,b;
int8 dv0,ch0,tr0,dv1,ch1,tr1;
int8 i;
int8 j,x;
int8 ADC0;
int8 count,d;

#fuses NOWDT,NOPROTECT,NOLVP,HS,NOPUT,NODEBUG, NOBROWNOUT,NOCPD, NOWRT
#use delay(clock=20000000)
#use rs232(baud=9600,parity=n,xmit=pin_C6,rcv=pin_C7)
#use rtos(timer=1, minor_cycle=100ms)

#define LCD portd
#define RS RC2
#define RW RC1
#define E RC0




void ghima()
{

RS=0;
RW=0;
E=1;
E=0;
delay_ms(10);
}
void hienthi()
{
RS=1;
RW=0;
E=1;
E=0;
delay_ms(10);

}
void khoitaoLCD()
{
portd=0x38;
ghima();
portd=0x0c;
ghima();
portd=0x01;
ghima();
portd=0x080;
ghima();

}

#task(rate=200ms, max=10ms, queue=1)
void UpandDown()
{ if(rtos_msg_poll()>0)
if(rtos_msg_read()==1)
{
a=read_eeprom(0x01);
if(rc6==0) // nhan nut UP
{
a=a++;

write_eeprom(0x01,a);
}
if(rc7==0) // nhan nut DOWN
{
a=a--;

write_eeprom(0x01,a);
}


}
}

#task(rate=500ms, max=100ms, queue=1)
void baodong()
{
PORTB=0x00;
if(rtos_msg_poll()>0)
{
x=rtos_msg_read();

tr1=(read_eeprom(0x01))/100;
ch1=((read_eeprom(0x01))-100*tr1)/10;
dv1=((read_eeprom(0x01))-100*tr1-10*ch1);

LCD=0xE5;
ghima();
LCD=code[tr1];
hienthi();

LCD=code[ch1];
hienthi();

LCD=code[dv1];
hienthi();


if(x >=(read_eeprom(0x01)))
{
portB=0xff;

LCD=0x9A;
ghima();
LCD='W';
hienthi();
LCD='A';
hienthi();
LCD='R';
hienthi();
LCD='N';
hienthi();
LCD='I';
hienthi();
LCD='N';
hienthi();
LCD='G';
hienthi();


}
else
{
portB=0x00;

LCD=0x9A;
ghima();
LCD=' ';
hienthi();
LCD=' ';
hienthi();
LCD=' ';
hienthi();
LCD=' ';
hienthi();
LCD=' ';
hienthi();
LCD=' ';
hienthi();
LCD=' ';
hienthi();

}
}
}

#task(rate=500ms, max=100ms, queue=1)
void LCDa()
{

if(rtos_msg_poll()>0)
{


b=rtos_msg_read();



tr0=b/100;
ch0=(b-100*tr0)/10;
dv0=(b-100*tr0-10*ch0);
}


LCD=0xD1;
ghima();
LCD=code[tr0];
hienthi();

LCD=code[ch0];
hienthi();

LCD=code[dv0];
hienthi();

LCD=0xD4;
ghima();
LCD='N';
hienthi();
LCD='H';
hienthi();
LCD='I';
hienthi();
LCD='E';
hienthi();
LCD='T';
hienthi();
LCD=' ';
hienthi();
LCD='D';
hienthi();
LCD='O';
hienthi();
LCD=' ';
hienthi();
LCD='C';
hienthi();
LCD='H';
hienthi();
LCD='A';
hienthi();
LCD='Y';
hienthi();
LCD=':';
hienthi();

}

#task(rate=500ms, max=100ms, queue=1)
void dulieu()
{ if(rtos_msg_poll()>0)
d=rtos_msg_read();
if(d==1)
{
set_adc_channel(0);
delay_us(10);
ADC0=read_ADC();

rtos_msg_send(LCDa,ADC0);
rtos_msg_send(baodong,ADC0);
}

}

#task(rate=1s, max=100ms, queue=1)
void nutnhan()
{

count=0;
if(re0==0)

count=1;

if(count==1)
{
setup_adc(ADC_clock_internal);

setup_adc_ports(RA0_RA1_ANALOG_RA3_REF);

trisd=0;
trisc=0;
set_tris_b(0);

khoitaolcd();
for(i=0;i<4;i++)
for(j=0;j<20;j++)
{
LCD=t[i][j];
hienthi();

if((j==19)&&(i==0))
{
LCD=0xc0; //dau dong 2
ghima();
}
if((j==19)&&(i==1))
{
LCD=0x94;
ghima();
}
if((j==19)&&(i==2))
{
LCD=0x44;
ghima();
}
}




rtos_msg_send(UpandDown,count);
rtos_msg_send(dulieu,count);
}


}




void main()
{
rtos_run();
}