On the 18f2520, some of portb can be analog. You need to either set config bits or initialize it to be all digital. Here's some sample code from the datasheet: CLRF PORTB ; Initialize PORTB by ; clearing output ; data latches CLRF LATB ; Alternate method ; to clear output ; data latches MOVLW 0Fh ; Set RB<4:0> as MOVWF ADCON1 ; digital I/O pins ; (required if config bit ; PBADEN is set) MOVLW 0CFh ; Value used to ; initialize data ; direction MOVWF TRISB ; Set RB<3:0> as inputs ; RB<5:4> as outputs ; RB<7:6> as inputs Harold > Hello, > Running this code in MPLAB using the C18 compiler, > > #include // or > #pragma config WDT = OFF > > void main(void){ > TRISB = 0; > > PORTB = 0; > PORTB = 0x5A; > > while(1); > } > > I get the value of 0x40 in PORTB in the while loop instead of 0x5A. > I'm > using MPLAB SIM to debug the code. Whatever I set PORTB to in my main > function, it never ends up being that value when I debug it. > Could anyone please let me know what might be causing the odd value? > -- > http://www.piclist.com PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist > -- FCC Rules Updated Daily at http://www.hallikainen.com - Advertising opportunities available! -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist