HELLO all
i have 16f677 .. i wrote the code and have no errors but when i simulate(proteus simulation) it didnot work properly
i wana to know where the error?
the code:
Code:
int sensor;
void main() {
TRISA=0Xff; //configure PORTA as input port
TRISC=0X00; //configure PORTC as output port
TRISB=0XFF; //configure PORTB as input port
sensor=RA0_bit;
do{
if(RB4_bit==1)
{
RC1_bit=1;
RC2_bit=1;
delay_ms(300);
}
if(sensor==1)
{
RC1_bit=1;
RC2_bit=1;
delay_ms(1000);
RC3_bit=1;
}
if(sensor==0)
{
RC1_bit=0;
RC2_bit=0;
RC3_bit=1;
}
delay_ms(3000);
RC1_bit=0;
RC2_bit=0;
RC3_bit=0;
RC4_bit=1;
RC5_bit=1;
}
while(1);
}
Re: 16f677 not work properly...how to resolve it??
how i configured the oscillator??
the code is to control heater ... i have heat sensor(sensor) Is the one who controls the stop and run the heater(RC1_BIT)
Re: 16f677 not work properly...how to resolve it??
Before starting, you should configure some registers in order to set the MCU in your desired configuration (periferals, oscillator, watchdog... ) take a look p48 of the datasheet: OSCCON: OSCILLATOR CONTROL REGISTER
Don't forget to set also the reset input (internal reset or external, if external you need a capacitor and a pull-up)
Re: 16f677 not work properly...how to resolve it??
It's been a few years since I've mucked with PIC's and I'm not familiar with Proteus, BUT shouldn't you need to set the Register Bank Select bits (or at least RP0) in the STATUS register to access the TRIS memory locations? Does Proteus do that for you? Without setting the bank select bits, you may be writing directly to the ports instead of setting there I/O status.
There may be other peripherals that use some or all I/O pins that your are using. You may need to initialize those peripherals as well.
It's been a few years since I've mucked with PIC's and I'm not familiar with Proteus, BUT shouldn't you need to set the Register Bank Select bits (or at least RP0) in the STATUS register to access the TRIS memory locations? Does Proteus do that for you? Without setting the bank select bits, you may be writing directly to the ports instead of setting there I/O status.
In Proteus simulations you must right click on the PIC and correctly set the required oscillator frequency under device properties.
Otherwise, I believe the simulation defaults to 1 or 4 MHz oscillator frequency.
Also, for compilers like mikroC, you must specific the oscillator frequency within the IDE project properties so that routines such as delay_ms() generate the correct delay.