Soy novato en la programación C en un microcontrolador pic. Me estoy abriendo paso lentamente a través de los diversos tutoriales y la literatura disponible para tratar de aplicar mis conocimientos.
Actualmente estoy tratando de hacer parpadear un LED con el pic16f1619 usando el tablero de curiosidad usando MPLAB IDE X, específicamente el pin A5.
Mi código es el siguiente:
#include <xc.h>
#include <stdlib.h>
#include <stdio.h>
#define _XTAL_FREQ 32000000 //internal oscillator of pic16f1619 is 32MHz
// Above is header files - xc is for compiler, stdlib is for general function and stdio is for I/O
// Below is the bit configuration - this is taken from the curiosity mcc generated bit configuration
// CONFIG1
#pragma config FOSC = INTOSC // Oscillator Selection Bits (INTOSC oscillator: I/O function on CLKIN pin)
#pragma config PWRTE = OFF // Power-up Timer Enable (PWRT disabled)
#pragma config MCLRE = ON // MCLR Pin Function Select (MCLR/VPP pin function is MCLR)
#pragma config CP = OFF // Flash Program Memory Code Protection (Program memory code protection is disabled)
#pragma config BOREN = ON // Brown-out Reset Enable (Brown-out Reset enabled)
#pragma config CLKOUTEN = OFF // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin)
#pragma config IESO = ON // Internal/External Switch Over (Internal External Switch Over mode is enabled)
#pragma config FCMEN = ON // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is enabled)
// CONFIG2
#pragma config WRT = OFF // Flash Memory Self-Write Protection (Write protection off)
#pragma config PPS1WAY = ON // Peripheral Pin Select one-way control (The PPSLOCK bit cannot be cleared once it is set by software)
#pragma config ZCD = OFF // Zero Cross Detect Disable Bit (ZCD disable. ZCD can be enabled by setting the ZCDSEN bit of ZCDCON)
#pragma config PLLEN = ON // PLL Enable Bit (4x PLL is always enabled)
#pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset)
#pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)
#pragma config LPBOR = OFF // Low-Power Brown Out Reset (Low-Power BOR is disabled)
#pragma config LVP = ON // Low-Voltage Programming Enable (Low-voltage programming enabled)
// CONFIG3
#pragma config WDTCPS = WDTCPS1F// WDT Period Select (Software Control (WDTPS))
#pragma config WDTE = OFF // Watchdog Timer Enable (WDT disabled)
#pragma config WDTCWS = WDTCWSSW// WDT Window Select (Software WDT window size control (WDTWS bits))
#pragma config WDTCCS = SWC // WDT Input Clock Selector (Software control, controlled by WDTCS bits)
void main(void) {
TRISAbits.TRISA5= 0; // set pin as output
LATAbits.LATA5 = 1; //set pin as high
while(1)
{
LATAbits.LATA5 = 1; //set pin as high
__delay_ms(1000); //delay of 1second
LATAbits.LATA5 = 0; //set pin as high
}
}
Por el momento no hay efecto en la salida del pin A5. He intentado cambiar la función del pin con los diferentes registros. ¡Cualquier ayuda sería muy apreciada! Soy consciente de este código - LATAbits.LATA5=~ LATAbits.LATA5; // Alternar bit del puerto A5
¡Cualquier ayuda sería muy apreciada ya que estoy realmente atascado!
while(1) {
LATAbits.LATA5 = 1; //set pin as high
__delay_ms(1000); //delay of 1second
LATAbits.LATA5 = 0; //set pin as low
}
No dejas que el LED permanezca apagado el tiempo suficiente para que se note. Llevas el pin bajo en la última línea del while
ciclo. Tan pronto como eso sucede, la ejecución vuelve a la parte superior del bucle. Inmediatamente, enciendes el LED. Si puede mirar la salida digital con un osciloscopio, debería ver una caída muy breve con una duración del orden de un microsegundo. Es demasiado breve para que un ojo lo note. Así que agregue otro retraso.
while(1) {
LATAbits.LATA5 = 1; //set pin as high
__delay_ms(1000); //delay of 1second
LATAbits.LATA5 = 0; //set pin as low
__delay_ms(1000); // <-
}
pd Este es un error popular en "Hello Blinky LED!" programas
tubo