Ir ao conteúdo

Posts recomendados

Postado

Bom dia. Estou iniciando em programação de microcontroladores, porém, estou com dificuldade em fazer um led piscar com microcontrolador PIC18F4520. 

Eu li o datasheet e coloquei os pinos como saída digital e desliguei os comparadores, estou escrevendo nos pinos com o registrador LAT, mas o led não pisca nem acende. Usei o analisador logico para ver o estado do pino mas ele não altera. Será que pode ser algum problema no hardware que eu montei na protoboard?

Segue as o código que eu escrevi e a imagem do hardware que eu montei.

 

Desde já agradecido. 

// CONFIG1H
#pragma config OSC = XT         // Oscillator Selection bits (HS oscillator)
#pragma config FCMEN = OFF      // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor disabled)
#pragma config IESO = OFF       // Internal/External Oscillator Switchover bit (Oscillator Switchover mode disabled)

// CONFIG2L
#pragma config PWRT = OFF       // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = SBORDIS  // Brown-out Reset Enable bits (Brown-out Reset enabled in hardware only (SBOREN is disabled))
#pragma config BORV = 3         // Brown Out Reset Voltage bits (Minimum setting)

// CONFIG2H
#pragma config WDT = OFF        // Watchdog Timer Enable bit (WDT disabled (control is placed on the SWDTEN bit))
#pragma config WDTPS = 32768    // Watchdog Timer Postscale Select bits (1:32768)

// CONFIG3H
#pragma config CCP2MX = PORTC   // CCP2 MUX bit (CCP2 input/output is multiplexed with RC1)
#pragma config PBADEN = ON      // PORTB A/D Enable bit (PORTB<4:0> pins are configured as analog input channels on Reset)
#pragma config LPT1OSC = OFF    // Low-Power Timer1 Oscillator Enable bit (Timer1 configured for higher power operation)
#pragma config MCLRE = ON      // MCLR Pin Enable bit (RE3 input pin enabled; MCLR disabled)

// CONFIG4L
#pragma config STVREN = ON      // Stack Full/Underflow Reset Enable bit (Stack full/underflow will cause Reset)
#pragma config LVP = ON         // Single-Supply ICSP Enable bit (Single-Supply ICSP enabled)
#pragma config XINST = OFF      // Extended Instruction Set Enable bit (Instruction set extension and Indexed Addressing mode disabled (Legacy mode))

// CONFIG5L
#pragma config CP0 = OFF        // Code Protection bit (Block 0 (000800-001FFFh) not code-protected)
#pragma config CP1 = OFF        // Code Protection bit (Block 1 (002000-003FFFh) not code-protected)
#pragma config CP2 = OFF        // Code Protection bit (Block 2 (004000-005FFFh) not code-protected)
#pragma config CP3 = OFF        // Code Protection bit (Block 3 (006000-007FFFh) not code-protected)

// CONFIG5H
#pragma config CPB = OFF        // Boot Block Code Protection bit (Boot block (000000-0007FFh) not code-protected)
#pragma config CPD = OFF        // Data EEPROM Code Protection bit (Data EEPROM not code-protected)

// CONFIG6L
#pragma config WRT0 = OFF       // Write Protection bit (Block 0 (000800-001FFFh) not write-protected)
#pragma config WRT1 = OFF       // Write Protection bit (Block 1 (002000-003FFFh) not write-protected)
#pragma config WRT2 = OFF       // Write Protection bit (Block 2 (004000-005FFFh) not write-protected)
#pragma config WRT3 = OFF       // Write Protection bit (Block 3 (006000-007FFFh) not write-protected)

// CONFIG6H
#pragma config WRTC = OFF       // Configuration Register Write Protection bit (Configuration registers (300000-3000FFh) not write-protected)
#pragma config WRTB = OFF       // Boot Block Write Protection bit (Boot block (000000-0007FFh) not write-protected)
#pragma config WRTD = OFF       // Data EEPROM Write Protection bit (Data EEPROM not write-protected)

// CONFIG7L
#pragma config EBTR0 = OFF      // Table Read Protection bit (Block 0 (000800-001FFFh) not protected from table reads executed in other blocks)
#pragma config EBTR1 = OFF      // Table Read Protection bit (Block 1 (002000-003FFFh) not protected from table reads executed in other blocks)
#pragma config EBTR2 = OFF      // Table Read Protection bit (Block 2 (004000-005FFFh) not protected from table reads executed in other blocks)
#pragma config EBTR3 = OFF      // Table Read Protection bit (Block 3 (006000-007FFFh) not protected from table reads executed in other blocks)

// CONFIG7H
#pragma config EBTRB = OFF      // Boot Block Table Read Protection bit (Boot block (000000-0007FFh) not protected from table reads executed in other blocks)

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.



#define _XTAL_FREQ 4000000
#include <xc.h>
#include <pic18f4520.h>

void setPort(void);
void togglePort(void);

void main(void) {
    
    int i = 0;
    int j = 0;
    
    setPort();
   
    while(1)
    {
        LATAbits.LATA0 = 0x00; 
        for(i = 0; i < 100; i++)
        {
            for(j = 0; j < 200; j++)
            {
                
            }
        }
        LATAbits.LATA0 = 0x01;
        for(i = 0; i < 100; i++)
        {
            for(j = 0; j < 200; j++)
            {
                
            }
        }
    }
    return;
}

void setPort(void)
{
    ADCON1 = 0xFF; // Configura os pinos como entrada digital 
    CMCON = 0x07;  // Desliga os comparadores
    TRISAbits.TRISA0 = 0x00; // Configura os pinos como saída
}

Este é o hardware que estou montando, os capacitores são de 15pF, oscilador de 4 Mhz e a fonte é um carregador de celular. Tem alguma coisa errada?1120992311_WhatsAppImage2020-06-20at10_17_14AM.thumb.jpeg.5f7b891e9e5af2cc0aaa4b00d947672d.jpeg

  • Membro VIP
Postado

-verifique vcc

-Ve se o led está no pino certo, no seu caso deve ser RA0, certo?

-este negócio de lat nunca usei. Tenta direto no pino algo como RA0^=1 ou PORTABits.BIT0^=1;... consulte compilador

-verifique se RA0 não trabalha só como entrada. Na dúvida, pisque o port todo PORTA^=0xff; e troque o led de pino

-troque de port ou pisque tudo...PORTB^=0xff... PORTE^=0xff;

-Coloque reset por fora. Rpullup + C pro gnd e remova o que vem do programador

-você configura como xt mas se o cristal for 40MHz tem que ser hs. Confira no datasheet... ah ... é 4Mhz... ok. Teste com intosc

-capacitor de desacoplamento lhe cai bem

  • 2 semanas depois...

Crie uma conta ou entre para comentar

Você precisa ser um usuário para fazer um comentário

Criar uma conta

Crie uma nova conta em nossa comunidade. É fácil!

Crie uma nova conta

Entrar

Já tem uma conta? Faça o login.

Entrar agora

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...

LANÇAMENTO!

eletronica2025-popup.jpg


CLIQUE AQUI E BAIXE AGORA MESMO!