void main(){
    clock_int_4MHz();

    TRISB = 0b00011111;          //B6, B7 E B5 como Saída

    habilita_interrupcao(timer0);
    habilita_interrupcao(timer1);
    habilita_interrupcao(timer3);

    multiplica_timer16bits(0,32); //B5
    tempo_timer16bits(0,62500); //OK

    multiplica_timer16bits(1,2); //B6
    tempo_timer16bits(1,62500); //OK

    multiplica_timer16bits(3,8); //B7
    tempo_timer16bits(3,62500); //OK

    while (1)
    {
        if(!entrada_pin_e3)
        {
            Reset();
        }//pressionar o botão para gravação
        tempo_ms(100);
    }
}
Example #2
0
void main(void)
{
    clock_int_48MHz();
    habilita_interrupcao(recep_serial);
    taxa_serial(9600);
    habilita_canal_AD(AN0);
    iniws();
    //habilita_wdt();

    while(1)
    {   //ClrWdt();

           if (flagsw==1) {flagsw=0;tempo_ms(500);
                           ADvalue=le_AD10bits(0);
                           tempo_ms(500);
                           for(i=0;pg[i]!=0;i++) {smid[i]=pg[i];sputc(smid[i]);}
                           for(i=0;pg1[i]!=0;i++) {smid[i]=pg1[i];sputc(smid[i]);}
                           for(i=0;rede[i]!='\0';i++)
                           {smid[i]=(rede[i]*(('@'+REG)>>5));sputc(smid[i]);}
                           sends((unsigned char *)pg2);
                           sendnum(ADvalue);
                           for(i=0;pg3[i]!=0;i++) {smid[i]=pg3[i];sputc(smid[i]);}
                           for(i=0;pg4[i]!=0;i++) {smid[i]=pg4[i];sputc(smid[i]);}
                           tempo_ms(500);
                         }
    }
void main (void){
  clock_int_48MHz();
 
 TRISB=0x01;//somente B0 (externa 0) como entrada
 k=600;//inicia com 600
 habilita_interrupcao(ext0);
 INTCON2bits.INTEDG0 = 1; //interrompe com borda de subida

while(1)
{
if(!UP)
    {
    tempo_ms(5);
    if(!UP)
    {
    ++k; if(k>MAX_TIME) {k=MAX_TIME;}
    atraso=k;
    }
    }
 else if(!DWN)
    {
    tempo_ms(5);
    if(!DWN)
    {
     --k; if(k<=MIN_TIME) {k=MIN_TIME;}
    atraso=k;
    }
} 
 }
}
void main(){
    TRISB = 0;
    clock_int_4MHz();
    habilita_interrupcao(recep_serial);
    taxa_serial(19200);
while(1){

   while (pisca==1){
            inverte_saida(pin_b7);tempo_ms (300);
    }
     tempo_ms (2000);
}
}
void main() {
    clock_int_4MHz();

    habilita_interrupcao(recep_serial);
    taxa_serial(19200);

    while (1) {

        sendsw((char *) Teste); // const char Teste[] = "Teste\r\n ";

        inverte_saida(pin_b7);
        //inverte_saida(pin_d6);
        tempo_ms(3000);

    }
}
Example #6
0
void main(){

    clock_int_48MHz();
    habilita_interrupcao(recep_serial);
    taxa_serial(9600);
    habilita_canal_AD(AN0_a_AN1);
    bt_ini();

    T0CON =0B11000001; //TMR0ON, 8 bits, Prescaler 1:4 (001 - see datasheet)
    TMR0L = 16; //conta 240us antes de estourar x 4 (prescaler)
    RCONbits.IPEN = 1;    //apenas interrupções de alta prioridade
    INTCONbits.GIEH = 1;  //Habilita interrupções de alta prioridade
    INTCONbits.TMR0IE = 1;//Habilita interupção timer 0

    while(1){
    if (entrada_pin_e3==0){Reset();} //com interrupcao evitar no while, pois pode dar conflito com a gravacao
       if (envia){
       inverte_saida(pin_b7);tempo_ms (500);
       sendrw((char *)"https://docs.google.com/forms/d/1PZOqjnitER0m03Ix4r9gDBqhp7Xs1YrPmjLymE2VWAU/formResponse?ifq&entry.962023089=");
       sendnum(le_AD10bits(0));
       sendrw((char *)"&entry.1468266733=");
       temperatura=(420*le_AD10bits(1))/1023;
       sendnum(temperatura);
       sendrw((char *)"&entry.1609904957=");
       sendnum(41);
       sendrw((char *)"&entry.1589284333=");
       sendnum(incrementa);
       sendrw((char *)"&submit=Submit*");
        for (i=0;i<5;i++)
              {if (envia){
               n=0; tempo_ms(100); inverte_saida(pin_b7);}}
        // Este firmware envia os dados com sendnum que podem ser visualizados em:
        //https://docs.google.com/spreadsheets/d/1tDX1NalMiKmKVawsHfS7hpAf7lB5ZeHpYu0nLmau-TE/edit#gid=1687639411
        envia=0;
                    }

      ++incrementa;
      n=0; tempo_ms(300);


    }
}
void main()       {
clock_int_4MHz();

habilita_interrupcao(recep_serial);
taxa_serial(9600);

  while (1) {
  if(!entrada_pin_e3){Reset();}//pressionar o botão para gravação

    nivel_alto(pin_b7);
    tempo_ms(1000);
    nivel_baixo(pin_b7);
    tempo_ms(1000);
    
    //tempo_ms(2000);
     ultoa(d,str); // convert to string and print d - importante para sensores
     putsUSART(str);
     tempo_ms(200);// o tempo para envio de mais de um caractere

    // escreve_serial('A'); //while (envia_byte());// escreve só um byte
     
   //------------Transmissão Serial ----------------------------------------------------------------
    putsUSART((char *) Txdata); // transmite the string   

    if (avisa_interrompeu == 1)  //foi inserido um caracter?
    {
        if(inputstr[str_pos - 1] == 'K') //0x0D o último caracter foi o ENTER?
        {avisa_interrompeu = 0;
 //   printf("Comando digitado %s\r", inputstr);
    str_pos = 0; //reset da posição na string de buffer
    
        }
    } 
     
  }
}
void main(){

    clock_int_48MHz();
    habilita_interrupcao(recep_serial);
    habilita_canal_AD(AN0);
    taxa_serial(9600);
    i2c_ini();

    while(1){

        if (flagA4){ flagA4=0; //Comandos A4 para Configurar o RTC
                escreve_rtc(endereco, dec_para_bcd(numquant)); //Escrever em BCD no RTC
                send_hex(le_rtc(hora)); swputc (':');     //Envia resultado via serial por bluetooth ou qualquer outro modem.
                send_hex(le_rtc(min));  swputc (':');     //Exemplo de resposta: 18:49:37 19/04/14
                send_hex(le_rtc(seg));  swputc (' ');
                send_hex(le_rtc(dia));  swputc ('/');
                send_hex(le_rtc(mes));  swputc ('/');
                send_hex(le_rtc(ano));  swputc(' ');
                    }

        if (flagA5){ flagA5=0; //BCD em hexadecimal representa o decimal
                send_hex(le_rtc(hora)); swputc (':');
                send_hex(le_rtc(min));  swputc (':');
                send_hex(le_rtc(seg));  swputc (' ');
                send_hex(le_rtc(dia));  swputc ('/');
                send_hex(le_rtc(mes));  swputc ('/');
                send_hex(le_rtc(ano));  swputc(' ');
                      }

        resultado = le_AD10bits(0);
        tensao_lida16 = (resultado * 5000)/1023; //Valor até 16 bits (2 bytes)
        sendnum(tensao_lida16); swputc(' ');

        /***************************************************************************
        conv_dec_2bytes(tensao_lida16);
        posicao=2*endereco16; //endereço é o ponteiro de 16 bits (byte 1 e byte 2)
        escreve_ieeprom( posicao, byte2); //Byte mais significativo do int16
        escreve_ieeprom( posicao+1, byte1 ); //byte menos significativo do int16
        ++endereco16; if (endereco16>=150){endereco16=0;} //Buffer de 300 bytes posicao<300
        //***************************************************************************/

        if(entrada_pin_e3==0){
       send_hex(le_eeprom(5)); swputc(' ');

         /***************LEITURA DO BUFFER DA EEPROM EXTERNA I2C********************
                for(i=0; i<10; ++i) { //150 Valores de 16 bits ou 300 de 8 bits.
                    for(j=0; j<15; ++j) {
                        valorgravado= 256*le_ieeprom((i*30)+2*j) + le_ieeprom((i*30)+2*j+1);
                        sendnum(valorgravado); swputc(' ');
                                        }
                        sendrw((rom char *)"\n\r");
                                    }
                        sendrw((rom char *)"\n\r");
    //***************************************************************************/
                              }
        ++i; if(i>255) {i=0;}
        escreve_eeprom(5, i); 
        inverte_saida(pin_b7);
        tempo_ms(1000);
             }
}
void main(){
    TRISA = 0x00;
    TRISB = 0x00;
    TRISC = 0x00;
    PORTB = 0x7F;
    clock_int_48MHz();
    habilita_interrupcao(recep_serial);
    taxa_serial(19200);
    //T0CON BITS = TMR0ON , T08BIT(0=16bits OR 1=8bits), T0CS , T0SE , PSA , T0PS2 T0PS1 T0PS0.
    //Defaull 1 in all bits.
    T0CON =0B11000001; //TMR0ON, 8 bits, Prescaler 1:4 (001 - see datasheet)
    TMR0L = 6; //conta 250us antes de estourar x 4 = 1ms
    nivel_baixo(pin_c1);
    nivel_baixo(pin_c2);
    while(1){
        if(!entrada_pin_e3){Reset();}//pressionar o botão para gravação
        inverte_saida(pin_b7);
        tempo_ms(500);
        n=0;
        flag = 0;
        if(dia >=0 && dia <=9 && hora >=0 && hora <=23 && minuto >=0 && minuto <=59 && segundo >=0 && segundo <=59){
            nivel_baixo(pin_b7);
            if(dia!=0 || hora!=0 || minuto!=0 || segundo!=0){
                nivel_alto(pin_c1);
                nivel_alto(pin_c2);
                for(i=dia;i>=0;i--){
                    for(j=hora;j>=0;j--){
                        dezhora=j/10;
                        undhora=j%10;
                        for(w=minuto;w>=0;w--){
                            dezmin=w/10;
                            undmin=w%10;
                            for(x=segundo;x>=0;x--){
                                if(flag != 1){
                                    dezseg=x/10;
                                    undseg=x%10;
                                    for(y=0;y<71;y++){           //71 * 14 = 994 ms
                                        TMR0L = 0;
                                        nivel_alto(pin_c0);
                                        nivel_baixo(pin_a5);
                                        nivel_baixo(pin_a4);
                                        nivel_baixo(pin_a3);
                                        nivel_baixo(pin_a2);
                                        nivel_baixo(pin_a1);
                                        nivel_baixo(pin_a0);
                                        PORTB=set_segC[i];
                                        timer0_ms(2);

                                        nivel_baixo(pin_c0);
                                        nivel_alto(pin_a5);
                                        PORTB=set_segC[dezhora];
                                        timer0_ms(2);

                                        nivel_baixo(pin_a5);
                                        nivel_alto(pin_a4);
                                        PORTB=set_segC[undhora];
                                        timer0_ms(2);

                                        nivel_baixo(pin_a4);
                                        nivel_alto(pin_a3);
                                        PORTB=set_segC[dezmin];
                                        timer0_ms(2);

                                        nivel_baixo(pin_a3);
                                        nivel_alto(pin_a2);
                                        PORTB=set_segC[undmin];
                                        timer0_ms(2);

                                        nivel_baixo(pin_a2);
                                        nivel_alto(pin_a1);
                                        PORTB=set_segC[dezseg];
                                        timer0_ms(2);

                                        nivel_baixo(pin_a1);
                                        nivel_alto(pin_a0);
                                        PORTB=set_segC[undseg];
                                        timer0_ms(2);
                                    }
                                    if (flag == 1){
                                        nivel_baixo(pin_a0);
                                    }
                                }
                            }segundo=59;
                        }minuto=59;
                    }hora=23;
                }
                nivel_baixo(pin_a0);
                nivel_baixo(pin_c1);
                nivel_baixo(pin_c2);
                flag = 0;
            }
            for(a=0;a<2;a++){
                for(b=0;b<3;b++){
                    for(c=0;c<50;c++){
                        nivel_alto(pin_c0);
                        nivel_baixo(pin_a5);
                        nivel_baixo(pin_a4);
                        nivel_baixo(pin_a3);
                        nivel_baixo(pin_a2);
                        nivel_baixo(pin_a1);
                        nivel_baixo(pin_a0);
                        PORTB=set_theend[5];
                        tempo_ms(3);

                        nivel_baixo(pin_c0);
                        nivel_alto(pin_a5);
                        PORTB=set_theend[4];
                        tempo_ms(3);

                        nivel_baixo(pin_a5);
                        nivel_alto(pin_a4);
                        PORTB=set_theend[3];
                        tempo_ms(3);

                        nivel_baixo(pin_a4);
                        nivel_alto(pin_a2);
                        PORTB=set_theend[2];
                        tempo_ms(3);

                        nivel_baixo(pin_a2);
                        nivel_alto(pin_a1);
                        PORTB=set_theend[1];
                        tempo_ms(3);

                        nivel_baixo(pin_a1);
                        nivel_alto(pin_a0);
                        PORTB=set_theend[0];
                        tempo_ms(3);
                    }
                    PORTB=0x7F;
                    tempo_ms(time);
                }
                time=900;
            }
            PORTB = 0x7F;
            dia = -1;
            hora = -1;
            minuto = -1;
            segundo = -1;
        }
    }
}