delay_100++; else
{
counter++; delay_100=0; output_toggle(Led0); adc=read_adc();
if((counter>60)&&(adc!=old_value))
{
counter=0; enable=1;
}
old_value += Filter*(adc - old_value);
}
return 0;
Có thể bạn quan tâm!
- Sơ Đồ Mạch Led Thu Với Bộ So Sánh Tương Đương
- Hệ Thống Được Cấp Nguồn Và Sẵng Sàng Hoạt Động
- Xây dựng hệ thống giám sát mực nước, nhiệt độ và phát cảnh báo qua mạng tin nhắn SMS/GSM - 10
- Xây dựng hệ thống giám sát mực nước, nhiệt độ và phát cảnh báo qua mạng tin nhắn SMS/GSM - 12
Xem toàn bộ 104 trang tài liệu này.
}
#INT_RDA
void rda()
{ UART_ISR();
}
void GSM_init(void)
{
output_bit(GSM_PW,1); output_bit(Led1,1); output_float(GSM_SENSE);
}
void GSM_start(void)
{
//start up GSM module
delay_ms(2000); lcd_init(); output_bit(GSM_PW,0); output_bit(Led1,0); delay_ms(2000); output_bit(GSM_PW,1); output_bit(Led1,1);
lcd_putc("nGSM initializing"); delay_ms(5000); lcd_putc("nPlease wait......."); delay_ms(5000); lcd_putc("n..to init Sim900"); delay_ms(5000); lcd_putc("nPlease wait......."); delay_ms(5000); lcd_putc("n..to init Sim900"); delay_ms(5000); lcd_putc("nPlease wait......."); delay_ms(5000); lcd_putc("n..to init Sim900");
}
void GSM_sync(void)
{
putc(13);//enter CR delay_ms(1000);
output_bit(Led1,0); new_frame=0; frame_get=0;
printf("AT");
putc(13);//enter CR delay_ms(1000);
printf("AT"); putc(13);//enter CR delay_ms(1000);
printf("AT"); putc(13);//enter CR delay_ms(1000);
}
void GSM_sel_mess_mode(char mode)
{
if(mode>0) //text mode
{
output_bit(Led1,0);
printf("AT+CMGF=1"); putc(13);//enter CR output_bit(Led1,1); delay_ms(1000); output_bit(Led1,0);
printf("AT+CMGF=1"); putc(13);//enter CR output_bit(Led1,1); delay_ms(1000); output_bit(Led1,0);
}
else //PDU mode
{
output_bit(Led1,0);
printf("AT+CMGF=0"); putc(13);//enter CR output_bit(Led1,1); delay_ms(1000); output_bit(Led1,0);
printf("AT+CMGF=0"); putc(13);//enter CR output_bit(Led1,1); delay_ms(1000); output_bit(Led1,0);
}
}
void lcd_display()
{
if(old_value !=new_value)
{
lcd_putc("fNhiet do:"); new_value = old_value;
tmp_temp=(char)convertC2K(old_value); Converter(tmp_temp);
lcd_gotoxy( 1,2 );
if(x!=0) lcd_send_byte(1,tmp[x]); lcd_send_byte(1,tmp[y]); lcd_send_byte(1,tmp[z]); lcd_putc("oC");
}
}
char Converter(char n)
{
char tmp; tmp=n; x=n/100; tmp=n%100; y=tmp/10; z=tmp%10;
}
float convertC2K(float adc)
{
float temp_value;
temp_value = (adc-139.25)/0.512;
return temp_value;
}
void KiemTraMucNuoc(char temp)
{
char sensor4 char sensor3 char sensor2 char sensor1. if(sensor4==1)
{
delay_ms(10);
if((sensor4==1)&& (num_count4==0))
{
send_message(4,temp); num_count4++; output_toggle(Led0);enable1=1;
num_count3=0;num_count2=0;num_count1=0;
}
}
else if(sensor3==1)
{
delay_ms(10);
if((sensor3==1)&& (num_count3==0))
{
send_message(3,temp); num_count3++; output_toggle(Led0);enable1=1; num_count2=0;num_count1=0;
}
}
else if(sensor2==1)
{
delay_ms(10);
if((sensor2==1)&& (num_count2==0))
{
send_message(2,temp); num_count2++ ; output_toggle(Led0);enable1=1; num_count1=0;
}
}
else if(sensor1==1)
{
delay_ms(10);
if((sensor1==1)&& (num_count1==0))
{
send_message(1,temp); num_count1++; output_toggle(Led0); enable1=1;
}
}
void clear_status()//XOA GIA TRI CUA CAM BIEN
{
if((sensor1==0)&&(sensor2==0)&&(sensor3==0)&&(sensor4==0) )
{
if((num_count1!=0)||(num_count2!=0)||(num_count3!=0)||(num_count4!=0))
{
num_count1=0; num_count2=0; num_count3=0; num_count4=0; enable1=0;
}
}
}
void main()
{
GSM_init();// thiet lap GSM setup_spi(SPI_SS_DISABLED);// thiet lap SPI
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256); // thiet lap timer setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1); setup_comparator(NC_NC_NC_NC); enable_interrupts(INT_TIMER0); // thiet lap ngat enable_interrupts(INT_RDA); enable_interrupts(GLOBAL); setup_adc(adc_clock_internal); // thiet lap ADC setup_adc_ports(sAN0);
set_adc_channel(0);
Pic GSM 1 demo");
GSM_start();
GSM_sync();// dong bo GSM
GSM_sel_mess_mode(5);// khai bao chon tin nhan trong ma lenh AT control printf("ATE1"); //echo on
putc(13);//enter CR delay_ms(1000);// printf("AT"); putc(13);//enter CR delay_ms(1000); output_bit(Led1,1); printf("AT"); putc(13);//enter CR delay_ms(1000); output_bit(Led1,0); printf("AT+CMGS="); putc(34);//"
printf(PHONE_NUM); putc(34);//" putc(13);//enter CR
delay_ms(1000);//cho ki tu ">" putc(0x1A);//CTRL+Z output_bit(Led1,1); delay_ms(2000);// set_tris_b(0xff);
while(1)
{
lcd_display();
KiemTraMucNuoc(tmp_temp);// kiem tra muc nuoc va nhiet do if((enable==1)&&(enable1==0))
{
send_message(10,tmp_temp);// ham gui tin nhan