embedded - PIC16F887 PORT won't work with XC8 C compiler -
i'm pretty new pic programming , i'm trying use c (compiled microchip's xc8 free in mplabx) make simple "input output" program.
problem i'm having ra2, ra3 , ra5 input pins not working when programming in c.
it's not hardware problem, because when programming in ladder pins work fine.
i've searched around on internet while , couldn't find same problem yet.
the program i'm trying burn onto pic follows:
#define _xtal_freq 20000000 #include <xc.h> // begin config #pragma config fosc = hs // oscillator selection bits (hs oscillator) #pragma config wdte = on // watchdog timer enable bit (wdt enabled) #pragma config pwrte = off // power-up timer enable bit (pwrt disabled) #pragma config boren = on // brown-out reset enable bit (bor enabled) #pragma config lvp = off // low-voltage (single-supply) in-circuit serial programming enable bit (rb3 digital i/o, hv on mclr must used programming) #pragma config cpd = off // data eeprom memory code protection bit (data eeprom code protection off) #pragma config wrt = off // flash program memory write enable bits (write protection off; program memory may written eecon control) #pragma config cp = off // flash program memory code protection bit (code protection off) //end config int main() { trisb = 0x00; trise = 0x00; trisc = 0x00; trisd = 0xff; trisa = \ _trisa_trisa2_mask |\ _trisa_trisa3_mask |\ _trisa_trisa4_mask |\ _trisa_trisa5_mask; portd = 0x00; porta = 0x00; portb = 0x00; porte = 0x00; portc = 0x00; while(1){ portb = porta; } return 0; }
i output on portb if set ra4 high, not ra2, ra3 nor ra5. believe might problem configuration bits or something, i'm not sure.
hardware being used:
microchip pic16f887
flexis plus board (sorry no english manual, in page 8 , 9 there board schematics)
software being used:
i think problem specific pins analog inputs adc module, have configure them digital i/o use them. try setting ansel = 0x00
@ beginning of program.
you can see in datasheet default value of ansel
on por 0xff
analog pins configured analog inputs default.
Comments
Post a Comment