piero55:
Sto lavorando ad un piccolo progetto con il 16F819. Vorrei usare il PORTA.5 come ingresso digitale per un pulsante ma non riesco. Ho verificato che il registro PORTA relativo al bit 5, non varia alla pressione del pulsante che mette a massa l'ingresso. Ovviamente, essendo il pin il MCLR, dalla configuration word ho impostato MCLR_OFF quindi il pin dovrebbe essere un ingresso digitale.... ma non va.... Ho provato anche a scrivere un piccolissimo programma di 10 righe che sente il pulsante sul PORTA.5 e accende/spegne un led ma nulla da fare. Qualche suggerimento?
/*
* File: main.c
* Author: Utente
*
* Created on 21 gennaio 2023, 18.08
*/
#define _XTAL_FREQ 4000000UL
#include <stdio.h>
#include <stdlib.h>
// 'C' source line config statements
// CONFIG
#pragma config FOSC = XT // Oscillator Selection bits (XT oscillator)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = ON // 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 I/O, MCLR internally tied to VDD)
#pragma config BOREN = ON // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = OFF // Low-Voltage Programming Enable bit (RB3/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 (Code protection off)
#pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off)
#pragma config CCPMX = RB2 // CCP1 Pin Selection bit (CCP1 function on RB2)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
#define IN PORTAbits.RA5
#include <xc.h>
/*
*
*/
void main() {
ADCON1=6;
TRISAbits.TRISA5=1;
TRISB=0x00;
PORTB=0;
while(1){
if (PORTAbits.RA5==0){
__delay_ms(5);
PORTBbits.RB0=1;
}else{
PORTBbits.RB0=0;
}
}
}