Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC16F877A PORTE problem

Status
Not open for further replies.

Mithun_K_Das

Advanced Member level 3
Advanced Member level 3
Joined
Apr 24, 2010
Messages
899
Helped
24
Reputation
48
Reaction score
26
Trophy points
1,318
Location
Dhaka, Bangladesh, Bangladesh
Visit site
Activity points
8,254
Problem with PIRTE of PIC16F877A

A very simple program works fine in proteus. But in real hardware it works differently.

Code:
void main()
{

  TRISE = 0x00;
  ADCON1 = 0x07;//all digital
  CMCON = 0x07;

  while(1)
  {
      RE2_bit = 1;Delay_ms(1000);
      RE1_bit = 1;Delay_ms(1000);
      RE0_bit = 1;Delay_ms(1000);
      RE2_bit = 0;Delay_ms(1000);
      RE1_bit = 0;Delay_ms(1000);
      RE0_bit = 0;Delay_ms(1000);

  } 
}

This is a very simple code. It should work like, PIN2 of PORTE on then PIN1 and PIN0. Then turning off one by one again. It works in simulation. But in hardware only one PIN becoming ON.
 

Are you sure that on the actual device the oscillator settings are correct? I mean, it may be that only the first statement above has been executed for the time being, and that the execution time is actually much longer than in the simulation (although usually is the opposite that happens).
 

I'm sorry that I did not mentioned about compiler. I'm using mikroC pro for PIC. This compiler have oscillator settings in edit project option. So no need to write in code.
 

Generate the frequency 1HZ.Try to toggle one pin.It will verify your settings.

Regards,
Akshay.
 

hello,


I'm sorry that I did not mentioned about compiler. I'm using mikroC pro for PIC. This compiler have oscillator settings in edit project option.
So no need to write in code

With MikroC program, it is a good habit to show the config words value in the code !
copy/past config register
example :
CONFIG : $2007 : 0x2B4A

or join the *.cfgsh (config schem file)

Show us this mikroC window
Projetc
Edit project
General setting project
 

This is the settings window.

Capture.PNG
 

You did not understand the purpose of doing that. By explicitly configuring the fuses on code you ensure that by dowloading the firmware to target outside the IDE would keep the configuration on the HEX file, regardless what is configured on that window.
 

so, have you got a quartz of 8Mhz installed on your hardware ?

- - - Updated - - -

Hello Andre,

By explicitly configuring the fuses on code you ensure that by dowloading the firmware to target outside the IDE would keep the configuration on the HEX file, regardless what is configured on that window.

Unfortunatly, we can NOT configure "configuration bits " inside the code ! like with MPLAB
It is a old request we did to Mikroelektronika
But we can SHOW what is config bit..in the code within a comment
copy/past the config words
or copy/past the config file *.cfg


As well to configure PIC EEPROM data in the code , instead of in a special Eeprom config window.
 

I don't think it is configuration bit problem. I did many projects with PIC microcontroller. But this problem is first I've found. I'll ask the mikroe team about this. It may be a hardware problem. May be the MCU itself is faulty. Although I tried with 3 MCUs, I must check again with different MCU.
 

hello,


Try to use XT oscillator instead of HS oscillator
Try to Disable Brown Out Reset
What are the values of the 2 capacitors around the Quartz .

Did you try also to change your Quartz ..
Are you sure FOSC is OK ?
 

Re-read post #4, which is the simplest way to check what is really happening with the oscillator settings.
 

I tried with changing oscillator settings. No result. But when I set the analog settings as all digital I/O and only setting as Analog in just when the reading is taking then all digital again, all problems gone with portE. I know it is not a good practice with ADC settings but this is the first time I'm having this type of problem.

- - - Updated - - -

Generate the frequency 1HZ.Try to toggle one pin.It will verify your settings.

Regards,
Akshay.

Any type of work like this is ok. Problem is I can not turn on the pins sequentially.

If I set PORTE = 0xFF, all pins are high and ok.
just after that if I set RE0, RE1 and RE2 separately, it dosen't work. I checked carefully and found this: If RE2 is high and 1&0 are low. Now if I set RE0 as high, RE2 become low. Again if I set RE0 as low, RE2 high again without any change in the code. Code will be like this:

RE2_bit = 1;// RE2 high.
delay_ms(1000);
RE0_bit = 1;// set RE0 high..... in this moment RE2 become low.
delay_ms(1000);
RE0_bit = 0;// in this moment RE2 become high again.
delay_ms(1000);


After all these I can not say that the MCU oscillator is not ok. All other works are ok, all other pins are ok. Only problem with RE0; Even I checked without any connection with RE0 pin. same problem.

All I found is only the ADC settings.

- - - Updated - - -

Re-read post #4, which is the simplest way to check what is really happening with the oscillator settings.

Thanks for your suggestion, but I'm not new with microcontrollers. I checked everything before. Also I've found a solution although the solution I found is not a good way of coding. But it works.
 

hello,

did you try to use
PORTE0_bit instead of RE0_bit
and confirm PSPMODE bit =0


Code:
sbit LED0_Dir at TRISE0_bit;
sbit LED1_Dir at TRISE1_bit;
sbit LED2_Dir at TRISE2_bit;
sbit LED0 at PORTE0_bit;
sbit LED1 at PORTE1_bit;
sbit LED2 at PORTE2_bit;

void main()
{
  ADCON1=0x06;  // or 0x07  All digital, NO analog
  CMCON=0x07;
 
 TRISE.PSPMODE=0;  
 
 LED0_Dir=0;
 LED1_Dir=0;
 LED2_Dir=0;
 
 LED0=0;
 LED1=0;
 LED2=0;
 
 while(1)
 {
  
  Delay_ms(1000);LED0=1;
  Delay_ms(1000);LED1=1;
  Delay_ms(1000);LED2=1;
  Delay_ms(1000);LED0=0;
  Delay_ms(1000);LED1=0;
  Delay_ms(1000);LED2=0;
  }
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top