[Moved] 16f677 not work properly...how to resolve it??

Status
Not open for further replies.

roaa said

Newbie level 4
Joined
Jul 6, 2013
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
44
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);
}
 
Last edited by a moderator:

Re: 16f677 not work properly...how to resolve it??

Is the oscillator or something like that configured?
 

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.
 

Re: 16f677 not work properly...how to resolve it??

thnx for replay
i read datasheet carefully & set OSCCON but still not work...
what can i do now ... have any idea???
plz help
 

Re: 16f677 not work properly...how to resolve it??


If the code were written in Assembly Language, Yes.

However, in this case the C Compiler takes care of all required bank switching during compilation.

thnx for replay
i read datasheet carefully & set OSCCON but still not work...

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.


BigDog
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…