pic 16f877A this code not working

Discussion in 'Embedded Systems and Microcontrollers' started by damilarem, Aug 11, 2017.

  1. damilarem

    Thread Starter Member

    Aug 5, 2017
    41
    1
    help on this


    sbit LCD_RS at RE0_bit;
    sbit LCD_EN at RE2_bit;
    sbit LCD_D4 at RD4_bit;
    sbit LCD_D5 at RD5_bit;
    sbit LCD_D6 at RD6_bit;
    sbit LCD_D7 at RD7_bit;

    sbit LCD_RS_Direction at TRISE0_bit;
    sbit LCD_EN_Direction at TRISE2_bit;
    sbit LCD_D4_Direction at TRISD4_bit;
    sbit LCD_D5_Direction at TRISD5_bit;
    sbit LCD_D6_Direction at TRISD6_bit;
    sbit LCD_D7_Direction at TRISD7_bit;
    // End LCD module connections

    void main()
    {
    Lcd_Init(); // Initialize LCD
    Lcd_Cmd(_LCD_CLEAR); // Clear display
    Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
    Lcd_Out(1,1,"Hello World"); // Write text'Hello World' in first row
    }
     
  2. AlbertHall

    AAC Fanatic!

    Jun 4, 2014
    6,379
    1,476
    What is the problem?
     
    Motanache likes this.
  3. jayanthd

    Active Member

    Jul 4, 2015
    689
    64

    while(1); is missing. PIC will restart repeateadly. You will see a blank LCD.

    Add while(1); loop at the end of the code before closing the main() loop.
     
  4. hexreader

    Active Member

    Apr 16, 2011
    316
    132
    Op is using mikroC, where end loop is added automatically. Does no harm to put a while(1) loop, but not actually necessary for this compiler
     
  5. jayanthd

    Active Member

    Jul 4, 2015
    689
    64
    Which version of mikroC PRO PIC adds while(1); loop automatically. I have been using mikroC Compilers since 5 years and when I omit the while(1) loop the device resets after reaching the end of main() function.
     
  6. hexreader

    Active Member

    Apr 16, 2011
    316
    132
    I have believed it to be the case for the 7 years that I have been using microC, but I must admit that I always include while(1) just for portability. Not many programs end anyway.

    Looks like some testing is needed to prove it one way or the other, but I am away from my PIC gear for a few days, so it will have to wait.

    EDIT: - did try compile of very simple program and found a goto $+0 statement at the end of the listing, which seems to support my theory I think.

    _main:
    ;junk.c,2 :: void main() {
    ;junk.c,3 :: CMCON = 0x07;
    0x0016 0x3007 MOVLW 7
    0x0017 0x1683 BSF STATUS, 5
    0x0018 0x1303 BCF STATUS, 6
    0x0019 0x009C MOVWF CMCON
    ;junk.c,4 :: TRISB = 0x00;
    0x001A 0x0186 CLRF TRISB
    ;junk.c,5 :: PORTB = 0x55;
    0x001B 0x3055 MOVLW 85
    0x001C 0x1283 BCF STATUS, 5
    0x001D 0x0086 MOVWF PORTB
    ;junk.c,7 :: }
    L_end_main:
    0x001E 0x281E GOTO $+0
    ; end of _main
     
    Last edited: Aug 11, 2017
  7. damilarem

    Thread Starter Member

    Aug 5, 2017
    41
    1
    i have tried it still not working but i used pic16f877A and i used the port E for the LCD in which is an AD.. so any help to turn the AD off so i can used for my LCD
     
  8. jayanthd

    Active Member

    Jul 4, 2015
    689
    64
    For PIC16F877A to turn off the Analog functions on all pins you have to set

    Code (Text):
    1.  
    2. ADCON1 = 0x8F;
    3.  
    Also you need before

    Code (Text):
    1.  
    2. LCD_Init();
    3.  
    these

    Code (Text):
    1.  
    2. TRIAD = 0x00;
    3. TRISE = 0x00;
    4.  
    @hexreader

    I don't code in asm. I have used C code and it resets the PIC. I will make video of hardware (EasyPIC v7) resetting the PIC when while(1); loop is absent. I will update the thread after I make the video and upload it.
     
    Motanache likes this.
  9. damilarem

    Thread Starter Member

    Aug 5, 2017
    41
    1
    THANKS JAYANTHD I AV TRIED D CODE AND IT WORKS



    CAN YOU HELP ME WITH USING LOADCELL AND PIC?
     
  10. jayanthd

    Active Member

    Jul 4, 2015
    689
    64
    Ok
    I can help you with Load Cell and PIC. I just finished a project of weighing scale which uses HX711 (24-bit adc module for load cell).
     
  11. damilarem

    Thread Starter Member

    Aug 5, 2017
    41
    1

    OKAY THATS GREAT PLS SEND ME THE CODE AND D SETUP.. THANKS IN ADVANCE
     
  12. jayanthd

    Active Member

    Jul 4, 2015
    689
    64
    To write code I want to know what is the max mV your Load Cell gives and what is the max gms or Kgs your Load Cell measures. I will then write a code for you using PIC16F877A with 4 MHz Crystal.

    Open a new thread regarding your weighing scale requirement. I will continue the weighing scale conversation there.
     
    Last edited: Aug 12, 2017
  13. hexreader

    Active Member

    Apr 16, 2011
    316
    132
    @ damilarem

    Sorry for taking your thread off-track a little. Hopefully the discussion is of interest just the same.

    @jayanthd

    My code was in mikroC, which produced a listing file after compilation.

    Attached is a project folder which I believe proves my theory to be the correct one....

    Thank you for all of the help that you give to others :)
     
  14. jayanthd

    Active Member

    Jul 4, 2015
    689
    64
    @hexreader

    Ok. I will test your project on easypic v7 and update the thread.
     
  15. damilarem

    Thread Starter Member

    Aug 5, 2017
    41
    1
    I HAVE PUT THE POST IN A NEW THREAD CALLED WEIGHT SCALE REQUIREMENT SO PLS VISIT ..THANKS
     
  16. jayanthd

    Active Member

    Jul 4, 2015
    689
    64
    Where is the thread. I can't see the thread. And why are you SHOUTING ?
     
  17. damilarem

    Thread Starter Member

    Aug 5, 2017
    41
    1
    is not shouting is just to make u know that what u assked me to do have been done... the name of the thread is "weight scale requirement" thanks
     
  18. jayanthd

    Active Member

    Jul 4, 2015
    689
    64
    If you type in all caps then it means you are shouting.

    I could not find the thread "weight scale requirement".
     
  19. damilarem

    Thread Starter Member

    Aug 5, 2017
    41
    1
    never knew the caps meant someting like that sorry... i just coppy and paste this from the thread i made a mistake ... this is the name "
    weighing scale requirement"
     
  20. jayanthd

    Active Member

    Jul 4, 2015
    689
    64
    Why don't you provide the link for the "Weighing Scale requirement" thread instead of providing the thread name ?
     
Loading...