'気象データ送信Xbee $prog &HFF , &H62 , &HDF , &HF9 ' generated. Take care that the chip supports all fuse bytes. '2014/7/03 動作試験バージョ・ '2014/07/12 '2014 8/2 送信フォーマット変更 '------------------ ' W_tx26260801 '------------------ $prog &HFF , &H62 , &HDF , &HF9 ' generated. Take care that the chip supports all fuse bytes. ' 回路図は5Fxc '2014/07/12 AD変換追加データ番号追加データ順変更 '2014/8/1 データのフォーマット変更 ' '----送信データの順番 '1data_no 送信データの連番 '2Batt_V 送信基板のバッテリ電圧 '3Temp  外気温 オフセット=600mV '4 0  未使用 常に0を送信 '5Rain 雨 1パルス0.254mm 0.25として処理 '6Sun 日照(校正してなし、単に目安) '7Boxtemp 基板温度 ' 'データスタート標識は S データ終了はE セパレータは@ ' 1 S 1465 C/R LF ' 2 @ 846 C/R LF ' 3 @ 0 C/R LF ' 7 @ 364 E C/R LF ' ' data Start : [:&H5b data sep:@ &h40 Data end ] &h5d '---------------- 'write fuse bit for cLOCK div=1 cLOCK=8MHZ $regfile = "m88Adef.dat" 'm88Adef.dat でないと書き込み出ない $crystal = 8000000 'AVRクロックを設定。 $baud = 9600 ' use baud rate $hwstack = 32 ' default use 32 for the hardware stack $swstack = 10 ' default use 10 for the SW stack $framesize = 40 Dim Ck_int As Byte Dim Cnt_no As Byte Dim Sec_cnt As Byte Dim Wari_flag As Byte Dim Key_flag As Byte Dim Fo_cnt As Byte '一時ループカウンタ Dim D_wd As Word Dim Ep_data As Word Dim Ep_rain As Eram Word At $10 'EEPROM rain_data Dim Ep_temp As Eram Word At $14 Dim Ep_sun As Eram Word At $18 Dim Ep_battry As Eram Word At $22 'battry E Dim Ep_dtno As Eram Word At $26 'data_NO Dim Ep_intemp As Eram Word At $28 'BOX temp Vref_on Alias Portd.6 Xbee_on Alias Portd.7 Rain_sw Alias Pinb.0 '-----設定----------------- Ddrb = &B1111_1100 'DDRCは0-1ビットをLEDにして動作試験用 Ddrc = &B0000_0011 'TEST 0-1bit_OUT Ddrd = &B1100_0010 Config Vref_on = Output Config Xbee_on = Output Config Aci = Off 'analogCMP_off Config Adc = Single , Prescaler = Auto , Reference = Off Eimsk = 1 'int0有効 Eicra = 0 'Int0=Low Pcmsk0 = &B0000_0001 'PCInt=0bit only On Int0 Wake_up0 'RTC_on SUB On Pcint0 Wake_up1 'Rain on SUB Enable Int0 '5sec RTC Enable Pcint0 Enable Interrupts 'int 許可 '------------------------------ Wari_flag = 0 Key_flag = 0 '最初のデータはゴミが出るので1発目は30秒設定 Sec_cnt = 15 Gosub Port_init Ep_rain = 0 Ep_dtno = 0 '========================== Main: Gosub Port_init Power Powerdown If Wari_flag = 1 Then Goto Sec_countdown If Wari_flag = 2 Then Goto Ck_key Wari_flag = 0 Goto Main '---------------------------- Ck_key: If Key_flag = 1 Then Goto Now_low Waitms 10 If Rain_sw = 0 Then Goto Key_set Goto Main '------------------------------ Key_set: Key_flag = 1 Wari_flag = 0 Goto Main '-------------------------------- Now_low: Waitms 10 If Rain_sw = 1 Then Goto Rain_put If Rain_sw = 0 Then Goto Key_set Goto Main '--------------------------------- Rain_put: Ep_data = Ep_rain Ep_data = Ep_data + 1 Ep_rain = Ep_data '******************************** デバックトラップ Set Portc.0 Waitms 100 Reset Portc.0 '********************************** Goto Main '----------2秒単位カウントダウン(旧VerのままRTCのバックアップ=0Vにならないと5秒カウントにならない) Sec_countdown: Sec_cnt = Sec_cnt - 1 Select Case Sec_cnt Case 10 Reset Xbee_on Case 1 Set Vref_on Waitms 200 'Vref wait Start Adc D_wd = Ep_dtno '1-data_NO send Ep_data = D_wd + 1 Ep_dtno = Ep_data Print 1 ; "S" ; Ep_data Gosub Battry '2-battry SEND Ep_data = Ep_battry Print 2 ; "@" ; Ep_data Gosub Temp_adcon '3-Temp SEND Ep_data = Ep_temp Print 3 ; "@" ; Ep_data Gosub Humi_adcon '4-湿度 Print 4 ; "@" ; 0 '--Rain SEND-- '5-雨量SEND Ep_data = Ep_rain '0.25mm/H Print 5 ; "@" ; Ep_data Gosub Sun_adcon '6---日照SEND Ep_data = Ep_sun Print 6 ; "@" ; Ep_data Gosub Intemp_adcon Ep_data = Ep_intemp Print 9 ; "@" ; Ep_data ; "E" Waitms 600 'Xbee Send after Time Reset Vref_on Set Xbee_on '---------------test Set Portc.0 Waitms 50 Reset Portc.0 '--------------test End Select If Sec_cnt = 0 Then Sec_cnt = 150 ' If Sec_cnt = 0 Then Sec_cnt = 15 'Enable Interrupts Goto Main '==%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% '----ポート設定-------------- Port_init: Set Portd.2 'PULL_UP INT0 Set Portb.0 'PULL_UP PCINT0 Return '-----INT0 SUB -RTC INT-------------- 'Waitを重複割り込みに合わせて設定する事・ Wake_up0: Waitms 20 Eifr.intf0 = 1 Wari_flag = 1 Return '----PCINT0 SUB Rain_SW ON-------- Wake_up1: Wari_flag = 2 Return '---温度測定--AD変換は6回平均----data_NO=3------------------- Temp_adcon: Ep_data = 0 For Fo_cnt = 1 To 6 D_wd = Getadc(5) Ep_data = Ep_data + D_wd Next Fo_cnt D_wd = Ep_data / 6 Ep_temp = D_wd Return '---箱内温度測定- data_NO=9-------------------------- Intemp_adcon: Ep_data = 0 For Fo_cnt = 1 To 6 D_wd = Getadc(2) Ep_data = Ep_data + D_wd Next Fo_cnt D_wd = Ep_data / 6 Ep_intemp = D_wd Return '---日照測定--6回平均-dataNO=6---------------------- Sun_adcon: Ep_data = 0 For Fo_cnt = 1 To 6 D_wd = Getadc(4) Ep_data = Ep_data + D_wd Next Fo_cnt D_wd = Ep_data / 6 Ep_sun = D_wd Return '---電池電圧測定----data-_NO=2----------------------- Battry: Ep_data = 0 For Fo_cnt = 1 To 6 D_wd = Getadc(3) Ep_data = Ep_data + D_wd Next Fo_cnt D_wd = Ep_data / 6 Ep_battry = D_wd Return '---湿度測定--------data_NO=4----------------- Humi_adcon: Return