practica micros

Upload: tania-torres

Post on 13-Apr-2018

241 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/26/2019 Practica Micros

    1/52

    05/08/2015 18:36:23MyProject.c

    1: /*-------------------------------------------------------------------

    2: UNIVERSIDAD POLITECNICA SALESIANA

    3: CARRERA DE INGENIERIA ELECTRICA-ELECTRONICA

    4: SISTEMAS MICROPROCESADOS I

    5:

    6: Nombre: ContadorCronometroReloj

    7: Autores: Tania Torres

    8: Johana Castillo9: Creacin: 04-Agosto-2015

    10: Revisin: 05-Agosto-2015

    11: ******************************************************************/

    12:

    13: unsignedshortcontusuario, valorL, valorH, cont0, bandera, bandera2;

    14: unsignedshortbandera3, bandera4, bandera5, bandegiropaso, bandegiro;

    15: unsignedshortcont1, cont2, veces, auxcont3, auxcont2, cont6, cont7;

    16: unsignedvalor = 0;

    17: floatvalor1 = 0;

    18: unsignedcomprobacion = 0;

    19: unsignedciclo1 = 0;

    20: unsignedshortmotpaso = 0;

    21: unsignedshortflag_start_stop = 0;22: unsignedshortflag_start_stop2 = 0;

    23: unsignedshortpasoadmin = 0;

    24: unsignedcontvelocidad = 4000;

    25: unsignedrespcontvelocidad = 4000;

    26: unsignedtemporal = 0;

    27: unsignedshorthlflag = 0;

    28:

    29: unsignedshortpasodirec = 2;

    30:

    31:

    32: unsignedsignal1 = 0;

    33: longtsignal1 = 0;

    34:

    35: unsignedshortsegundos, minutos, horas, diaNombre, dia, mes, anio, motor, alarma;36:

    37: unsignedclaveadmin = 4070;

    38: floataux;

    39: floatciclof;

    40: unsignedshorteeprom1[4];

    41: unsignedshorteeprom2[4];

    42: charreloj[3];

    43: char*txt;

    44:

    45:

    46: chardato[] = " ";

    47: charplotdato[4] = "";

    48:

    49: charposicion1[2] = "";

    50:

    51:

    52: sbitLCD_RS atRD2_bit;

    53: sbitLCD_EN atRD3_bit;

    54: sbitLCD_D4 atRD4_bit;

    55: sbitLCD_D5 atRD5_bit;

    56: sbitLCD_D6 atRD6_bit;

    57: sbitLCD_D7 atRD7_bit;

    mikroC PRO for PIC by mikroElektroik!1/52

  • 7/26/2019 Practica Micros

    2/52

    05/08/2015 18:36:23MyProject.c

    58:

    59: sbitLCD_RS_Direction atTRISD2_bit;

    60: sbitLCD_EN_Direction atTRISD3_bit;

    61: sbitLCD_D4_Direction atTRISD4_bit;

    62: sbitLCD_D5_Direction atTRISD5_bit;

    63: sbitLCD_D6_Direction atTRISD6_bit;

    64: sbitLCD_D7_Direction atTRISD7_bit;

    65:66:

    67: chartxt1[] = "ADMINISTRADOR A";

    68: chartxt3[] = " USUARIO B ";

    69: chartxt5[] = " ";

    70:

    71: chartxtaux2[] = "";

    72: chartxtaux[] = " ";

    73: chartxtaux10[] = " ";

    74: chartxtdato[] = " ";

    75: chartxt15[] = " ";

    76:

    77:

    78: voidinterrupt()79: {

    80: if(pir1.TMR1IF == 1)

    81: {

    82:

    83: if(bandegiro == 0)

    84: {

    85: portc.b2 = 0;

    86:

    87: if(hlflag == 1)

    88: {

    89: portc.b1 = 0;

    90: temporal = 65036 - 50000 + ciclo1;

    91: tmr1l = temporal & 0xFF;

    92: tmr1h = (temporal >> 8) & 0xFF;93: hlflag = 0;

    94: }

    95: else

    96: {

    97: portc.b1 = 1;

    98: temporal = 65535 - ciclo1;

    99: tmr1l = temporal & 0xFF;

    100: tmr1h = (temporal >> 8) & 0xFF;

    101: hlflag = 1;

    102: }

    103: }

    104:

    105: if(bandegiro == 1)

    106: {

    107: portc.b1 = 0;

    108:

    109: if(hlflag == 1)

    110: {

    111:

    112: portc.b2 = 0;

    113: temporal = 65036 - 50000 + ciclo1;

    114: tmr1l = temporal & 0xFF;

    mikroC PRO for PIC by mikroElektroik!2/52

  • 7/26/2019 Practica Micros

    3/52

    05/08/2015 18:36:23MyProject.c

    115: tmr1h = (temporal >> 8) & 0xFF;

    116: hlflag = 0;

    117: }

    118: else

    119: {

    120: portc.b2 = 1;

    121: temporal = 65535 - ciclo1;

    122: tmr1l = temporal & 0xFF;123: tmr1h = (temporal >> 8) & 0xFF;

    124: hlflag = 1;

    125: }

    126: }

    127: pir1.TMR1IF = 0;

    128:

    129:

    130: }

    131:

    132: if(intcon.TMR0IF == 1)

    133: {

    134:

    135: respcontvelocidad = contvelocidad;136: tmr0l = respcontvelocidad & 0xFF;

    137: tmr0h = (respcontvelocidad >> 8) & 0xFF;

    138:

    139: if(bandegiropaso == 0)

    140: {

    141: switch(motpaso)

    142: {

    143: case0:

    144: porte.b0 = 1;

    145: porte.b1 = 1;

    146: porte.b2 = 0;

    147: porta.b5 = 0;

    148: motpaso = 1;

    149: break;150:

    151: case1:

    152: porte.b0 = 0;

    153: porte.b1 = 1;

    154: porte.b2 = 1;

    155: porta.b5 = 0;

    156: motpaso = 2;

    157: break;

    158:

    159: case2:

    160: porte.b0 = 0;

    161: porte.b1 = 0;

    162: porte.b2 = 1;

    163: porta.b5 = 1;

    164: motpaso = 3;

    165: break;

    166:

    167: case3:

    168: porte.b0 = 1;

    169: porte.b1 = 0;

    170: porte.b2 = 0;

    171: porta.b5 = 1;

    mikroC PRO for PIC by mikroElektroik!3/52

  • 7/26/2019 Practica Micros

    4/52

    05/08/2015 18:36:23MyProject.c

    172: motpaso = 0;

    173: break;

    174: }

    175:

    176: }

    177:

    178: if(bandegiropaso == 1)

    179: {180: switch(motpaso)

    181: {

    182: case0:

    183: porte.b0 = 1;

    184: porte.b1 = 0;

    185: porte.b2 = 0;

    186: porta.b5 = 1;

    187: motpaso = 1;

    188: break;

    189:

    190: case1:

    191: porte.b0 = 0;

    192: porte.b1 = 0;193: porte.b2 = 1;

    194: porta.b5 = 1;

    195: motpaso = 2;

    196: break;

    197:

    198: case2:

    199: porte.b0 = 0;

    200: porte.b1 = 1;

    201: porte.b2 = 1;

    202: porta.b5 = 0;

    203: motpaso = 3;

    204: break;

    205:

    206: case3:207: porte.b0 = 1;

    208: porte.b1 = 1;

    209: porte.b2 = 0;

    210: porta.b5 = 0;

    211: motpaso = 0;

    212: break;

    213: }

    214:

    215: }

    216:

    217: intcon.TMR0IF = 0;

    218:

    219: }

    220:

    221:

    222: }

    223:

    224:

    225:

    226: voidteclado()

    227: {

    228:

    mikroC PRO for PIC by mikroElektroik!"/52

  • 7/26/2019 Practica Micros

    5/52

    05/08/2015 18:36:23MyProject.c

    229: RB3_BIT = 0;

    230:

    231: if(RB7_BIT == 0)

    232: {

    233: txt5[0] = 49;

    234: bandera = 1;

    235: }

    236:237: if(RB6_BIT == 0)

    238: {

    239: txt5[0] = 50;

    240: bandera = 1;

    241: }

    242:

    243: if(RB5_BIT == 0)

    244: {

    245: txt5[0] = 51;

    246: bandera = 1;

    247: }

    248:

    249: if(RB4_BIT == 0)250: {

    251: txt5[0] = 97;

    252: bandera = 1;

    253: }

    254:

    255: RB3_BIT = 1;

    256:

    257: //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

    258:

    259: RC0_BIT = 0;

    260:

    261: if(RB7_BIT == 0)

    262: {

    263: txt5[0] = 52;264: bandera = 1;

    265: }

    266:

    267: if(RB6_BIT == 0)

    268: {

    269: txt5[0] = 53;

    270: bandera = 1;

    271: }

    272:

    273: if(RB5_BIT == 0)

    274: {

    275: txt5[0] = 54;

    276: bandera = 1;

    277: }

    278:

    279: if(RB4_BIT == 0)

    280: {

    281: txt5[0] = 98;

    282: bandera = 1;

    283: }

    284:

    285: RC0_BIT = 1;

    mikroC PRO for PIC by mikroElektroik!5/52

  • 7/26/2019 Practica Micros

    6/52

    05/08/2015 18:36:23MyProject.c

    286:

    287: //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

    288:

    289: RD0_BIT = 0;

    290:

    291: if(RB7_BIT == 0)

    292: {

    293: txt5[0] = 55;294: bandera = 1;

    295: }

    296:

    297: if(RB6_BIT == 0)

    298: {

    299: txt5[0] = 56;

    300: bandera = 1;

    301: }

    302:

    303: if(RB5_BIT == 0)

    304: {

    305: txt5[0] = 57;

    306: bandera = 1;307: }

    308:

    309: if(RB4_BIT == 0)

    310: {

    311: txt5[0] = 99;

    312: bandera = 1;

    313:

    314: }

    315:

    316: RD0_BIT = 1;

    317:

    318: //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

    319:

    320: RD1_BIT = 0;321:

    322: if(RB7_BIT == 0)

    323: {

    324: cont1 = cont1 - 1;

    325: cont0 = cont0 - 1;

    326: if(cont1

  • 7/26/2019 Practica Micros

    7/52

    05/08/2015 18:36:23MyProject.c

    343: if(bandera3 == 17 || bandera3 == 18)

    344: {

    345: txt5[0] = 46;

    346: bandera = 1;

    347: }

    348: else

    349: {

    350: txt5[0] = 35;351: }

    352:

    353: }

    354:

    355: if(RB4_BIT == 0)

    356: {

    357: txt5[0] = 0;

    358: bandera = 1;

    359: bandera2 = 1;

    360: }

    361:

    362: RD1_BIT = 1;

    363:364: //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

    365:

    366: }

    367:

    368: voidnumero()

    369: {

    370: cont0 = 0;

    371: valor = 0;

    372: bandera = 0;

    373: bandera2 = 0;

    374: txt5[0] = 0;

    375: dato[0] = " ";

    376: dato[1] = " ";

    377: dato[2] = " ";378: dato[3] = " ";

    379:

    380: while(bandera2 == 0)

    381: {

    382: while(bandera == 0)

    383: {

    384: teclado();

    385: }

    386:

    387: delay_ms(400);

    388: Lcd_Out(2, cont1, txt5);

    389: dato[cont0] = txt5[0];

    390: if(bandera3 == 17 || bandera3 == 18)

    391: {

    392: valor1 = atof(dato);

    393: }

    394: else

    395: {

    396: valor = atoi(dato);

    397: }

    398: bandera = 0;

    399: cont0 = cont0 + 1;

    mikroC PRO for PIC by mikroElektroik!#/52

  • 7/26/2019 Practica Micros

    8/52

    05/08/2015 18:36:23MyProject.c

    400: cont1 = cont1 + 1;

    401: }

    402: }

    403:

    404:

    405: voidver_reloj()

    406: {

    407: I2C1_Start();408: I2C1_Wr(0xD0);

    409: I2C1_Wr(0);

    410: I2C1_Repeated_Start();

    411: I2C1_Wr(0xD1);

    412: segundos = I2C1_Rd(1);

    413: minutos = I2C1_Rd(1);

    414: horas = I2C1_Rd(1);

    415: diaNombre = I2C1_Rd(1);

    416: dia = I2C1_Rd(1);

    417: mes = I2C1_Rd(1);

    418: anio = I2C1_Rd(0);

    419: I2C1_Stop();

    420:421: segundos = ((segundos & 0x70) >> 4) * 10 + (segundos & 0x0F);

    422: minutos = ((minutos & 0xF0) >> 4) * 10 + (minutos & 0x0F);

    423: horas = ((horas & 0x30) >> 4) * 10 + (horas & 0x0F);

    424: diaNombre = (diaNombre & 0x07);

    425: dia = ((dia & 0xF0) >> 4) * 10 + (dia & 0x0F);

    426: mes = ((mes & 0x10) >> 4) * 10 + (mes & 0x0F);

    427: anio = ((anio & 0xF0) >> 4) * 10 + (anio & 0x0F);

    428: }

    429:

    430:

    431: voidmain()

    432: {

    433:

    434: Lcd_Init(); // Initialize LCD435: Lcd_Cmd(_LCD_CLEAR); // Clear display

    436: Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off

    437:

    438:

    439:

    440: Adc_init();

    441:

    442: ADCON1 = 10;

    443: trisa.b5 = 0;

    444: trisa.b4 = 0;

    445: porta = 0;

    446:

    447: pie1.b0 = 1;

    448: t1con = 0b00000000;

    449:

    450: intcon = 0b11100000;

    451: t0con = 0b00000011;

    452:

    453:

    454: pie1.b1 = 1;

    455: t2con = 0b01111100;

    456:

    mikroC PRO for PIC by mikroElektroik!8/52

  • 7/26/2019 Practica Micros

    9/52

    05/08/2015 18:36:23MyProject.c

    457:

    458:

    459: INTCON2.RBPU = 0; //habilito resistencias pull up

    460:

    461: ciclo1 = 0; // initial value for current_duty

    462:

    463:

    464: trisb = 0b11110000; //entradas salidas465: portb = 0;

    466: trisd.B0 = 0;

    467: trisd.B1 = 0;

    468: trisC.B0 = 0;

    469: trisc.B4 = 1;

    470: trisc.B5 = 1;

    471: trisc.B1 = 0;

    472: trisc.B2 = 0;

    473: portd = 0;

    474: trise.b0 = 0;

    475: trise.b1 = 0;

    476: trise.b2 = 0;

    477: trise.b3 = 0;478: porte = 0;

    479: portc = 0;

    480:

    481: I2C1_Init(100000); // initialize I2C communication

    482:

    483:

    484: bandera = 0;

    485: bandera2 = 0;

    486: cont2 = 1;

    487: bandera3 = 0;

    488: bandera4 = 0;

    489: auxcont3 = 0;

    490: auxcont2 = 0;

    491: bandera5 = 0;492:

    493:

    494:

    495: while(1)

    496: {

    497: Lcd_Cmd(_LCD_CLEAR); // Clear dimultiplicaciony

    498: Lcd_Out(1, 1, txt1); // escribo admin

    499: Lcd_Out(2, 1, txt3); // escribo user

    500:

    501:

    502:

    503: while(1) //choose admin or user

    504: {

    505:

    506: teclado();

    507:

    508: if(txt5[0] == 97) //admin

    509: {

    510: delay_ms(500);

    511: cont1 = 7;

    512: Lcd_Cmd(_LCD_CLEAR);

    513: lcd_out(1, 3, "ADIMINISTRADOR");

    mikroC PRO for PIC by mikroElektroik!$/52

  • 7/26/2019 Practica Micros

    10/52

    05/08/2015 18:36:23MyProject.c

    514: lcd_out(2, 1, "CLAVE: ");

    515: numero();

    516:

    517: if(valor == claveadmin)

    518: {

    519: Lcd_Cmd(_LCD_CLEAR);

    520: lcd_out(1, 5, "CORRECTO");

    521: bandera3 = 10;522: delay_ms(1000);

    523: break;

    524: }

    525: else

    526: {

    527: Lcd_Cmd(_LCD_CLEAR);

    528: lcd_out(1, 4, "INCORRECTO");

    529: delay_ms(1000);

    530: cont1 = 7;

    531: bandera3 = 0;

    532: break;

    533:

    534: }535:

    536: }

    537:

    538: if(txt5[0] == 98) //user

    539: {

    540: bandera3 = 30;

    541: delay_ms(500);

    542: break;

    543:

    544: }

    545: }

    546:

    547: while(1)

    548: {549: //admin

    550: while(bandera3 == 10)

    551: {

    552: cont1 = 7;

    553: Lcd_Cmd(_LCD_CLEAR);

    554: lcd_out(1, 1, "USUARIO(A)");

    555: lcd_out(2, 1, "OPCION(B) VER(C)");

    556: delay_ms(1000);

    557: bandera3 = 0;

    558: txt5[0] = 0;

    559:

    560: while(1)

    561: {

    562:

    563: teclado();

    564:

    565: if(txt5[0] == 97) //usuarios

    566: {

    567: bandera3 = 11;

    568: delay_ms(500);

    569: break;

    570: }

    mikroC PRO for PIC by mikroElektroik!10/52

  • 7/26/2019 Practica Micros

    11/52

    05/08/2015 18:36:23MyProject.c

    571:

    572: if(txt5[0] == 98) //opciones

    573: {

    574: bandera3 = 12;

    575: delay_ms(500);

    576: break;

    577: }

    578:579: if(txt5[0] == 99) //ver

    580: {

    581: bandera3 = 13;

    582: delay_ms(500);

    583: break;

    584:

    585: }

    586:

    587: if(txt5[0] == 35) //regresar

    588: {

    589: bandera3 = 0;

    590: delay_ms(500);

    591: break;592:

    593: }

    594:

    595: }

    596:

    597:

    598:

    599: while(bandera3 == 11) //usuarios

    600: {

    601:

    602: Lcd_Cmd(_LCD_CLEAR);

    603: lcd_out(1, 5, "USUARIOS");

    604: delay_ms(2000);

    605: Lcd_Cmd(_LCD_CLEAR);606: lcd_out(1, 1, "NEW(A) BORRAR(B)");

    607: lcd_out(2, 1, "MODIFICAR(C) ");

    608: txt5[0] = 0;

    609: cont1 = 7;

    610:

    611: while(1)

    612: {

    613: teclado();

    614:

    615: if(txt5[0] == 97)

    616: {

    617: bandera3 = 14; //nuevo

    usuario

    618: delay_ms(500);

    619: break;

    620: }

    621:

    622: if(txt5[0] == 98)

    623: {

    624: bandera3 = 15; //borrar

    usuario

    625: delay_ms(500);

    mikroC PRO for PIC by mikroElektroik!11/52

  • 7/26/2019 Practica Micros

    12/52

    05/08/2015 18:36:23MyProject.c

    626: break;

    627: }

    628:

    629: if(txt5[0] == 99)

    630: {

    631: bandera3 = 16; //modifi

    car usuario

    632: delay_ms(500);633: break;

    634: }

    635:

    636: if(txt5[0] == 35) //regresa

    r

    637: {

    638: bandera3 = 10;

    639: delay_ms(500);

    640: break;

    641: }

    642:

    643:

    644: }645:

    646: while(bandera3 == 14) //nuevo usuario

    647: {

    648:

    649: Lcd_Cmd(_LCD_CLEAR);

    650: lcd_out(1, 6, "NUEVO");

    651: lcd_out(2, 5, "USUARIO");

    652: delay_ms(2000);

    653: Lcd_Cmd(_LCD_CLEAR);

    654: lcd_out(1, 3, "# DE USUARIO");

    655:

    656: numero();

    657:

    658: if(valor>0 && valor

  • 7/26/2019 Practica Micros

    13/52

    05/08/2015 18:36:23MyProject.c

    678: eeprom1[3] = (valor - eeprom1[0] * 1

    000) - eeprom1[1] * 100 - eeprom1[2] * 10;

    679:

    680: if(contusuario == 1)

    681: {

    682: EEPROM_WRITE(2, eeprom1[0]);

    683: EEPROM_WRITE(3, eeprom1[1]);

    684: EEPROM_WRITE(4, eeprom1[2]);685: EEPROM_WRITE(5, eeprom1[3]);

    686: }

    687:

    688: if(contusuario == 2)

    689: {

    690: EEPROM_WRITE(6, eeprom1[0]);

    691: EEPROM_WRITE(7, eeprom1[1]);

    692: EEPROM_WRITE(8, eeprom1[2]);

    693: EEPROM_WRITE(9, eeprom1[3]);

    694: }

    695:

    696: if(contusuario == 3)

    697: {698: EEPROM_WRITE(10, eeprom1[0])

    ;

    699: EEPROM_WRITE(11, eeprom1[1])

    ;

    700: EEPROM_WRITE(12, eeprom1[2])

    ;

    701: EEPROM_WRITE(13, eeprom1[3])

    ;

    702: }

    703:

    704: if(contusuario == 4)

    705: {

    706: EEPROM_WRITE(14, eeprom1[0])

    ;707: EEPROM_WRITE(15, eeprom1[1])

    ;

    708: EEPROM_WRITE(16, eeprom1[2])

    ;

    709: EEPROM_WRITE(17, eeprom1[3])

    ;

    710: }

    711:

    712: if(contusuario == 5)

    713: {

    714: EEPROM_WRITE(18, eeprom1[0])

    ;

    715: EEPROM_WRITE(19, eeprom1[1])

    ;

    mikroC PRO for PIC by mikroElektroik!13/52

  • 7/26/2019 Practica Micros

    14/52

    05/08/2015 18:36:23MyProject.c

    716: EEPROM_WRITE(20, eeprom1[2])

    ;

    717: EEPROM_WRITE(21, eeprom1[3])

    ;

    718: }

    719: if(contusuario0 && valor

  • 7/26/2019 Practica Micros

    15/52

    05/08/2015 18:36:23MyProject.c

    768: EEPROM_WRITE(8, 0);

    769: EEPROM_WRITE(9, 0);

    770: }

    771:

    772: if(valor == 3)

    773: {

    774: EEPROM_WRITE(10, 0);

    775: EEPROM_WRITE(11, 0);776: EEPROM_WRITE(12, 0);

    777: EEPROM_WRITE(13, 0);

    778: }

    779:

    780: if(valor == 4)

    781: {

    782: EEPROM_WRITE(14, 0);

    783: EEPROM_WRITE(15, 0);

    784: EEPROM_WRITE(16, 0);

    785: EEPROM_WRITE(17, 0);

    786: }

    787:

    788: if(valor == 5)789: {

    790: EEPROM_WRITE(18, 0);

    791: EEPROM_WRITE(19, 0);

    792: EEPROM_WRITE(20, 0);

    793: EEPROM_WRITE(21, 0);

    794: }

    795:

    796:

    797: Lcd_Cmd(_LCD_CLEAR);

    798: lcd_out(1, 5, "BORRADO");

    799: delay_ms(2000);

    800:

    801: bandera3 = 11;

    802: break;803: }

    804:

    805: while(bandera3 == 16) //modificar usuari

    o

    806: {

    807: Lcd_Cmd(_LCD_CLEAR);

    808: lcd_out(1, 4, "MODIFICAR");

    809: lcd_out(2, 5, "USUARIO");

    810: delay_ms(2000);

    811: Lcd_Cmd(_LCD_CLEAR);

    812: lcd_out(1, 3, "# DE USUARIO");

    813:

    814: numero();

    815:

    816: if(valor>0 && valor

  • 7/26/2019 Practica Micros

    16/52

    05/08/2015 18:36:23MyProject.c

    824: lcd_out(1, 1, "INCORRECTO");

    825: delay_ms(2000);

    826: bandera3 = 11;

    827: break;

    828: }

    829: Lcd_Cmd(_LCD_CLEAR);

    830: lcd_out(1, 1, "NUEVA CLAVE: ");

    831:832: numero();

    833: eeprom1[0] = valor / 1000;

    834: eeprom1[1] = (valor - eeprom1[0] * 1

    000) / 100;

    835: eeprom1[2] = ((valor - eeprom1[0] *

    1000) - (eeprom1[1] * 100)) / 10;

    836: eeprom1[3] = (valor - eeprom1[0] * 1

    000) - eeprom1[1] * 100 - eeprom1[2] * 10;

    837:

    838: if(contusuario == 1)

    839: {

    840: EEPROM_WRITE(2, eeprom1[0]);

    841: EEPROM_WRITE(3, eeprom1[1]);842: EEPROM_WRITE(4, eeprom1[2]);

    843: EEPROM_WRITE(5, eeprom1[3]);

    844: }

    845:

    846: if(contusuario == 2)

    847: {

    848: EEPROM_WRITE(6, eeprom1[0]);

    849: EEPROM_WRITE(7, eeprom1[1]);

    850: EEPROM_WRITE(8, eeprom1[2]);

    851: EEPROM_WRITE(9, eeprom1[3]);

    852: }

    853:

    854: if(contusuario == 3)

    855: {856: EEPROM_WRITE(10, eeprom1[0])

    ;

    857: EEPROM_WRITE(11, eeprom1[1])

    ;

    858: EEPROM_WRITE(12, eeprom1[2])

    ;

    859: EEPROM_WRITE(13, eeprom1[3])

    ;

    860: }

    861:

    862: if(contusuario == 4)

    863: {

    864: EEPROM_WRITE(14, eeprom1[0])

    ;

    mikroC PRO for PIC by mikroElektroik!16/52

  • 7/26/2019 Practica Micros

    17/52

    05/08/2015 18:36:23MyProject.c

    865: EEPROM_WRITE(15, eeprom1[1])

    ;

    866: EEPROM_WRITE(16, eeprom1[2])

    ;

    867: EEPROM_WRITE(17, eeprom1[3])

    ;

    868: }

    869:870: if(contusuario == 5)

    871: {

    872: EEPROM_WRITE(18, eeprom1[0])

    ;

    873: EEPROM_WRITE(19, eeprom1[1])

    ;

    874: EEPROM_WRITE(20, eeprom1[2])

    ;

    875: EEPROM_WRITE(21, eeprom1[3])

    ;

    876: }

    877: if(contusuario

  • 7/26/2019 Practica Micros

    18/52

    05/08/2015 18:36:23MyProject.c

    912: }

    913:

    914:

    915: if(txt5[0] == 35) //regresa

    r

    916: {

    917: bandera3 = 10;

    918: delay_ms(500);919: break;

    920:

    921: }

    922:

    923:

    924: }

    925:

    926:

    927: while(bandera3 == 19) //reloj

    928: {

    929: Lcd_Cmd(_LCD_CLEAR);

    930: lcd_out(1, 6, "RELOJ");

    931:932: delay_ms(2000);

    933: Lcd_Cmd(_LCD_CLEAR);

    934: lcd_out(1, 1, "AJUSTAR (A)");

    935: lcd_out(2, 1, "VER RELOJ (B)");

    936:

    937: while(1)

    938: {

    939:

    940: teclado();

    941:

    942: if(txt5[0] == 97)

    //Ajustar

    943: {

    944: bandera3 = 20;945: delay_ms(500);

    946: break;

    947: }

    948:

    949: if(txt5[0] == 98)

    //ver

    950: {

    951: bandera3 = 21;

    952: delay_ms(500);

    953: Lcd_Cmd(_LCD_CLEAR);

    954: break;

    955: }

    956:

    957: if(txt5[0] == 35) /

    /regresar

    958: {

    959: bandera3 = 12;

    960: delay_ms(500);

    961: break;

    962:

    963: }

    mikroC PRO for PIC by mikroElektroik!18/52

  • 7/26/2019 Practica Micros

    19/52

    05/08/2015 18:36:23MyProject.c

    964:

    965:

    966: }

    967:

    968: while(bandera3 == 20) //ajustar

    reloj

    969: {

    970:971: Lcd_Cmd(_LCD_CLEAR);

    972: lcd_out(1, 5, "AJUSTAR");

    973: delay_ms(2000);

    974: cont1 = 7;

    975:

    976: Lcd_Cmd(_LCD_CLEAR);

    977: lcd_out(1, 1, "segundos");

    978: numero();

    979:

    980: if(valor>59)

    981: {

    982: Lcd_Cmd(_LCD_CLEAR);

    983: lcd_out(1, 1, "invalido");

    984: delay_ms(2000);

    985: bandera3 = 19;

    986: break;

    987: }

    988: segundos = Dec2Bcd16(valor);

    989:

    990: cont1 = 7;

    991: Lcd_Cmd(_LCD_CLEAR);

    992: lcd_out(1, 1, "minutos");

    993: numero();

    994:

    995: if(valor>59)

    996: {997: Lcd_Cmd(_LCD_CLEAR);

    998: lcd_out(1, 1, "inval

    ido");

    999: delay_ms(2000);

    1000: bandera3 = 19;

    1001: break;

    1002: }

    1003: minutos = Dec2Bcd16(valor);

    1004:

    1005: cont1 = 7;

    1006: Lcd_Cmd(_LCD_CLEAR);

    1007: lcd_out(1, 1, "horas");

    1008: numero();

    1009:

    1010: if(valor>23)

    1011: {

    1012: Lcd_Cmd(_LCD_CLEAR);

    1013: lcd_out(1, 1, "inval

    ido");

    mikroC PRO for PIC by mikroElektroik!1$/52

  • 7/26/2019 Practica Micros

    20/52

    05/08/2015 18:36:23MyProject.c

    1014: delay_ms(2000);

    1015: bandera3 = 19;

    1016: break;

    1017: }

    1018: horas = Dec2Bcd16(valor);

    1019:

    1020: cont1 = 7;

    1021: Lcd_Cmd(_LCD_CLEAR);1022: lcd_out(1, 1, "D=1,L=2,Mar=3

    ...");

    1023: numero();

    1024:

    1025: if(valor>7)

    1026: {

    1027: Lcd_Cmd(_LCD_CLEAR);

    1028: lcd_out(1, 1, "inval

    ido");

    1029: delay_ms(2000);

    1030: bandera3 = 19;

    1031: break;

    1032: }1033: diaNombre = Dec2Bcd16(valor)

    ;

    1034:

    1035: cont1 = 7;

    1036: Lcd_Cmd(_LCD_CLEAR);

    1037: lcd_out(1, 1, "Dia 1,2,3..."

    );

    1038: numero();

    1039:

    1040: if(valor>31)

    1041: {

    1042: Lcd_Cmd(_LCD_CLEAR);

    1043: lcd_out(1, 1, "inval

    ido");1044: delay_ms(2000);

    1045: bandera3 = 19;

    1046: break;

    1047: }

    1048: dia = Dec2Bcd16(valor);

    1049:

    1050: cont1 = 7;

    1051: Lcd_Cmd(_LCD_CLEAR);

    1052: lcd_out(1, 1, "Mes 1,2,3..")

    ;

    1053: numero();

    1054:

    1055: if(valor>12)

    1056: {

    1057: Lcd_Cmd(_LCD_CLEAR);

    1058: lcd_out(1, 1, "inval

    ido");

    1059: delay_ms(2000);

    1060: bandera3 = 19;

    mikroC PRO for PIC by mikroElektroik!20/52

  • 7/26/2019 Practica Micros

    21/52

    05/08/2015 18:36:23MyProject.c

    1061: break;

    1062: }

    1063: mes = Dec2Bcd16(valor);

    1064:

    1065: cont1 = 7;

    1066: Lcd_Cmd(_LCD_CLEAR);

    1067: lcd_out(1, 1, "Anio");

    1068: numero();1069:

    1070: if(valor>99)

    1071: {

    1072: Lcd_Cmd(_LCD_CLEAR);

    1073: lcd_out(1, 1, "inval

    ido");

    1074: delay_ms(2000);

    1075: bandera3 = 19;

    1076: break;

    1077: }

    1078:

    1079: anio = Dec2Bcd16(valor);

    1080:1081: I2C1_Start(); // is

    sue start signal

    1082: I2C1_Wr(0xD0); // ad

    dress DS1307

    1083: I2C1_Wr(0); // st

    art from word at address (REG0)

    1084: I2C1_Wr(segundos); /

    / write $80 to REG0. (pause counter + 0 sec)

    1085: I2C1_Wr(minutos);

    // write 0 to minutes word to (REG1)

    1086: I2C1_Wr(horas); // w

    rite 17 to hours word (24-hours mode)(REG2)

    1087: I2C1_Wr(diaNombre);

    // write 2 - Monday (REG3)1088: I2C1_Wr(dia); // wri

    te 4 to date word (REG4)

    1089: I2C1_Wr(mes); // wri

    te 5 (May) to month word (REG5)

    1090: I2C1_Wr(anio); // wr

    ite 01 to year word (REG6)

    1091: I2C1_Stop(); // is

    sue stop signal

    1092:

    1093: I2C1_Start(); // is

    sue start signal

    1094: I2C1_Wr(0xD0); // ad

    dress DS1307

    1095: I2C1_Wr(0); // st

    art from word at address 0

    1096: I2C1_Wr(0); // wr

    ite 0 to REG0 (enable counting + 0 sec)

    1097: I2C1_Stop(); // is

    sue stop signal

    1098:

    1099: Lcd_Cmd(_LCD_CLEAR);

    mikroC PRO for PIC by mikroElektroik!21/52

  • 7/26/2019 Practica Micros

    22/52

    05/08/2015 18:36:23MyProject.c

    1100: lcd_out(1, 1, reloj);

    1101: delay_ms(2000);

    1102: bandera3 = 19;

    1103: break;

    1104:

    1105: }

    1106:

    1107:1108: while(bandera3 == 21) //ver r

    eloj

    1109: {

    1110: ver_reloj();

    1111:

    1112:

    1113: switch(diaNombre)

    1114: {

    1115: case1: txt = "Sun"; break;

    1116: case2: txt = "Mon"; break;

    1117: case3: txt = "Tue"; break;

    1118: case4: txt = "Wed"; break;

    1119: case5: txt = "Thu"; break;1120: case6: txt = "Fri"; break;

    1121: case7: txt = "Sat"; break;

    1122: }

    1123: LCD_Out(1, 1, txt);

    1124: Lcd_Chr(1, 6, (dia / 10) + 4

    8); // Print tens digit of day variable

    1125: Lcd_Chr(1, 7, (dia % 10) + 4

    8); // Print oness digit of day variable

    1126: Lcd_Chr(1, 9, (mes / 10) + 4

    8);

    1127: Lcd_Chr(1, 10, (mes % 10) +

    48);

    1128: Lcd_Chr(1, 12, (anio / 10) +

    48); // Print year vaiable + 8 (start from year 2008)1129: Lcd_Chr(1, 13, (anio % 10) +

    48); // Print year vaiable + 8 (start from year 2008)

    1130: //shorttostr(anio,txtaux);

    1131: //Lcd_out(1,15, txtaux);

    // Print year vaiable + 8 (start from year 2008)

    1132:

    1133: Lcd_Chr(2, 6, (horas / 10) +

    48);

    1134: Lcd_Chr(2, 7, (horas % 10) +

    48);

    1135: Lcd_Chr(2, 9, (minutos / 10)

    + 48);

    1136: Lcd_Chr(2, 10, (minutos % 10

    ) + 48);

    1137: Lcd_Chr(2, 12, (segundos / 1

    0) + 48);

    1138: Lcd_Chr(2, 13, (segundos % 1

    0) + 48);

    1139:

    1140: teclado();

    1141: if(txt5[0] == 35)

    1142: {

    mikroC PRO for PIC by mikroElektroik!22/52

  • 7/26/2019 Practica Micros

    23/52

    05/08/2015 18:36:23MyProject.c

    1143: bandera3 = 19;

    1144: txt5[0] == 0;

    1145: delay_ms(200);

    1146: break;

    1147: }

    1148: delay_ms(1000);

    1149:

    1150: }1151:

    1152: }

    1153:

    1154:

    1155: }

    1156:

    1157:

    1158: while(bandera3 == 13) //ver

    1159: {

    1160: delay_ms(300);

    1161: pasoadmin = 1;

    1162: bandera3 = 30;

    1163: break;1164:

    1165: }

    1166:

    1167: if(bandera3 == 0) //regresar

    1168: {

    1169: break;

    1170: }

    1171:

    1172:

    1173: }

    1174:

    1175:

    1176:

    1177: //user1178: if(bandera3 == 30)

    1179: {

    1180: if(pasoadmin == 0)

    1181: {

    1182: Lcd_Cmd(_LCD_CLEAR);

    1183: lcd_out(1, 1, "USUARIO");

    1184: lcd_out(2, 1, "CLAVE:");

    1185: cont1 = 7;

    1186: numero();

    1187: bandera4 = 0;

    1188: }

    1189: else

    1190: {

    1191: comprobacion = valor;

    1192: bandera4 = 5;

    1193: }

    1194:

    1195: if(bandera4 != 5)

    1196: {

    1197: eeprom2[0] = eeprom_read(2);

    1198: eeprom2[1] = eeprom_read(3);

    1199: eeprom2[2] = eeprom_read(4);

    mikroC PRO for PIC by mikroElektroik!23/52

  • 7/26/2019 Practica Micros

    24/52

    05/08/2015 18:36:23MyProject.c

    1200: eeprom2[3] = eeprom_read(5);

    1201:

    1202: comprobacion = eeprom2[0] * 1000 + eeprom2[1

    ] * 100 + eeprom2[2] * 10 + eeprom2[3];

    1203:

    1204: if(comprobacion == valor)

    1205: {

    1206: contusuario = 1;1207: bandera4 = 5;

    1208: }

    1209: }

    1210:

    1211: if(bandera4 != 5)

    1212: {

    1213: eeprom2[0] = eeprom_read(6);

    1214: eeprom2[1] = eeprom_read(7);

    1215: eeprom2[2] = eeprom_read(8);

    1216: eeprom2[3] = eeprom_read(9);

    1217:

    1218: comprobacion = eeprom2[0] * 1000 + eeprom2[1

    ] * 100 + eeprom2[2] * 10 + eeprom2[3];1219:

    1220: if(comprobacion == valor)

    1221: {

    1222: contusuario = 2;

    1223: bandera4 = 5;

    1224: }

    1225: }

    1226:

    1227: if(bandera4 != 5)

    1228: {

    1229: eeprom2[0] = eeprom_read(10);

    1230: eeprom2[1] = eeprom_read(11);

    1231: eeprom2[2] = eeprom_read(12);

    1232: eeprom2[3] = eeprom_read(13);1233:

    1234: comprobacion = eeprom2[0] * 1000 + eeprom2[1

    ] * 100 + eeprom2[2] * 10 + eeprom2[3];

    1235:

    1236: if(comprobacion == valor)

    1237: {

    1238: contusuario = 3;

    1239: bandera4 = 5;

    1240: }

    1241: }

    1242:

    1243: if(bandera4 != 5)

    1244: {

    1245: eeprom2[0] = eeprom_read(14);

    1246: eeprom2[1] = eeprom_read(15);

    1247: eeprom2[2] = eeprom_read(16);

    1248: eeprom2[3] = eeprom_read(17);

    1249:

    1250: comprobacion = eeprom2[0] * 1000 + eeprom2[1

    ] * 100 + eeprom2[2] * 10 + eeprom2[3];

    1251:

    1252: if(comprobacion == valor)

    mikroC PRO for PIC by mikroElektroik!2"/52

  • 7/26/2019 Practica Micros

    25/52

    05/08/2015 18:36:23MyProject.c

    1253: {

    1254: contusuario = 4;

    1255: bandera4 = 5;

    1256: }

    1257: }

    1258:

    1259: if(bandera4 != 5)

    1260: {1261: eeprom2[0] = eeprom_read(18);

    1262: eeprom2[1] = eeprom_read(19);

    1263: eeprom2[2] = eeprom_read(20);

    1264: eeprom2[3] = eeprom_read(21);

    1265:

    1266: comprobacion = eeprom2[0] * 1000 + eeprom2[1

    ] * 100 + eeprom2[2] * 10 + eeprom2[3];

    1267:

    1268: if(comprobacion == valor)

    1269: {

    1270: contusuario = 5;

    1271: bandera4 = 5;

    1272: }1273: }

    1274:

    1275:

    1276: Lcd_Cmd(_LCD_CLEAR);

    1277:

    1278: if(comprobacion != valor)

    1279: {

    1280: lcd_out(1, 4, "INCORRECTO");

    1281: }

    1282: else

    1283: {

    1284: lcd_out(1, 5, "CORRECTO");

    1285: if(pasoadmin == 0)

    1286: {1287: lcd_out(2, 5, "USUARIO");

    1288: shorttostr(contusuario, txtaux);

    1289: lcd_out(2, 10, txtaux);

    1290:

    1291: }

    1292: else

    1293: {

    1294: lcd_out(2, 1, "ADMINISTRADOR");

    1295: pasoadmin = 0;

    1296: }

    1297: bandera3 = 31;

    1298: delay_ms(2000);

    1299: }

    1300:

    1301:

    1302: while(bandera3 == 31)

    1303: {

    1304: Lcd_Cmd(_LCD_CLEAR);

    1305: lcd_out(1, 1, "Vel. Motores (A)");

    1306: txt5[0] = 0;

    1307:

    1308: while(1)

    mikroC PRO for PIC by mikroElektroik!25/52

  • 7/26/2019 Practica Micros

    26/52

    05/08/2015 18:36:23MyProject.c

    1309: {

    1310:

    1311: teclado();

    1312:

    1313: if(txt5[0] == 97) //contro

    l de velocidad

    1314: {

    1315: bandera3 = 32;1316: delay_ms(500);

    1317: break;

    1318: }

    1319:

    1320:

    1321: if(txt5[0] == 35) //regresa

    r

    1322: {

    1323: bandera3 = 0;

    1324: delay_ms(500);

    1325: break;

    1326:

    1327: }1328: }

    1329:

    1330: while(bandera3 == 32)

    1331: {

    1332:

    1333: Lcd_Cmd(_LCD_CLEAR);

    1334: lcd_out(1, 4, "VELOCIDAD");

    1335: delay_ms(2000);

    1336: Lcd_Cmd(_LCD_CLEAR);

    1337: lcd_out(1, 1, "Motor DC (A)");

    1338: txt5[0] = 0;

    1339:

    1340: while(1)

    1341: {1342:

    1343: teclado();

    1344:

    1345: if(txt5[0] == 97)

    //Motor DC

    1346: {

    1347:

    1348: portc = 0b00000010;

    1349: delay_ms(2000);

    1350: portc = 0b00000000;

    1351: portc = 0b00000100;

    1352: delay_ms(2000);

    1353: portc = 0b00000000;

    1354: bandera3 = 33;

    1355: delay_ms(500);

    1356: break;

    1357: }

    1358:

    1359:

    1360: if(txt5[0] == 35) /

    /regresar

    1361: {

    mikroC PRO for PIC by mikroElektroik!26/52

  • 7/26/2019 Practica Micros

    27/52

    05/08/2015 18:36:23MyProject.c

    1362: bandera3 = 31;

    1363: delay_ms(500);

    1364: break;

    1365:

    1366: }

    1367:

    1368: }

    1369:1370: while(bandera3 == 33)

    1371: {

    1372: Lcd_Cmd(_LCD_CLEAR);

    1373: lcd_out(1, 1, "Motor DC");

    1374:

    1375: while(1)

    1376: {

    1377:

    1378: teclado();

    1379:

    1380: if(txt5[0] == 35)

    //regresar

    1381: {1382: bandera3 = 3

    2;

    1383: delay_ms(500

    );

    1384: break;

    1385:

    1386: }

    1387:

    1388: if(portc.b4 == 1)

    //bandera cambio de giro

    1389: {

    1390: bandegiro =

    bandegiro + 1;

    1391: if(bandegiro>1)

    1392: {

    1393: band

    egiro = 0;

    1394: }

    1395: delay_ms(300

    );

    1396: }

    1397:

    1398:

    1399: if(portc.b5 == 1)

    //bandera start stop

    1400: {

    1401: flag_start_s

    top = flag_start_stop + 1;

    1402: if(flag_sta

    rt_stop>1)

    1403: {

    1404: flag

    _start_stop = 0;

    1405: }

    1406: delay_ms(300

    );

    mikroC PRO for PIC by mikroElektroik!2#/52

  • 7/26/2019 Practica Micros

    28/52

    05/08/2015 18:36:23MyProject.c

    1407: }

    1408:

    1409: if(txt5[0] == 97)

    //Subir velocidad

    1410: {

    1411: delay_ms(300

    );

    1412: txt5[0] = 0;1413: ciclo1 = cic

    lo1 + 2000;

    1414: if(ciclo1>5

    0000)

    1415: {

    1416: cicl

    o1 = 50000;

    1417: }

    1418:

    1419: }

    1420:

    1421: if(txt5[0] == 98)

    //Bajar Velocidad1422: {

    1423: delay_ms(300

    );

    1424: txt5[0] = 0;

    1425: ciclo1 = cic

    lo1 - 2000;

    1426:

    1427: if(ciclo1 1)

    1477: {

    1478: band

    egiropaso = 0;

    1479: }

    1480: delay_ms(300

    );

    1481: }

    1482:

    1483: if(portc.b5 == 1)

    //bandera cambio star stop

    1484: {

    1485: flag_start_s

    top2 = flag_start_stop2 + 1;

    1486: if(flag_sta

    rt_stop2>1)

    1487: {

    1488: flag

    _start_stop2 = 0;

    1489: }

    mikroC PRO for PIC by mikroElektroik!2$/52

  • 7/26/2019 Practica Micros

    30/52

    05/08/2015 18:36:23MyProject.c

    1490: delay_ms(300

    );

    1491: }

    1492:

    1493: if(flag_start_stop2

    == 1)

    1494: {

    1495: t0con.tmr0on= 1;

    1496: }

    1497: if(flag_start_stop2

    == 0)

    1498: {

    1499: t0con.tmr0on

    = 0;

    1500: }

    1501:

    1502: if(txt5[0] == 97)

    //Subir velocidad

    1503: {

    1504: delay_ms(300);

    1505: txt5[0] = 0;

    1506: contvelocida

    d = contvelocidad + 500;

    1507: if(contvelo

    cidad>64000)

    1508: {

    1509: cont

    velocidad = 64000;

    1510: }

    1511: }

    1512:

    1513: if(txt5[0] == 98)

    //Bajar Velocidad1514: {

    1515: delay_ms(300

    );

    1516: txt5[0] = 0;

    1517: contvelocida

    d = contvelocidad - 500;

    1518:

    1519: if(contvelo

    cidad

  • 7/26/2019 Practica Micros

    31/52

    05/08/2015 18:36:23MyProject.c

    1528: delay_ms(10);

    1529:

    1530: }

    1531:

    1532: }

    1533:

    1534: }

    1535:1536:

    1537:

    1538:

    1539:

    1540:

    1541: while(bandera3 == 33)

    1542: {

    1543: Lcd_Cmd(_LCD_CLEAR);

    1544: lcd_out(1, 1, "*VISUALIZACION* ");

    1545: delay_ms(2000);

    1546: Lcd_Cmd(_LCD_CLEAR);

    1547:

    1548: txt5[0] = 0;1549:

    1550:

    1551: while(1)

    1552: {

    1553: lcd_out(1, 1, "t1:");

    1554: lcd_out(2, 1, "t2:");

    1555: lcd_out(1, 9, "c1:");

    1556: lcd_out(2, 9, "c2:");

    1557:

    1558:

    1559: teclado();

    1560:

    1561: if(txt5[0] == 35)

    1562: {1563: bandera3 = 31;

    1564: txt5[0] = 0; bandera

    3 = 33;

    1565: break;

    1566: }

    1567: delay_ms(100);

    1568:

    1569: }

    1570:

    1571:

    1572: }

    1573:

    1574: }

    1575:

    1576:

    1577: }

    1578:

    1579: if(bandera3 == 0)

    1580: {

    1581: break;

    1582: }

    1583:

    mikroC PRO for PIC by mikroElektroik!31/52

  • 7/26/2019 Practica Micros

    32/52

    05/08/2015 18:36:23MyProject.c

    1584: }

    1585: }

    1586:

    1587: }

    1588:

    1589: }}

    1590:

    1591:1592:

    1593:

    1594:

    1595:

    1596: voidteclado()

    1597: {

    1598:

    1599: RB3_BIT=0;

    1600:

    1601: if(RB7_BIT==0)

    1602: {

    1603: txt5[0]=49;

    1604: bandera=1;1605: }

    1606:

    1607: if(RB6_BIT==0)

    1608: {

    1609: txt5[0]=50;

    1610: bandera=1;

    1611: }

    1612:

    1613: if(RB5_BIT==0)

    1614: {

    1615: txt5[0]=51;

    1616: bandera=1;

    1617: }

    1618:1619: if(RB4_BIT==0)

    1620: {

    1621: txt5[0]=97;

    1622: bandera=1;

    1623: }

    1624:

    1625: RB3_BIT=1;

    1626:

    1627: //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

    1628:

    1629: RC0_BIT=0;

    1630:

    1631: if(RB7_BIT==0)

    1632: {

    1633: txt5[0]=52;

    1634: bandera=1;

    1635: }

    1636:

    1637: if(RB6_BIT==0)

    1638: {

    1639: txt5[0]=53;

    1640: bandera=1;

    mikroC PRO for PIC by mikroElektroik!32/52

  • 7/26/2019 Practica Micros

    33/52

    05/08/2015 18:36:23MyProject.c

    1641: }

    1642:

    1643: if(RB5_BIT==0)

    1644: {

    1645: txt5[0]=54;

    1646: bandera=1;

    1647: }

    1648:1649: if(RB4_BIT==0)

    1650: {

    1651: txt5[0]=98;

    1652: bandera=1;

    1653: }

    1654:

    1655: RC0_BIT=1;

    1656:

    1657: //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

    1658:

    1659: RD0_BIT=0;

    1660:

    1661: if(RB7_BIT==0)1662: {

    1663: txt5[0]=55;

    1664: bandera=1;

    1665: }

    1666:

    1667: if(RB6_BIT==0)

    1668: {

    1669: txt5[0]=56;

    1670: bandera=1;

    1671: }

    1672:

    1673: if(RB5_BIT==0)

    1674: {

    1675: txt5[0]=57;1676: bandera=1;

    1677: }

    1678:

    1679: if(RB4_BIT==0)

    1680: {

    1681: txt5[0]=99;

    1682: bandera=1;

    1683:

    1684: }

    1685:

    1686: RD0_BIT=1;

    1687:

    1688: //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

    1689:

    1690: RD1_BIT=0;

    1691:

    1692: if(RB7_BIT==0)

    1693: {

    1694: cont1=cont1-1;

    1695: cont0=cont0-1;

    1696: if(cont1

  • 7/26/2019 Practica Micros

    34/52

    05/08/2015 18:36:23MyProject.c

    1698: cont1=7;

    1699: cont0=0;

    1700: }

    1701: lcd_out(2,cont1," ");

    1702: delay_ms(250);

    1703: }

    1704:

    1705: if(RB6_BIT==0)1706: {

    1707: txt5[0]=48;

    1708: bandera=1;

    1709: }

    1710:

    1711: if(RB5_BIT==0)

    1712: {

    1713: if(bandera3==17 || bandera3==18)

    1714: {

    1715: txt5[0]=46;

    1716: bandera=1;

    1717: }

    1718: else1719: {

    1720: txt5[0]=35;

    1721: }

    1722:

    1723: }

    1724:

    1725: if(RB4_BIT==0)

    1726: {

    1727: txt5[0]=0;

    1728: bandera=1;

    1729: bandera2=1;

    1730: }

    1731:

    1732: RD1_BIT=1;1733:

    1734: //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

    1735:

    1736: }

    1737:

    1738: voidnumero()

    1739: {

    1740: cont0=0;

    1741: valor=0;

    1742: bandera=0;

    1743: bandera2=0;

    1744: txt5[0]=0;

    1745: dato[0]=" ";

    1746: dato[1]=" ";

    1747: dato[2]=" ";

    1748: dato[3]=" ";

    1749:

    1750: while(bandera2==0)

    1751: {

    1752: while(bandera==0)

    1753: {

    1754: teclado();

    mikroC PRO for PIC by mikroElektroik!3"/52

  • 7/26/2019 Practica Micros

    35/52

    05/08/2015 18:36:23MyProject.c

    1755: }

    1756:

    1757: delay_ms(400);

    1758: Lcd_Out(2,cont1,txt5);

    1759: dato[cont0]=txt5[0];

    1760: if(bandera3==17 || bandera3==18)

    1761: {

    1762: valor1=atof(dato);1763: }

    1764: else

    1765: {

    1766: valor=atoi(dato);

    1767: }

    1768: bandera=0;

    1769: cont0=cont0+1;

    1770: cont1=cont1+1;

    1771: }

    1772: }

    1773:

    1774:

    1775: voidver_reloj()1776: {

    1777: I2C1_Start();

    1778: I2C1_Wr(0xD0);

    1779: I2C1_Wr(0);

    1780: I2C1_Repeated_Start();

    1781: I2C1_Wr(0xD1);

    1782: segundos =I2C1_Rd(1);

    1783: minutos =I2C1_Rd(1);

    1784: horas =I2C1_Rd(1);

    1785: diaNombre =I2C1_Rd(1);

    1786: dia =I2C1_Rd(1);

    1787: mes =I2C1_Rd(1);

    1788: anio =I2C1_Rd(0);

    1789: I2C1_Stop();1790:

    1791: segundos = ((segundos & 0x70) >> 4)*10 + (segundos & 0x0F);

    1792: minutos = ((minutos & 0xF0) >> 4)*10 + (minutos & 0x0F);

    1793: horas = ((horas & 0x30) >> 4)*10 + (horas & 0x0F);

    1794: diaNombre =(diaNombre & 0x07);

    1795: dia = ((dia & 0xF0) >> 4)*10 + (dia & 0x0F);

    1796: mes = ((mes & 0x10) >> 4)*10 + (mes & 0x0F);

    1797: anio = ((anio & 0xF0)>>4)*10+(anio & 0x0F);

    1798: }

    1799:

    1800:

    1801: voidmain()

    1802: {

    1803:

    1804: Lcd_Init(); // Initialize LCD

    1805: Lcd_Cmd(_LCD_CLEAR); // Clear display

    1806: Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off

    1807:

    1808:

    1809:

    1810: Adc_init();

    1811:

    mikroC PRO for PIC by mikroElektroik!35/52

  • 7/26/2019 Practica Micros

    36/52

    05/08/2015 18:36:23MyProject.c

    1812: ADCON1=10;

    1813: trisa.b5=0;

    1814: trisa.b4=0;

    1815: porta=0;

    1816:

    1817: pie1.b0=1;

    1818: t1con=0b00000000;

    1819:1820: intcon=0b11100000;

    1821: t0con=0b00000011;

    1822:

    1823:

    1824: pie1.b1=1;

    1825: t2con=0b01111100;

    1826:

    1827:

    1828:

    1829: INTCON2.RBPU=0; //habilito resistencias pull up

    1830:

    1831: ciclo1 = 0; // initial value for current_duty

    1832:1833:

    1834: trisb=0b11110000; //entradas salidas

    1835: portb=0;

    1836: trisd.B0=0;

    1837: trisd.B1=0;

    1838: trisC.B0=0;

    1839: trisc.B4=1;

    1840: trisc.B5=1;

    1841: trisc.B1=0;

    1842: trisc.B2=0;

    1843: portd=0;

    1844: trise.b0=0;

    1845: trise.b1=0;

    1846: trise.b2=0;1847: trise.b3=0;

    1848: porte=0;

    1849: portc=0;

    1850:

    1851: I2C1_Init(100000); // initialize I2C communication

    1852:

    1853:

    1854: bandera=0;

    1855: bandera2=0;

    1856: cont2=1;

    1857: bandera3=0;

    1858: bandera4=0;

    1859: auxcont3=0;

    1860: auxcont2=0;

    1861: bandera5=0;

    1862:

    1863:

    1864:

    1865: eeprom1[0]=eeprom_read(50);

    1866: eeprom1[1]=eeprom_read(51);

    1867: eeprom1[2]=eeprom_read(52);

    1868: limsuptemp=(eeprom1[0]*100+eeprom1[1]*10+eeprom1[2])/10;

    mikroC PRO for PIC by mikroElektroik!36/52

  • 7/26/2019 Practica Micros

    37/52

    05/08/2015 18:36:23MyProject.c

    1869:

    1870: eeprom1[0]=eeprom_read(55);

    1871: eeprom1[1]=eeprom_read(56);

    1872: eeprom1[2]=eeprom_read(57);

    1873: liminftemp=(eeprom1[0]*100+eeprom1[1]*10+eeprom1[2])/10;

    1874:

    1875: eeprom1[0]=eeprom_read(60);

    1876: eeprom1[1]=eeprom_read(61);1877: eeprom1[2]=eeprom_read(62);

    1878: limsupcorr=(eeprom1[0]*100+eeprom1[1]*10+eeprom1[2])/100;

    1879:

    1880: eeprom1[0]=eeprom_read(65);

    1881: eeprom1[1]=eeprom_read(66);

    1882: eeprom1[2]=eeprom_read(67);

    1883: liminfcorr=(eeprom1[0]*100+eeprom1[1]*10+eeprom1[2])/100;

    1884:

    1885:

    1886: while(1)

    1887: {

    1888: Lcd_Cmd(_LCD_CLEAR); // Clear dimultiplicaciony

    1889: Lcd_Out(1,1,txt1); // escribo admin1890: Lcd_Out(2,1,txt3); // escribo user

    1891:

    1892:

    1893:

    1894: while(1) //choose admin or user

    1895: {

    1896:

    1897: teclado();

    1898:

    1899: if(txt5[0]==97) //admin

    1900: {

    1901: delay_ms(500);

    1902: cont1=7;

    1903: Lcd_Cmd(_LCD_CLEAR);1904: lcd_out(1,2,"ADIMINISTRADOR");

    1905: lcd_out(2,1,"CLAVE:");

    1906: numero();

    1907:

    1908: if(valor==claveadmin)

    1909: {

    1910: Lcd_Cmd(_LCD_CLEAR);

    1911: lcd_out(1,5,"CORRECTO");

    1912: bandera3=10;

    1913: delay_ms(1000);

    1914: break;

    1915: }

    1916: else

    1917: {

    1918: Lcd_Cmd(_LCD_CLEAR);

    1919: lcd_out(1,4,"INCORRECTO");

    1920: delay_ms(1000);

    1921: cont1=7;

    1922: bandera3=0;

    1923: break;

    1924:

    1925: }

    mikroC PRO for PIC by mikroElektroik!3#/52

  • 7/26/2019 Practica Micros

    38/52

    05/08/2015 18:36:23MyProject.c

    1926:

    1927: }

    1928:

    1929: if(txt5[0]==98) //user

    1930: {

    1931: bandera3=30;

    1932: delay_ms(500);

    1933: break;1934:

    1935: }

    1936: }

    1937:

    1938: while(1)

    1939: {

    1940: //admin

    1941: while(bandera3==10)

    1942: {

    1943: cont1=7;

    1944: Lcd_Cmd(_LCD_CLEAR);

    1945: lcd_out(1,4,"USUARIOS A");

    1946: lcd_out(2,1,"OPCION B VER C");1947: delay_ms(1000);

    1948: bandera3=0;

    1949: txt5[0]=0;

    1950:

    1951: while(1)

    1952: {

    1953:

    1954: teclado();

    1955:

    1956: if(txt5[0]==97) //usuarios

    1957: {

    1958: bandera3=11;

    1959: delay_ms(500);

    1960: break;1961: }

    1962:

    1963: if(txt5[0]==98) //opciones

    1964: {

    1965: bandera3=12;

    1966: delay_ms(500);

    1967: break;

    1968: }

    1969:

    1970: if(txt5[0]==99) //ver

    1971: {

    1972: bandera3=13;

    1973: delay_ms(500);

    1974: break;

    1975:

    1976: }

    1977:

    1978: if(txt5[0]==35) //regresar

    1979: {

    1980: bandera3=0;

    1981: delay_ms(500);

    1982: break;

    mikroC PRO for PIC by mikroElektroik!38/52

  • 7/26/2019 Practica Micros

    39/52

    05/08/2015 18:36:23MyProject.c

    1983:

    1984: }

    1985:

    1986: }

    1987:

    1988:

    1989:

    1990: while(bandera3==11) //usuarios1991: {

    1992:

    1993: Lcd_Cmd(_LCD_CLEAR);

    1994: lcd_out(1,5,"USUARIOS");

    1995: delay_ms(2000);

    1996: Lcd_Cmd(_LCD_CLEAR);

    1997: lcd_out(1,1,"NEW: A BORRAR: B");

    1998: lcd_out(2,4,"MODIFICAR C");

    1999: txt5[0]=0;

    2000: cont1=7;

    2001:

    2002: while(1)

    2003: {2004: teclado();

    2005:

    2006: if(txt5[0]==97)

    2007: {

    2008: bandera3=14; //nuevo usuario

    2009: delay_ms(500);

    2010: break;

    2011: }

    2012:

    2013: if(txt5[0]==98)

    2014: {

    2015: bandera3=15; //borrar usuario

    2016: delay_ms(500);

    2017: break;2018: }

    2019:

    2020: if(txt5[0]==99)

    2021: {

    2022: bandera3=16; //modificar usuario

    2023: delay_ms(500);

    2024: break;

    2025: }

    2026:

    2027: if(txt5[0]==35) //regresar

    2028: {

    2029: bandera3=10;

    2030: delay_ms(500);

    2031: break;

    2032: }

    2033:

    2034:

    2035: }

    2036:

    2037: while(bandera3==14) //nuevo usuario

    2038: {

    2039:

    mikroC PRO for PIC by mikroElektroik!3$/52

  • 7/26/2019 Practica Micros

    40/52

    05/08/2015 18:36:23MyProject.c

    2040: Lcd_Cmd(_LCD_CLEAR);

    2041: lcd_out(1,6,"NUEVO");

    2042: lcd_out(2,5,"USUARIO");

    2043: delay_ms(2000);

    2044: Lcd_Cmd(_LCD_CLEAR);

    2045: lcd_out(1,3,"# DE USUARIO");

    2046:

    2047: numero();2048:

    2049: if(valor>0 && valor

  • 7/26/2019 Practica Micros

    41/52

    05/08/2015 18:36:23MyProject.c

    2095: if(contusuario==4)

    2096: {

    2097: EEPROM_WRITE(14,eeprom1[0]);

    2098: EEPROM_WRITE(15,eeprom1[1]);

    2099: EEPROM_WRITE(16,eeprom1[2]);

    2100: EEPROM_WRITE(17,eeprom1[3]);

    2101: }

    2102:2103: if(contusuario==5)

    2104: {

    2105: EEPROM_WRITE(18,eeprom1[0]);

    2106: EEPROM_WRITE(19,eeprom1[1]);

    2107: EEPROM_WRITE(20,eeprom1[2]);

    2108: EEPROM_WRITE(21,eeprom1[3]);

    2109: }

    2110: if(contusuario0 && valor

  • 7/26/2019 Practica Micros

    42/52

    05/08/2015 18:36:23MyProject.c

    2152: EEPROM_WRITE(5,0);

    2153: }

    2154:

    2155: if(valor==2)

    2156: {

    2157: EEPROM_WRITE(6,0);

    2158: EEPROM_WRITE(7,0);

    2159: EEPROM_WRITE(8,0);2160: EEPROM_WRITE(9,0);

    2161: }

    2162:

    2163: if(valor==3)

    2164: {

    2165: EEPROM_WRITE(10,0);

    2166: EEPROM_WRITE(11,0);

    2167: EEPROM_WRITE(12,0);

    2168: EEPROM_WRITE(13,0);

    2169: }

    2170:

    2171: if(valor==4)

    2172: {2173: EEPROM_WRITE(14,0);

    2174: EEPROM_WRITE(15,0);

    2175: EEPROM_WRITE(16,0);

    2176: EEPROM_WRITE(17,0);

    2177: }

    2178:

    2179: if(valor==5)

    2180: {

    2181: EEPROM_WRITE(18,0);

    2182: EEPROM_WRITE(19,0);

    2183: EEPROM_WRITE(20,0);

    2184: EEPROM_WRITE(21,0);

    2185: }

    2186:2187:

    2188: Lcd_Cmd(_LCD_CLEAR);

    2189: lcd_out(1,5,"BORRADO");

    2190: delay_ms(2000);

    2191:

    2192: bandera3=11;

    2193: break;

    2194: }

    2195:

    2196: while(bandera3==16) //modificar usuario

    2197: {

    2198: Lcd_Cmd(_LCD_CLEAR);

    2199: lcd_out(1,4,"MODIFICAR");

    2200: lcd_out(2,5,"USUARIO");

    2201: delay_ms(2000);

    2202: Lcd_Cmd(_LCD_CLEAR);

    2203: lcd_out(1,3,"# DE USUARIO");

    2204:

    2205: numero();

    2206:

    2207: if(valor>0 && valor

  • 7/26/2019 Practica Micros

    43/52

    05/08/2015 18:36:23MyProject.c

    2209: contusuario=valor;

    2210: cont1=7;

    2211: }

    2212: else

    2213: {

    2214: Lcd_Cmd(_LCD_CLEAR);

    2215: lcd_out(1,4,"INCORRECTO");

    2216: delay_ms(2000);2217: bandera3=11;

    2218: break;

    2219: }

    2220: Lcd_Cmd(_LCD_CLEAR);

    2221: lcd_out(1,1,"NUEVA CLAVE: ");

    2222:

    2223: numero();

    2224: eeprom1[0]=valor/1000;

    2225: eeprom1[1]=(valor-eeprom1[0]*1000)/100;

    2226: eeprom1[2]=((valor-eeprom1[0]*1000)-(eeprom1[1]*100))/10

    ;

    2227: eeprom1[3]=(valor-eeprom1[0]*1000)-eeprom1[1]*100-eeprom

    1[2]*10;2228:

    2229: if(contusuario==1)

    2230: {

    2231: EEPROM_WRITE(2,eeprom1[0]);

    2232: EEPROM_WRITE(3,eeprom1[1]);

    2233: EEPROM_WRITE(4,eeprom1[2]);

    2234: EEPROM_WRITE(5,eeprom1[3]);

    2235: }

    2236:

    2237: if(contusuario==2)

    2238: {

    2239: EEPROM_WRITE(6,eeprom1[0]);

    2240: EEPROM_WRITE(7,eeprom1[1]);

    2241: EEPROM_WRITE(8,eeprom1[2]);2242: EEPROM_WRITE(9,eeprom1[3]);

    2243: }

    2244:

    2245: if(contusuario==3)

    2246: {

    2247: EEPROM_WRITE(10,eeprom1[0]);

    2248: EEPROM_WRITE(11,eeprom1[1]);

    2249: EEPROM_WRITE(12,eeprom1[2]);

    2250: EEPROM_WRITE(13,eeprom1[3]);

    2251: }

    2252:

    2253: if(contusuario==4)

    2254: {

    2255: EEPROM_WRITE(14,eeprom1[0]);

    2256: EEPROM_WRITE(15,eeprom1[1]);

    2257: EEPROM_WRITE(16,eeprom1[2]);

    2258: EEPROM_WRITE(17,eeprom1[3]);

    2259: }

    2260:

    2261: if(contusuario==5)

    2262: {

    2263: EEPROM_WRITE(18,eeprom1[0]);

    mikroC PRO for PIC by mikroElektroik!"3/52

  • 7/26/2019 Practica Micros

    44/52

    05/08/2015 18:36:23MyProject.c

    2264: EEPROM_WRITE(19,eeprom1[1]);

    2265: EEPROM_WRITE(20,eeprom1[2]);

    2266: EEPROM_WRITE(21,eeprom1[3]);

    2267: }

    2268: if(contusuario

  • 7/26/2019 Practica Micros

    45/52

    05/08/2015 18:36:23MyProject.c

    2321: lcd_out(1,6,"RELOJ");

    2322:

    2323: delay_ms(2000);

    2324: Lcd_Cmd(_LCD_CLEAR);

    2325: lcd_out(1,4,"AJUSTAR: A");

    2326: lcd_out(2,3,"VER RELOJ: B");

    2327:

    2328: while(1)2329: {

    2330:

    2331: teclado();

    2332:

    2333: if(txt5[0]==97) //Ajustar

    2334: {

    2335: bandera3=20;

    2336: delay_ms(500);

    2337: break;

    2338: }

    2339:

    2340: if(txt5[0]==98) //ver

    2341: {2342: bandera3=21;

    2343: delay_ms(500);

    2344: Lcd_Cmd(_LCD_CLEAR);

    2345: break;

    2346: }

    2347:

    2348: if(txt5[0]==35) //regresar

    2349: {

    2350: bandera3=12;

    2351: delay_ms(500);

    2352: break;

    2353:

    2354: }

    2355:2356:

    2357: }

    2358:

    2359: while(bandera3==20) //ajustar reloj

    2360: {

    2361:

    2362: Lcd_Cmd(_LCD_CLEAR);

    2363: lcd_out(1,5,"AJUSTAR");

    2364: delay_ms(2000);

    2365: cont1=7;

    2366:

    2367: Lcd_Cmd(_LCD_CLEAR);

    2368: lcd_out(1,5,"SEGUNDOS");

    2369: numero();

    2370:

    2371: if(valor>59)

    2372: {

    2373: Lcd_Cmd(_LCD_CLEAR);

    2374: lcd_out(1,4,"INCORRECTO");

    2375: delay_ms(2000);

    2376: bandera3=19;

    2377: break;

    mikroC PRO for PIC by mikroElektroik!"5/52

  • 7/26/2019 Practica Micros

    46/52

    05/08/2015 18:36:23MyProject.c

    2378: }

    2379: segundos = Dec2Bcd16(valor);

    2380:

    2381: cont1=7;

    2382: Lcd_Cmd(_LCD_CLEAR);

    2383: lcd_out(1,5,"MINUTOS");

    2384: numero();

    2385:2386: if(valor>59)

    2387: {

    2388: Lcd_Cmd(_LCD_CLEAR);

    2389: lcd_out(1,4,"INCORRECTO");

    2390: delay_ms(2000);

    2391: bandera3=19;

    2392: break;

    2393: }

    2394: minutos = Dec2Bcd16(valor);

    2395:

    2396: cont1=7;

    2397: Lcd_Cmd(_LCD_CLEAR);

    2398: lcd_out(1,6,"HORAS");2399: numero();

    2400:

    2401: if(valor>23)

    2402: {

    2403: Lcd_Cmd(_LCD_CLEAR);

    2404: lcd_out(1,4,"INCORRECTO");

    2405: delay_ms(2000);

    2406: bandera3=19;

    2407: break;

    2408: }

    2409: horas = Dec2Bcd16(valor);

    2410:

    2411: cont1=7;

    2412: Lcd_Cmd(_LCD_CLEAR);2413: lcd_out(1,1,"D=1,L=2,Mar=3...");

    2414: numero();

    2415:

    2416: if(valor>7)

    2417: {

    2418: Lcd_Cmd(_LCD_CLEAR);

    2419: lcd_out(1,4,"INCORRECTO");

    2420: delay_ms(2000);

    2421: bandera3=19;

    2422: break;

    2423: }

    2424: diaNombre = Dec2Bcd16(valor);

    2425:

    2426: cont1=7;

    2427: Lcd_Cmd(_LCD_CLEAR);

    2428: lcd_out(1,1,"Dia 1,2,3...");

    2429: numero();

    2430:

    2431: if(valor>31)

    2432: {

    2433: Lcd_Cmd(_LCD_CLEAR);

    2434: lcd_out(1,4,"INCORRECTO");

    mikroC PRO for PIC by mikroElektroik!"6/52

  • 7/26/2019 Practica Micros

    47/52

    05/08/2015 18:36:23MyProject.c

    2435: delay_ms(2000);

    2436: bandera3=19;

    2437: break;

    2438: }

    2439: dia = Dec2Bcd16(valor);

    2440:

    2441: cont1=7;

    2442: Lcd_Cmd(_LCD_CLEAR);2443: lcd_out(1,1,"Mes 1,2,3..");

    2444: numero();

    2445:

    2446: if(valor>12)

    2447: {

    2448: Lcd_Cmd(_LCD_CLEAR);

    2449: lcd_out(1,4,"INCORRECTO");;

    2450: delay_ms(2000);

    2451: bandera3=19;

    2452: break;

    2453: }

    2454: mes = Dec2Bcd16(valor);

    2455:2456: cont1=7;

    2457: Lcd_Cmd(_LCD_CLEAR);

    2458: lcd_out(1,1,"Anio");

    2459: numero();

    2460:

    2461: if(valor>99)

    2462: {

    2463: Lcd_Cmd(_LCD_CLEAR);

    2464: lcd_out(1,4,"INCORRECTO");

    2465: delay_ms(2000);

    2466: bandera3=19;

    2467: break;

    2468: }

    2469:2470: anio = Dec2Bcd16(valor);

    2471:

    2472: I2C1_Start(); // issue start signal

    2473: I2C1_Wr(0xD0); // address DS1307

    2474: I2C1_Wr(0); // start from word at address (REG

    0)

    2475: I2C1_Wr(segundos); // write $80 to REG0. (pause c

    ounter + 0 sec)

    2476: I2C1_Wr(minutos); // write 0 to minutes word t

    o (REG1)

    2477: I2C1_Wr(horas); // write 17 to hours word (24-hou

    rs mode)(REG2)

    2478: I2C1_Wr(diaNombre); // write 2 - Monday (REG3)

    2479: I2C1_Wr(dia); // write 4 to date word (REG4)

    2480: I2C1_Wr(mes); // write 5 (May) to month word (REG

    5)

    2481: I2C1_Wr(anio); // write 01 to year word (REG6)

    2482: I2C1_Stop(); // issue stop signal

    2483:

    2484: I2C1_Start(); // issue start signal

    2485: I2C1_Wr(0xD0); // address DS1307

    2486: I2C1_Wr(0); // start from word at address 0

    mikroC PRO for PIC by mikroElektroik!"#/52

  • 7/26/2019 Practica Micros

    48/52

    05/08/2015 18:36:23MyProject.c

    2487: I2C1_Wr(0); // write 0 to REG0 (enable countin

    g + 0 sec)

    2488: I2C1_Stop(); // issue stop signal

    2489:

    2490: Lcd_Cmd(_LCD_CLEAR);

    2491: lcd_out(1,1,reloj);

    2492: delay_ms(2000);

    2493: bandera3=19;2494: break;

    2495:

    2496: }

    2497:

    2498:

    2499: while(bandera3==21) //ver reloj

    2500: {

    2501: ver_reloj();

    2502:

    2503:

    2504: switch(diaNombre)

    2505: {

    2506: case1: txt="Sun"; break;2507: case2: txt="Mon"; break;

    2508: case3: txt="Tue"; break;

    2509: case4: txt="Wed"; break;

    2510: case5: txt="Thu"; break;

    2511: case6: txt="Fri"; break;

    2512: case7: txt="Sat"; break;

    2513: }

    2514: LCD_Out(1,1,txt);

    2515: Lcd_Chr(1, 6, (dia / 10) + 48); // Print tens digit

    of day variable

    2516: Lcd_Chr(1, 7, (dia % 10) + 48); // Print oness digit

    of day variable

    2517: Lcd_Chr(1, 9, (mes / 10) + 48);

    2518: Lcd_Chr(1,10, (mes % 10) + 48);2519: Lcd_Chr(1,12, (anio / 10) + 48); // Print year v

    aiable + 8 (start from year 2008)

    2520: Lcd_Chr(1,13, (anio % 10) + 48); // Print year v

    aiable + 8 (start from year 2008)

    2521: //shorttostr(anio,txtaux);

    2522: //Lcd_out(1,15, txtaux); // Print year vaiable

    + 8 (start from year 2008)

    2523:

    2524: Lcd_Chr(2, 6, (horas / 10) + 48);

    2525: Lcd_Chr(2, 7, (horas % 10) + 48);

    2526: Lcd_Chr(2, 9, (minutos / 10) + 48);

    2527: Lcd_Chr(2,10, (minutos % 10) + 48);

    2528: Lcd_Chr(2,12, (segundos / 10) + 48);

    2529: Lcd_Chr(2,13, (segundos % 10) + 48);

    2530:

    2531: teclado();

    2532: if(txt5[0]==35)

    2533: {

    2534: bandera3=19;

    2535: txt5[0]==0;

    2536: delay_ms(200);

    2537: break;

    mikroC PRO for PIC by mikroElektroik!"8/52

  • 7/26/2019 Practica Micros

    49/52

    05/08/2015 18:36:23MyProject.c

    2538: }

    2539: delay_ms(1000);

    2540:

    2541: }

    2542:

    2543: }

    2544:

    2545:2546: }

    2547:

    2548:

    2549: while(bandera3==13) //ver

    2550: {

    2551: delay_ms(300);

    2552: pasoadmin=1;

    2553: bandera3=30;

    2554: break;

    2555:

    2556: }

    2557:

    2558: if(bandera3==0) //regresar2559: {

    2560: break;

    2561: }

    2562:

    2563:

    2564: }

    2565:

    2566:

    2567:

    2568: //user

    2569: if(bandera3==30)

    2570: {

    2571: if(pasoadmin==0)

    2572: {2573: Lcd_Cmd(_LCD_CLEAR);

    2574: lcd_out(1,1,"USUARIO");

    2575: lcd_out(2,1,"CLAVE:");

    2576: cont1=7;

    2577: numero();

    2578: bandera4=0;

    2579: }

    2580: else

    2581: {

    2582: comprobacion=valor;

    2583: bandera4=5;

    2584: }

    2585:

    2586: if(bandera4!=5)

    2587: {

    2588: eeprom2[0]=eeprom_read(2);

    2589: eeprom2[1]=eeprom_read(3);

    2590: eeprom2[2]=eeprom_read(4);

    2591: eeprom2[3]=eeprom_read(5);

    2592:

    2593: comprobacion=eeprom2[0]*1000+eeprom2[1]*100+eeprom2[2]*10+eeprom2[3];

    mikroC PRO for PIC by mikroElektroik!"$/52

  • 7/26/2019 Practica Micros

    50/52

    05/08/2015 18:36:23MyProject.c

    2594:

    2595: if(comprobacion==valor)

    2596: {

    2597: contusuario=1;

    2598: bandera4=5;

    2599: }

    2600: }

    2601:2602: if(bandera4!=5)

    2603: {

    2604: eeprom2[0]=eeprom_read(6);

    2605: eeprom2[1]=eeprom_read(7);

    2606: eeprom2[2]=eeprom_read(8);

    2607: eeprom2[3]=eeprom_read(9);

    2608:

    2609: comprobacion=eeprom2[0]*1000+eeprom2[1]*100+eeprom2[2]*10+eeprom2[3];

    2610:

    2611: if(comprobacion==valor)

    2612: {

    2613: contusuario=2;

    2614: bandera4=5;2615: }

    2616: }

    2617:

    2618: if(bandera4!=5)

    2619: {

    2620: eeprom2[0]=eeprom_read(10);

    2621: eeprom2[1]=eeprom_read(11);

    2622: eeprom2[2]=eeprom_read(12);

    2623: eeprom2[3]=eeprom_read(13);

    2624:

    2625: comprobacion=eeprom2[0]*1000+eeprom2[1]*100+eeprom2[2]*10+eeprom2[3];

    2626:

    2627: if(comprobacion==valor)

    2628: {2629: contusuario=3;

    2630: bandera4=5;

    2631: }

    2632: }

    2633:

    2634: if(bandera4!=5)

    2635: {

    2636: eeprom2[0]=eeprom_read(14);

    2637: eeprom2[1]=eeprom_read(15);

    2638: eeprom2[2]=eeprom_read(16);

    2639: eeprom2[3]=eeprom_read(17);

    2640:

    2641: comprobacion=eeprom2[0]*1000+eeprom2[1]*100+eeprom2[2]*10+eeprom2[3];

    2642:

    2643: if(comprobacion==valor)

    2644: {

    2645: contusuario=4;

    2646: bandera4=5;

    2647: }

    mikroC PRO for PIC by mikroElektroik!50/52

  • 7/26/2019 Practica Micros

    51/52

    05/08/2015 18:36:23MyProject.c

    2648: }

    2649:

    2650: if(bandera4!=5)

    2651: {

    2652: eeprom2[0]=eeprom_read(18);

    2653: eeprom2[1]=eeprom_read(19);

    2654: eeprom2[2]=eeprom_read(20);

    2655: eeprom2[3]=eeprom_read(21);2656:

    2657: comprobacion=eeprom2[0]*1000+eeprom2[1]*100+eeprom2[2]*10+eeprom2[3];

    2658:

    2659: if(comprobacion==valor)

    2660: {

    2661: contusuario=5;

    2662: bandera4=5;

    2663: }

    2664: }

    2665:

    2666:

    2667: Lcd_Cmd(_LCD_CLEAR);

    2668:2669: if(comprobacion!=valor)

    2670: {

    2671: lcd_out(1,4,"INCORRECTO");

    2672: }

    2673: else

    2674: {

    2675: lcd_out(1,5,"CORRECTO");

    2676: if(pasoadmin==0)

    2677: {

    2678: lcd_out(2,1,"USUARIO");

    2679: shorttostr(contusuario,txtaux);

    2680: lcd_out(2,10,txtaux);

    2681:

    2682: }2683: else

    2684: {

    2685: lcd_out(2,1,"ADMINISTRADOR");

    2686: pasoadmin=0;

    2687: }

    2688: bandera3=31;

    2689: delay_ms(2000);

    2690: }

    2691:

    2692:

    2693: while(bandera3==31)

    2694: {

    2695: Lcd_Cmd(_LCD_CLEAR);

    2696: }

    2697:

    2698:

    2699: }

    2700:

    2701: if(bandera3==0)

    2702: {

    2703: break;

    mikroC PRO for PIC by mikroElektroik!51/52

  • 7/26/2019 Practica Micros

    52/52

    05/08/2015 18:36:23MyProject.c

    2704: }

    2705:

    2706: }

    2707: }