proyecto graduacion espol-fiec: anexo - codigo en mikrobasic

25
Diseño e implementación de un sistema Inalámbrico de Alarma Domiciliaria con alerta vía celular Contenido Código fuente en lenguaje Basic de los microcontroladores PIC16F628 y PIC18F4550 comprendidos en los bloques Alarma y Controlador respectivamente Autores Jorge Galarza Rosas Titulo Ing. Telemático Ricardo Cajo DíazTitulo Ing. Electrónica y Telecomunicaciones Índice Consola GSM…………………………………………………………………….……………………..2 Alarma Puerta…………………………………………………………………………………………19 Alarma Movimiento………………………………………………………………………………..22 ESCUELA SUPERIOR POLITÉCNICA DEL LITORAL FACULTAD DE INGENIERÍA EN ELECTRICIDAD Y COMPUTACIÓN Proyecto de Graduación

Upload: jorsh-g-lo

Post on 07-Apr-2015

418 views

Category:

Documents


4 download

DESCRIPTION

Codigo fuente de los principales bloques del sistema. Alarma y Controlador. Microcontroladores a usar: PIC16F628 y PIC18F4550

TRANSCRIPT

Page 1: Proyecto Graduacion ESPOL-FIEC: Anexo - Codigo en MikroBasic

Diseño e implementación de un sistema Inalámbrico de Alarma

Domiciliaria con alerta vía celular Contenido

Código fuente en lenguaje Basic de los microcontroladores PIC16F628 y

PIC18F4550 comprendidos en los bloques Alarma y Controlador

respectivamente

Autores

Jorge Galarza Rosas – Titulo Ing. Telemático Ricardo Cajo Díaz– Titulo Ing. Electrónica y Telecomunicaciones

Índice

Consola GSM…………………………………………………………………….……………………..2 Alarma Puerta…………………………………………………………………………………………19 Alarma Movimiento………………………………………………………………………………..22

ESCUELA SUPERIOR POLITÉCNICA DEL LITORAL FACULTAD DE INGENIERÍA EN ELECTRICIDAD Y COMPUTACIÓN

Proyecto de Graduación

Page 2: Proyecto Graduacion ESPOL-FIEC: Anexo - Codigo en MikroBasic

Autores: Ricardo Cajo - Jorge GalarzaCodigo Consola GSM

1: program ConsolaGSM2: '***************************DECLARACION DE VARIABLES****************************3: Dim kp,received_byte,viajero,alert_alarma,cod_alarma, Estado_Alarma,acknoledge,

num_telf as byte4: Dim checksun_recibido,checksun_calculado as byte5: dim claveInicial,ClaveIngresada,Codigos_Alarmas,Codigos as byte[6] ' clave de 5

digitos6: dim bte_old_pass,bte_new_pass,bte_rep_pass , dato as byte[6]7: dim bandera_oldPass,bandera_newPass,bandera_repPass as byte8: dim i,ind_clave,opcion,bandera,veces as byte9: dim txt_numero as char[16]10: dim txt_numero_p as char[16]11: dim txt_clave as char[7]12: dim txt_codigo as char[4]13: dim str_cadena as char[4]14: dim str_numero_convertido as char[3]15: dim bte_numero_add as byte[10]16: 17: '*****************************CONSTANTES****************************************18: const esc = $23 'ESC/CANCEL esta Tecla sirve para salir o para CANCELAR OJO19: const enter = $7020: const INICIO = $2421: const ID = $4922: const FIN = $4623: '*********************************ESTRUCTURAS***********************************

*24: structure Telf_Usuarios25: dim Telf as string[10][9]26: end structure27: 28: dim Telefonos as Telf_Usuarios29: 30: '*******************************INTERRUPCION************************************31: sub procedure interrupt()32: 33: ' Usart_Data_Ready es lo mismo que haber puesto PIR1.RCIF34: if Usart_Data_Ready = 1 then35: received_byte = Usart_Read36: select case viajero37: 38: case 039: if (received_byte=INICIO) then '$'40: porta.0=041: viajero=142: else43: viajero=044: end if45: 46: case 147: if (received_byte=ID) then 'I' ID48: viajero=249: else50: viajero=051: end if52: 53: case 254: dato[0]=(received_byte) 'Codigo Alarma55: viajero=356: case 357: dato[1]= received_byte 'Estado Alarma

mikroBasic compiler for PIC by mikroElektronika2/25

Page 3: Proyecto Graduacion ESPOL-FIEC: Anexo - Codigo en MikroBasic

Autores: Ricardo Cajo - Jorge GalarzaCodigo Consola GSM

58: viajero=459: case 460: dato[2]= received_byte 'Alerta Alarma61: viajero=562: case 563: dato[3]= received_byte 'acknoledge64: viajero=665: case 666: dato[4]= received_byte 'checksun_recibido67: checksun_recibido =dato[4]68: viajero=769: case 770: dato[5]=received_byte71: if(dato[5]= FIN)then 'F' STOP72: checksun_calculado = dato[0]+dato[1]+dato[2]+dato[3]73: if(checksun_calculado = checksun_recibido )then74: cod_alarma=dato[0]75: Estado_Alarma=dato[1]76: alert_alarma =dato[2]77: acknoledge=dato[3]78: viajero=079: else80: viajero=081: end if82: else83: viajero=084: end if85: end select86: 87: end if88: PIR1.RCIF=0 ' Si el dato a llegado limpio la bandera de recepcion89: PIE1.RCIE=1 ' Habilitar nuevamente la interrupcion por USART90: end sub91: 92: '****************************ENVIAR MENSAJES GSM********************************93: sub procedure enviar_sms(dim byref Telefonos as Telf_Usuarios,dim i as byte,dim

byref texto as string[40])94: dim j as byte95: dim k as Byte96: 97: for j = 0 to i-198: 99: Usart_Write_Text("AT+CMGF=1")100: Usart_Write(10)101: Usart_Write(13)102: delay_ms(1000)'500103: Usart_Write_Text("AT+CMGS=")104: Usart_Write(34)' "105: Usart_Write_Text(Telefonos.Telf[j])106: Usart_Write(34)' "107: Usart_Write(10)108: Usart_Write(13)109: delay_ms(1000)110: 111: for k = 0 to Strlen(texto)-1112: Usart_Write(texto[k])113: next k114: 115: Usart_Write(26)116: Usart_Write(10)

mikroBasic compiler for PIC by mikroElektronika3/25

Page 4: Proyecto Graduacion ESPOL-FIEC: Anexo - Codigo en MikroBasic

Autores: Ricardo Cajo - Jorge GalarzaCodigo Consola GSM

117: Usart_Write(13)118: delay_ms(8000)'8000119: next j120: texto=""121: 122: end sub123: '************************FUNCION LEER TECLADO**********************************124: sub procedure leer_teclado()125: kp = 0126: portb.0=0127: portb.1=1128: portb.2=1129: portb.3=1130: '' portb=%11111110131: if(portb.4=0)then132: while(portb.4=0) wend133: kp=$31 end if'1134: if(portb.5=0)then135: while(portb.5=0) wend136: kp=$32 end if'2137: if(portb.6=0)then138: while(portb.6=0) wend139: kp=$33 end if'3140: if (portb.7=0)then141: while(portb.7=0) wend142: kp=$41 end if'A143: if(kp=0)then144: portb.0=1145: portb.1=0146: portb.2=1147: portb.3=1148: ''portb=%11111101149: if(portb.4=0)then150: while(portb.4=0) wend151: kp=$34 end if'4152: if(portb.5=0)then153: while(portb.5=0) wend154: kp=$35 end if'5155: if(portb.6=0)then156: while(portb.6=0) wend157: kp=$36 end if'6158: if (portb.7=0)then159: while(portb.7=0) wend160: kp=$42 end if'B161: else return162: end if163: if(kp=0) then164: portb.0=1165: portb.1=1166: portb.2=0167: portb.3=1168: 169: ''=%111101011170: if(portb.4=0)then171: while(portb.4=0) wend172: kp=$37 end if'7173: if(portb.5=0)then174: while(portb.5=0) wend175: kp=$38 end if'8176: if(portb.6=0)then

mikroBasic compiler for PIC by mikroElektronika4/25

Page 5: Proyecto Graduacion ESPOL-FIEC: Anexo - Codigo en MikroBasic

Autores: Ricardo Cajo - Jorge GalarzaCodigo Consola GSM

177: while(portb.6=0) wend178: kp=$39 end if'9179: if (portb.7=0)then180: while(portb.7=0) wend181: kp=$43 end if'C182: else return183: end if184: if(kp=0)then185: portb.0=1186: portb.1=1187: portb.2=1188: portb.3=0189: ''portb=%11110111190: if(portb.4=0)then191: while(portb.4=0) wend192: kp=$23 end if'esc193: if(portb.5=0)then194: while(portb.5=0) wend195: kp=$30 end if'0196: if(portb.6=0)then197: while(portb.6=0) wend198: kp=$70 end if'enter <-199: if (portb.7=0)then200: while(portb.7=0) wend201: kp=$44 end if'D202: else return203: end if204: 205: end sub206: '***************************MOSTRAR MENSAJE LCD*********************************207: sub procedure ShowMessage(dim fil,col as byte,dim delayms as word,dim byref msg

as string[16])208: Lcd_Cmd(LCD_CLEAR)209: Lcd_Out(fil, col,msg)210: VDelay_ms(delayms)211: end sub212: '**********************GUARDAR PASSWORD*****************************************213: sub procedure SavePassword(dim byref clave as byte[6] )214: for i=0 to 4215: EEprom_write(i,clave[i])216: delay_ms(25)217: next i218: end sub219: '********************OBTENER NUMERO TELEFONICO DESDE EEPROM*********************220: sub procedure GetFono(dim byref strText as char[16], dim pos as byte)221: dim numeroObtenido,j as byte222: dim txt_save as char[9][3]223: dim valor_inicio,valor_fin as byte224: 225: for j=0 to 8226: txt_save[j][2] = " "227: next j228: numeroObtenido=0229: 230: valor_inicio = 176 + (pos -1)*8231: valor_fin = valor_inicio +7232: for j=valor_inicio to valor_fin233: numeroObtenido = EEprom_read(j)234: if numeroObtenido = 255 then return end if235: ByteToStr(numeroObtenido,txt_save[j-valor_inicio+1])

mikroBasic compiler for PIC by mikroElektronika5/25

Page 6: Proyecto Graduacion ESPOL-FIEC: Anexo - Codigo en MikroBasic

Autores: Ricardo Cajo - Jorge GalarzaCodigo Consola GSM

236: next j237: 238: for j = 1 to 8239: strText[j]=txt_save[j][2]240: next j241: strText[0]="0"242: end sub243: '********************OBTENER CODIGO DE ALARMA DESDE EEPROM*********************244: sub procedure GetCode(dim byref Codigo as byte[6], dim pos as byte)245: dim numeroObtenido,j as byte246: dim valor_inicio,valor_fin as byte247: numeroObtenido=0248: 249: valor_inicio = 64 + (pos -1)*8250: valor_fin = valor_inicio +1251: for j=valor_inicio to valor_fin252: numeroObtenido = EEprom_read(j)253: delay_ms(30)254: Codigo[j-valor_inicio]=numeroObtenido255: next j256: 257: end sub258: '*************************SETEAR ARREGLO****************************************259: sub procedure SetStr(dim byref strText as char[16], dim caracter as string,dim

tamano as byte)260: dim j as byte261: for j=0 to tamano-1262: strText[j] = caracter263: next j264: end sub265: '**********************GUARDAR NUMERO DE TELEFONO EN EEPROM*********************266: sub function SaveEprom_Number(dim byref number as byte[9]) as boolean267: dim estado as boolean268: dim cont as byte269: dim num as byte270: dim j as word271: estado=1 cont =1 j=176272: while j<=255273: Delay_ms(30)274: num=EEprom_read(j)275: Delay_ms(30)276: if num<>$FF then277: j= j+7278: else279: EEprom_write(j,number[cont])280: Inc(cont)281: end if282: if (cont = 9) then283: result = estado284: return285: end if286: inc(j)287: wend288: result=0289: end sub290: '**********************GUARDAR CODIGO DE ALARMA EN EEPROM *********************291: sub function SaveEprom_Code(dim byref code as byte[9]) as boolean292: dim estado as boolean293: dim cont as byte294: dim num as byte

mikroBasic compiler for PIC by mikroElektronika6/25

Page 7: Proyecto Graduacion ESPOL-FIEC: Anexo - Codigo en MikroBasic

Autores: Ricardo Cajo - Jorge GalarzaCodigo Consola GSM

295: dim j as word296: estado=1 cont =0 j=64297: while j<=143298: Delay_ms(30)299: num=EEprom_read(j)300: Delay_ms(30)301: if num<>$FF then302: j= j+7303: else304: EEprom_write(j,code[cont])305: Inc(cont)306: end if307: if (cont = 2) then308: result = estado309: return310: end if311: inc(j)312: wend313: result=0314: end sub315: '**********************BORRAR NUMERO DE TELEFONO DESDE EEPROM*******************316: sub procedure DeleteEprom_Number(dim addres as byte , dim pos as byte)317: dim valor_inicio,valor_fin as byte318: valor_inicio = addres + (pos -1)*8319: valor_fin = valor_inicio +7320: for i=valor_inicio to valor_fin321: EEprom_write(i,$FF)322: delay_ms(30)323: next i324: end sub325: '*********************************INDICADOR*************************************326: sub procedure led()327: PORTA.0=1328: delay_ms(200)329: PORTA.0=0330: delay_ms(200)331: PORTA.0=1332: delay_ms(200)333: PORTA.0=0334: delay_ms(200)335: PORTA.0=1336: end sub337: '*****************************DESPLAZAR MENU************************************338: sub procedure DesplazarMenu()339: if(porta.1=1)then340: while(porta.1=1) wend341: if(opcion=7) then342: opcion=1343: else344: inc(opcion)345: end if346: end if347: if(porta.2=1)then348: while(porta.2=1) wend349: if(opcion=1)then350: opcion=7351: else352: dec(opcion)353: end if354: end if

mikroBasic compiler for PIC by mikroElektronika7/25

Page 8: Proyecto Graduacion ESPOL-FIEC: Anexo - Codigo en MikroBasic

Autores: Ricardo Cajo - Jorge GalarzaCodigo Consola GSM

355: end sub356: '****************************DESPLAZAR NUMEROS**********************************357: sub procedure DesplazarNumeros()358: if(porta.1=1)then359: while(porta.1=1) wend360: veces=0361: if(opcion=10) then362: opcion=1363: else364: inc(opcion)365: end if366: end if367: if(porta.2=1)then368: while(porta.2=1) wend369: veces=0370: if(opcion=1)then371: opcion=10372: else373: dec(opcion)374: end if375: end if376: end sub377: '********************************VALIDAR CLAVE**********************************378: sub function validar_clave(dim byref clave,clv as byte[6],dim digitos as byte)

as boolean379: dim estado as boolean380: if digitos=5 then381: estado=1382: for i=0 to 4383: estado = ((clave[i]) = (clv[i]))and estado384: next i385: result=estado386: else387: result=0388: end if389: end sub390: '****************ENVIA TRAMA DE ACTIVACION O DESACTIVACION DE ALARMAS***********391: sub procedure Enviar_Trama_Alarma(dim code as byte,dim estado as byte,dim

respuesta as byte)392: checksun_calculado =code + estado + respuesta393: USART_Write (INICIO)394: USART_Write (ID)395: USART_Write (code)396: USART_Write (estado)397: USART_Write (respuesta)398: USART_Write (checksun_calculado)399: Usart_Write (FIN)400: end sub401: 402: '***************************VERIFICAR ALERTA DE ALARMA**************************403: sub procedure Verificar_Alerta_Alarma()404: if(alert_alarma =1)then405: Enviar_Trama_Alarma (cod_alarma,1,1) 'Envio respuesta de Acknoledge406: led()407: num_telf =0408: SetStr (txt_numero_p ," ",9)409: for i=1 to 10410: GetFono(txt_numero_p,i)411: if(txt_numero_p[1]<>" ")then412: strcpy(Telefonos.Telf[num_telf],txt_numero_p )

mikroBasic compiler for PIC by mikroElektronika8/25

Page 9: Proyecto Graduacion ESPOL-FIEC: Anexo - Codigo en MikroBasic

Autores: Ricardo Cajo - Jorge GalarzaCodigo Consola GSM

413: inc(num_telf)414: end if415: SetStr (txt_numero_p ," ",9)416: next i417: if(num_telf>0) then418: enviar_sms (Telefonos ,num_telf ,"Alerta Alarma" )419: end if420: alert_alarma=0421: end if422: end sub423: '****************ENVIA TRAMA DE ACTIVACION O DESACTIVACION DE ALARMAS***********424: sub procedure Activar_Desactivar_Alarmas(dim estado as byte)425: dim indicador ,cont as byte426: indicador=0427: acknoledge=0428: cont=0429: led()430: num_telf =0431: for i=1 to 10432: GetCode(Codigos_Alarmas ,i)433: if(Codigos_Alarmas [0]<>$FF)then434: Codigos[num_telf]=(Codigos_Alarmas[0]*10) + Codigos_Alarmas[1]435: inc(num_telf)436: end if437: next i438: if(num_telf>0) then439: while(num_telf>0)440: if(indicador=0)then441: dec(num_telf)442: Enviar_Trama_Alarma(Codigos[num_telf],estado,acknoledge)443: end if444: Delay_ms(1000)445: if(acknoledge =1)then446: indicador=0447: acknoledge =0448: cont=0449: else450: inc(cont)451: if(cont<5)then452: num_telf =num_telf +1453: else cont=0454: end if455: indicador=0456: end if457: wend458: 459: end if460: 461: end sub462: '***************************PROGRAMA PRINCIPAL**********************************463: main:464: 465: ''RCON.7=0466: INTCON = %11000000 'habilito int globales y periferifericos int467: ADCON0=0468: ADCON1 =$0F 'digital input469: 470: INTCON2=$00471: PIE1=%00100000472: PIR1=0

mikroBasic compiler for PIC by mikroElektronika 9/25

Page 10: Proyecto Graduacion ESPOL-FIEC: Anexo - Codigo en MikroBasic

Autores: Ricardo Cajo - Jorge GalarzaCodigo Consola GSM

473: IPR1=%00100000474: CMCON= $07475: '' T1CON =$31 'preescalador (8)476: ''TMR1H = $3C ' 10ms477: ''TMR1L = $AF '(Prescaler=8)*(2^16 -$0BDB)*(4/Fosc) = 500ms478: 479: TRISA = $0E ' PORTB is output480: TRISC = $80 ' PORTB is output481: TRISB = $F0482: TRISD = $00483: TRISE= $00484: PORTC=0485: PORTE=0486: PORTD=0487: alert_alarma =0488: cod_alarma=0489: viajero=0490: acknoledge=0491: veces=0492: i=0493: ind_clave=0494: Usart_Init(9600)495: 496: Usart_Write_Text("Inicio Alarma GSM")497: Lcd_Config(PORTD,3,2,1,0,PORTE,0,1,2)498: Lcd_Cmd(Lcd_CURSOR_OFF)499: led()500: '**************************** CLAVE DEFAULT ***********************************501: claveInicial[0]= 1502: claveInicial[1]= 2503: claveInicial[2]= 3504: claveInicial[3]= 4505: claveInicial[4]= 5506: 507: if (portA.3 = 1) then508: for i=0 to 4509: EEprom_write(i,claveInicial[i])510: delay_ms(30)511: next i512: '' SavePassword (claveInicial)513: led()514: end if515: '***************************** INICIO ******************************************516: INICIO:517: LCD_Cmd(LCD_CLEAR)518: txt_clave =""519: Delay_ms(500)520: Lcd_Out(1, 1," ALARMA GSM ")521: Lcd_Out(2, 1,"PASSWORD:")522: ind_clave=0523: SetStr (txt_clave ," ",7)524: while true525: leer_teclado()526: if kp = esc then527: ind_clave=0528: goto INICIO '**529: end if530: if kp =enter then 'Tecla ENTER531: led()532: Lcd_Cmd(LCD_CLEAR)

mikroBasic compiler for PIC by mikroElektronika10/25

Page 11: Proyecto Graduacion ESPOL-FIEC: Anexo - Codigo en MikroBasic

Autores: Ricardo Cajo - Jorge GalarzaCodigo Consola GSM

533: for i=0 to 4534: claveInicial[i]=EEprom_read(i)535: Delay_ms(30)536: next i537: 538: if validar_clave(claveInicial,ClaveIngresada,ind_clave)=1 then539: led()540: opcion=1541: ind_clave=0542: goto MENU543: else544: Lcd_Out(2, 7,"ERROR")545: delay_ms(500)546: Lcd_Cmd(LCD_CLEAR)547: ind_clave=0548: goto INICIO549: end if550: end if551: if (kp = $43) and (ind_clave>0) then 'Tecla DELETE552: dec(ind_clave)553: txt_clave [ind_clave]=" "554: Lcd_Out(2,10,txt_clave )555: end if556: 557: 558: if (kp >=$30) and (kp <= $39)and (ind_clave<5) then559: txt_clave [ind_clave]= "*"560: ClaveIngresada[ind_clave]=kp-48561: Delay_ms(20)562: Lcd_Out(2,10,txt_clave )563: inc(ind_clave) 'contador de digitos ingresados564: Delay_ms(20)565: end if566: 'Verificar_Alerta_Alarma()567: wend568: '********************************** MENU ***************************************569: MENU:570: LCD_Cmd(LCD_CLEAR)571: Lcd_Out(1, 1," BIENVENIDOS ")572: Delay_ms(500)573: opcion=1574: ind_clave=0575: while True576: leer_teclado()577: DesplazarMenu()578: if kp = esc then579: ind_clave=0580: goto INICIO '**581: end if582: Lcd_Out(1, 1," ALARMA GSM ")583: select case opcion584: case 1585: Lcd_Out(2, 1,"1 TURN ON ALARM ")586: if(kp=enter) then goto TurnOnAlarm end if587: case 2588: Lcd_Out(2, 1,"2 TURN OFF ALARM")589: if(kp=enter) then goto TurnOffAlarm end if590: case 3591: Lcd_Out(2, 1,"3 ADD ALARM ")592: if(kp=enter) then goto AddAlarm end if

mikroBasic compiler for PIC by mikroElektronika11/25

Page 12: Proyecto Graduacion ESPOL-FIEC: Anexo - Codigo en MikroBasic

Autores: Ricardo Cajo - Jorge GalarzaCodigo Consola GSM

593: case 4594: Lcd_Out(2, 1,"4 DELETE ALARM ")595: if(kp=enter) then goto DeleteAlarm end if596: case 5597: Lcd_Out(2, 1,"5 ENTER NUMBER ")598: if(kp=enter) then goto EnterNumber end if599: case 6600: Lcd_Out(2, 1,"6 DELETE NUMBER ")601: if(kp=enter) then goto DeleteNumber end if602: case 7603: Lcd_Out(2, 1,"7 CHANGE PASSWOR")604: ' if(kp=enter) then goto ChangePassword end if605: end select606: Verificar_Alerta_Alarma()607: wend608: '************************** OPCION 1 TURN ON ALARM******************************609: TurnOnAlarm:610: LCD_Cmd(LCD_CLEAR)611: Lcd_Out(1, 1,"1 TURN ON ALARM ")612: Lcd_Out(2, 1," PRESS ENTER ")613: while True614: leer_teclado()615: 616: if kp = esc then617: ind_clave=0618: goto MENU '**619: end if620: 621: if(kp=enter) then622: ShowMessage(2,1,0,"WAIT PLEASE.....")623: Activar_Desactivar_Alarmas(1)624: ShowMessage(2,1,1000,"WAIT PLEASE.....")625: goto MENU626: end if627: 628: wend629: '''************************** OPCION 2 TURN OFF

ALARM*****************************630: TurnOffAlarm:631: LCD_Cmd(LCD_CLEAR)632: Lcd_Out(1, 1,"1 TURN OFF ALARM")633: Lcd_Out(2, 1," PRESS ENTER ")634: while True635: leer_teclado()636: 637: if kp = esc then638: ind_clave=0639: goto MENU '**640: end if641: if(kp=enter) then642: ShowMessage(2,1,0,"WAIT PLEASE.....")643: Activar_Desactivar_Alarmas(0)644: ShowMessage(2,1,1000,"WAIT PLEASE.....")645: goto MENU646: end if647: 648: wend''************************** OPCION 3 ADD

ALARM**********************************649: AddAlarm:650: ind_clave=0

mikroBasic compiler for PIC by mikroElektronika12/25

Page 13: Proyecto Graduacion ESPOL-FIEC: Anexo - Codigo en MikroBasic

Autores: Ricardo Cajo - Jorge GalarzaCodigo Consola GSM

651: bandera=0652: LCD_Cmd(LCD_CLEAR)653: Lcd_Out(1,1," ENTER CODE: ")654: SetStr(txt_numero," ",16)655: while True656: leer_teclado()657: 658: if (kp >=$30) and (kp <= $39) and (ind_clave<2)then659: bte_numero_add[ind_clave] = kp - 48660: txt_numero[ind_clave]= kp661: Lcd_Out(2,1,txt_numero)662: inc(ind_clave) 'contador de digitos ingresados663: end if664: 665: if (kp = esc) and (bandera=0) then666: goto MENU '**667: end if668: 669: if (kp = $43) and (ind_clave>0) and (bandera=0) then 'Tecla DELETE670: dec(ind_clave)671: txt_numero[ind_clave]=" "672: Lcd_Out(2,1,txt_numero)673: end if674: 675: if (kp = esc) and (bandera=1) then 'Estan en YES/CANCEL presiono cancel

vuelve a mostrar el numero676: ShowMessage(1,1,0," ENTER CODE: ")677: Lcd_Out(2,1,txt_numero)678: bandera=0679: end if680: 681: if (kp=enter) and (ind_clave<2) then682: ShowMessage(1,1,500,"CODE INCOMPLETO")683: ShowMessage(1,1,0," ENTER CODE: ")684: Lcd_Out(2,1,txt_numero)685: end if686: 687: if (kp=enter) and (ind_clave=2) then688: LCD_Cmd(LCD_CLEAR)689: Lcd_Out(1,1,"Add #:")690: Lcd_Out(1,7,txt_numero)691: Lcd_Out(1,9,"?")692: Lcd_Out(2,1," YES/CANCEL")693: bandera=1694: end if695: 696: if (kp=$44) and (bandera=1) then'Tecla YES697: ShowMessage(2,1,0," SAVING...")698: if SaveEprom_Code (bte_numero_add )=1 then699: ShowMessage(2,1,500," SAVED OK")700: else701: Lcd_Out(1,1," SAVE ERROR ") Lcd_Out(2,1," MEMORY FULL ")702: Delay_ms(500) LCD_Cmd(LCD_CLEAR) Delay_ms(200)703: Lcd_Out(1,1," SAVE ERROR ") Lcd_Out(2,1," MEMORY FULL ")704: Delay_ms(500) LCD_Cmd(LCD_CLEAR) Delay_ms(200)705: Lcd_Out(1,1," SAVE ERROR ") Lcd_Out(2,1," MEMORY FULL ")706: Delay_ms(500)707: end if708: goto MENU709: end if

mikroBasic compiler for PIC by mikroElektronika13/25

Page 14: Proyecto Graduacion ESPOL-FIEC: Anexo - Codigo en MikroBasic

Autores: Ricardo Cajo - Jorge GalarzaCodigo Consola GSM

710: wend711: ''************************** OPCION 4 DELETE

ALARM*******************************712: DeleteAlarm:713: LCD_Cmd(LCD_CLEAR)714: Lcd_Out(1, 1,"4 DELETE ALARM ")715: opcion=1716: bandera=0717: veces=0718: while true719: leer_teclado()720: DesplazarNumeros()721: if (kp = esc) and (bandera=0) then722: ind_clave=0723: goto MENU '**724: end if725: if (bandera=0) and (veces=0) then726: SetStr(txt_codigo," ",4)727: SetStr(str_cadena ," ",4)728: ByteToStr(opcion,str_numero_convertido)729: if opcion = 10 then str_cadena[0] = "1" else str_cadena[0] = "0" end if730: str_cadena[1] = str_numero_convertido[2]731: str_cadena[2] = "."732: str_cadena[3] = "-"733: Lcd_Out(2, 1,str_cadena)734: GetCode(Codigos_Alarmas,opcion)735: if(Codigos_Alarmas [0]<>$FF)then736: Codigos[0] =(Codigos_Alarmas[0]*10)+Codigos_Alarmas[1]737: ByteToStr(Codigos[0] ,txt_codigo)738: end if739: end if740: 741: if (txt_codigo[2]=" ") and (veces=0) then742: Lcd_Out(2, 5," ")743: Lcd_Out(2, 6,"(VACIO) ")744: veces=1745: end if746: 747: if (txt_codigo [2]<>" ") and (bandera=0)and (veces=0) then748: Lcd_Out(2, 5," ")749: Lcd_Out(2, 6,"Code:" )750: Lcd_Out(2, 11,txt_codigo )751: Lcd_Out(2, 14," " )752: veces=1753: end if754: 755: if (kp = $43) and (txt_codigo [2]<>" ") then 'Tecla DELETE756: LCD_Cmd(LCD_CLEAR)757: Lcd_Out(1,1,"DEL ALARM #:")758: Lcd_Out(1,13,txt_codigo )759: Lcd_Out(1,16,"?")760: Lcd_Out(2,1," YES/CANCEL")761: bandera=1762: end if763: 764: if (kp=$44) and (bandera=1) then'Tecla YES765: DeleteEprom_Number(64,opcion)766: LCD_Cmd(LCD_CLEAR)767: Lcd_Out(2,1," DELETING...")768: LCD_Cmd(LCD_CLEAR)

mikroBasic compiler for PIC by mikroElektronika14/25

Page 15: Proyecto Graduacion ESPOL-FIEC: Anexo - Codigo en MikroBasic

Autores: Ricardo Cajo - Jorge GalarzaCodigo Consola GSM

769: Lcd_Out(2,1," DELETE OK...")770: Delay_ms(500)771: goto MENU772: end if773: 774: if (kp = esc) and (bandera=1) then775: goto DeleteAlarm '**776: end if777: 778: wend'************************** OPCION 5 ENTER NUMBER

******************************779: EnterNumber:780: ind_clave=0781: bandera=0782: txt_numero=""783: LCD_Cmd(LCD_CLEAR)784: Lcd_Out(1,1," ENTER NUMBER: ")785: SetStr(txt_numero," ",16)786: 787: while True788: leer_teclado() 'Lee del Teclado y se guarda en kp789: 790: if (kp >=$30) and (kp <= $39) and (ind_clave<9)then791: bte_numero_add[ind_clave] = kp - 48792: txt_numero[ind_clave]= kp793: Lcd_Out(2,1,txt_numero)794: inc(ind_clave) 'contador de digitos ingresados795: end if796: 797: if (kp = esc) and (bandera=0) then798: goto MENU '**799: end if800: 801: if (kp = $43) and (ind_clave>0) and (bandera=0) then 'Tecla DELETE802: dec(ind_clave)803: txt_numero[ind_clave]=" "804: Lcd_Out(2,1,txt_numero)805: end if806: 807: if (kp = esc) and (bandera=1) then 'Estan en YES/CANCEL presiono cancel

vuelve a mostrar el numero808: ShowMessage(1,1,0," ENTER NUMBER: ")809: Lcd_Out(2,1,txt_numero)810: bandera=0811: end if812: 813: if (kp=enter) and (ind_clave<9) then814: ShowMessage(1,1,500,"NUMERO INCOMPLETO")815: ShowMessage(1,1,0," ENTER NUMBER: ")816: Lcd_Out(2,1,txt_numero)817: end if818: 819: if (kp=enter) and (ind_clave=9) then820: LCD_Cmd(LCD_CLEAR)821: Lcd_Out(1,1,"Add #:")822: Lcd_Out(1,7,txt_numero)823: Lcd_Out(1,16,"?")824: Lcd_Out(2,1," YES/CANCEL")825: bandera=1826: end if

mikroBasic compiler for PIC by mikroElektronika15/25

Page 16: Proyecto Graduacion ESPOL-FIEC: Anexo - Codigo en MikroBasic

Autores: Ricardo Cajo - Jorge GalarzaCodigo Consola GSM

827: 828: if (kp=$44) and (bandera=1) then'Tecla YES829: ShowMessage(2,1,0," SAVING...")830: if SaveEprom_Number(bte_numero_add)=1 then831: ShowMessage(2,1,500," SAVED OK")832: else833: Lcd_Out(1,1," SAVE ERROR ") Lcd_Out(2,1," MEMORY FULL ")834: Delay_ms(500) LCD_Cmd(LCD_CLEAR) Delay_ms(200)835: Lcd_Out(1,1," SAVE ERROR ") Lcd_Out(2,1," MEMORY FULL ")836: Delay_ms(500) LCD_Cmd(LCD_CLEAR) Delay_ms(200)837: Lcd_Out(1,1," SAVE ERROR ") Lcd_Out(2,1," MEMORY FULL ")838: Delay_ms(500)839: end if840: goto MENU841: end if842: wend843: '************************** OPCION 6 DELETE NUMBER *****************************844: DeleteNumber:845: LCD_Cmd(LCD_CLEAR)846: Lcd_Out(1, 1," DELETE NUMBER ")847: SetStr(txt_numero_p," ",16)848: opcion=1849: bandera=0850: veces=0851: while true852: leer_teclado()853: DesplazarNumeros()854: 855: if (kp = esc) and (bandera=0) then856: ind_clave=0857: goto MENU '**858: end if859: 860: if (bandera=0) and (veces=0) then861: SetStr(txt_numero_p," ",16)862: SetStr(str_cadena ," ",4)863: ByteToStr(opcion,str_numero_convertido)864: if opcion = 10 then str_cadena[0] = "1" else str_cadena[0] = "0" end if865: str_cadena[1] = str_numero_convertido[2]866: str_cadena[2] = "."867: str_cadena[3] = "-"868: Lcd_Out(2, 1,str_cadena)869: GetFono(txt_numero_p,opcion)870: 871: end if872: 873: if (txt_numero_p[1]=" ") AND (veces=0) then874: Lcd_Out(2, 5," ")875: Lcd_Out(2, 6,"(VACIO) ")876: Delay_ms(1)877: veces=1878: end if879: 880: if (txt_numero_p[1]<>" ") and (bandera=0) AND (veces=0) then881: Lcd_Out(2, 5," ")882: Lcd_Out(2, 6,txt_numero_p)883: Lcd_Out(2, 15," ")884: Delay_ms(1)885: veces=1886: end if

mikroBasic compiler for PIC by mikroElektronika16/25

Page 17: Proyecto Graduacion ESPOL-FIEC: Anexo - Codigo en MikroBasic

Autores: Ricardo Cajo - Jorge GalarzaCodigo Consola GSM

887: 888: if (kp = $43) and (txt_numero_p[1]<>" ") then 'Tecla DELETE889: LCD_Cmd(LCD_CLEAR)890: Lcd_Out(1,1,"DEL #:")891: Lcd_Out(1,7,txt_numero_p)892: Lcd_Out(1,16,"?")893: Lcd_Out(2,1," YES/CANCEL")894: bandera=1895: end if896: 897: if (kp=$44) and (bandera=1) then'Tecla YES898: DeleteEprom_Number(176,opcion)899: LCD_Cmd(LCD_CLEAR)900: Lcd_Out(2,1," DELETING...")901: LCD_Cmd(LCD_CLEAR)902: Lcd_Out(2,1," DELETE OK...")903: Delay_ms(500)904: goto MENU905: end if906: 907: if (kp = esc) and (bandera=1) then908: goto DeleteNumber '**909: end if910: 911: wend912: ************************** OPCION 7 CHANGE PASSWORD ***************************913: ChangePassword:914: ind_clave=0 bandera_oldPass =1 bandera_newPass =0 bandera_repPass =0915: LCD_Cmd(LCD_CLEAR)916: Lcd_Out(1,1,"OLD PASS:")917: SetStr(txt_numero," ",16)918: Lcd_Out(2,1,txt_numero)919: while True920: leer_teclado() 'Lee del Teclado y se guarda en kp921: if (kp >=$30) and (kp <= $39) and (ind_clave<5) then922: txt_numero[ind_clave]= "*"923: if bandera_oldPass =1 then924: bte_old_pass[ind_clave] = kp - 48925: Lcd_Out(2,1,txt_numero) end if926: if bandera_newPass =1 then927: bte_new_pass[ind_clave] = kp - 48928: Lcd_Out(1,11,txt_numero) end if929: if bandera_repPass =1 then930: bte_rep_pass[ind_clave] = kp - 48931: Lcd_Out(2,11,txt_numero) end if932: inc(ind_clave) 'contador de digitos ingresados933: end if934: 935: if kp = esc then goto MENU end if 'Presiona ESC936: 937: if (kp = $43) and (ind_clave>0) then 'Tecla DELETE938: dec(ind_clave)939: txt_numero[ind_clave]=" "940: if bandera_oldPass =1 then Lcd_Out(2,1,txt_numero) end if941: if bandera_newPass =1 then Lcd_Out(1,11,txt_numero) end if942: if bandera_repPass =1 then Lcd_Out(2,11,txt_numero) end if943: end if944: 945: if (kp=enter) and (bandera_oldPass =1) then946: Lcd_Cmd(LCD_CLEAR)

mikroBasic compiler for PIC by mikroElektronika17/25

Page 18: Proyecto Graduacion ESPOL-FIEC: Anexo - Codigo en MikroBasic

Autores: Ricardo Cajo - Jorge GalarzaCodigo Consola GSM

947: for i=0 to 4948: claveInicial[i]=EEprom_read(i)949: next i950: 951: if validar_clave(claveInicial,bte_old_pass,ind_clave)=1 then952: led()953: Lcd_Out(1, 1,"NEW PASS:")954: ind_clave=0 bandera_oldPass =0 bandera_newPass =1

bandera_repPass =0955: SetStr(txt_numero," ",16)956: else957: ShowMessage(2,7,500,"ERROR")958: ind_clave=0959: goto ChangePassword960: end if961: end if962: if (kp=enter) and (bandera_newPass =1) and (ind_clave=5) then963: Lcd_Out(2, 1,"REP PASS:")964: ind_clave=0 bandera_oldPass =0 bandera_newPass =0 bandera_repPass =1965: SetStr(txt_numero," ",16)966: end if967: if (kp=enter) and (bandera_repPass =1) and (ind_clave=5) then968: if validar_clave(bte_new_pass,bte_rep_pass ,ind_clave)=1 then969: SavePassword(bte_new_pass)970: ShowMessage(2,3,900,"PASS CHANGED")971: ind_clave=0972: goto INICIO973: else974: ShowMessage(2,3,900,"PASS NO MATCH")975: ind_clave=0976: goto MENU977: end if978: end if979: wend980: END.

mikroBasic compiler for PIC by mikroElektronika18/25

Page 19: Proyecto Graduacion ESPOL-FIEC: Anexo - Codigo en MikroBasic

Autores: Ricardo Cajo - Jorge GalarzaCodigo Alarma Puerta

1: program Codigo_Alarma_Puerta2: dim n_envios,received_byte,viajero,cod_alarma as byte3: dim Estado_Alarma,checksun_enviar, acknoledge as byte4: dim checksun_recibido, checksun_calculado ,cont as byte5: dim dato as byte[5]6: const INICIO = $247: const ID = $498: const FIN = $469: const CODIGO=$0710: 11: sub procedure interrupt()12: 13: ' Usart_Data_Ready es lo mismo que haber puesto PIR1.RCIF14: if Usart_Data_Ready = 1 then15: received_byte = Usart_Read16: select case viajero17: 18: case 019: if (received_byte=INICIO) then '$'20: viajero=121: else22: viajero=023: end if24: 25: case 126: if (received_byte=ID) then 'I' ID27: viajero=228: else29: viajero=030: end if31: 32: case 233: dato[0]=(received_byte) 'Codigo Alarma34: viajero=335: case 336: dato[1]= received_byte 'Estado Alarma37: viajero=438: case 439: dato[2]= received_byte 'Acknoledge40: viajero=541: 42: case 543: dato[3]= received_byte 'checksun_recibido44: checksun_recibido =dato[3]45: viajero=646: case 647: dato[4]=received_byte48: if(dato[4]= FIN)then 'F' STOP49: checksun_calculado = dato[0]+dato[1]+dato[2]50: if(checksun_calculado = checksun_recibido )then51: cod_alarma =dato[0]52: Estado_Alarma=dato[1]53: acknoledge =dato[2]54: viajero=055: else56: viajero=057: end if58: else59: viajero=060: end if

mikroBasic compiler for PIC by mikroElektronka19/25

Page 20: Proyecto Graduacion ESPOL-FIEC: Anexo - Codigo en MikroBasic

Autores: Ricardo Cajo - Jorge GalarzaCodigo Alarma Puerta

61: end select62: 63: end if64: PIR1.RCIF=0 ' Si el dato a llegado limpio la bandera de recepcion65: PIE1.RCIE=1 ' Habilitar nuevamente la interrupcion por USART66: end sub67: 68: sub procedure Led()69: SetBit(PORTB,3)70: Delay_ms(200)71: ClearBit(PORTB,3)72: Delay_ms(200)73: SetBit(PORTB,3)74: Delay_ms(200)75: ClearBit(PORTB,3)76: Delay_ms(200)77: SetBit(PORTB,3)78: Delay_ms(200)79: ClearBit(PORTB,3)80: end sub81: 82: sub procedure Enable_HMTR()83: SetBit(PORTB,4) 'Enable HM-TR84: end sub85: 86: sub procedure Disable_HMTR()87: ClearBit(PORTB,4) 'Enable HM-TR88: end sub89: sub procedure Enviar_Alerta_Respuesta(dim Estado,Alerta,respuesta as byte)90: 91: checksun_enviar =Estado +Alerta +CODIGO+ respuesta92: USART_Write (INICIO )93: USART_Write (ID)94: USART_Write (CODIGO)95: USART_Write (Estado)96: USART_Write (Alerta)97: USART_Write (respuesta) 'Acknoledge98: USART_Write (checksun_enviar )99: Usart_Write (FIN )100: 101: end sub102: main:103: 104: OPTION_REG = %10000000105: INTCON = %11000000 ' Enable external interrupts bit(7) and bit(6) de

permiso q no se controlan con INTCON106: 107: PIE1=%00100000108: PIR1=0109: 110: CMCON=$07 'Para Configurar el PORTA COMO I/O Digitales y apagar el

comparador Analogico111: 112: TRISA = %10000000 'RA0,RA1,RA2,RA3,RA4,RA7 Input RA6 OUTPUT113: TRISB = %00000011114: 115: PORTA=0116: PORTB=0117: n_envios =0118: received_byte=0

mikroBasic compiler for PIC by mikroElektronika20/25

Page 21: Proyecto Graduacion ESPOL-FIEC: Anexo - Codigo en MikroBasic

Autores: Ricardo Cajo - Jorge GalarzaCodigo Alarma Puerta

119: viajero=0120: cod_alarma=0121: Estado_Alarma=0122: acknoledge=0123: cont=0124: checksun_enviar =0125: checksun_recibido =0126: checksun_calculado =0127: Usart_Init(9600)128: Led()129: 'sleep130: Enable_HMTR ()131: while(1) ' While there is no interrupt, program runs in

endless loop:132: 133: if(cod_alarma =CODIGO )then134: if( Estado_Alarma =1)then135: SetBit(PORTB,3)136: delay_ms(50)137: Enviar_Alerta_Respuesta (1,0,1)138: 139: 140: else141: ClearBit(PORTB,3)142: delay_ms(50)143: Enviar_Alerta_Respuesta (0,0,1)144: end if145: cod_alarma=0146: end if147: if(Estado_Alarma=1)then148: if(PortB.0=1)then149: if(n_envios =0) then150: Enviar_Alerta_Respuesta (1,1,1)151: delay_ms(1000)152: if(acknoledge =1)then153: n_envios=1154: acknoledge =0155: cont=0156: else157: inc(cont)158: if(cont<5)then159: n_envios=0160: else161: cont=0162: n_envios=1163: end if164: end if165: end if166: else167: n_envios =0168: end if169: end if170: 171: wend172: 173: end.

mikroBasic compiler for PIC by mikroElektronika21/25

Page 22: Proyecto Graduacion ESPOL-FIEC: Anexo - Codigo en MikroBasic

Codigo Alarma Movimiento Autores: Ricardo Cajo - Jorge Galarza

1: program Codigo_Alarma_Movimiento2: dim n_envios,received_byte,viajero,cod_alarma,n_presencia as byte3: dim Alert_Alarma,Estado_Alarma,checksun_enviar, acknoledge as byte4: dim checksun_recibido, checksun_calculado ,cont as byte5: dim dato as byte[5]6: const INICIO = $247: const ID = $498: const FIN = $469: const CODIGO=$0A10: 11: sub procedure interrupt()12: 13: ' Usart_Data_Ready es lo mismo que haber puesto PIR1.RCIF14: if Usart_Data_Ready = 1 then15: received_byte = Usart_Read16: select case viajero17: 18: case 019: if (received_byte=INICIO) then '$'20: viajero=121: else22: viajero=023: end if24: 25: case 126: if (received_byte=ID) then 'I' ID27: viajero=228: else29: viajero=030: end if31: 32: case 233: dato[0]=(received_byte) 'Codigo Alarma34: viajero=335: case 336: dato[1]= received_byte 'Estado Alarma37: viajero=438: case 439: dato[2]= received_byte 'Acknoledge40: viajero=541: 42: case 543: dato[3]= received_byte 'checksun_recibido44: checksun_recibido =dato[3]45: viajero=646: case 647: dato[4]=received_byte48: if(dato[4]= FIN)then 'F' STOP49: checksun_calculado = dato[0]+dato[1]+dato[2]50: if(checksun_calculado = checksun_recibido )then51: cod_alarma =dato[0]52: Estado_Alarma=dato[1]53: acknoledge =dato[2]54: viajero=055: else56: viajero=057: end if58: else59: viajero=060: end if

22/25 mikroBasic compiler for PIC by mikroElektronika

Page 23: Proyecto Graduacion ESPOL-FIEC: Anexo - Codigo en MikroBasic

Codigo Alarma Movimiento Autores: Ricardo Cajo - Jorge Galarza

61: end select62: 63: end if64: 65: if(INTCON.INTF =1)THEN66: Inc(n_presencia )67: if(n_presencia =4)then68: Alert_Alarma =169: n_presencia =070: end if71: end if72: 73: INTCON.INTF=074: INTCON.INTE =175: PIR1.RCIF=0 ' Si el dato a llegado limpio la bandera de recepcion76: PIE1.RCIE=1 ' Habilitar nuevamente la interrupcion por USART77: end sub78: 79: sub procedure Led()80: SetBit(PORTB,3)81: Delay_ms(200)82: ClearBit(PORTB,3)83: Delay_ms(200)84: SetBit(PORTB,3)85: Delay_ms(200)86: ClearBit(PORTB,3)87: Delay_ms(200)88: SetBit(PORTB,3)89: Delay_ms(200)90: ClearBit(PORTB,3)91: end sub92: 93: sub procedure Enable_HMTR()94: SetBit(PORTB,4) 'Enable HM-TR95: end sub96: 97: sub procedure Disable_HMTR()98: ClearBit(PORTB,4) 'Enable HM-TR99: end sub100: sub procedure Enviar_Alerta_Respuesta(dim Estado,Alerta,respuesta as byte)101: 102: checksun_enviar =Estado +Alerta +CODIGO+ respuesta103: USART_Write (INICIO )104: USART_Write (ID)105: USART_Write (CODIGO)106: USART_Write (Estado)107: USART_Write (Alerta)108: USART_Write (respuesta) 'Acknoledge109: USART_Write (checksun_enviar )110: Usart_Write (FIN )111: 112: end sub113: main:114: 115: OPTION_REG = %10000000116: INTCON = %11010000 ' Enable external interrupts bit(7) and bit(6) de117: ' permiso q no se controlan con INTCON118: 119: PIE1=%00100000120: PIR1=0

23/25 mikroBasic compiler for PIC by mikroElektronika

Page 24: Proyecto Graduacion ESPOL-FIEC: Anexo - Codigo en MikroBasic

Codigo Alarma Movimiento Autores: Ricardo Cajo - Jorge Galarza

121: 122: CMCON=$07 'Para Configurar el PORTA COMO I/O Digitales y apagar el123: 'comparador Analogico124: 125: TRISA = %10000000 'RA0,RA1,RA2,RA3,RA4,RA7 Input RA6 OUTPUT126: TRISB = %00000011127: 128: PORTA=0129: PORTB=0130: n_envios =0131: received_byte=0132: viajero=0133: cod_alarma=0134: Estado_Alarma=0135: Alert_Alarma=0136: acknoledge=0137: n_presencia =0138: cont=0139: checksun_enviar =0140: checksun_recibido =0141: checksun_calculado =0142: Usart_Init(9600)143: Led()144: 'sleep145: Enable_HMTR ()146: while(1) ' While there is no interrupt, program runs in endless loop:147: 148: if(cod_alarma =CODIGO )then149: if( Estado_Alarma =1)then150: SetBit(PORTB,3)151: delay_ms(50)152: Enviar_Alerta_Respuesta (1,0,1)153: 154: 155: else156: ClearBit(PORTB,3)157: delay_ms(50)158: Enviar_Alerta_Respuesta (0,0,1)159: end if160: cod_alarma=0161: end if162: if(Estado_Alarma=1)then163: if(Alert_Alarma =1)then164: if(n_envios =0) then165: Enviar_Alerta_Respuesta (1,1,1)166: delay_ms(1000)167: if(acknoledge =1)then168: n_envios=1169: Alert_Alarma =0170: acknoledge =0171: cont=0172: else173: inc(cont)174: if(cont<5)then175: n_envios=0176: else177: cont=0178: n_envios=1179: end if180: end if

24/25 mikroBasic compiler for PIC by mikroElektronika

Page 25: Proyecto Graduacion ESPOL-FIEC: Anexo - Codigo en MikroBasic

Codigo Alarma Movimiento Autores: Ricardo Cajo - Jorge Galarza

181: end if182: else183: n_envios =0184: end if185: end if186: 187: wend188: 189: end.

25/25 mikroBasic compiler for PIC by mikroElektronika