Ir ao conteúdo
  • Cadastre-se

Gregorio Leão

Membro Pleno
  • Posts

    28
  • Cadastrado em

  • Última visita

Reputação

4
  1. @.if Aquele quadradinho parece o caractere de final de string, '\0'. Creio que eu esteja certo porque já tentei aumentar um laço de repetição de maior no laço for onde ocorre a leitura da string. Mas eu gostaria de saber porque sempre há um caractere perdido no meio da transmissão?
  2. Estou tentando fazer um código para ler um string e retorná-la pela UART do PIC16F887. Entretanto, o microcontrolador não retorna a string de forma correta. Estou utilizando o Arduino como intermediário para poder exibir o resultado no monitor serial da IDE Arduino. Codigo do PIC16F887: /* * File: ESP-01.c * Author: Gregorio Leão * * Created on 23 de Dezembro de 2021, 15:54 */ // PIC16F887 Configuration Bit Settings // 'C' source line config statements // CONFIG1 #pragma config FOSC = HS // Oscillator Selection bits (LP oscillator: Low-power crystal on RA6/OSC2/CLKOUT and RA7/OSC1/CLKIN) #pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled and can be enabled by SWDTEN bit of the WDTCON register) #pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled) #pragma config MCLRE = OFF // RE3/MCLR pin function select bit (RE3/MCLR pin function is digital input, MCLR internally tied to VDD) #pragma config CP = OFF // Code Protection bit (Program memory code protection is disabled) #pragma config CPD = OFF // Data Code Protection bit (Data memory code protection is disabled) #pragma config BOREN = OFF // Brown Out Reset Selection bits (BOR disabled) #pragma config IESO = OFF // Internal External Switchover bit (Internal/External Switchover mode is disabled) #pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enabled bit (Fail-Safe Clock Monitor is disabled) #pragma config LVP = OFF // Low Voltage Programming Enable bit (RB3 pin has digital I/O, HV on MCLR must be used for programming) // CONFIG2 #pragma config BOR4V = BOR40V // Brown-out Reset Selection bit (Brown-out Reset set to 4.0V) #pragma config WRT = OFF // Flash Program Memory Self Write Enable bits (Write protection off) // #pragma config statements should precede project file includes. // Use project enums instead of #define for ON and OFF. #include <xc.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #define _XTAL_FREQ 20000000 void Inicia_RS232(){ SPBRG = 129; TXSTAbits.BRGH= 1; BAUDCTLbits.BRG16 = 0; TXSTAbits.SYNC = 0; RCSTAbits.SPEN = 1; INTCONbits.GIE = 1; INTCONbits.PEIE = 1; PIE1bits.TXIE = 1; PIE1bits.RCIE = 1; TXSTAbits.TXEN = 1; RCSTAbits.CREN = 1; } void Escreve_RS232(char dado){ while(!PIR1bits.TXIF); TXREG = dado; } char Le_RS232(){ while(!PIR1bits.RCIF); if(RCSTAbits.OERR){ RCSTAbits.CREN = 0; RCSTAbits.CREN = 1; } return RCREG; } void EscrevePalavra_RS232(char dados[]){ for(int i = 0; i < strlen(dados); i++){ Escreve_RS232(dados[i]); } } void Verifica_Funcionamento(){ char AT[] = "AT"; int guia = 0; char *verificacao = NULL; char *aux; char recebido[10]; do{ if(guia == 9){ for(int i = 0; i < 10; i++){ recebido[i] = 0; } } __delay_ms(1000); EscrevePalavra_RS232(AT); if(guia == 9){ guia = 0; } if(!BAUDCTLbits.RCIDL){ recebido[guia] = Le_RS232(); guia++; } Escreve_RS232('\n'); EscrevePalavra_RS232(recebido); Escreve_RS232('\n'); aux = recebido; verificacao = strstr(aux, "OK"); }while(verificacao == NULL); } void Zera_Palavra(char dado[], int TAM){ for(int i = 0; i < TAM; i++){ dado[i] = 0; } } void LePalavra_RS232(char dado[], int tamanho){ int i; for(i = 0; i < tamanho; i++){ dado[i] = Le_RS232(); } } void main(){ Inicia_RS232(); TRISDbits.TRISD2 = 0; PORTDbits.RD2 = 0; char letra; char recebido[8]; while(1){ Zera_Palavra(&recebido, 8); LePalavra_RS232(&recebido, 8); __delay_ms(1000); EscrevePalavra_RS232(recebido); Escreve_RS232('\n'); } } Codigo carregado no Arduino que estou utilizando de intermediário para usufruir de recursos de sua IDE: #include "SoftwareSerial.h" SoftwareSerial ESP_Serial(5, 11); // RX, TX void setup(){ Serial.begin(9600); ESP_Serial.begin(9600); } void loop(){ if (ESP_Serial.available()){ Serial.write(ESP_Serial.read()); } if (Serial.available()){ ESP_Serial.write(Serial.read()); } } Resultado obtido após enviar a palavra "gregorio" para o PIC:
  3. @.if O PWM do PIC funcionou, o problema estava em não ter um atraso entre um ciclo e outro, fazendo com que o microcontrolador tentasse executar todos os duty cicles de uma só vez. Muito obrigado pela ajuda.
  4. Ola, o PWM do meu pic16f887 não está funcionando. Codigo: /* * File: PWM.c * Author: Gregorio Leão * * Created on 12 de Janeiro de 2022, 23:36 */ // PIC16F887 Configuration Bit Settings // 'C' source line config statements // CONFIG1 #pragma config FOSC = HS // Oscillator Selection bits (HS oscillator: High-speed crystal/resonator on RA6/OSC2/CLKOUT and RA7/OSC1/CLKIN) #pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled and can be enabled by SWDTEN bit of the WDTCON register) #pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled) #pragma config MCLRE = OFF // RE3/MCLR pin function select bit (RE3/MCLR pin function is digital input, MCLR internally tied to VDD) #pragma config CP = OFF // Code Protection bit (Program memory code protection is disabled) #pragma config CPD = OFF // Data Code Protection bit (Data memory code protection is disabled) #pragma config BOREN = OFF // Brown Out Reset Selection bits (BOR disabled) #pragma config IESO = OFF // Internal External Switchover bit (Internal/External Switchover mode is disabled) #pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enabled bit (Fail-Safe Clock Monitor is disabled) #pragma config LVP = OFF // Low Voltage Programming Enable bit (RB3 pin has digital I/O, HV on MCLR must be used for programming) // CONFIG2 #pragma config BOR4V = BOR40V // Brown-out Reset Selection bit (Brown-out Reset set to 4.0V) #pragma config WRT = OFF // Flash Program Memory Self Write Enable bits (Write protection off) // #pragma config statements should precede project file includes. // Use project enums instead of #define for ON and OFF. #include <xc.h> #include <stdio.h> #include <stdlib.h> #define _XTAL_FREQ 20000000 void Inicia_PWM(){ INTCONbits.GIE = 1; INTCONbits.PEIE = 1; PIE1bits.TMR2IE = 1; TRISCbits.TRISC2 = 1; PR2 = 255; CCP1CONbits.CCP1M0 = 0; CCP1CONbits.CCP1M1 = 0; CCP1CONbits.CCP1M3 = 1; CCP1CONbits.CCP1M2 = 1; CCP1CONbits.P1M0 = 0; CCP1CONbits.P1M1 = 0; CCP1CONbits.DC1B0 = 0; CCP1CONbits.DC1B1 = 0; CCPR1L = 0x0; PIR1bits.TMR2IF = 0; T2CONbits.T2CKPS0 = 0; T2CONbits.T2CKPS1 = 0; T2CONbits.TMR2ON = 1; while(!PIR1bits.TMR2IF); TRISCbits.TRISC2 = 0; PIR1bits.TMR2IF = 0; } void Gera_PWM(int DutyCicle){ CCPR1L = DutyCicle >> 2; CCP1CONbits.DC1B1 = DutyCicle >> 1; CCP1CONbits.DC1B0 = DutyCicle; } void Blink(){ TRISDbits.TRISD2 = 0; while(1){ PORTDbits.RD2 = 1; __delay_ms(1000); PORTDbits.RD2 = 0; __delay_ms(1000); } } void main(void) { Inicia_PWM(); while(1){ for(int i = 0; i < 1023; i++){ Gera_PWM(i); } } } Estou seguindo o que informa o datasheet do produto, entretanto, mesmo assim, não funciona. Gostaria de ajuda.
  5. @vtrx Eu corrigi isso, mas mesmo assim obrigado pela resposta.
  6. @.if Obrigado, vou ver se acho algo pesquisando
  7. Tenho um ESP-01 conectado a um arduino uno e por meio do monitor serial, atuando junto a um código carregado na placa, estou mandando comandos AT ao ESP. No entanto, ao mandar comandos que suas respectivas respostas são muito grandes, como os comandos AT+CIFSR e AT+GMR, o ESP responde com símbolos. Código carregado no Arduino: /******************************************************************************* * RoboCore - ESP8266 Primeiros Passos com Arduino * Codigo utilizado para enviar comandos AT atraves do monitor serial da Arduino * IDE. *******************************************************************************/ #include "SoftwareSerial.h" SoftwareSerial ESP_Serial(10, 6); // RX, TX void setup(){ Serial.begin(9600); ESP_Serial.begin(115200); } void loop(){ if (ESP_Serial.available()){ Serial.write(ESP_Serial.read()); } if (Serial.available()){ ESP_Serial.write(Serial.read()); } } O erro: Desde já grato pela colaboração.
  8. @Ricardov O problema foi resolvido, mas ainda assim é estranho visto que, até ontem, o executável gerado a partir do código C rodava normalmente. O problema começou ontem a noite, após eu compilar, pelo terminal, um código de um servidor socket em C. Fiz o código como informado a página da Microsoft sobre o winsock. Teria algum vínculo entre o problema e o procedimento que eu realizei?
  9. Olá a todos, estou com problemas para rodar um arquivo .exe. Compilo um código em C no vs code, o programa executa no terminal da própria IDE, mas se tento rodar o executável gerado, ele abre e fecha instantaneamente. Desde já grato.
  10. Olá a todos, estou tentando fazer uma comunicação serial através do modulo I²C do microcontrolador PIC16f887. Rodei o cogido sem erros e sem warnings, mas o microcontrolador não faz nada. Testei o circuito no real e no Proteus. Código: // CONFIG1 #pragma config FOSC = HS // Oscillator Selection bits (HS oscillator: High-speed crystal/resonator on RA6/OSC2/CLKOUT and RA7/OSC1/CLKIN) #pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled and can be enabled by SWDTEN bit of the WDTCON register) #pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled) #pragma config MCLRE = OFF // RE3/MCLR pin function select bit (RE3/MCLR pin function is digital input, MCLR internally tied to VDD) #pragma config CP = OFF // Code Protection bit (Program memory code protection is disabled) #pragma config CPD = OFF // Data Code Protection bit (Data memory code protection is disabled) #pragma config BOREN = OFF // Brown Out Reset Selection bits (BOR disabled) #pragma config IESO = OFF // Internal External Switchover bit (Internal/External Switchover mode is disabled) #pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enabled bit (Fail-Safe Clock Monitor is disabled) #pragma config LVP = OFF // Low Voltage Programming Enable bit (RB3 pin has digital I/O, HV on MCLR must be used for programming) // CONFIG2 #pragma config BOR4V = BOR40V // Brown-out Reset Selection bit (Brown-out Reset set to 4.0V) #pragma config WRT = OFF // Flash Program Memory Self Write Enable bits (Write protection off) // #pragma config statements should precede project file includes. // Use project enums instead of #define for ON and OFF. #include <xc.h> #include <stdio.h> #include <stdlib.h> #include <pic16f887.h> //Testei sem essa biblioteca #define _XTAL_FREQ 20000000 void Inicia (const unsigned long feq_K){ TRISC3 = 1; // Configurando como entrada conforme fornecido na ficha TRISC4 = 1; // Configurando como entrada conforme fornecido na ficha SSPCON = 0b00101000; SSPCON2 = 0; SSPADD = (_XTAL_FREQ / (4 * feq_K * 100)) - 1; //Testei essa parte colocando o numero decimal direto, sem a equação SSPSTAT = 0b10000000; } void Espera(){ PIR1bits.SSPIF = 0; while(PIR1bits.SSPIF); } void Condicao_de_Inicio(){ Espera(); SSPCON2bits.SEN = 1; } void Condicao_de_Reinicio(){ Espera(); SSPCON2bits.RSEN = 1; } void Condicao_de_Parada(){ Espera(); SSPCON2bits.PEN = 1; } void Transmite(unsigned byte){ Espera(); SSPBUF = byte; } void Pisca_LED(){ TRISDbits.TRISD0 = 0; while(1){ PORTDbits.RD0 = 0; __delay_ms(1000); PORTDbits.RD0 = 1; __delay_ms(1000); } } void main(){ Inicia(100); INTCONbits.GIE = 1; INTCONbits.PEIE = 1; PIE1bits.SSPIE = 1; Pisca_LED(); while(1){ Condicao_de_Inicio(); Transmite(0xD0); Transmite(0x88); Transmite(0xFF); Condicao_de_Parada(); __delay_ms(1000); } }
  11. Como eu configuro isso no MPLAB? obs: Estou usando o compilador XC8
  12. Olá, estou tendo um problema com a energia do meu ci, o código compila e tudo mais, o problema é que o PIC informa que o programador, PicKit 3 no caso, não está dectando uma tensão, que o dispositivo alvo não consegue ser detectado... basicamente isso. Gostaria de alguma ajuda, sugestões, qualquer coisa do tipo. Desde já, grato!
  13. @.if Acho que o problema todo é, no caso se eu estivesse utilizando a função, é a sintaxe que deve estar errada. Na verdade coloquei pull-down externo no botão, funcionou kkkk Agora vou voltar para o meu projeto e verificar se há algum problema com a UART, assim que eu acabar ou se eu tiver alguma duvida posto aqui. Seria legal, mesmo depois que eu acabar o projeto, postar aqui, quem sabe alguem me da uma dica para melhorar o codigo kkkk
  14. @.if eu fiz o que você recomendou, tirei a interrupção do loop e funcionou. Tambem desabilitei as resistencias pull-up da PORTB e setei a porta RB0/INT como entrada. Exclui a função de interrupção e usei o codigo na função principal. funcionou o codigo: #pragma config FOSC = INTOSCIO // Oscillator Selection bits (INTOSC oscillator: I/O function on RA6/OSC2/CLKOUT pin, I/O function on RA7/OSC1/CLKIN) #pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled) #pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled) #pragma config MCLRE = OFF // RA5/MCLR/VPP Pin Function Select bit (RA5/MCLR/VPP pin function is digital input, MCLR internally tied to VDD) #pragma config BOREN = OFF // Brown-out Detect Enable bit (BOD disabled) #pragma config LVP = OFF // Low-Voltage Programming Enable bit (RB4/PGM pin has digital I/O function, HV on MCLR must be used for programming) #pragma config CPD = OFF // Data EE Memory Code Protection bit (Data memory code protection off) #pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off) #define _XTAL_FREQ 4000000 #include <xc.h> #include <stdio.h> #include <stdlib.h> void Basic_Configurators(void){ CMCON = 0x07; TRISAbits.TRISA2 = 0; TRISBbits.TRISB0 = 1; } void Init_Interrupt(void){ INTCONbits.GIE = 1; //habilita todas as interrupções INTCONbits.PEIE = 0; //habilita interrupção periférica INTCONbits.INTE = 1; //habilita interrupção externa INTCONbits.INTF = 0; //limpa o sinalizador de interrupção externa OPTION_REGbits.INTEDG = 1; //borda de subida, transição de '0' para '1' configura uma interrupção INTCONbits.T0IF = 0; // desabilita sinalizador de interrrupção Overflow INTCONbits.RBIF = 0; // desabilita sinalizador de interrupção por alteração na porta B OPTION_REGbits.nRBPU = 1; //desabilita resistencia pull-up do PORTB } void main(void) { Basic_Configurators(); Init_Interrupt(); if(INTCONbits.INTF == 1){ PORTAbits.RA2 = 1; __delay_ms(1000); PORTAbits.RA2 = 0; __delay_ms(100); INTCONbits.INTF = 0; } }

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...