PIC: 16F887 a 4Mhz
Solo simulacion: con ISIS 7.10
XC8 v1.12 y MPLABX v1.80
A pesar que el datasheet dice que no es necesario ajustar el registro ANSELH para usar el puerto B como salida...
3.4.1 ANSELH REGISTER
The ANSELH register (Register 3-4) is used to
configure the Input mode of an I/O pin to analog.
Setting the appropriate ANSELH bit high will cause all
digital reads on the pin to be read as ‘0’ and allow
analog functions on the pin to operate correctly.
The state of the ANSELH bits has no affect on digital
output functions. A pin with TRIS clear and ANSELH
set will still operate as a digital output, but the Input
mode will be analog. This can cause unexpected
behavior when executing read-modify-write
instructions on the affected port.
Ha sido necesario ponerlo a 0 para que el siguiente programa corra como debe en la simulacion:
#include <xc.h>
#define _XTAL_FREQ 4000000
// PIC16F887 Configuration Bit Settings
// CONFIG1
#pragma config FOSC = XT // 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 = ON // Power-up Timer Enable bit (PWRT enabled)
#pragma config MCLRE = ON // RE3/MCLR pin function select bit (RE3/MCLR pin function is MCLR)
#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 = ON // Internal External Switchover bit (Internal/External Switchover mode is enabled)
#pragma config FCMEN = ON // Fail-Safe Clock Monitor Enabled bit (Fail-Safe Clock Monitor is enabled)
#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)
void main(void)
{
ANSELH = 0; //si comentan esto RB5 nunca prende.
PORTB = 0;
TRISB = 0;
while (1)
{
RB5 = 1;
RB7 = 1;
__delay_ms(2000);
RB5 = 0;
RB7 = 0;
__delay_ms(1000);
}
}
El problema cuando no esta borrado ANSELH es que hace que al ejecutarse RB7=1, este apage al RB5 y por eso nunca lo deja prender.
Talvez sea por que es simulacion o por que no entiendo bien el ingles del datasheet o porque en otra parte dice lo contrario pero esto me ha tenido asi varias horas.
Solo es una advertencia para que no sufran como yo xD, otro dia ya lo probare en fisico.
Porsiacaso lo dejo adjuntado todo para haber si, a los que puedan probarlo, les pasa los mismo en sus proteus.
Por cierto, muy buenos datos que están poniendo por aquí. Se agradece.
Saludos!