Strange PIC18F1220 behaviour

Thread Starter

ecka333

Joined Oct 1, 2009
76
I wrote simple code:
#include <Ctype.h>
#include <Math.h>
#include <htc.h>
unsigned int adcTime, clock;
void main()
{
TRISA=11000001;
PORTA=00000000;
TRISB=01000000;
PORTB=01000000;
RBPU=0; //turn on PORTB pullups
ADCON1=01111110; //pin AN0-analog, others-digital
for(;;)
{
if(RB6==0){RA2=1;}else{RA2=0;}
}
}
On reset relay must be turned off (RA2 low level). But instead of this after reset relay turns on and there is no reaction when i push button SW1 (RB6 port).
But when i change PORTB configuration to PORTB=11000000; then everything is working ok: on turn on relay is denergised, on button SW1 press relay coil energises. So how to explain such microcontroller behaviour? How RB6 is connected with RB7? Tried to write the same code in MikroC and HiTech, result is the same.
 

Attachments

Thread Starter

ecka333

Joined Oct 1, 2009
76
Forgot to write configuration words:
Configuration bits settings:


IESO=0 Internal External Switchover mode disabled
FSCM=0 Fail-Safe Clock Monitor disabled
FOSC<3:0>=0010 HS oscillator
BORV1:BORV0=00 VBOR set to 4.5V
BOR=1 Brown-out Reset enabled
PWRTEN=0 PWRT enabled
WDTPS<3:0>=0000 Watchdog Timer Postscale 1:1
WDT=0: WDT disabled
MCLRE=0 RA5 input pin enabled, MCLR disabled
DEBUG=1 Background debugger disabled, RB6 and RB7 configured as general purpose I/O pins
LVP=0 Low-Voltage ICSP disabled
STVR=0 Stack full/underflow will not cause Reset
CP1=1 Block 1 ((000800-000FFFh) not code-protected
CP0=1 Block 0 (000200-0007FFh) not code-protected
CPD=1 Data EEPROM not code-protected
CPB=1 Boot Block (000000-0001FFh) not code-protected
WRT1=1 Block 1 (000800-000FFFh) not write-protected
WRT0=1 Block 0 (000200-0007FFh) not write-protected
WRTD=1 Data EEPROM not write-protected
WRTB=1 Boot Block (000000-0001FFh) not write-protected
WRTC=1 Configuration registers (300000-3000FFh) not write-protected
EBTR1=1 Block 1 (000800-000FFFh) not protected from table reads executed in other blocks
EBTR0=1 Block 0 (000200-0007FFh) not protected from table reads executed in other blocks
EBTRB=1 Boot Block (000000-0001FFh) not protected from table reads executed in other blocks
 

t06afre

Joined May 11, 2009
5,934
Rich (BB code):
binary->0b number or 0B number->0b10011010 octal->0 number->0763 decimal->number->129 hexadecimal->0x number or 0X number->0x2F​
Somehow it seams as you have used octal numbers in your coding:rolleyes:
 
Top