+ Post New Thread
Results 1 to 18 of 18
  1. #1
    Advanced Member level 3
    Points: 5,376, Level: 17
    Achievements:
    Created Blog entry 7 years registered
    Mithun_K_Das's Avatar
    Join Date
    Apr 2010
    Location
    Dhaka, Bangladesh, Bangladesh
    Posts
    828
    Helped
    22 / 22
    Points
    5,376
    Level
    17
    Blog Entries
    3

    PIC16F877A PORTE problem

    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.
    I love my profession, I love my M's Lab. __MKDas

  2. #2
    Super Moderator
    Points: 29,631, Level: 41
    andre_teprom's Avatar
    Join Date
    Nov 2006
    Location
    Brazil
    Posts
    8,862
    Helped
    1114 / 1114
    Points
    29,631
    Level
    41
    Blog Entries
    9

    Re: PIC16F877A PORTE problem

    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).
    --------------------------------------------------------------------------------------------------
    Part of the world that you live in, You are the part that you're giving ( Renaissance )



  3. #3
    Advanced Member level 3
    Points: 5,376, Level: 17
    Achievements:
    Created Blog entry 7 years registered
    Mithun_K_Das's Avatar
    Join Date
    Apr 2010
    Location
    Dhaka, Bangladesh, Bangladesh
    Posts
    828
    Helped
    22 / 22
    Points
    5,376
    Level
    17
    Blog Entries
    3

    Re: PIC16F877A PORTE problem

    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.
    I love my profession, I love my M's Lab. __MKDas



  4. #4
    Full Member level 2
    Points: 1,051, Level: 7

    Join Date
    May 2016
    Posts
    135
    Helped
    2 / 2
    Points
    1,051
    Level
    7

    Re: PIC16F877A PORTE problem

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

    Regards,
    Akshay.



    •   AltAdvertisement

        
       

  5. #5
    Advanced Member level 4
    Points: 8,209, Level: 21
    Achievements:
    7 years registered
    paulfjujo's Avatar
    Join Date
    Jun 2008
    Location
    France 01120
    Posts
    1,324
    Helped
    269 / 269
    Points
    8,209
    Level
    21

    Re: PIC16F877A PORTE problem

    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



  6. #6
    Advanced Member level 3
    Points: 5,376, Level: 17
    Achievements:
    Created Blog entry 7 years registered
    Mithun_K_Das's Avatar
    Join Date
    Apr 2010
    Location
    Dhaka, Bangladesh, Bangladesh
    Posts
    828
    Helped
    22 / 22
    Points
    5,376
    Level
    17
    Blog Entries
    3

    Re: PIC16F877A PORTE problem

    This is the settings window.

    Click image for larger version. 

Name:	Capture.PNG 
Views:	14 
Size:	97.6 KB 
ID:	142190
    I love my profession, I love my M's Lab. __MKDas



  7. #7
    Super Moderator
    Points: 29,631, Level: 41
    andre_teprom's Avatar
    Join Date
    Nov 2006
    Location
    Brazil
    Posts
    8,862
    Helped
    1114 / 1114
    Points
    29,631
    Level
    41
    Blog Entries
    9

    Re: PIC16F877A PORTE problem

    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.
    --------------------------------------------------------------------------------------------------
    Part of the world that you live in, You are the part that you're giving ( Renaissance )



    •   AltAdvertisement

        
       

  8. #8
    Advanced Member level 4
    Points: 8,209, Level: 21
    Achievements:
    7 years registered
    paulfjujo's Avatar
    Join Date
    Jun 2008
    Location
    France 01120
    Posts
    1,324
    Helped
    269 / 269
    Points
    8,209
    Level
    21

    Re: PIC16F877A PORTE problem

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

    - - - Updated - - -

    Hello Andre,

    Quote Originally Posted by andre_teprom View Post
    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.



    •   AltAdvertisement

        
       

  9. #9
    Advanced Member level 3
    Points: 5,376, Level: 17
    Achievements:
    Created Blog entry 7 years registered
    Mithun_K_Das's Avatar
    Join Date
    Apr 2010
    Location
    Dhaka, Bangladesh, Bangladesh
    Posts
    828
    Helped
    22 / 22
    Points
    5,376
    Level
    17
    Blog Entries
    3

    Re: PIC16F877A PORTE problem

    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.
    I love my profession, I love my M's Lab. __MKDas



  10. #10
    Advanced Member level 4
    Points: 8,209, Level: 21
    Achievements:
    7 years registered
    paulfjujo's Avatar
    Join Date
    Jun 2008
    Location
    France 01120
    Posts
    1,324
    Helped
    269 / 269
    Points
    8,209
    Level
    21

    Re: PIC16F877A PORTE problem

    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 ?



  11. #11
    Advanced Member level 3
    Points: 5,376, Level: 17
    Achievements:
    Created Blog entry 7 years registered
    Mithun_K_Das's Avatar
    Join Date
    Apr 2010
    Location
    Dhaka, Bangladesh, Bangladesh
    Posts
    828
    Helped
    22 / 22
    Points
    5,376
    Level
    17
    Blog Entries
    3

    Re: PIC16F877A PORTE problem

    OK, I'll try with XT oscillator.

    I'm using 22pf, X-Tal: 8MHz,
    I love my profession, I love my M's Lab. __MKDas



  12. #12
    Full Member level 4
    Points: 2,948, Level: 12
    Achievements:
    7 years registered
    nagkiller's Avatar
    Join Date
    Jul 2009
    Location
    Brazil
    Posts
    226
    Helped
    37 / 37
    Points
    2,948
    Level
    12

    Re: PIC16F877A PORTE problem

    MCLR pin, in the real hardware, have the pull up resistor???



  13. #13
    Advanced Member level 3
    Points: 5,376, Level: 17
    Achievements:
    Created Blog entry 7 years registered
    Mithun_K_Das's Avatar
    Join Date
    Apr 2010
    Location
    Dhaka, Bangladesh, Bangladesh
    Posts
    828
    Helped
    22 / 22
    Points
    5,376
    Level
    17
    Blog Entries
    3

    Re: PIC16F877A PORTE problem

    Yes! I checked it and it is pulled up by 10KOhm resistor and a 0.1 uF ceramic capacitor.
    I love my profession, I love my M's Lab. __MKDas



  14. #14
    Full Member level 4
    Points: 2,948, Level: 12
    Achievements:
    7 years registered
    nagkiller's Avatar
    Join Date
    Jul 2009
    Location
    Brazil
    Posts
    226
    Helped
    37 / 37
    Points
    2,948
    Level
    12

    Re: PIC16F877A PORTE problem

    Show your code and the hardware!!!



  15. #15
    Advanced Member level 3
    Points: 5,376, Level: 17
    Achievements:
    Created Blog entry 7 years registered
    Mithun_K_Das's Avatar
    Join Date
    Apr 2010
    Location
    Dhaka, Bangladesh, Bangladesh
    Posts
    828
    Helped
    22 / 22
    Points
    5,376
    Level
    17
    Blog Entries
    3

    Re: PIC16F877A PORTE problem

    This is the PCB of the complete circuit. I'm working on it.

    Click image for larger version. 

Name:	as.PNG 
Views:	4 
Size:	111.7 KB 
ID:	142254

    And the code is already posted.
    I love my profession, I love my M's Lab. __MKDas



    •   AltAdvertisement

        
       

  16. #16
    Super Moderator
    Points: 29,631, Level: 41
    andre_teprom's Avatar
    Join Date
    Nov 2006
    Location
    Brazil
    Posts
    8,862
    Helped
    1114 / 1114
    Points
    29,631
    Level
    41
    Blog Entries
    9

    Re: PIC16F877A PORTE problem

    Re-read post #4, which is the simplest way to check what is really happening with the oscillator settings.
    --------------------------------------------------------------------------------------------------
    Part of the world that you live in, You are the part that you're giving ( Renaissance )



  17. #17
    Advanced Member level 3
    Points: 5,376, Level: 17
    Achievements:
    Created Blog entry 7 years registered
    Mithun_K_Das's Avatar
    Join Date
    Apr 2010
    Location
    Dhaka, Bangladesh, Bangladesh
    Posts
    828
    Helped
    22 / 22
    Points
    5,376
    Level
    17
    Blog Entries
    3

    Re: PIC16F877A PORTE problem

    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 - - -

    Quote Originally Posted by akshaybhavsar View Post
    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 - - -

    Quote Originally Posted by andre_teprom View Post
    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.
    I love my profession, I love my M's Lab. __MKDas



  18. #18
    Advanced Member level 4
    Points: 8,209, Level: 21
    Achievements:
    7 years registered
    paulfjujo's Avatar
    Join Date
    Jun 2008
    Location
    France 01120
    Posts
    1,324
    Helped
    269 / 269
    Points
    8,209
    Level
    21

    Re: PIC16F877A PORTE problem

    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;
      }
    }



--[[ ]]--